summaryrefslogtreecommitdiff
path: root/gamemode/client/cl_quickmenu.lua
blob: d2c19615c29332bb0f2625f85265652c6c3ec967 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
local cMenuOpen = false
local pnl

local ply = nil

function GM:OnContextMenuOpen()
	cMenuOpen = !cMenuOpen
	gui.EnableScreenClicker(true)
	
	-- Derma Menu
	
	self.Think = function()
	
	if !cMenuOpen then return end
	//print(LocalPlayer():GetEyeTrace().Entity:GetClass())
		if (input.IsMouseDown(MOUSE_RIGHT)) then
			local tr = LocalPlayer():GetEyeTrace().Entity
			
			local menu = DermaMenu()
			if tr:IsPlayer() and LocalPlayer():IsSuperAdmin() and pnl == nil then
			menu:AddOption( "Player Information", function()
			
				pnl = vgui.Create("AdminCMenu")
			
			end )
			end
			
			if tr and tr:IsValid() and !tr:IsPlayer() and !tr:IsWorld() and LocalPlayer():IsAdmin() then
			menu:AddOption( "Remove", function() 

				net.Start('removeEntity')		
					net.WriteEntity(tr)
				net.SendToServer()

			end )
			end
			
			menu:AddOption( "Cancel", function() end )
			menu:Open()
			
			
			
			return
		end
		
	end
	
	
	
end

function GM:OnContextMenuClose()
	if cMenuOpen then return end
	if pnl != nil then pnl:Close() end
	cMenuOpen = false
	if pnl == nil then gui.EnableScreenClicker(false) end
end

// ADMIN MENU

PANEL = {}

PANEL.CMDS = {

	{
		
		txt = "Give Resource",
		tooltip = "Gives player the specified resource",
		func = function()
			
			local fr = vgui.Create("DFrame")
			fr:SetTitle("Give Resource")
			fr:SetSize(400, 120)
			fr:Center()
			fr:SetBackgroundBlur( true )
			fr:MakePopup()
			
			
			
			local TextEntry = vgui.Create( "DTextEntry", fr )
			TextEntry:SetSize( fr:GetWide()-100, 20 )
			TextEntry:SetPos( (fr:GetWide()/2) - (TextEntry:GetWide()/2), (fr:GetTall()/2) - (TextEntry:GetTall()/2) - 5 )
			TextEntry:SetText( "" )
			TextEntry:RequestFocus()
			
			local lbl = vgui.Create( "DLabel", fr )
			lbl:SetPos( TextEntry:GetPos(),TextEntry:GetPos()-TextEntry:GetTall() - 5 )
			lbl:SetText("Resource")
			
			local NumSlider = vgui.Create( "DNumSlider", fr )
			NumSlider:SetPos( TextEntry:GetPos(),TextEntry:GetPos()+10 )
			NumSlider:SetSize( fr:GetWide()-100, 50 )
			NumSlider:SetText( "Amount" )
			NumSlider:GetTextArea():SetEditable(false)
			NumSlider:SetMin( 1 )
			NumSlider:SetMax( 200 )
			NumSlider:SetDecimals( 0 )
			NumSlider:SetValue( 0 )
			NumSlider.DoClick = function() print(NumSlider:GetValue()) end
			
			local dbtn = vgui.Create("DButton", fr)
			dbtn:SetSize( 50, 25 )
			dbtn:SetPos( fr:GetWide()-dbtn:GetWide()-10, fr:GetTall()-dbtn:GetTall()-5 )
			dbtn:SetText("Give")
			dbtn.DoClick = function()
				txtval = string.Trim(TextEntry:GetValue())
				txtval = string.gsub(" "..txtval, "%W%l", string.upper):sub(2)
				
				if(GMS.Resources[txtval] == nil) then --This resource is not registered!
					LocalPlayer():PrintMessage(HUD_PRINTTALK, TextEntry:GetValue().." is not a valid resource!")
				else
					net.Start('giveres')
						
						net.WriteEntity(ply)
						net.WriteString(txtval)
						net.WriteInt(NumSlider:GetTextArea():GetValue(),32)
						
					net.SendToServer()
					LocalPlayer():PrintMessage(HUD_PRINTTALK, txtval.." x"..NumSlider:GetTextArea():GetValue().." has been given to "..ply:Nick())
				end
			end
			
		end,
		
	},
	/*
	{
		
		txt = "Test",
		tooltip = "Gives player the specified resource",
		func = function()
			
			print("TEST")
			
		end,
		
	},
	*/
}

