diff options
Diffstat (limited to 'gamemode/client')
| -rw-r--r-- | gamemode/client/cl_inventory.lua | 238 | ||||
| -rw-r--r-- | gamemode/client/cl_npcmap.lua | 24 | ||||
| -rw-r--r-- | gamemode/client/cl_pac.lua | 2 | ||||
| -rw-r--r-- | gamemode/client/healthbar.lua | 107 |
4 files changed, 291 insertions, 80 deletions
diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua index 6db72dd..837f7a1 100644 --- a/gamemode/client/cl_inventory.lua +++ b/gamemode/client/cl_inventory.lua @@ -2,11 +2,127 @@ Displays the inventory, for more information see /gamemode/shared/inventory.lua ]] print("Hello from cl_inventory.lua") -local invfuncs = include("../shared/inventory_common.lua") +--debug.Trace() +local invfuncs +invfuncs = ART.invfuncs +--invfuncs = include("../gamemodes/artery/gamemode/shared/inventory_common.lua") +--invfuncs = include("../shared/inventory_common.lua") +assert(invfuncs ~= nil, "Dependency failed") local plyisininventory = false +--Displays a dropdown of options under the players mouse, if the option is clicked, does the function +--Requires a table of strings to functions, or strings to tables of strings to functions. +--Be careful not to make this a recursive table. +local function createMenuFor(menu, tbl) + for k,v in pairs(tbl) do + if(isfunction(v)) then --This is a dead-end, add the menu + local thisoption = menu:AddOption(k,v) + else --Otherwise it should be a table, recursively call to create + local submenu = menu:AddSubMenu(k) + createMenuFor(submenu,v) + end + end +end + +local function DrawBackpackOnDPanel(dp, backpack, backpacknum, tent) + local width = ScrW() + local height = ScrH() + local slotsize = math.Round(width / 32) + local backgrid = vgui.Create( "DGrid", dp ) + backgrid:SetPos( 10, 30 ) + backgrid:SetCols( backpack[2][1] ) + backgrid:SetColWide( backpack[2][2] ) + backgrid:Dock(FILL) + for i = 1,#(backpack[1]) do + for j = 1,#(backpack[1][i]) do + local item = backpack[1][j][i] + if type(backpack[1][j][i]) == "table" then + local itemwidth = 0 + for _,l in pairs(item.Shape) do + itemwidth = math.Max(itemwidth,#l) + end + local itemheight = #item.Shape + local invicon = vgui.Create( "DImageButton", dp ) + invicon:SetSize(slotsize * itemwidth, slotsize * itemheight) + invicon:SetPos(slotsize * (i - 1), slotsize * (j - 1)) + invicon:SetText(item.Name) + if item.Tooltip then + invicon:SetTooltip(item.Tooltip) + end + if item.Paint then + invicon.Paint = item.Paint + end + if item.DoOnPanel then + item.DoOnPanel(invicon) + end + --invicon.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,100,0)) end + invicon.DoClick = function() + if not item.GetOptions then return end + local menu = vgui.Create("DMenu") + createMenuFor(menu,item:GetOptions()) + menu:Open() + end + invicon.Item = item + invicon.invpos = {j,i} + invicon.ent = tent + invicon.backpacknum = backpacknum + invicon:Droppable("Inventory") + elseif not backpack[1][j][i] then + local emptyslot = vgui.Create("DPanel", dp) + emptyslot:SetSize(slotsize,slotsize) + emptyslot:SetPos(slotsize * (i - 1), slotsize * (j - 1)) + --emptyslot.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,0,100)) end + emptyslot:Receiver( "Inventory", function( receiver, tableOfDroppedPanels, isDropped, menuIndex, mouseX, mouseY ) + if not isDropped then return end + local icon = tableOfDroppedPanels[1] + local item = icon.Item + local curpos = icon.invpos + --Set the shape it was at to false + if not icon.wasequiped and icon.ent == tent then + assert(curpos ~= nil, "print curpos was nil when not equiped") + for k = 1,#item.Shape do + for l = 1,#(item.Shape[k]) do + if k == 1 and l == 1 then continue end + backpack[1][curpos[1] + k - 1][curpos[2] + l - 1] = false + end + end + backpack[1][curpos[1]][curpos[2]] = false + end + if invfuncs.CanFitInBackpack(backpack,j,i,item) then + local fromtbl = icon.invpos + local wasequiped = icon.wasequiped + if wasequiped then + net.Start("unequipitem") + net.WriteString(wasequiped) + net.WriteUInt(backpacknum,16) + net.WriteUInt(i,16) + net.WriteUInt(j,16) + net.SendToServer() + else + net.Start("moveitem") + net.WriteEntity(icon.ent) -- from ent + net.WriteEntity(tent) -- to ent + net.WriteUInt(icon.backpacknum,16) -- from backpack number + net.WriteUInt(backpacknum,16) -- to backpack number + net.WriteUInt(fromtbl[1],16) -- From position + net.WriteUInt(fromtbl[2],16) + net.WriteUInt(j,16) -- To position + net.WriteUInt(i,16) + net.SendToServer() + if item.onEquip ~= nil then + item:onEquip(LocalPlayer()) + end + end + end + end, {} ) + end + end + end +end + function ShowInventory(ply,cmd,args) if plyisininventory then return end + LocalPlayer().invdisplays = LocalPlayer().invdisplays or {} plyisininventory = true local width = ScrW() local height = ScrH() @@ -35,6 +151,30 @@ function ShowInventory(ply,cmd,args) skillsheet.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 157, 160, 167 ) ) end sheet:AddSheet( "Skills", skillsheet, "icon16/tick.png" ) + local questsheet = vgui.Create( "DPanel", sheet) + questsheet.Paint = function(self,w,h) draw.RoundedBox(4,0,0,w,h,Color(157,160,167)) end + sheet:AddSheet( "Quests", questsheet, "icon16/house.png") + + --Display quests + local questselector = vgui.Create( "DScrollPanel", questsheet ) + questselector:SetSize((width / 4) - 20, (height / 2) - 40) + questselector:SetPos(0,0) + local questinfo = vgui.Create("DScrollPanel", questsheet) + questinfo:SetSize(width / 4, (height / 2)) + --questinfo.Paint = function(self,w,h) draw.RoundedBox(4,0,0,w,h,Color(0,160,167)) end + questinfo:SetPos(0,height / 2) + for k,v in pairs(LocalPlayer().Quests or {}) do + print("Displaying quest:" .. k) + local questbutton = vgui.Create( "DButton" , questselector ) + questbutton:Dock(TOP) + questbutton:SetText(k) + questbutton.DoClick = function() + print("At point of clicking, art is:") + PrintTable(ART) + ART.GetQuest(k).DrawQuestInfo(questinfo,v) + end + end + --Display gear local slotsize = math.Round(width / 32) local displaypos = { @@ -74,9 +214,15 @@ function ShowInventory(ply,cmd,args) else print("eqslot",k,"was not false, it was") PrintTable(v) - local eqslot = vgui.Create("DPanel",invsheet) + local eqslot = vgui.Create("DImageButton",invsheet) eqslot:SetSize(slotsize,slotsize) eqslot:SetPos(displaypos[k][1],displaypos[k][2]) + if v.PaintEquiped then + eqslot.Paint = v.PaintEquiped + end + if v.DoOnEqupPanel then + v.DoOnEqupPanel(eqslot) + end --eqslot:SetImage( "overviews/de_inferno", "vgui/avatar_default" ) --eqslot.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(100,0,0)) end eqslot:Droppable("Inventory") @@ -88,93 +234,29 @@ function ShowInventory(ply,cmd,args) local backpacksheet = vgui.Create( "DPropertySheet", invsheet ) backpacksheet:SetPos(0,slotsize * 6) backpacksheet:SetSize((width / 4) - 25, height - (slotsize * 6) - 50) - + print("Displaying backpacks:") + PrintTable(LocalPlayer().Inventory.Backpacks) + print("That was all the backpacks") for k,v in pairs(LocalPlayer().Inventory.Backpacks) do local tbacksheet = vgui.Create( "DPanel", backpacksheet ) tbacksheet.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 157, 160, 167 ) ) end backpacksheet:AddSheet( v[3], tbacksheet, "icon16/cross.png" ) - invfuncs.DrawBackpackOnDPanel(tbacksheet,v,k,LocalPlayer()) - - --[[ - local backgrid = vgui.Create( "DGrid", tbacksheet ) - backgrid:SetPos( 10, 30 ) - backgrid:SetCols( v[2][1] ) - backgrid:SetColWide( v[2][2] ) - backgrid:Dock(FILL) - - for i=1,#(v[1]) do - for j=1,#(v[1][i]) do - if type(v[1][j][i]) == "table" then - print("Loading icon") - local item = v[1][j][i] - print("Item is:") - PrintTable(item) - local itemwidth = 0 - for _,l in pairs(item.Shape) do - itemwidth = math.Max(itemwidth,#l) - end - local itemheight = #item.Shape - local invicon = vgui.Create( "DButton", tbacksheet ) - invicon:SetSize(slotsize*itemwidth,slotsize*itemheight) - invicon:SetPos(slotsize*(i-1),slotsize*(j-1)) - --invicon.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,100,0)) end - invicon.Item = item - invicon.invpos = {j,i} - invicon.backpack = k - invicon:Droppable("Inventory") - elseif not v[1][j][i] then - local emptyslot = vgui.Create("DPanel", tbacksheet) - emptyslot:SetSize(slotsize,slotsize) - emptyslot:SetPos(slotsize*(i-1),slotsize*(j-1)) - --emptyslot.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,0,100)) end - emptyslot:Receiver( "Inventory", function( receiver, tableOfDroppedPanels, isDropped, menuIndex, mouseX, mouseY ) - if not isDropped then return end - print("receiver",receiver) - print("menuIndex",menuIndex) - print("tableOfDroppedPanels",tableOfDroppedPanels) - PrintTable(tableOfDroppedPanels) - local item = tableOfDroppedPanels[1].Item - print("Checking if item:") - PrintTable(item) - print("Can fit in pack:",j,i) - if invfuncs.CanFitInBackpack(v,j,i,item) then - local fromtbl = tableOfDroppedPanels[1].invpos - local wasequiped = tableOfDroppedPanels[1].wasequiped - if wasequiped then - print("wasequiped",wasequiped) - net.Start("unequipitem") - net.WriteString(wasequiped) - net.WriteUInt(k,16) - net.WriteUInt(i,16) - net.WriteUInt(j,16) - net.SendToServer() - else - net.Start("moveitem") - net.WriteUInt(k,16) -- Backpack number - net.WriteUInt(fromtbl[1],16) -- From position - net.WriteUInt(fromtbl[2],16) - net.WriteUInt(j,16) -- To position - net.WriteUInt(i,16) - net.SendToServer() - if item.onEquip ~= nil then - item:onEquip(LocalPlayer()) - end - end - end - end, {} ) - end - end - end - ]] + DrawBackpackOnDPanel(tbacksheet,v,k,LocalPlayer()) end end hook.Add("OnSpawnMenuOpen","ArteryOpenInventory",ShowInventory) hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function() - if LocalPlayer().invpanel == nil then return end - LocalPlayer().invpanel:Remove() + for k,v in pairs(LocalPlayer().invdisplays) do + if not v.panel:IsValid() then continue end + PrintTable(v) + v.panel:Close() + LocalPlayer().invdisplays[k] = nil + end + --if LocalPlayer().invpanel == nil then return end + --LocalPlayer().invpanel:Remove() plyisininventory = false end) diff --git a/gamemode/client/cl_npcmap.lua b/gamemode/client/cl_npcmap.lua new file mode 100644 index 0000000..784ca45 --- /dev/null +++ b/gamemode/client/cl_npcmap.lua @@ -0,0 +1,24 @@ + +local drawmap = false +hook.Add( "ScoreboardShow", "ShowNPCMap", function() + print("Showing npc map") + drawmap = true + return true +end ) +hook.Add( "ScoreboardHide", "ShowNPCMap", function() + print("Hiding npc map") + drawmap = false +end ) +local white = Color( 255, 255, 255, 255 ) + +hook.Add( "HUDPaint", "paintsprites", function() + if drawmap then + LocalPlayer().MapIcons = LocalPlayer().MapIcons or {} + cam.Start3D() + for k,v in pairs(LocalPlayer().MapIcons) do + render.SetMaterial( v.material ) + render.DrawSprite( v.pos, 64, 64, white ) + end + cam.End3D() + end +end ) diff --git a/gamemode/client/cl_pac.lua b/gamemode/client/cl_pac.lua deleted file mode 100644 index 6a7abed..0000000 --- a/gamemode/client/cl_pac.lua +++ /dev/null @@ -1,2 +0,0 @@ - -local pmeta = FindMetaTable("Player") diff --git a/gamemode/client/healthbar.lua b/gamemode/client/healthbar.lua new file mode 100644 index 0000000..d9a050c --- /dev/null +++ b/gamemode/client/healthbar.lua @@ -0,0 +1,107 @@ + +hook.Add( "HUDShouldDraw", "HideHUD", function( name ) + if name == "CHudHealth" then return false end +end ) + +--A function that rotates a point around another point +local function rotatepoint(x,y,cx,cy,rot) + rot = math.rad(rot) + local cs,sn = math.cos(rot),math.sin(rot) + local px = x * cs - y * sn; + local py = x * sn + y * cs; + return px,py +end + +--Add a function to the draw library to draw elipses for blood +local segments = 20 +local fade = 0.5 +function draw.DrawElipse(x,y,radius,elong,rotation) + rotation = math.rad(rotation) + local cir = {} + table.insert( cir, { x = x, y = y, u = fade, v = fade } ) + for i = 0, segments do + local a = math.rad( ( i / segments ) * -360 ) + local xu,yu = math.sin(a),math.cos(a) + local xpos = xu * radius * elong + local ypos = yu * radius + local cs,sn = math.cos(rotation),math.sin(rotation) + xpos,ypos = xpos * cs - ypos * sn, xpos * sn + ypos * cs + table.insert( cir, { + x = x + xpos, + y = y + ypos, + u = 1, + v = 1 } ) + end + surface.DrawPoly( cir ) +end + +local blobs = {} +local lastpos = 0 +local delpoint = ScrH() +hook.Add( "Tick", "Hudpaintbloodtick",function() + for k,v in pairs(blobs) do + if v.y > delpoint then + blobs[k] = nil + else + blobs[k] = { + ["x"] = v.x + v.xv, + ["y"] = v.y + v.yv, + ["xv"] = v.xv, + ["yv"] = v.yv + 1, + } + end + end +end) + +local lasthealth +local width,height = ScrW(),ScrH() +local padding = height / 32 +local barheight = height / 16 +local obarlength = width / 4 +local barlength = obarlength +local xs,ys = padding,height - padding - barheight +hook.Add( "HUDPaint", "HUD_DrawHealth", function() + + --Spawn a bunch of blobs if our health has changed + local health = LocalPlayer():Health() + if lasthealth == nil then + lasthealth = health + end + if health ~= lasthealth then + local difference = lasthealth - health + barlength = obarlength * (health/100) + for i=0,difference*3 do + local rtime = math.random() + timer.Simple(rtime,function() + local yvel = -20 + math.random(10) + local xvel = (math.random()*5) + local xpos = padding + xs + barlength - difference - 5 + local ypos = ys + (math.random() * barheight) + table.insert(blobs,{ + x = xpos, + y = ypos, + xv = xvel, + yv = yvel, + }) + end) + end + lasthealth = health + end + + --Draw the current health thing + surface.SetDrawColor(100,100,100,100) + surface.DrawRect( xs, ys, obarlength, barheight) + surface.SetDrawColor( 150, 0, 0, 255 ) + surface.DrawRect( xs, ys, barlength, barheight ) + + --Draw the animation for blobs + for k,v in pairs(blobs) do + --Elongation is based on velocity + local elong = (v.yv^2 + v.xv^2)^0.5 + elong = elong/5 + elong = math.Clamp(elong,1,3) + --Rotation is also based on velcotiy + local rot = math.deg(math.atan(v.yv/v.xv)) + draw.DrawElipse(v.x,v.y,10/elong,elong,rot) + end +end ) |
