--[[ One of the tabs in the inventory ]] local inv = nrequire("inventory/inventory.lua") local itm = nrequire("item.lua") --local state = nrequire("cl_state.lua") local q = {} local known_inventories = {} local inventory_frames = {} local invsheet q.known_inventories = known_inventories local drawfloatinginventory = function(id, inventory) --print("Drawing a floating inventory!") local frame = vgui.Create("DFrame") frame:SetPos( ScrW() - (ScrW()/4), 0 ) frame:SetSize( ScrW()/4, ScrH()/4 ) frame:SetTitle( inventory.Name ) frame:SetDraggable( true ) local panel = vgui.Create("DPanel",frame) panel:Dock(FILL) if inventory.DrawOnDPanel then local prox = inventory:DrawOnDPanel(panel) frame.id = known_inventories[id]:AddObserver(prox) else error("Inventory needs a DrawOnDPanel method!") end frame:MakePopup() frame.OnClose = function(self) --print("Closeing chest id", id) --print("entity is", known_inventories[id].Owner) known_inventories[id]:RemoveObserver(self.id) net.Start("closechestinv") net.WriteEntity(known_inventories[id].Owner) net.SendToServer() known_inventories[id] = nil self:Remove() end end local drawsheeton = function(id,inventory) --print("Drawing an inventory on a sheet!") if invsheet == nil then return end local tpanel = vgui.Create( "DPanel", invsheet ) --tpanel.Paint = function( self, w, h ) -- draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 128, 255 ) ) --end if inventory.DrawOnDPanel then --print("Has drawondpanel") local prox = inventory:DrawOnDPanel(tpanel) --print("Prox returned was",prox) --PrintTable(prox) known_inventories[id]:AddObserver(prox) --print("Oservers is now") --PrintTable(known_inventories[id].observers) end invsheet:AddSheet( inventory.Name, tpanel, "icon16/tab.png" ) end net.Receive("art_ObserveInventory",function() local id = net.ReadUInt(32) local inv_type = net.ReadString() --print("Got inv type", inv_type,"id",id) local datalen = net.ReadUInt(32) local inital_data = net.ReadData(datalen) local ownent = net.ReadEntity() assert(known_inventories[id] == nil, "Trying to observe the same inventory twice!",id) local tinv = inv.CreateInventoryFromData(inv_type,inital_data,ownent) tinv.id = id known_inventories[id] = tinv if id > 10 then drawfloatinginventory(id,tinv) hook.Call("OnSpawnMenuOpen") else drawsheeton(id,tinv) end end) net.Receive("art_UpdateInventory",function() local id = net.ReadUInt(32) local isput = net.ReadBool() local position = net.ReadTable() if isput then local item_name = net.ReadString() --print("Putting ", item_name, "into inventory ",id, " at position") --PrintTable(position) local item_data = net.ReadData(net.ReadUInt(32)) local item = itm.GetItemFromData(item_name,item_data) known_inventories[id]:Put(position,item) --print("Inventorie's observers:") --PrintTable(known_inventories[id].observers) --print("Inventory is now") --PrintTable(known_inventories[id]) else known_inventories[id]:Remove(position) end end) net.Receive("art_CloseInventory",function() local id = net.ReadUInt(32) known_inventories[id] = nil if inventory_frames[id] then inventory_frames[id]:Close() inventory_frames[id] = nil end end) q.CreateInventorySheet = function(dpanel_parent) --assert(known_inventories[watch_id] ~= nil,"Attempted to watch an inventory that dosn't exist!") --Display the equipment inventories invsheet = vgui.Create( "DPropertySheet", dpanel_parent ) invsheet:Dock( FILL ) for k,v in pairs(known_inventories) do --print("This inventory id in known_inventories is", k) if k <= 10 then drawsheeton(k,v) else drawfloatinginventory(k,v) end --[[ local tpanel = vgui.Create( "DPanel", invsheet ) tpanel.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 0, 128, 255 ) ) end if v.DrawOnDPanel then local prox = v:DrawOnDPanel(tpanel) known_inventories[k]:AddObserver(prox) end invsheet:AddSheet( v.Name, tpanel, "icon16/tab.png" ) ]] end return invsheet end concommand.Add("PrintKnownInventories",function(ply,cmd,args) PrintTable(known_inventories) end) return q