diff options
Diffstat (limited to 'gamemode/inventorysystem')
| -rw-r--r-- | gamemode/inventorysystem/cl_common.lua | 3 | ||||
| -rw-r--r-- | gamemode/inventorysystem/equipment/cl_equipment.lua | 22 | ||||
| -rw-r--r-- | gamemode/inventorysystem/equipment/sh_equipment.lua | 4 | ||||
| -rw-r--r-- | gamemode/inventorysystem/shapedinventory/cl_shaped.lua | 29 | ||||
| -rw-r--r-- | gamemode/inventorysystem/shapedinventory/sh_shaped.lua | 20 |
5 files changed, 34 insertions, 44 deletions
diff --git a/gamemode/inventorysystem/cl_common.lua b/gamemode/inventorysystem/cl_common.lua index 5b461d3..361cf3c 100644 --- a/gamemode/inventorysystem/cl_common.lua +++ b/gamemode/inventorysystem/cl_common.lua @@ -1,4 +1,7 @@ +--[[ + A bunch of functions that a lot of inventories have in common, dragged out here so bugfixing is easier +]] local com = {} --Displays a dropdown of options under the players mouse, if the option is clicked, does the function diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua index 8a14a1a..82560be 100644 --- a/gamemode/inventorysystem/equipment/cl_equipment.lua +++ b/gamemode/inventorysystem/equipment/cl_equipment.lua @@ -104,7 +104,7 @@ inv.DrawOnDPanel = function(self,panel) print("Drawing equipment on panel") local prox = {} for k,v in pairs(eqp) do - local pn = vgui.Create("DButton",panel) + local pn = vgui.Create("DModelPanel",panel) pn:SetSize(iconsize,iconsize) pn:SetPos(v.x,v.y) pn.info = {} @@ -125,13 +125,8 @@ inv.DrawOnDPanel = function(self,panel) print("Found something equiped in ", k) if self.equiped[k].OnEqpPaint then pn.Paint = self.equiped[k].OnEqpPaint - else - pn.Paint = function(tp,w,h) - draw.RoundedBox( 8, 0, 0, w, h, Color( 255, 0, 0 ) ) - end end else --We don't have something equiped! - print("Nothing was equiped in ", k) if v.img and v.img.material then local c = col.ui.border pn.Paint = function(tp,w,h) @@ -149,10 +144,8 @@ inv.DrawOnDPanel = function(self,panel) end prox[k] = pn end + prox.Put = function(self,position,item) - print("Put was called!",position,item) - PrintTable(position) - PrintTable(item) assert(self[position[1]] ~= nil, "Tried to put an item into an unknown slot! Slot:" .. position[1]) if item.GetOptions then self[position[1]].DoClick = function() @@ -164,10 +157,13 @@ inv.DrawOnDPanel = function(self,panel) if item.OnEqpPaint then self[position[1]].Paint = item.OnEqpPaint else - self[position[1]].Paint = function(tp,w,h) - draw.RoundedBox( 8, 0, 0, w, h, Color( 255, 0, 0 ) ) + self[position[1]].Paint = function(panel) + draw.DrawText( item.Name, "DermaDefault", 10, 10, Color( 0, 0, 0, 0 )) end end + if item.DoOnEquipPanel then + item:DoOnEquipPanel(self[position[1]]) + end self[position[1]]:Droppable("item") end prox.Remove = function(self,position) @@ -181,8 +177,10 @@ inv.DrawOnDPanel = function(self,panel) surface.SetMaterial( eqp[position[1]].img.material ) surface.DrawTexturedRect( 0, 0, w, h ) end - print("Remove was called!",position) pn:Droppable("none") + for k,v in pairs(pn:GetChildren()) do + v:Remove() + end end return prox end diff --git a/gamemode/inventorysystem/equipment/sh_equipment.lua b/gamemode/inventorysystem/equipment/sh_equipment.lua index 793eeac..be930e0 100644 --- a/gamemode/inventorysystem/equipment/sh_equipment.lua +++ b/gamemode/inventorysystem/equipment/sh_equipment.lua @@ -5,8 +5,6 @@ local itm = nrequire("item.lua") local ste = nrequire("utility/stream.lua") local inventory = nrequire("inventory/inventory.lua") local col = nrequire("config/colortheme.lua") -print("Got invnetory table, it is:") -PrintTable(inventory) local slots = { "Head", "Shoulders", @@ -98,6 +96,7 @@ end inv.Remove = function(self,position) local item = self.equiped[position[1]] + if not item then return end --Make sure we'r enot dragging an empty space if item.onUnEquip then item:onUnEquip(self.Owner) end self.equiped[position[1]] = nil end @@ -115,7 +114,6 @@ inv.Serialize = function(self) end inv.DeSerialize = function(self,data) - print("deserializeing, data was",data) if data ~= nil and data ~= "" then local tbl = util.JSONToTable(data) local cpy = table.Copy(self) diff --git a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua index c40ffa0..83c2217 100644 --- a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua +++ b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua @@ -6,7 +6,7 @@ local inv = {} local width = ScrW() --local height = ScrH() -local iconsize = width / 40 +local iconsize = ((width / 4) - 20) / 5 local function default_paint(self,w,h) --Draw a box @@ -35,8 +35,6 @@ local function runonshape(self,shape,x,y,func) for i = 1,#shape do for j = 1, #shape[i] do if shape[i][j] then - print("Running on ",i,j) - print("Which translates to", x + j, y + i) func(self.gridpanels[x + i - 1][y + j - 1]) end end @@ -47,6 +45,9 @@ end local function drawitemat(self,x,y,item) print("Drawing item at ",x,y) local tp = self.gridpanels[x][y] + if tp == nil then + error("Unable to continue") + end tp:Droppable("item") runonshape(self,item.Shape,x,y,function(panel) panel:SetVisible(false) @@ -54,17 +55,29 @@ local function drawitemat(self,x,y,item) tp:SetVisible(true) local sx,sy = shapebounds(item.Shape) tp:SetSize(iconsize * sx, iconsize * sy) + tp:SetText(item.Name) tp.DoClick = function() if item.GetOptions then - com.CreateMenuFor(tp,item:GetOptions()) + local dm = DermaMenu() + com.CreateMenuFor(dm,item:GetOptions()) + dm:Open() end end + if item.DoOnPanel then + item:DoOnPanel(tp) + end + if item.Paint then + tp.Paint = item.Paint + end end --Reset the position, using the item and it's shape local function undrawitemat(self,x,y) local item = self:Get({x,y}) - self.gridpanels[x][y]:Droppable("") + local dpn = self.gridpanels[x][y] + dpn:Droppable("") + dpn:SetText("") + for k,v in pairs(dpn:GetChildren()) do v:Remove() end runonshape(self,item.Shape,x,y,function(panel) panel:SetVisible(true) panel:SetSize(iconsize,iconsize) @@ -117,7 +130,6 @@ end ]] inv.DrawOnDPanel = function(self,panel) - print("Drawing shaped on panel") local DScrollPanel = vgui.Create( "DScrollPanel",panel) DScrollPanel:SetPos( 0, 0 ) DScrollPanel:Dock(FILL) @@ -134,9 +146,10 @@ inv.DrawOnDPanel = function(self,panel) --Create the full grid of dpanels for x = 1, self.dimx do for y = 1, self.dimy do - local dp = vgui.Create("DButton") + local dp = vgui.Create("DModelPanel") dp:SetSize(iconsize,iconsize) dp.Paint = default_paint + dp:SetText("") --dp:Droppable("item") dp:Receiver("item",com.generatereceiver(),{"one","two","three"}) dp.info = {} @@ -161,11 +174,9 @@ inv.DrawOnDPanel = function(self,panel) local observer = {} observer.Put = function(obs,position,item) - print("Drawing item at",position[1],position[2]) drawitemat(self,position[1],position[2],item) end observer.Remove = function(obs,position) - print("Undrawing item at",position[1],position[2]) undrawitemat(self,position[1],position[2]) end return observer diff --git a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua index 00beb7f..b77f378 100644 --- a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua +++ b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua @@ -17,13 +17,10 @@ local function calcposition(dimx,dimy,x,y) end local function canfitin(self,x,y,shape) - print("Checking canfitin, tracker was") - PrintTable(self.tracker) for rn,row in ipairs(shape) do for cn,col in ipairs(row) do local absx,absy = x + rn - 1, y + cn - 1 local slot = calcposition(self.dimx,self.dimy,absx,absy) - print("Checking slot", slot) if col and ((self.tracker[slot] ~= nil) or (absx > self.dimx) or (absy > self.dimy)) then return false end @@ -45,19 +42,13 @@ end function inv:CanFitIn(tbl,item) if canfitin(self,tbl[1],tbl[2],item.Shape) then - print("calculated, and can fit") return true else - print("calculated, could not fit") return "Could not fit :(" end end function inv:Put(tbl,item) - print("Before putting ", item) - PrintTable(item) - print("tracker was") - PrintTable(self.tracker) --Set the item's shape to true for rn,row in ipairs(item.Shape) do @@ -72,8 +63,6 @@ function inv:Put(tbl,item) --Now set the item in the correct slot local slot = calcposition(self.dimx,self.dimy,tbl[1],tbl[2]) self.tracker[slot] = item - print("After, tracker was ") - PrintTable(self.tracker) end function inv:Has(ptr) @@ -94,14 +83,8 @@ function inv:Has(ptr) end function inv:Remove(tbl) - print("Removeing from",tbl[1],tbl[2]) local slot = calcposition(self.dimx,self.dimy,tbl[1],tbl[2]) - print("Slot is",slot) - print("Tracking structure is:") - PrintTable(self.tracker) local item = self.tracker[slot] - print("Removeing item",item) - PrintTable(item) self.tracker[slot] = nil for rn,row in ipairs(item.Shape) do for cn,col in ipairs(row) do @@ -111,8 +94,6 @@ function inv:Remove(tbl) end end end - print("After, tracker was") - PrintTable(self.tracker) end function inv:Get(tbl) @@ -132,7 +113,6 @@ function inv:Serialize() end function inv:DeSerialize(str) - print("Deserializeing from ", str) --TODO:Implement local tbl = util.JSONToTable(str) for k,v in pairs(tbl) do |
