aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem/shapedinventory/cl_shaped.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/inventorysystem/shapedinventory/cl_shaped.lua')
-rw-r--r--gamemode/inventorysystem/shapedinventory/cl_shaped.lua29
1 files changed, 20 insertions, 9 deletions
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