local targetRes
local targetSkills

function PANEL:Init()
	ply = LocalPlayer():GetEyeTrace().Entity

	
	

	self:SetSize(250,350)
	self:Center()
	self:SetTitle("Player Information")
	
	local sheet = vgui.Create( "DPropertySheet", self )
	sheet:Dock( FILL )
	
	// Commands
	
	local cmdpnl = vgui.Create( "DPanel", sheet )
	
	for k,v in pairs(self.CMDS) do
		
		dpnl = vgui.Create("DButton", cmdpnl)
		dpnl:SetSize(224, 20)
		dpnl:SetPos(0,(k-1)*(dpnl:GetTall()+1))
		dpnl:SetText("")
		dpnl:SetToolTip( v['tooltip'] )
		dpnl.Paint = function()
			draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 78, 2, 78, 125 ) )
			surface.SetFont("Default")
			surface.SetTextColor( 0,0,0 )
			surface.SetTextPos( ( dpnl:GetWide()/2 ) - (surface.GetTextSize( v['txt'] )/2), 2)
			surface.DrawText(v['txt'])
		end
		dpnl.DoClick = v['func']
	end
	
	
	
	
	
	
	
	cmdpnl.Paint = function( self, w, h )
		draw.RoundedBox( 4, 0, 0, w, h, Color( 78, 78, 78, 125 ) )
		
	end
	
	sheet:AddSheet( "Commands", cmdpnl, "icon16/user.png" )

	// Skills
	
	local levelpnl = vgui.Create( "DPanel", sheet )
	
	local layout = vgui.Create( "DListLayout", levelpnl )
	layout:SetSize(224, 20)
	//Draw a background so we can see what it's doing
	layout:SetPaintBackground( true )
	layout:SetBackgroundColor( Color( 0, 100, 100 ) )
	
	-- Skills Update
	lastThinkSkills = CurTime()
	updateSkills(layout)
	layout.Think = function()
		if ( CurTime() >= lastThinkSkills + 3 )then
		layout:Clear()
		updateSkills(layout)
		lastThinkSkills = CurTime()
		end
	end
	
	levelpnl.Paint = function( self, w, h )
		draw.RoundedBox( 4, 0, 0, w, h, Color( 78, 78, 78, 125 ) )
		
	end
	
	sheet:AddSheet( "Skills", levelpnl, "icon16/wand.png" )
	
	// Resources
	
	local respnl = vgui.Create( "DPanel", sheet )
	
	local layout = vgui.Create( "DListLayout", respnl )
	layout:SetSize(224, 20)
	//Draw a background so we can see what it's doing
	layout:SetPaintBackground( true )
	layout:SetBackgroundColor( Color( 0, 100, 100 ) )
	
	-- Resource Update
	lastThinkRes = CurTime()
	updateResources(layout)
	layout.Think = function()
		if ( CurTime() >= lastThinkRes + 3 )then
		layout:Clear()
		updateResources(layout)
		lastThinkRes = CurTime()
		end
	end
	
	respnl.Paint = function( self, w, h )
		draw.RoundedBox( 4, 0, 0, w, h, Color( 78, 78, 78, 125 ) )
	end
	
	sheet:AddSheet( "Resources", respnl, "icon16/rainbow.png" )
 

end

function updateResources(layout)
	net.Start('adminCMenuResRequest')		
		net.WriteEntity(ply)
		net.Receive( 'adminCMenuResSend', function()
				
			targetRes = net.ReadTable()
			for k,v in pairs (targetRes) do
				layout:Add( Label( "   "..k.." x"..v ) )
			end
		end)
	net.SendToServer()
end

function updateSkills(layout)
	net.Start('adminCMenuSkillRequest')		
		net.WriteEntity(ply)
		net.Receive( 'adminCMenuSkillSend', function()
			
			targetSkills = net.ReadTable()
			for k,v in pairs (targetSkills) do
				layout:Add( Label( "   "..k.." : "..v ) )
			end
		end)
	net.SendToServer()
end

function PANEL:OnClose()
	
	pnl = nil
	gui.EnableScreenClicker(false)
	cMenuOpen = false
	self:Remove()
end

function PANEL:Paint()
	
	draw.RoundedBox(4, 0, 0, self:GetWide(), self:GetTall(), Color(28, 28, 28, 125))
	
end

vgui.Register("AdminCMenu", PANEL, "DFrame")