--[[ Displays the inventory, for more information see /gamemode/shared/inventory.lua ]] print("Hello from cl_inventory.lua") --debug.Trace() ART.PrayerEquiped = ART.PrayerEquiped or { false,false,false,false } net.Receive("equiphelpprayer",function() print("equiphelp received client side!") ART.PrayerEquiped[4] = "Noob Help" end) local lastpanel = lastpanel or 1 local inventorysheets = {} ART.RegisterInventorySheet = function(func) inventorysheets[#inventorysheets + 1] = func end local plyisininventory = false --Displays a dropdown of options under the players mouse, if the option is clicked, does the function --Requires a table of strings to functions, or strings to tables of strings to functions. --Be careful not to make this a recursive table. local function createMenuFor(menu, 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 function ART.RefreshDisplays() local discopy = LocalPlayer().invdisplays LocalPlayer().invdisplays = {} for k,ptbl in pairs(discopy) do if not ptbl.panel:IsValid() then continue end if ptbl.panel.Close ~= nil then ptbl.panel:Close() else print(ptbl.panel) error("panel has no close method") ptbl.panel:Remove() end ptbl.redraw() end end local sheet function ShowInventory(ply,cmd,args) if plyisininventory then return end LocalPlayer().invdisplays = LocalPlayer().invdisplays or {} plyisininventory = true local width = ScrW() local height = ScrH() local dat = {} dat.panel = vgui.Create( "DFrame" ) dat.redraw = ShowInventory table.insert(LocalPlayer().invdisplays,dat) local invpanel = dat.panel invpanel:SetPos( 0, 0 ) invpanel:SetSize( width / 4, height ) invpanel:SetTitle( "Inventory" ) invpanel:SetDraggable( true ) invpanel:MakePopup() invpanel.OnClose = function(self) plyisininventory = false end sheet = vgui.Create( "DPropertySheet", invpanel ) sheet:Dock( FILL ) for k,v in pairs(inventorysheets) do local name,tsheet,image = v() sheet:AddSheet(name,tsheet,image) tsheet.sheetnum = name end sheet:SwitchToName(lastpanel) --[[ local prayersheet = vgui.Create( "DListLayout", sheet) sheet:AddSheet( "Prayers", prayersheet, "icon16/coins.png") --Prayers local prayergridscroll = vgui.Create("DScrollPanel") prayergridscroll:SetSize( (width / 4) - 20, height / 3 ) prayergridscroll:SetPos( 5, 5 ) prayersheet:Add(prayergridscroll) local prayergrid = vgui.Create( "DGrid", prayergridscroll ) prayergrid:SetPos( 5 , 5 ) prayergrid:Dock(FILL) prayergrid:SetCols( (width / 4) / 64 ) prayergrid:SetColWide( 64 ) prayergrid:SetRowHeight(64) prayergridscroll:AddItem(prayergrid) for k,v in pairs(ART.Prayer) do local but = vgui.Create( "DButton", prayergrid ) but:SetText( v.Name ) but:SetSize( 64, 64 ) but:SetWrap(true) prayergrid:AddItem( but ) but.PrayerName = v.Name but:Droppable("PrayerBind") end local prayerbindgrid = vgui.Create("DGrid") prayerbindgrid:SetPos(height * (2 / 3),5) prayerbindgrid:SetSize((width / 4) - 20, height / 3) prayerbindgrid:SetColWide(64) prayerbindgrid:SetRowHeight(64) function prayerbindgrid:Paint(w,h) draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 255, 0 ) ) end local n = 0 for k,v in pairs(ART.PrayerEquiped) do n = n + 1 local but = vgui.Create( "DPanel", prayerbindgrid ) but:SetSize(64, 64) if v ~= false then local prayerbut = vgui.Create( "DLabel", but ) prayerbut:SetText( v.Name ) prayerbut:SetSize( 64, 64 ) prayerbut:SetWrap(true) else local blabel = vgui.Create( "DLabel", but ) blabel:SetText( "F" .. k ) blabel:SetDark(true) but:Receiver( "PrayerBind", function( self, tableOfDroppedPanels, isDropped, menuIndex, mouseX, mouseY ) if not isDropped then return end ART.PrayerEquiped[k] = tableOfDroppedPanels.PrayerName print("Prayer bound to " .. k) end) end prayerbindgrid:AddItem(but) end prayersheet:Add(prayerbindgrid) --Display quests local questselector = vgui.Create( "DScrollPanel", questsheet ) questselector:SetSize((width / 4) - 20, (height / 2) - 40) questselector:SetPos(0,0) local questinfo = vgui.Create("DScrollPanel", questsheet) questinfo:SetSize(width / 4, height / 2) questinfo:SetPos(0,height / 2) for k,v in pairs(LocalPlayer().Quests or {}) do print("Displaying quest:" .. k) local questbutton = vgui.Create( "DButton" , questselector ) questbutton:Dock(TOP) questbutton:SetText(k) questbutton.DoClick = function() print("At point of clicking, art is:") PrintTable(ART) ART.GetQuest(k).DrawQuestInfo(questinfo,v) end end --Display gear local slotsize = math.Round(width / 32) local displaypos = { ["Head"] = {(width / 8) - slotsize, 25}, ["Body"] = {(width / 8) - slotsize, slotsize + 26}, ["Legs"] = {(width / 8) - slotsize, (slotsize * 2) + 27}, ["Boots"] = {(width / 8) - slotsize, (slotsize * 3) + 28}, ["Gloves"] = {(width / 8) + (slotsize), (slotsize * 2) + 27}, ["Left"] = {(width / 8) - (1.5 * slotsize), (slotsize * 4) + 29}, ["Right"] = {(width / 8) - (0.5 * slotsize), (slotsize * 4) + 29} } print("Displaying inventory:") PrintTable(LocalPlayer().Inventory.Equiped) for k,v in pairs (LocalPlayer().Inventory.Equiped) do if v == false then local eqslot = vgui.Create( "DPanel", invsheet ) eqslot:SetSize( slotsize, slotsize ) eqslot:SetPos(displaypos[k][1],displaypos[k][2]) eqslot:Receiver( "Inventory", function( receiver, tableOfDroppedPanels, isDropped, menuIndex, mouseX, mouseY ) if not isDropped then return end print("Attempting to equip") local icon = tableOfDroppedPanels[1] local item = icon.Item PrintTable(item) print("In",k) if item.Equipable == k then net.Start("equipitem") net.WriteUInt(icon.backpacknum,16) -- Backpack number local fromtbl = icon.invpos net.WriteUInt(fromtbl[1],16) -- From position net.WriteUInt(fromtbl[2],16) print("Writing string",k) net.WriteString(k) net.SendToServer() end end, {} ) else print("eqslot",k,"was not false, it was") PrintTable(v) local eqslot = vgui.Create("DImageButton",invsheet) eqslot:SetSize(slotsize,slotsize) eqslot:SetPos(displaypos[k][1],displaypos[k][2]) if v.PaintEquiped then eqslot.Paint = v.PaintEquiped end if v.DoOnEqupPanel then v.DoOnEqupPanel(eqslot) end eqslot:Droppable("Inventory") eqslot.Item = v eqslot.wasequiped = k end end local backpacksheet = vgui.Create( "DPropertySheet", invsheet ) backpacksheet:SetPos(0,slotsize * 6) backpacksheet:SetSize((width / 4) - 25, height - (slotsize * 6) - 50) print("Displaying backpacks:") PrintTable(LocalPlayer().Inventory.Backpacks) print("That was all the backpacks") for k,v in pairs(LocalPlayer().Inventory.Backpacks) do local tbacksheet = vgui.Create( "DPanel", backpacksheet ) tbacksheet.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 157, 160, 167 ) ) end backpacksheet:AddSheet( v[3], tbacksheet, "icon16/cross.png" ) DrawBackpackOnDPanel(tbacksheet,v,k,LocalPlayer()) end ]] end hook.Add("OnSpawnMenuOpen","ArteryOpenInventory",ShowInventory) hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function() lastpanel = sheet:GetActiveTab():GetPanel().sheetnum for k,v in pairs(LocalPlayer().invdisplays) do if not v.panel:IsValid() then continue end --PrintTable(v) v.panel:Close() LocalPlayer().invdisplays[k] = nil end plyisininventory = false end) concommand.Add("showinventory",ShowInventory) local viewdistance = 100 local rotatespeed = 65 local bone = nil local previousheadscale = Vector(1,1,1) hook.Add("CalcView","ArteryInventoryView",function(ply,pos,ang,fov,nearz,farz) if bone == nil then bone = LocalPlayer():LookupBone("ValveBiped.Bip01_Head1") end local view = {} --view.origin = LocalPlayer():GetBonePosition(bone) + LocalPlayer():GetUp() * 2 view.origin = pos if plyisininventory then local trot = math.rad(CurTime() * rotatespeed) local xoff = viewdistance * math.sin(trot) local yoff = viewdistance * math.cos(trot) view.origin = view.origin + Vector(xoff,yoff,10) ang.pitch = 20 ang.yaw = (-CurTime() * rotatespeed) - 90 end view.angles = ang view.fov = fov if not plyisininventory then LocalPlayer():ManipulateBoneScale(bone,Vector(0,0,0)) else LocalPlayer():ManipulateBoneScale(bone,previousheadscale) end view.drawviewer = plyisininventory return view end)