diff options
Diffstat (limited to 'gamemode/inventorysystem')
| -rw-r--r-- | gamemode/inventorysystem/prayers/cl_prayers.lua | 67 | ||||
| -rw-r--r-- | gamemode/inventorysystem/prayers/sh_prayers.lua | 13 |
2 files changed, 79 insertions, 1 deletions
diff --git a/gamemode/inventorysystem/prayers/cl_prayers.lua b/gamemode/inventorysystem/prayers/cl_prayers.lua new file mode 100644 index 0000000..aba778e --- /dev/null +++ b/gamemode/inventorysystem/prayers/cl_prayers.lua @@ -0,0 +1,67 @@ + +local pray = {} + +local explain +pray.activeprayers = {} +function pray:DrawOnDPanel(panel) + print("Attempted to draw prayer panel") + --Active grid + local agrid = vgui.Create("DGrid",panel) + agrid:SetCols(4) + local w = ((ScrW()/4) - 10) / 4 + agrid:SetHeight(w) + agrid:SetColWide(w) + agrid:SetRowHeight(w) + for i=1,4 do + local rec = vgui.Create("DImageButton",agrid) + rec:SetText("F"..i) + rec:SetSize(w,w) + rec.DoClick = function(s) + local ap = self.activeprayers[i] + explain:SetText(ap ~= nil and ap.Description or "Select a prayer") + end + agrid:AddItem(rec) + end + agrid:Dock(TOP) + --Explanation of spells + local explainpanel = vgui.Create("DPanel",panel) + explainpanel:SetHeight(w*2) + explainpanel:Dock(TOP) + explainpanel:SetText("This panel will explain information about a hovered skill") + explain = vgui.Create("DLabel",explainpanel) + explain:Dock(FILL) + explain:SetDark(true) + --All spells we know + local scroll = vgui.Create( "DScrollPanel", panel ) + scroll:Dock( FILL ) + local grid = vgui.Create("DGrid",scroll) + grid:SetCols(4) + grid:SetColWide(w) + grid:SetRowHeight(w) + for k,v in pairs(self.track) do + local rec = vgui.Create("DImageButton",grid) + rec:SetText(v.Name) + rec:SetSize(w,w) + if(v.DoOnPanel) then + v:DoOnPanel(rec) + end + grid:AddItem(rec) + end +end + +--Rebind f1, f2, f3, f4 to prayers +local prayerhooks = { + ["gm_showhelp"] = 1, + ["gm_showteam"] = 2, + ["gm_showspare1"] = 3, + ["gm_showspare2"] = 4 +} +hook.Add("PlayerBindPress", function( ply, bind, pressed ) + local phn = prayerhooks[bind] + if phn == nil then return end + local pap = pray.activeprayers[phn] + if pap == nil then return end + pap:pray() +end) + +return pray diff --git a/gamemode/inventorysystem/prayers/sh_prayers.lua b/gamemode/inventorysystem/prayers/sh_prayers.lua index 83414b7..15cd2af 100644 --- a/gamemode/inventorysystem/prayers/sh_prayers.lua +++ b/gamemode/inventorysystem/prayers/sh_prayers.lua @@ -1,7 +1,16 @@ +--[[ + prayers must have a "Pray" method, + a "Name" string, + a "Description" string +]] local reg = nrequire("inventory/inventory.lua") local itm = nrequire("item.lua") local inv = {} +if CLIENT then + inv = nrequire("cl_prayers.lua") +end + inv.Name = "Prayers" inv.track = {} function inv:FindPlaceFor(item) @@ -42,12 +51,14 @@ function inv:Serialize() end function inv:DeSerialize(str) + local cpy = table.Copy(self) local tbl = util.JSONToTable(str) local i = 1 for k,v in pairs(tbl) do local this_prayer = itm.GetItemByName(k):DeSerialize(v) - self:Put({i},this_prayer) + cpy:Put({i},this_prayer) end + return cpy end |
