aboutsummaryrefslogtreecommitdiff
path: root/gamemode/ents/art_chest/cl_art_chest.lua
blob: 680081072692bf30386695f6391b52f8561bc7d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local ENT = nrequire("sh_art_chest.lua")
--local invfuncs = include("../../../gamemode/shared/inventory_common.lua")
local invfuncs = nrequire("inventory/inventory.lua")

ENT.RenderGroup = RENDERGROUP_BOTH

function ENT:Initialize()
end

function ENT:OnRemove()
end

function ENT:Think()
end

function ENT:Draw()

	self:DrawModel()
end

local oldpanel = nil
local namecache = {}

net.Receive("openchestinv",function(len,ply)
	if oldpanel ~= nil then oldpanel:Remove() end
	local what = net.ReadEntity()
	local chest = invfuncs.DeSerializeBackpack()
	ShowInventory()
	local dat = {}
	dat.redraw = function()
		net.Start("requestchestinv")
		net.WriteEntity(what)
		net.SendToServer()
	end
	dat.panel = vgui.Create( "DFrame" )
	oldpanel = dat.panel
	dat.panel.OnClose = function()
		net.Start("closechestinv")
		net.WriteEntity(what)
		net.SendToServer()
	end
	table.insert(LocalPlayer().invdisplays,dat)
	local width = ScrW()
	local height = ScrH()
	local invpanel = dat.panel
	invpanel:SetPos( width - (width / 4), 0 )
	invpanel:SetSize( width / 4, height )
	if namecache[what] == nil then
		net.Start("requestchestname")
		net.WriteEntity(what)
		net.SendToServer()
		invpanel:SetTitle( "Chest" )
	else
		invpanel:SetTitle(namecache[what])
	end
	invpanel:SetDraggable( true )
	invpanel:MakePopup()
	local innerpanel = vgui.Create("DPanel",dat.panel)
	innerpanel:Dock(FILL)
	innerpanel.Paint = function( self, w, h ) draw.RoundedBox( 4, 0, 0, w, h, Color( 157, 160, 167 ) ) end
	invfuncs.DrawBackpackOnDPanel(innerpanel, chest, 1, what)
end)

scripted_ents.Register(ENT, "art_chest")