aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem/shapedinventory
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2017-05-20 11:37:23 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2017-05-20 11:37:23 -0400
commitc6698dad925e75ffd2ca2f2e30a595d4ce48d240 (patch)
tree226338dc7ee26a6316951554cf953112ba072c76 /gamemode/inventorysystem/shapedinventory
parent9e0537b0aa417e88a6a61238484ddcef74080ae0 (diff)
downloadartery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.gz
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.tar.bz2
artery-c6698dad925e75ffd2ca2f2e30a595d4ce48d240.zip
Massive changes I guess
Diffstat (limited to 'gamemode/inventorysystem/shapedinventory')
-rw-r--r--gamemode/inventorysystem/shapedinventory/cl_shaped.lua29
-rw-r--r--gamemode/inventorysystem/shapedinventory/sh_shaped.lua20
2 files changed, 20 insertions, 29 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
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