summaryrefslogtreecommitdiff
path: root/ftp_gmstranded/gamemode/cl_deathmenu.lua
blob: 472547ad281f1644e873d66d3c1e9360187ac1d7 (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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
surface.CreateFont( "Header", {
	font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	size = 16,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )

surface.CreateFont( "Items", {
	font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	size = 14,
	weight = 0,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )



active = 0

local res
local wep
local dmFrame
	
local function receive_message(len)

res = net.ReadTable()
wep = net.ReadTable()

if (active == 0) then dmFrame = vgui.Create("dmFrame") active = 1 end
	
end
net.Receive('deathmenu', receive_message)



local PANEL = {}

width = 100
height = 100

function PANEL:Init()
	
	self:SetSize( 440, 400 )
	self:Center()
	self:MakePopup()
	self:SetTitle("")
	
	local pnl = vgui.Create( "DPanel", self )
	pnl:SetSize(self:GetWide()-10, self:GetTall()-25)
	pnl:SetPos(5,25)
	
	local DScrollPanel = vgui.Create( "DScrollPanel", pnl )
	DScrollPanel:SetSize( pnl:GetWide(), pnl:GetTall() )
	DScrollPanel:SetPos( 0, 0 )
	
	// Weapons
	
	local wepPnlHeader = vgui.Create("DPanel", DScrollPanel)
	wepPnlHeader:SetSize( DScrollPanel:GetWide(), 25 )
	wepPnlHeader:SetPos(0,0)
	wepPnlHeader.Paint = function()
		
		draw.RoundedBox( 0, 0, 0, wepPnlHeader:GetWide(), wepPnlHeader:GetTall(), Color( 48, 48, 48, 255 ) )
		draw.SimpleText( "Weapons", "Header", 30, 12, Color(255, 255, 255), 1, 1 )
	end
	
	column = 1
	row = 1
	XOffset = 12
	for k,v in pairs(wep) do
		local wepPNL = vgui.Create( "DButton", DScrollPanel )
		wepPNL:SetSize( width, height )
		if (k/4 <= column) then
			wepPNL:SetPos( (row-1)*(width+2) + XOffset,(column-1)*(height+2) + 25)
			row=row+1
		else
			column=column+1
			row=1
			wepPNL:SetPos( (row-1)*(width+2) + XOffset,(column-1)*(height+2) + 25)
			row=row+1
		end
		
		wepPNL:SetDrawBackground( false )
		
		wepPNL.Paint = function()
		
			draw.RoundedBox( 0, 0, 0, wepPNL:GetWide(), wepPNL:GetTall(), Color(69,69,69,125) )
			
			surface.SetFont("Items")
			surface.SetTextColor( 0,0,0 )
			surface.SetTextPos( (width/2)-(surface.GetTextSize(v)/2), height-20 )
			surface.DrawText(v)
		end
		
		wepPNL.DoClick = function()
			if (!LocalPlayer():HasWeapon(v)) then
				
				net.Start('givePlayerWeapon')
					net.WriteString(v)
					for i,o in pairs(wep) do
						if (v == o) then
							net.WriteInt(i, 32)
							table.remove(wep,i)
						end
					end
					wepPNL:Remove()
					
				net.SendToServer()
			end
		end
		
		local img = vgui.Create("DImage", wepPNL)
		img:SetPos(0, 0)
		img:SetSize(wepPNL:GetSize())
		img:SetImage("gms_icons/gms_weapon.png")
		
		
	end
	
	// Resources
	
	local resPnlHeader = vgui.Create("DPanel", DScrollPanel)
	resPnlHeader:SetSize( DScrollPanel:GetWide(), 25 )
	resPnlHeader:SetPos(0,column*height + 25)
	resPnlHeader.Paint = function()
		draw.RoundedBox( 0, 0, 0, resPnlHeader:GetWide(), resPnlHeader:GetTall(), Color( 48, 48, 48, 255 ) )
		draw.SimpleText( "Resources", "Header", 35, 12, Color(255, 255, 255), 1, 1 )
	end
	
	row2 = 1
	column2 = 1
	for k,v in pairs(res) do
		local resPNL = vgui.Create( "DButton", DScrollPanel )
		resPNL:SetSize( width, height )
		if (k/4 <= column2) then
			resPNL:SetPos( (row2-1)*(width+2) + XOffset,(column2-1)*(height+2) + (column*height + 50))
			row2=row2+1
		else
			column2=column2+1
			row2=1
			resPNL:SetPos( (row2-1)*(width+2) + XOffset,(column2-1)*(height+2) + (column*height + 50))
			row2=row2+1
		end
		
		local tbl1 = string.Split(res[k], " ")
		local tbl2 = string.Split(tbl1[2], "x")
		local amount = tbl2[2]
			
		resPNL.DoClick = function()
			local mb = DermaMenu()
			
			
			mb:AddOption("Take x1", function()
				
				if (amount - 1 <= 0) then
					amount = 0
					for i,o in pairs(res) do
						spl1 = string.Split(v, " ")
						spl2 = string.Split(o, " ")
						if (spl1[1] == spl2[1]) then
							giveRes(tbl1[1], 1, i)
							table.remove(res,i)
						end
					end
					resPNL:Remove()
				else
					amount = amount - 1
					
					
					for i,o in pairs(res) do
						spl1 = string.Split(v, " ")
						spl2 = string.Split(o, " ")
						if (spl1[1] == spl2[1]) then	
							giveRes(tbl1[1], 1, i)
							res[i] = tbl1[1] .. " x" .. amount
							v = res[i]
						end
					end
					
				end
				
			end)
			mb:AddOption("Take x5", function() 
				
				if (amount - 5 <= 0) then
				
					if (amount - 5 == 0) then
						amount = 0
						
						
						for i,o in pairs(res) do
							spl1 = string.Split(v, " ")
							spl2 = string.Split(o, " ")
							if (spl1[1] == spl2[1]) then
								giveRes(tbl1[1], 5, i)
								table.remove(res, i)
							end
						end
						resPNL:Remove()
					else
					
						num1 = amount - 5
						num2 = 5 + num1
						amount = 0
						
						
						
						for i,o in pairs(res) do
							spl1 = string.Split(v, " ")
							spl2 = string.Split(o, " ")
							if (spl1[1] == spl2[1]) then
								giveRes(tbl1[1], num2, i)
								print(i)
								table.remove(res,i)
							end
						end
						resPNL:Remove()
					end
				else
					amount = amount - 5
					
					
					for i,o in pairs(res) do
						spl1 = string.Split(v, " ")
						spl2 = string.Split(o, " ")
						if (spl1[1] == spl2[1]) then
							giveRes(tbl1[1], 5, i)
							res[i] = tbl1[1] .. " x" .. amount
							v = res[i]
						end
					end
					
				end
			
			end)
			mb:AddOption("Take x10", function() 
				
				if (amount - 10 <= 0) then
				
					if (amount - 10 == 0) then
						amount = 0
						
						for i,o in pairs(res) do
							spl1 = string.Split(v, " ")
							spl2 = string.Split(o, " ")
							if (spl1[1] == spl2[1]) then
								giveRes(tbl1[1], 10, i)
								table.remove(res, i)
							end
						end
						resPNL:Remove()
					else
					
						num1 = amount - 10
						num2 = 10 + num1
						amount = 0
						
						
						for i,o in pairs(res) do
							spl1 = string.Split(v, " ")
							spl2 = string.Split(o, " ")
							if (spl1[1] == spl2[1]) then
								giveRes(tbl1[1], num2, i)
								table.remove(res,i)
							end
						end
						
						resPNL:Remove()
					
					end
				else
					amount = amount - 10
					
					
					for i,o in pairs(res) do
						spl1 = string.Split(v, " ")
						spl2 = string.Split(o, " ")
						if (spl1[1] == spl2[1]) then
							giveRes(tbl1[1], 10, i)
							res[i] = tbl1[1] .. " x" .. amount
							v = res[i]
						end
					end
					
				end
			
			end)
			mb:AddOption("Take All", function() 
				
				
				for i,o in pairs(res) do
					spl1 = string.Split(v, " ")
					spl2 = string.Split(o, " ")
					if (spl1[1] == spl2[1]) then
						giveRes(tbl1[1], amount, i)
						amount = 0
						table.remove(res,i)
					end
				end
				
				resPNL:Remove()
			end)
			mb:Open()
		end
		
		resPNL.Paint = function()
			draw.RoundedBox( 0, 0, 0, resPNL:GetWide(), resPNL:GetTall(), Color( 69, 69, 69, 125 ) )
			
			
			surface.SetFont("Items")
			surface.SetTextColor( 0,0,0 )
			surface.SetTextPos( (width/2)-(surface.GetTextSize(v)/2), height-20 )
			surface.DrawText(v)
		
		end
		
		local img = vgui.Create("DImage", resPNL)
		img:SetPos(0, 0)
		img:SetSize(resPNL:GetSize())
		img:SetImage("gms_icons/gms_resourcepack.png")
	end
	
end

function PANEL:Close()
	active = 0
	self:Remove()
end

function giveRes(res, amount, slot)
	
	net.Start('givePlayerResource')
		
		net.WriteString(res)
		net.WriteInt(amount, 32)
		net.WriteInt(slot, 32)
		
	net.SendToServer()
	
end

function PANEL:Paint( w, h )
	draw.RoundedBox( 0, 0, 0, w, h, Color( 69, 69, 69, 125 ) )
end

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