local ivf = include("inventory_common.lua") ART = ART or {} if SERVER then for k,v in pairs({ "art_openshop", "art_buyitem", "art_sellitem", }) do util.AddNetworkString(v) end function ART.OpenShop(tbl, ply) print("Called openshop!") print("tbl was") PrintTable(tbl) if CLIENT then return end net.Start("art_openshop") net.WriteTable(tbl) net.Send(ply) end function ART.CreateShop(npc) print("Createing shop npc") local npcent = ents.Create("npc_shop") for k,v in pairs(npc) do npcent[k] = v end npcent:Spawn() print("Called spawn") end end if SERVER then return end local w,h = ScrW(),ScrH() function DrawShopItemOnDPanel(dp,item) --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 for k=1,#shape do twidth = math.max(twidth,#shape[k]) end local slotsize = math.Round(w / 32) local backgrid = vgui.Create( "DGrid", dp ) backgrid:SetPos( 10, 30 ) backgrid:SetCols( twidth ) backgrid:SetColWide( theight ) backgrid:Dock(FILL) local shopicon = vgui.Create( "DImageButton", dp ) shopicon:SetSize(slotsize * twidth, slotsize * theight) shopicon:SetPos(0,0) shopicon:SetText(itemtbl.Name) if itemtbl.Tooltip then shopicon:SetTooltip(itemtbl.Tooltip) end if itemtbl.Paint then shopicon.Paint = itemtbl.Paint end 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.DoClick = function() print("You cliked me!") end shopicon.Item = itemtbl shopicon.Cost = cost shopicon:Droppable("Inventory") shopicon.ondropped = function(back,j,i,item) print("ondropped was called!") print("back",back,"j",j,"i",i,"item",item) PrintTable(item) net.Start("buyitem") net.WriteString(item.Name) net.WriteUInt(back,8) net.WriteUInt(j,8) net.WriteUInt(i,8) net.SendToServer() end print("Displaying shape:") PrintTable(shape) for k = 1, twidth do for i = 1, theight do if not shape[k][i] then print("Found false spot:",k,i) local emptyslot = vgui.Create("DPanel", dp) emptyslot:SetSize(slotsize,slotsize) emptyslot:SetPos(slotsize * (i - 1), slotsize * (k - 1)) end end end end function DrawShopOnDPanel(dp,items) --This gets pretty involved, lets try to not make it a clusterfuck. DrawShopItemOnDPanel(dp,items[1]) end local shopwindow,shoppanel local function createshopwindow() print("Createing shopwindow") shopwindow = vgui.Create( "DFrame" ) shopwindow:SetPos( w - (w / 4), 0 ) shopwindow:SetSize( w / 4, h ) shopwindow:SetTitle( "Unset shop" ) shopwindow:SetDraggable( true ) shopwindow.OnClose = function(self) self:SetVisible(false) print("After onclose, shopwindow was",shopwindow) end shopwindow:SetVisible(false) shoppanel = vgui.Create( "DPanel",shopwindow) shoppanel:SetPos( 10, 30 ) -- Set the position of the panel shoppanel:Dock(FILL) end createshopwindow() net.Receive("art_openshop",function() print("shopwindows was ",shopwindow) if not shopwindow:IsValid() then createshopwindow() end assert(shopwindow,"Shopwindow was not created, even after re-createing!") ShowInventory() shopwindow:SetVisible(true) local stock = net.ReadTable() DrawShopOnDPanel(shoppanel,stock) shopwindow:MakePopup() end)