diff options
Diffstat (limited to 'gamemode/shared/shop.lua')
| -rw-r--r-- | gamemode/shared/shop.lua | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/gamemode/shared/shop.lua b/gamemode/shared/shop.lua index b188e7c..c330fb3 100644 --- a/gamemode/shared/shop.lua +++ b/gamemode/shared/shop.lua @@ -1,3 +1,13 @@ +--[[ + Displays shop npc's interfaces + + public functions: + (sv)ART.OpenShop(shoptbl, ply) :: nil + (sv)ART.CreateShop(npctbl) :: nil + net messages: + art_openshop +]] + local ivf = include("inventory_common.lua") ART = ART or {} @@ -34,10 +44,8 @@ end if SERVER then return end local w,h = ScrW(),ScrH() -function DrawShopItemOnDPanel(dp,item) +local function DrawShopItemOnDPanel(dp,itemtbl,cost) --An item is a string, and int cost - local itemtbl = ART.GetItemByName(item[1]) - local cost = item[2] local shape = itemtbl.Shape local twidth,theight = 0,#shape @@ -50,7 +58,7 @@ function DrawShopItemOnDPanel(dp,item) backgrid:SetPos( 10, 30 ) backgrid:SetCols( twidth ) backgrid:SetColWide( theight ) - backgrid:Dock(FILL) + backgrid:Dock(LEFT) local shopicon = vgui.Create( "DImageButton", dp ) shopicon:SetSize(slotsize * twidth, slotsize * theight) @@ -65,7 +73,10 @@ function DrawShopItemOnDPanel(dp,item) if itemtbl.DoOnPanel then itemtbl.DoOnPanel(shopicon) end - --invicon.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,100,0)) end + shopicon.Paint = function(self, w, h) + surface.SetDrawColor( 0, 0, 0, 255 ) + surface.DrawOutlinedRect( 0, 0, w, h) + end shopicon.DoClick = function() print("You cliked me!") end @@ -92,16 +103,41 @@ function DrawShopItemOnDPanel(dp,item) print("Found false spot:",k,i) local emptyslot = vgui.Create("DPanel", dp) emptyslot:SetSize(slotsize,slotsize) - emptyslot:SetPos(slotsize * (i - 1), slotsize * (k - 1)) + emptyslot:SetPos(slotsize * (i - 1) + 2, slotsize * (k - 1) + 2) end end end end -function DrawShopOnDPanel(dp,items) +local slotsize = math.Round(w / 32) + +local function DrawShopOnDPanel(dp,items) --This gets pretty involved, lets try to not make it a clusterfuck. - DrawShopItemOnDPanel(dp,items[1]) + dp.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(100,0,0)) end + print("dp",dp) + local scrollpanel = vgui.Create( "DScrollPanel",dp ) + print("scollpanel",scrollpanel) + scrollpanel.Paint = function(self, w, h) draw.RoundedBox(4, 0,0,w,h,Color(0,0,100)) end + scrollpanel:Dock(FILL) + for k,v in pairs(items) do + local itemtbl = ART.GetItemByName(v[1]) + local invpanel = vgui.Create( "DPanel", scollpanel) + invpanel.Paint = function(self, w, h) + draw.RoundedBox(4, 1,1,w-4,h-4,Color(50,50,50)) + draw.RoundedBox(4, 2,2,w-5,h-5,Color(100,100,100)) + end + print("invpanel",invpanel) + DrawShopItemOnDPanel(invpanel,itemtbl,v[2]) + scrollpanel:AddItem(invpanel) + invpanel:Dock(TOP) + local x,_ = invpanel:GetSize() + print("item is",v) + PrintTable(v) + invpanel:SetSize(x,slotsize*(#itemtbl.Shape) + 4) + invpanel:Dock(TOP) + + end end |
