From 0ae33ad32868af226fba6d887320aa87aa19d3a4 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 20 May 2017 13:15:45 -0400 Subject: Fixed models drawing in inventory --- .../inventorysystem/equipment/cl_equipment.lua | 10 ++-- .../inventorysystem/shapedinventory/cl_shaped.lua | 59 +++++----------------- gamemode/itemsystem/exampleitem.lua | 12 ++--- gamemode/nrequire.lua | 3 +- 4 files changed, 25 insertions(+), 59 deletions(-) (limited to 'gamemode') diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua index 82560be..74152dc 100644 --- a/gamemode/inventorysystem/equipment/cl_equipment.lua +++ b/gamemode/inventorysystem/equipment/cl_equipment.lua @@ -124,12 +124,12 @@ inv.DrawOnDPanel = function(self,panel) end print("Found something equiped in ", k) if self.equiped[k].OnEqpPaint then - pn.Paint = self.equiped[k].OnEqpPaint + pn.PaintOver = self.equiped[k].OnEqpPaint end else --We don't have something equiped! if v.img and v.img.material then local c = col.ui.border - pn.Paint = function(tp,w,h) + pn.PaintOver = function(tp,w,h) surface.SetDrawColor(c.r,c.g,c.b) surface.DrawOutlinedRect(0, 0, w, h) surface.SetDrawColor(255,255,255) @@ -155,9 +155,9 @@ inv.DrawOnDPanel = function(self,panel) end end if item.OnEqpPaint then - self[position[1]].Paint = item.OnEqpPaint + self[position[1]].PaintOver = item.OnEqpPaint else - self[position[1]].Paint = function(panel) + self[position[1]].PaintOver = function(panel) draw.DrawText( item.Name, "DermaDefault", 10, 10, Color( 0, 0, 0, 0 )) end end @@ -170,7 +170,7 @@ inv.DrawOnDPanel = function(self,panel) local pn = self[position[1]] pn.DoClick = function() end local c = col.ui.border - pn.Paint = function(self,w,h) + pn.PaintOver = function(self,w,h) surface.SetDrawColor(c.r,c.g,c.b) surface.DrawOutlinedRect(0, 0, w, h) surface.SetDrawColor(255,255,255) diff --git a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua index 83c2217..051f0bc 100644 --- a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua +++ b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua @@ -8,12 +8,15 @@ local width = ScrW() --local height = ScrH() local iconsize = ((width / 4) - 20) / 5 + local function default_paint(self,w,h) --Draw a box surface.SetDrawColor(col.ui.border) - surface.DrawOutlinedRect( 0, 0, w, h ) + surface.DrawOutlinedRect( 0, 0, w, h ) + --xpcall(self.DrawModel,function() end,self) end + --[[ local function calcposition(dimx,dimy,x,y) return (y * dimx) + x @@ -64,10 +67,11 @@ local function drawitemat(self,x,y,item) end end if item.DoOnPanel then + print("Calling cl_shaped's DoOnPanel") item:DoOnPanel(tp) end if item.Paint then - tp.Paint = item.Paint + tp.PaintOver = item.Paint end end @@ -77,58 +81,18 @@ local function undrawitemat(self,x,y) local dpn = self.gridpanels[x][y] dpn:Droppable("") dpn:SetText("") + if dpn:GetModel() then + dpn.Entity:Remove() + end for k,v in pairs(dpn:GetChildren()) do v:Remove() end runonshape(self,item.Shape,x,y,function(panel) panel:SetVisible(true) panel:SetSize(iconsize,iconsize) - panel.Paint = default_paint + panel.PaintOver = default_paint panel.DoClick = function() end end) end ---[[ -local function generatereceiver(tinv,x,y) - return function(self,panels,dropped,index,cx,cy) - if dropped then - local froment,toent = panels[1].info.owner,self.info.owner - local fromid,toid = panels[1].info.id,self.info.id - local frompos,topos = panels[1].info.pos,self.info.pos - local frominv,toinv = panels[1].info.inv,self.info.inv - print("Something was dropped on:",x,y) - PrintTable(panels) - print("froment:",froment) - print("toent:",toent) - print("fromid",fromid) - print("toid",toid) - print("frompos:",frompos) - PrintTable(panels[1].info.pos) - print("topos:",topos) - PrintTable(self.info.pos) - print("frominv",frominv) - print("toinv",toinv) - local item = frominv:Get(frompos) - print("item was", item) - --Fake remove the item, in case the position we want to move it to overlaps with where it is now. - frominv:Remove(frompos) - local cf = toinv:CanFitIn(topos,item) - frominv:Put(frompos,item) - print("canfit was:",cf) - if cf == true then - --Send the request - net.Start("art_RequestInvMove") - net.WriteEntity(froment) - net.WriteEntity(toent) - net.WriteUInt(fromid,32) - net.WriteUInt(toid,32) - net.WriteTable(frompos) - net.WriteTable(topos) - net.SendToServer() - end - end - end -end -]] - inv.DrawOnDPanel = function(self,panel) local DScrollPanel = vgui.Create( "DScrollPanel",panel) DScrollPanel:SetPos( 0, 0 ) @@ -147,8 +111,9 @@ inv.DrawOnDPanel = function(self,panel) for x = 1, self.dimx do for y = 1, self.dimy do local dp = vgui.Create("DModelPanel") + function dp:LayoutEntity( Entity ) return end -- disables default rotation dp:SetSize(iconsize,iconsize) - dp.Paint = default_paint + dp.PaintOver = default_paint dp:SetText("") --dp:Droppable("item") dp:Receiver("item",com.generatereceiver(),{"one","two","three"}) diff --git a/gamemode/itemsystem/exampleitem.lua b/gamemode/itemsystem/exampleitem.lua index 3c76971..82483e6 100644 --- a/gamemode/itemsystem/exampleitem.lua +++ b/gamemode/itemsystem/exampleitem.lua @@ -41,16 +41,16 @@ if CLIENT then end --Optional. Something run once when this item is drawn in a backpack -function item.DoOnPanel(dimagebutton) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png") +function item.DoOnPanel(self,dmodelpanel) + dmodelpanel:SetModel( "models/player/alyx.mdl" ) -- you can only change colors on playermodels end --Optional. Something run once when this item is drawn in an equiped slot -function item.DoOnEquipPanel(dimagebutton) +function item.DoOnEquipPanel(self,dmodelpanel) print("called with panel:",panel) - dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png") + dmodelpanel:SetModel( "models/player/alyx.mdl" ) -- you can only change colors on playermodels end - +--[[ --Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack. function item.Paint(self,width,height) draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) @@ -60,7 +60,7 @@ end function item.PaintEquiped(self,width,height) draw.RoundedBox(4, 0,0,width,height,Color(0,100,0)) end - +]] --Required, the shape of this item in a backpack. item.Shape = { {true}, diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua index 1fc70bd..f25cbb7 100644 --- a/gamemode/nrequire.lua +++ b/gamemode/nrequire.lua @@ -191,7 +191,7 @@ local function doincludes() paths = {} TraverseFolder("",ins) ntbl = rebuild_include_table(paths) - reqtbl = {} + reqtbl = reqtbl or {} for k,v in pairs(paths) do if v:match("/?sv_[%w_]+%.lua$") then if SERVER then @@ -232,6 +232,7 @@ doincludes() --Do it the first time through if SERVER then util.AddNetworkString("art_refresh") end if CLIENT then net.Receive("art_refresh",doincludes) end concommand.Add("art_manualrefresh",function(ply,cmd,args) + reqtbl = {} doincludes() net.Start("art_refresh") net.Broadcast() -- cgit v1.2.3-70-g09d2