aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem/equipment
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/inventorysystem/equipment')
-rw-r--r--gamemode/inventorysystem/equipment/cl_equipment.lua66
-rw-r--r--gamemode/inventorysystem/equipment/sh_equipment.lua59
2 files changed, 61 insertions, 64 deletions
diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua
index 5ffcccc..7abd27a 100644
--- a/gamemode/inventorysystem/equipment/cl_equipment.lua
+++ b/gamemode/inventorysystem/equipment/cl_equipment.lua
@@ -1,6 +1,7 @@
local col = nrequire("colortheme.lua")
local svg = nrequire("cl_svg.lua")
+local com = nrequire("cl_common.lua")
local inv = {}
local width, height = (ScrW() / 4) - 25, ScrH()
@@ -98,20 +99,37 @@ local eqp = {
}
inv.DrawOnDPanel = function(self,panel)
+ print("Drawing equipment on panel")
local prox = {}
for k,v in pairs(eqp) do
- local pn = vgui.Create("DImage",panel)
+ local pn = vgui.Create("DButton",panel)
pn:SetSize(iconsize,iconsize)
pn:SetPos(v.x,v.y)
- if self.equiped[k] then
- if self.equiped[k].OnPaint then
- pn.Paint = self.equiped[k].OnPaint
+ pn.info = {}
+ pn.info.owner = LocalPlayer()
+ pn.info.id = self.id
+ pn.info.pos = {k}
+ pn.info.inv = self
+ pn:Droppable("item")
+ pn:Receiver("item",com.generatereceiver(),{"one","two","three"})
+ if self.equiped[k] then --We have something equiped!
+ if self.equiped[k].GetOptions then
+ pn.DoClick = function()
+ local dm = DermaMenu()
+ com.CreateMenuFor(dm,self.equiped[k].GetOptions())
+ dm:Open()
+ end
+ end
+ 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
+ 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)
@@ -129,12 +147,42 @@ inv.DrawOnDPanel = function(self,panel)
end
prox[k] = pn
end
- prox.Put = function(position,item)
- print("Put was called!")
+ 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!")
+ if item.GetOptions then
+ self[position[1]].DoClick = function()
+ local dm = DermaMenu()
+ com.CreateMenuFor(dm,item.GetOptions())
+ dm:Open()
+ end
+ end
+ 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 ) )
+ end
+ end
+ self[position[1]]:Droppable("item")
end
- prox.Remove = function(position)
- print("Remove was called!")
+ prox.Remove = function(self,position)
+ local pn = self[position[1]]
+ pn.DoClick = function() end
+ local c = col.ui.border
+ pn.Paint = function(self,w,h)
+ surface.SetDrawColor(c.r,c.g,c.b)
+ surface.DrawOutlinedRect(0, 0, w, h)
+ surface.SetDrawColor(255,255,255)
+ surface.SetMaterial( eqp[position[1]].img.material )
+ surface.DrawTexturedRect( 0, 0, w, h )
+ end
+ print("Remove was called!",position)
+ pn:Droppable("none")
end
+ return prox
end
return inv
diff --git a/gamemode/inventorysystem/equipment/sh_equipment.lua b/gamemode/inventorysystem/equipment/sh_equipment.lua
index ca7c22d..3c30df15 100644
--- a/gamemode/inventorysystem/equipment/sh_equipment.lua
+++ b/gamemode/inventorysystem/equipment/sh_equipment.lua
@@ -64,7 +64,7 @@ inv.FindPlaceFor = function(self, item)
end
--Otherwise, just check if the slot is empty
- if self.equiped[item.Equipable] == nil then
+ if self.equiped[item.Equipable] == nil and slots[self.equiped] ~= nil then
return {item.Equipable}
else
return nil
@@ -77,6 +77,7 @@ end
inv.Put = function(self,position,item)
self.equiped[position[1]] = item
+ if item.onEquip then item:onEquip(self.owner) end
end
inv.Has = function(self,string_or_compare_func)
@@ -95,6 +96,8 @@ inv.Has = function(self,string_or_compare_func)
end
inv.Remove = function(self,position)
+ local item = self.equiped[position[1]]
+ if item.onUnEquip then item:onUnEquip(self.owner) end
self.equiped[position[1]] = nil
end
@@ -124,57 +127,3 @@ inv.DeSerialize = function(self,data)
end
inventory.RegisterInventory(inv)
-
---[[
-for k,v in pairs(slots) do
- local inv = {}
- inv.Name = "inv_" .. v
- inv.FindPlaceFor = function(self, item)
- if self.item == nil then return {} else return nil end
- end
- inv.CanFitIn = function(self,position,item)
- if self.item == nil then return true else return "Inventory slot occupied by a(n)" .. self.item.Name end
- end
- inv.Put = function(self,pos,item)
- self.item = item
- end
- inv.Has = function(self,prt)
- if type(prt) == "string" then
- if self.item ~= nil and self.item.Name == prt then return {} else return nil end
- elseif type(prt) == "function" then
- if prt(self.item) then return {} else return nil end
- end
- error(string.format("Passed a %s to %s:Has(), expected string or function",type(prt),self.Name))
- end
- inv.Remove = function(self,pos)
- self.item = nil
- end
- inv.Get = function(self,pos)
- return self.item
- end
- inv.Serialize = function(self)
- if self.item then
- local data = ste.CreateStream()
- local itemname = self.item.Name
- local itemdata = self.item:Serialize()
- data:WriteString(itemname)
- data:WriteString(itemdata)
- return data:ToString()
- end
- return ""
- end
- inv.DeSerialize = function(self,str)
- print("data was",str)
- if str == "" or str == nil then
- return table.Copy(self)
- else
- local data = ste.CreateStream(str)
- local itemname = data:ReadString()
- local itemdata = data:ReadString()
- self.item = itm.GetItemFromData(itemname,itemdata)
- end
- end
- print("Attempting to register inventory with the name " .. inv.Name)
- inventory.RegisterInventory(inv)
-end
-]]