print("Custom inventory loaded") --Some calculations to draw the inventory nicely local scrx = ScrW() local scry = ScrH() --Make the menu 30% of the x to the closest 64 and 100% of the y local invxadj = ((scrx*0.4)%64) local invxsize = (scrx*0.40)-invxadj-38 --no idea why the 38 works, but it does local invysize = scry local function createMenuFor(menu, tbl) print("Createing actions for:") PrintTable(tbl) for k,v in pairs(tbl) do if(isfunction(v)) then --This is a dead-end, add the menu local thisoption = menu:AddOption(k,v) else --Otherwise it should be a table, recursively call to create local submenu = menu:AddSubMenu(k) createMenuFor(submenu,v) end end end local function createPanel() local frame = vgui.Create( "DFrame" ) frame:SetSize( invxsize, invysize ) frame:SetTitle( "Inventory" ) frame:MakePopup() frame:SetPos(scrx-invxsize,0) frame:SetKeyboardInputEnabled(true) frame:ShowCloseButton(false) frame.OnKeyCodePressed = function(self, key) if(key == KEY_Q) then frame:Close() end end local tabsheet = vgui.Create("DPropertySheet", frame) tabsheet:Dock(FILL) local invtab = vgui.Create("DPanel",tabsheet) tabsheet:AddSheet( "Inventory", invtab, "icon16/database.png" ) local structtab = vgui.Create("DPanel",tabsheet) tabsheet:AddSheet( "Structures", structtab, "icon16/bullet_blue.png") local combitab = vgui.Create("DPanel",tabsheet) tabsheet:AddSheet( "Combinations", combitab, "icon16/bullet_picture.png") local equiptab = vgui.Create("DPanel",tabsheet) tabsheet:AddSheet( "Equipment", equiptab, "icon16/user.png" ) local proptab = vgui.Create("DPanel",tabsheet) tabsheet:AddSheet( "Props", proptab, "icon16/wrench.png" ) if(LocalPlayer():IsAdmin()) then local admintab = vgui.Create("DPanel",tabsheet) tabsheet:AddSheet("Admin", admintab, "icon16/bullet_star.png") end --Combinations in the combinations button local layout = vgui.Create( "DTileLayout", combitab) layout:SetBaseSize( 64 ) -- Tile size layout:Dock( FILL ) layout:MakeDroppable( "unique_name" ) -- Allows us to rearrange children for k,v in pairs(GMS.Combinations["Combinations"]) do print("Combinator a " .. v.Name) local combipanel = vgui.Create("DButton", layout) combipanel:SetSize(64,64) combipanel:SetText(v.Name) combipanel.DoClick = function() print("I want to combine a " .. v.Name) LocalPlayer():ConCommand("gms_MakeCombination Combinations " .. v.Name) end layout:Add(combipanel) end --Structure building local layout = vgui.Create( "DTileLayout", structtab) layout:SetBaseSize( 64 ) -- Tile size layout:Dock( FILL ) layout:MakeDroppable( "unique_name" ) -- Allows us to rearrange children for k,v in pairs(GMS.Combinations["Structures"]) do --print("Createing panel for " .. v.BuildSiteModel) local modelPanel = vgui.Create( "DModelPanel", layout ) --modelPanel:SetPos( 0, 0 ) modelPanel:SetSize( 64, 64 ) modelPanel:SetModel( v.BuildSiteModel ) modelPanel.DoClick = function() print("I want to construct a " .. k) LocalPlayer():ConCommand("gms_MakeCombination Structures " .. k ) end layout:Add(modelPanel) end --Inventory local layout = vgui.Create( "DTileLayout", invtab ) layout:SetBaseSize( 64 ) -- Tile size layout:Dock( FILL ) layout:MakeDroppable( "unique_name" ) -- Allows us to rearrange children for k, v in SortedPairs( Resources ) do if(v == 0) then continue end local selection = vgui.Create("DImageButton") if(GMS.Resources[k] == nil) then --This resource is not registered! selection:SetImage("vgui/avatar_default") print("Resource:" .. k .. " not registed! This might be a bug!") continue elseif(GMS.Resources[k].Icon == nil) then selection:SetImage("vgui/avatar_default") print("Resource:" .. k .. " does not have an .Icon field! This might be a bug!") continue else selection:SetImage(GMS.Resources[k].Icon) selection:SetTooltip(GMS.Resources[k].Description) end selection:SetSize(64,64) selection.DoClick = function() if(GMS.Resources[k].UniqueData) then print("We should expand menu to show all uniqueid's") else if(GMS.Resources[k].Actions == nil) then print("gamemode/client/cl_inventory.lua: Looking for actions for " .. k .. " but found nil!") return end local menu = vgui.Create("DMenu") print("makeing menu for " .. k) PrintTable(GMS.Resources[k]) createMenuFor(menu,GMS.Resources[k].Actions) menu:Open() end end layout:Add( selection ) end return frame end local invpanel = nil function GM:OnSpawnMenuOpen() if(invpanel == nil) then invpanel = createPanel() return end if(! invpanel:IsValid()) then invpanel = createPanel() return end end function GM:ReloadSpawnMenu() if(invpanel == nil) then return end if(!invpanel:IsValid()) then return end if(invpanel != nil) then invpanel:Close() invpanel = createPanel() return end end function GM:OnSpawnMenuClose() end function GM:SpawnMenuEnabled() return false end