· 8 years ago · May 02, 2018, 03:18 AM
1--[[------------------------------------------------------------------------------
2 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
3 * Unauthorized copying of this file, via any medium is strictly prohibited
4 * Proprietary and confidential
5--]]------------------------------------------------------------------------------
6
7gElo = gElo or {};
8gElo.Config = gElo.Config or {};
9gElo.Languages = gElo.Languages or {};
10gElo.Version = "030418";
11gElo.UseDebug = true;
12
13
14---
15--- LoadFile
16---
17function gElo:LoadFile(path)
18 local filename = path:GetFileFromFilename();
19 filename = filename ~= "" and filename or path;
20
21 local flagCL = filename:StartWith("cl_");
22 local flagSV = filename:StartWith("sv_");
23 local flagSH = filename:StartWith("sh_");
24
25 if (SERVER) then
26 if (flagCL or flagSH) then
27 AddCSLuaFile(path);
28 end
29
30 if (flagSV or flagSH) then
31 include(path);
32 end
33 elseif (flagCL or flagSH) then
34 include(path);
35 end
36end
37
38---
39--- LoadDirectory
40---
41function gElo:LoadDirectory(dir)
42 local files, folders = file.Find(dir .. "/*", "LUA");
43
44 for _, v in ipairs(files) do
45 self:LoadFile(dir .. "/" .. v);
46 end
47
48 for _, v in ipairs(folders) do
49 self:LoadDirectory(dir .. "/" .. v);
50 end
51end
52
53gElo:LoadDirectory("gelo");
54
55if (CLIENT) then return; end
56
57resource.AddWorkshop("1150660344");
58
59--[[------------------------------------------------------------------------------
60 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
61 * Unauthorized copying of this file, via any medium is strictly prohibited
62 * Proprietary and confidential
63--]]------------------------------------------------------------------------------
64
65---
66--- DebugPrint
67---
68function gElo.DebugPrint(str)
69 if (not gElo.UseDebug) then return; end
70 str = " " .. str;
71
72 MsgC(Color(200, 255, 0, 200), "[");
73 MsgC(Color(200, 0, 0, 200), "DEBUG");
74 MsgC(Color(200, 255, 0, 200), "]")
75 MsgC(Color(200, 200, 200), str);
76 MsgN();
77
78 return true;
79end
80
81--[[------------------------------------------------------------------------------
82 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
83 * Unauthorized copying of this file, via any medium is strictly prohibited
84 * Proprietary and confidential
85--]]------------------------------------------------------------------------------
86
87util.AddNetworkString("gElo.AdminSetRank")
88util.AddNetworkString("gElo.AdminSetRP");
89util.AddNetworkString("gElo.AdminResetUserAll");
90util.AddNetworkString("gElo.AdminSetName");
91
92net.Receive("gElo.AdminSetRank", function(_, ply)
93 if (not IsValid(ply)) then return; end
94 if (not gElo.Config.UIAdmin[ply:GetUserGroup()]) then return; end
95
96 local steamid = net.ReadString();
97 local elo = net.ReadUInt(32);
98 local ELO = gElo.GetElo();
99
100 ELO:SetRank(steamid, elo, ply);
101end);
102
103net.Receive("gElo.AdminSetRP", function(_, ply)
104 if (not IsValid(ply)) then return; end
105 if (not gElo.Config.UIAdmin[ply:GetUserGroup()]) then return; end
106
107 local steamid = net.ReadString();
108 local rp = net.ReadUInt(8);
109 local ELO = gElo.GetElo();
110
111 ELO:SetRP(steamid, rp, ply);
112end);
113
114net.Receive("gElo.AdminResetUserAll", function(_, ply)
115 if (not gElo.Config.UIAdmin[ply:GetUserGroup()]) then return; end
116
117 local steamid = net.ReadString();
118 local SQL = gElo.GetSQL();
119 local ELO = gElo.GetElo();
120
121 ELO:SetRP(steamid, 0);
122 ELO:SetRank(steamid, 1600);
123
124 sql.Query(SQL:FormatSQL([[
125 UPDATE gElo_Stats SET
126 Kills = 0,
127 Deaths = 0,
128 InnocentWins = 0,
129 DetectiveWins = 0,
130 TraitorWins = 0,
131 TotalWins = 0,
132 TotalLosses = 0,
133 InnocentLosses = 0,
134 DetectiveLosses = 0,
135 TraitorLosses = 0,
136 BulletsFired = 0,
137 RoundsPlayed = 0,
138 DamageDealt = 0,
139 FireDamageDealt = 0,
140 InnocentKills = 0,
141 InnocentDeaths = 0,
142 DetectiveKills = 0,
143 DetectiveDeaths = 0,
144 TraitorKills = 0,
145 TraitorDeaths = 0,
146 InnocentDamage = 0,
147 DetectiveDamage = 0,
148 TraitorDamage = 0,
149 Headshots = 0,
150 Promos = 0,
151 PromoWins = 0,
152 PromoLoss = 0,
153 LossAtZeroRP = 0 WHERE SteamID = '%s'
154 ]], steamid));
155
156end);
157
158net.Receive("gElo.AdminSetName", function(_, ply)
159 if (not gElo.Config.UIAdmin[ply:GetUserGroup()]) then return; end
160
161 local steamid = net.ReadString();
162 local name = net.ReadString();
163 local SQL = gElo.GetSQL();
164
165 sql.Query(SQL:FormatSQL([[
166 UPDATE gElo_Stats SET Name = '%s' WHERE SteamID = '%s'
167 ]], name, steamid));
168end);
169
170--[[------------------------------------------------------------------------------
171 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
172 * Unauthorized copying of this file, via any medium is strictly prohibited
173 * Proprietary and confidential
174--]]------------------------------------------------------------------------------
175
176util.AddNetworkString("gElo.WipeDatabase");
177
178-- We're using SQLite
179
180local SQL = {};
181
182---
183--- CreateTables
184---
185function SQL:CreateTables()
186 -- Player Stats
187 if (!sql.TableExists("gElo_Stats")) then
188 if (sql.Query([[CREATE TABLE gElo_Stats (
189 ID INTEGER PRIMARY KEY AUTOINCREMENT,
190 SteamID VARCHAR(17),
191 Name VARCHAR(40),
192 Kills INTEGER DEFAULT 0,
193 Deaths INTEGER DEFAULT 0,
194 InnocentWins INTEGER DEFAULT 0,
195 DetectiveWins INTEGER DEFAULT 0,
196 TraitorWins INTEGER DEFAULT 0,
197 TotalWins INTEGER DEFAULT 0,
198 TotalLosses INTEGER DEFAULT 0,
199 InnocentLosses INTEGER DEFAULT 0,
200 DetectiveLosses INTEGER DEFAULT 0,
201 TraitorLosses INTEGER DEFAULT 0,
202 BulletsFired INTEGER DEFAULT 0,
203 Elo INTEGER DEFAULT 1600,
204 Rank VARCHAR(50) DEFAULT "Bronze",
205 Division INTEGER DEFAULT 5,
206 RoundsPlayed INTEGER DEFAULT 0,
207 DamageDealt INTEGER DEFAULT 0,
208 FireDamageDealt INTEGER DEFAULT 0,
209 InnocentKills INTEGER DEFAULT 0,
210 InnocentDeaths INTEGER DEFAULT 0,
211 DetectiveKills INTEGER DEFAULT 0,
212 DetectiveDeaths INTEGER DEFAULT 0,
213 TraitorKills INTEGER DEFAULT 0,
214 TraitorDeaths INTEGER DEFAULT 0,
215 InnocentDamage INTEGER DEFAULT 0,
216 DetectiveDamage INTEGER DEFAULT 0,
217 TraitorDamage INTEGER DEFAULT 0,
218 Headshots INTEGER DEFAULT 0,
219 RP INTEGER DEFAULT 0,
220 Promos BOOLEAN DEFAULT 0,
221 PromoWins INTEGER DEFAULT 0,
222 PromoLoss INTEGER DEFAULT 0,
223 LossAtZeroRP INTEGER DEFAULT 0,
224 UNIQUE(SteamID)
225 );]]) == false) then
226 gElo.DebugPrint("[gElo_Stats] -> SQL Error: " .. sql.LastError());
227 else
228 gElo.DebugPrint("[gElo_Stats] -> SQL Success: Created table gElo_Stats");
229 end
230 end
231
232 -- Player Match History
233 if (!sql.TableExists("gElo_History")) then
234 if (sql.Query([[CREATE TABLE gElo_History (
235 ID Integer PRIMARY KEY AUTOINCREMENT,
236 SteamID VARCHAR(17),
237 Kills INTEGER,
238 Won BOOLEAN,
239 Date INTEGER,
240 Role VARCHAR(70),
241 Map VARCHAR(100),
242 RoundTime INTEGER,
243 RP INTEGER,
244 DamageDealt INTEGER,
245 Shots INTEGER,
246 UNIQUE(ID)
247 );]]) == false) then
248 gElo.DebugPrint("[gElo_History] -> SQL Error: " .. sql.LastError());
249 else
250 gElo.DebugPrint("[gElo_History] -> SQL Success: Created table gElo_History");
251 end
252 end
253
254 if (!sql.TableExists("gElo_History_Count")) then
255 if (sql.Query([[CREATE TABLE gElo_History_Count (
256 ID Integer PRIMARY KEY AUTOINCREMENT,
257 SteamID VARCHAR(17),
258 Count INTEGER DEFAULT 0,
259 UNIQUE(SteamID)
260 );]]) == false) then
261 gElo.DebugPrint("[gElo_History_Count] -> SQL Error: " .. sql.LastError());
262 else
263 gElo.DebugPrint("[gElo_History_Count] -> SQL Success: Created table gElo_History_Count");
264 end
265 end
266end
267
268---
269--- FormatSQL
270---
271function SQL:FormatSQL(formatString, ...)
272 local repacked = {};
273 local args = {...};
274
275 for _, arg in ipairs(args) do
276 table.insert(repacked, sql.SQLStr(arg, true));
277 end
278
279 return string.format(formatString, unpack(repacked));
280end
281
282---
283--- GetSQL
284---
285function gElo.GetSQL()
286 return SQL;
287end
288
289hook.Add("Initialize", "gElo.CreateSQLTables", function()
290 SQL:CreateTables();
291end);
292
293hook.Add("PlayerInitialSpawn", "gElo.CreateSQLValues", function(ply)
294 if (not IsValid(ply) or ply:IsBot() and not gElo.UseDebug) then return; end
295
296 local q = sql.Query(SQL:FormatSQL([[
297 INSERT OR IGNORE INTO gElo_Stats
298 (SteamID, Name) VALUES('%s', '%s')]],
299 ply:SteamID64(), ply:Nick()));
300
301 if (q == false) then
302 gElo.DebugPrint("[PlayerInitialSpawn][gElo_Stats] -> SQL Error: " .. sql.LastError());
303 else
304 gElo.DebugPrint("[PlayerInitialSpawn][gElo_Stats] -> Successfully inserted values into player row");
305 end
306
307 local q = sql.Query(SQL:FormatSQL([[
308 INSERT OR IGNORE INTO gElo_History_Count
309 (SteamID) VALUES('%s')]],
310 ply:SteamID64()));
311
312 if (q == false) then
313 gElo.DebugPrint("[PlayerInitialSpawn][gElo_History_Count] -> SQL Error: " .. sql.LastError());
314 else
315 gElo.DebugPrint("[PlayerInitialSpawn][gElo_History_Count] -> Successfully inserted values into player row");
316 end
317
318 ply.CanUpdateProfile = true;
319end);
320
321net.Receive("gElo.WipeDatabase", function(_, ply)
322 if (not ply:IsSuperAdmin()) then return; end
323
324 local db = net.ReadUInt(2);
325
326 if (db == 1) then
327 sql.Query("DROP TABLE gElo_Stats");
328 elseif(db == 2) then
329 sql.Query("DROP TABLE gElo_History");
330 sql.Query("DROP TABLE gElo_History_Count");
331 elseif(db == 3) then
332 sql.Query("DROP TABLE gElo_Stats");
333 sql.Query("DROP TABLE gElo_History");
334 sql.Query("DROP TABLE gElo_History_Count");
335 end
336
337 RunConsoleCommand("changelevel", game.GetMap());
338end);
339
340--[[------------------------------------------------------------------------------
341 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
342 * Unauthorized copying of this file, via any medium is strictly prohibited
343 * Proprietary and confidential
344--]]------------------------------------------------------------------------------
345
346local Queue = {};
347local Queries = {};
348
349---
350--- AddSQLToQueue
351---
352function Queue:AddSQLToQueue(query, row, func)
353 local row = row or false;
354 table.insert(Queries, {q = query, r = row, f = func});
355
356 return true;
357end
358
359---
360--- GetQueue
361---
362function gElo.GetQueue()
363 return Queue;
364end
365
366local QueueCooldown = CurTime();
367hook.Add("Tick", "gELo.SQLQueue", function()
368 if (QueueCooldown > CurTime()) then return; end
369
370 for k, v in ipairs(Queries) do
371 local query;
372
373 if (v.r) then
374 query = sql.QueryRow(v.q);
375 else
376 query = sql.Query(v.q);
377 end
378
379 if (query == false) then
380 gElo.DebugPrint("SQL ERROR SV QUEUE: " .. sql.LastError());
381 else
382 gElo.DebugPrint("SUCCESSFULLY QUERY'D: " .. tostring(v.q));
383
384 if (v.f) then
385 v.f(query);
386 end
387 end
388
389 table.remove(Queries, k);
390 QueueCooldown = CurTime() + .01;
391 end
392end);
393
394--[[------------------------------------------------------------------------------
395 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
396 * Unauthorized copying of this file, via any medium is strictly prohibited
397 * Proprietary and confidential
398--]]------------------------------------------------------------------------------
399
400local history = {};
401local SQL = gElo.GetSQL();
402local Queue = gElo.GetQueue();
403history.players = {};
404
405---
406--- ResetPlayerVariables
407---
408function history:ResetPlayerVariables(ply)
409 if (not IsValid(ply)) then return; end
410
411 history.players[ply:SteamID64()] = {};
412 self.Client = history.players[ply:SteamID64()];
413
414 self.Client.Kills = 0;
415 self.Client.Won = false;
416 self.Client.Role = "Unknown";
417 self.Client.RP = 0;
418 self.Client.DamageDealt = 0;
419 self.Client.Map = "Unknown";
420 self.Client.RoundTime = 0;
421 self.Client.Shots = 0;
422end
423
424---
425--- SetPlayerVariables
426---
427function history:SetPlayerVariables(ply, var, val)
428 if (not IsValid(ply) or not history.players[ply:SteamID64()]) then return; end
429
430 history.players[ply:SteamID64()][var] = val;
431
432 return val;
433end
434
435---
436--- GetPlayerVariables
437---
438function history:GetPlayerVariables(ply, var)
439 if (not IsValid(ply)) then return; end
440
441 return history.players[ply:SteamID64()][var];
442end
443
444---
445--- UpdatePlayer
446---
447function history:UpdatePlayer(id, tbl)
448 Queue:AddSQLToQueue(SQL:FormatSQL([[INSERT INTO gElo_History (SteamID, Kills, RP, DamageDealt, Shots, Won, Date, Role, RoundTime, Map) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')]], id, tbl.Kills, tbl.RP, tbl.DamageDealt, tbl.Shots, tbl.Won, os.time(), tbl.Role, tbl.RoundTime, tbl.Map));
449 Queue:AddSQLToQueue("UPDATE gElo_History_Count SET Count = Count + 1 WHERE SteamID = '" .. id .. "'");
450 Queue:AddSQLToQueue("SELECT Count FROM gElo_History_Count WHERE SteamID = '" .. id .. "'", function(c)
451 local toDelete;
452 local numberedCount;
453
454 if (c and c[1]["Count"]) then
455 numberedCount = tonumber(c[1]["Count"]);
456 else
457 return;
458 end
459
460 if (numberedCount > 18) then
461 toDelete = numberedCount - 18;
462
463 for i = 1, toDelete do
464 Queue:AddSQLToQueue("DELETE FROM gElo_History WHERE Date = (SELECT Date FROM gElo_History WHERE SteamID = '" .. id .. "' ORDER BY Date LIMIT 1) AND SteamID = '" .. id .. "' LIMIT 1");
465 end
466
467 Queue:AddSQLToQueue("UPDATE gElo_History_Count SET Count = Count - '" .. toDelete .. "' WHERE SteamID = '" .. id .. "'");
468 end
469 end);
470end
471
472---
473--- GetHistory
474---
475function gElo.GetHistory()
476 return history;
477end
478
479--[[------------------------------------------------------------------------------
480 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
481 * Unauthorized copying of this file, via any medium is strictly prohibited
482 * Proprietary and confidential
483--]]------------------------------------------------------------------------------
484
485local history = gElo.GetHistory();
486local roundTime = 0;
487
488hook.Add("PlayerInitialSpawn", "gElo.ResetVariablesOnSpawn", function(ply)
489 if (not IsValid(ply)) then return; end
490 if (ply:IsBot() and not gElo.UseDebug) then return; end
491
492 ply.ShouldUpdateHistory = true;
493 history:ResetPlayerVariables(ply);
494end);
495
496hook.Add("TTTBeginRound", "gElo.ResetVariables", function()
497 for _, v in ipairs(player.GetAll()) do
498 if (not IsValid(v) or v:IsBot() and not gElo.UseDebug) then continue; end
499 if (v:Team() == TEAM_SPEC) then
500 history:ResetPlayerVariables(v);
501
502 continue;
503 end
504
505 -- Reset player variables.
506 history:ResetPlayerVariables(v);
507
508 -- Set their role.
509 history:SetPlayerVariables(v, "Role", v:GetRoleStringRaw());
510 end
511end);
512
513hook.Add("TTTEndRound", "gElo.AddToHistory", function(result)
514 if (result == WIN_INNOCENT or result == WIN_TIMELIMIT) then
515 for _, v in ipairs(player.GetAll()) do
516 if (not IsValid(v) or not v.gEloCanAddStats or v:IsBot() and not gElo.UseDebug) then continue; end
517
518 history:SetPlayerVariables(v, "RoundTime", roundTime);
519 history:SetPlayerVariables(v, "Map", game.GetMap());
520 v.ShouldUpdateHistory = true;
521
522 if (v:IsTraitor()) then
523 history:SetPlayerVariables(v, "Won", false);
524
525 continue;
526 end
527
528 history:SetPlayerVariables(v, "Won", true);
529 end
530 elseif(result == WIN_TRAITOR) then
531 for _, v in ipairs(player.GetAll()) do
532 if (not IsValid(v) or not v.gEloCanAddStats or v:IsBot() and not gElo.UseDebug) then continue; end
533
534 history:SetPlayerVariables(v, "RoundTime", roundTime);
535 history:SetPlayerVariables(v, "Map", game.GetMap());
536 v.ShouldUpdateHistory = true;
537
538 if (v:IsTraitor()) then
539 history:SetPlayerVariables(v, "Won", true);
540
541 continue;
542 end
543
544 history:SetPlayerVariables(v, "Won", false);
545 end
546 end
547
548 for k, v in ipairs(player.GetAll()) do
549 if (not IsValid(v) or not v.gEloCanAddStats or v:IsBot() and not gElo.UseDebug) then continue; end
550
551 history:UpdatePlayer(v:SteamID64(), history.players[v:SteamID64()]);
552 end
553
554 roundTime = 0;
555end);
556
557hook.Add("PlayerDeath", "gElo.HistoryAddKills", function(victim, _, attacker)
558 if (not IsValid(victim) or victim:IsBot() and not gElo.UseDebug) then return; end
559 if (victim == attacker) then return; end
560 if (SpecDM and victim:IsGhost()) then return; end
561 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
562
563 -- Now we deal with the attacker, if he is valid and player..
564 if (not IsValid(attacker) or not attacker:IsPlayer()) then return; end
565
566 -- Add to attacker kills.
567 history:SetPlayerVariables(attacker, "Kills", history:GetPlayerVariables(attacker, "Kills") + 1);
568end);
569
570hook.Add("EntityTakeDamage", "gElo.AddToDamage", function(ent, dmg)
571 if (not IsValid(ent) or not ent:IsPlayer()) then return; end
572 if (ent:IsBot() and not gElo.UseDebug) then return; end
573 if (SpecDM and ent:IsGhost()) then return; end
574 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
575
576 local attacker = dmg:GetAttacker();
577 if (not IsValid(attacker) or not attacker:IsPlayer()) then return; end
578
579 local damage = dmg:GetDamage();
580 history:SetPlayerVariables(attacker, "DamageDealt", history:GetPlayerVariables(attacker, "DamageDealt") + math.Round(damage));
581end);
582
583hook.Add("EntityFireBullets", "gElo.AddHistoryBullets", function(ent)
584 if (not IsValid(ent) or not ent:IsPlayer()) then return; end
585 if (SpecDM and ent:IsGhost()) then return; end
586 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
587
588 history:SetPlayerVariables(ent, "Shots", history:GetPlayerVariables(ent, "Shots") + 1);
589end);
590
591local roundCur = CurTime();
592hook.Add("Tick", "gElo.RoundCounter", function()
593 if (GetRoundState() == ROUND_ACTIVE and roundCur < CurTime()) then
594 roundTime = roundTime + 1;
595 roundCur = CurTime() + 1;
596 end
597end);
598
599--[[------------------------------------------------------------------------------
600 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
601 * Unauthorized copying of this file, via any medium is strictly prohibited
602 * Proprietary and confidential
603--]]------------------------------------------------------------------------------
604
605util.AddNetworkString("gElo.GetMatchHistory");
606util.AddNetworkString("gElo.SendMatchHistory");
607util.AddNetworkString("gElo.SendOldHistory");
608util.AddNetworkString("gElo.SendHeaderError")
609
610net.Receive("gElo.GetMatchHistory", function(_, ply)
611 if (not IsValid(ply)) then return; end
612
613 if (not ply.ShouldUpdateHistory) then
614 net.Start("gElo.SendOldHistory") net.Send(ply)
615 net.Start("gElo.SendHeaderError");
616 net.WriteString("svHistoryNotUpdated");
617 net.Send(ply)
618
619 return;
620 end
621
622 local matches = sql.Query("SELECT * FROM gElo_History WHERE SteamID = '" .. ply:SteamID64() .. "' ORDER BY Date DESC");
623 if (matches == false or matches == nil or not next(matches)) then
624 net.Start("gElo.SendHeaderError");
625 net.WriteString("svHistoryNotPlayedAny");
626 net.Send(ply)
627 else
628 net.Start("gElo.SendMatchHistory")
629 net.WriteTable(matches)
630 net.Send(ply)
631 end
632
633 ply.ShouldUpdateHistory = false;
634end);
635
636--[[------------------------------------------------------------------------------
637 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
638 * Unauthorized copying of this file, via any medium is strictly prohibited
639 * Proprietary and confidential
640--]]------------------------------------------------------------------------------
641
642local PLAYER = FindMetaTable("Player");
643
644---
645--- GetRank
646---
647function PLAYER:gEloGetPlayerRank()
648 return self:GetNWString("gElo_Rank", "Bronze");
649end
650
651---
652--- GetElo
653---
654function PLAYER:gEloGetPlayerElo()
655 return self:GetNWInt("gElo_Elo", 1600);
656end
657
658---
659--- GetDivision
660---
661function PLAYER:gEloGetPlayerDivision()
662 return self:GetNWInt("gElo_Division", 5);
663end
664
665---
666--- GetRP
667---
668function PLAYER:gEloGetPlayerRP()
669 return self:GetNWInt("gElo_RP", 0);
670end
671
672--[[------------------------------------------------------------------------------
673 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
674 * Unauthorized copying of this file, via any medium is strictly prohibited
675 * Proprietary and confidential
676--]]------------------------------------------------------------------------------
677
678local EloColors = {
679 ["challenger"] = Color(222, 194, 104, 255),
680 ["masters"] = Color(163, 184, 186, 255),
681 ["diamond"] = Color(54, 118, 161, 255),
682 ["platinum"] = Color(76, 179, 138, 255),
683 ["gold"] = Color(240, 235, 80, 255),
684 ["silver"] = Color(238, 237, 227, 255),
685 ["bronze"] = Color(146, 89, 51, 255)
686}
687
688---
689--- EloToColor
690---
691function gElo.EloToColor(r)
692 r = string.lower(r);
693
694 return EloColors[r] or EloColors["bronze"]
695end
696
697--[[------------------------------------------------------------------------------
698 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
699 * Unauthorized copying of this file, via any medium is strictly prohibited
700 * Proprietary and confidential
701--]]------------------------------------------------------------------------------
702
703util.AddNetworkString("gElo.RankInterface");
704util.AddNetworkString("gElo.SeriesInterface");
705
706local ELO = {};
707local SQL = gElo.GetSQL();
708
709-- R = Rank; E = Elo; D = Division;
710ELO.Ranks = {
711 {r = "Challenger", e = 4000, d = 1},
712 {r = "Masters", e = 3000, d = 1},
713
714 -- Diamond
715 {r = "Diamond", e = 2800, d = 1},
716 {r = "Diamond", e = 2750, d = 2},
717 {r = "Diamond", e = 2700, d = 3},
718 {r = "Diamond", e = 2650, d = 4},
719 {r = "Diamond", e = 2600, d = 5},
720
721 -- Platinum
722 {r = "Platinum", e = 2550, d = 1},
723 {r = "Platinum", e = 2500, d = 2},
724 {r = "Platinum", e = 2450, d = 3},
725 {r = "Platinum", e = 2400, d = 4},
726 {r = "Platinum", e = 2350, d = 5},
727
728 -- Gold
729 {r = "Gold", e = 2300, d = 1},
730 {r = "Gold", e = 2250, d = 2},
731 {r = "Gold", e = 2200, d = 3},
732 {r = "Gold", e = 2150, d = 4},
733 {r = "Gold", e = 2100, d = 5},
734
735 -- Silver
736 {r = "Silver", e = 2050, d = 1},
737 {r = "Silver", e = 2000, d = 2},
738 {r = "Silver", e = 1950, d = 3},
739 {r = "Silver", e = 1900, d = 4},
740 {r = "Silver", e = 1850, d = 5},
741
742 -- Bronze
743 {r = "Bronze", e = 1800, d = 1},
744 {r = "Bronze", e = 1750, d = 2},
745 {r = "Bronze", e = 1700, d = 3},
746 {r = "Bronze", e = 1650, d = 4},
747 {r = "Bronze", e = 1600, d = 5},
748}
749
750---
751--- SetCalculatedRank
752---
753function ELO:SetCalculatedRank(ply)
754 if (not IsValid(ply)) then
755 return false;
756 end
757
758 self.Elo = sql.QueryRow("SELECT Elo FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
759 if (self.Elo == false or self.Elo == nil or not next(self.Elo)) then
760 net.Start("gElo.SendMenuError")
761 net.WriteString("svEloUnableToStats")
762 net.Send(ply)
763
764 return false;
765 end
766
767 self.Elo = tonumber(self.Elo["Elo"]);
768 if (self.Elo >= 4000) then
769 ply:SetNWString("gElo_Rank", "Challenger");
770 ply:SetNWInt("gElo_Division", 1);
771 ply:SetNWInt("gElo_Elo", self.Elo);
772
773 return true;
774 end
775
776 if (self.Elo >= 3000) then
777 ply:SetNWString("gElo_Rank", "Masters");
778 ply:SetNWInt("gElo_Division", 1);
779 ply:SetNWInt("gElo_Elo", self.Elo);
780
781 return true;
782 end
783
784 if (self.Elo >= 2800 and self.Elo < 3000) then
785 ply:SetNWString("gElo_Rank", "Diamond");
786 ply:SetNWInt("gElo_Division", 1);
787 ply:SetNWInt("gElo_Elo", self.Elo);
788
789 return true;
790 end
791
792 for k, v in ipairs(ELO.Ranks) do
793 if (v.e == self.Elo) then
794 ply:SetNWString("gElo_Rank", v.r);
795 ply:SetNWInt("gElo_Division", v.d);
796 ply:SetNWInt("gElo_Elo", v.e);
797
798 return true;
799 end
800 end
801
802 net.Start("gElo.SendMenuError")
803 net.WriteString("svEloUnableToElo")
804 net.Send(ply)
805
806 return false;
807end
808
809---
810--- PromotePlayer
811---
812function ELO:PromotePlayer(ply)
813 -- No reason to do an sql query to retreive the elo,
814 -- We can just ue NWInt as NWInt is always up-to-date.
815 self.NextRank = (ply:GetNWInt("gElo_Elo", 1600) + 50);
816
817 -- If we find the next rank name in our table then it means we've been promoted
818 for k, v in ipairs(ELO.Ranks) do
819 if (v.e == self.NextRank) then
820 sql.Query("UPDATE gElo_Stats SET Elo = '" .. self.NextRank .. "', Rank = '" .. v.r .. "', Division = '" .. v.d .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
821 sql.Query("UPDATE gElo_Stats SET PromoWins = '0' WHERE SteamID = '" .. ply:SteamID64() .. "'");
822
823 self:SetCalculatedRank(ply);
824
825 gElo.DebugPrint("[ELO][Promoted]: Successfully promoted " .. ply:Nick() .. " to " .. v.r .. "(" .. v.e .. "); Division: " .. v.d);
826 gElo.ChatPrint("GLOBAL", "good", ply:Nick() .. " has been promoted to " .. v.r .. "(" .. v.e .. ")");
827
828 net.Start("gElo.RankInterface")
829 net.WriteBool(true);
830 net.WriteString(string.lower(v.r));
831 net.WriteUInt(v.d, 4);
832 net.Send(ply)
833
834 return true;
835 end
836 end
837
838 -- If we HAVEN'T found our rank in the table then it means we didn't gain any ranks just ELO.
839 -- This is useful because we don't want the player to be stopped even though he is Challenger,
840 -- We can keep going because of this.
841 sql.Query("UPDATE gElo_Stats SET Elo = '" .. self.NextRank .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
842
843 self:TakePlayerRP(ply, 100, true);
844 ply:SetNWInt("gElo_Elo", self.NextRank);
845
846 gElo.DebugPrint("[ELO][Promoted]: Successfully added 50 elo to " .. ply:Nick() .. "'s elo. No promotion though.");
847
848 if (self.NextRank > 2800 and self.NextRank < 3000) then
849 gElo.ChatPrint(ply, "good", "You have gained 50 ELO instead of a promotion; Next promotion at 3000 ELO");
850 end
851
852 if (self.NextRank > 3000 and self.NextRank < 4000) then
853 gElo.ChatPrint(ply, "good", "You have gained 50 ELO instead of a promotion; Next promotion at 4000 ELO");
854 end
855
856 return true;
857end
858
859---
860--- DemotePlayer
861---
862function ELO:DemotePlayer(ply)
863 self.PreviousRank = (ply:GetNWInt("gElo_Elo", 1600) - 50);
864 self.CurrentDivision = ply:GetNWInt("gElo_Division", 5);
865 self.CurrentRank = ply:GetNWString("gElo_Rank", "Bronze");
866 self.CurrentElo = ply:GetNWString("gElo_Elo", 1600);
867
868 if (self.PreviousRank < 1600) then
869 gElo.DebugPrint("[ELO][Demoted]: Can't deduct more ELO from " .. ply:Nick() .. " as its already at its lowest.");
870
871 return false;
872 end
873
874 for k, v in ipairs(ELO.Ranks) do
875 if (v.e == self.PreviousRank and (v.d ~= self.CurrentDivision or v.r ~= self.CurrentRank)) then
876 sql.Query("UPDATE gElo_Stats SET Elo = '" .. self.PreviousRank .. "', Rank = '" .. v.r .. "', Division = '" .. v.d .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
877
878 self:SetCalculatedRank(ply);
879
880 net.Start("gElo.RankInterface")
881 net.WriteBool(false);
882 net.WriteString(string.lower(v.r));
883 net.WriteUInt(v.d, 4);
884 net.Send(ply)
885
886 gElo.DebugPrint("[ELO][Demoted]: Successfully demoted " .. ply:Nick() .. " to " .. v.r .. "(" .. v.e .. "); Division: " .. v.d);
887 gElo.ChatPrint("GLOBAL", "bad", ply:Nick() .. " has been demoted to " .. v.r .. "(" .. v.e .. ")");
888
889 return true;
890 end
891 end
892
893 -- We have to do this if check due to our super rank, Challenger.
894 if (self.PreviousRank > 3000 and self.CurrentElo == 4000) then
895 ply:SetNWInt("gElo_Elo", self.PreviousRank);
896 ply:SetNWString("gElo_Rank", "Masters");
897 ply:SetNWInt("gElo_Division", 1);
898
899 sql.Query("UPDATE gElo_Stats SET Elo = '" .. self.PreviousRank .. "', Rank = 'Masters', Division = '1' WHERE SteamID = '" .. ply:SteamID64() .. "'");
900
901 gElo.DebugPrint("[ELO][Demoted]: Successfully demoted " .. ply:Nick() .. " to Masters(" .. self.PreviousRank .. "); Division: 1");
902 gElo.ChatPrint("GLOBAL", "bad", ply:Nick() .. " has been demoted to Masters 1");
903
904 net.Start("gElo.RankInterface")
905 net.WriteBool(false);
906 net.WriteString(string.lower("masters"));
907 net.WriteUInt(1, 4);
908 net.Send(ply)
909
910 return true;
911 end
912
913 -- We have to do this if check due to our super rank, Masters.
914 if (self.PreviousRank < 3000 and self.CurrentElo >= 3000) then
915 ply:SetNWInt("gElo_Elo", self.PreviousRank);
916 ply:SetNWString("gElo_Rank", "Diamond");
917 ply:SetNWInt("gElo_Division", 1);
918
919 sql.Query("UPDATE gElo_Stats SET Elo = '" .. self.PreviousRank .. "', Rank = 'Diamond', Division = '1' WHERE SteamID = '" .. ply:SteamID64() .. "'");
920
921 gElo.DebugPrint("[ELO][Demoted]: Successfully demoted " .. ply:Nick() .. " to Diamond(" .. self.PreviousRank .. "); Division: 1");
922 gElo.ChatPrint("GLOBAL", "bad", ply:Nick() .. " has been demoted to Diamond 1");
923
924 net.Start("gElo.RankInterface")
925 net.WriteBool(false);
926 net.WriteString(string.lower("diamond"));
927 net.WriteUInt(1, 4);
928 net.Send(ply)
929
930 return true;
931 end
932
933 gElo.DebugPrint("[ELO][Demoted]: Successfully deducted 50 elo from " .. ply:Nick() .. "'s elo. No demotion though.");
934 ply:SetNWInt("gElo_Elo", self.PreviousRank);
935 sql.Query("UPDATE gElo_Stats SET Elo = '" .. self.PreviousRank .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
936
937 return true;
938end
939
940---
941--- SetIsInPromos
942---
943function ELO:SetIsInPromos(ply, bool)
944 if (not IsValid(ply)) then
945 return false;
946 end
947
948 sql.Query("UPDATE gElo_Stats SET Promos = '" .. tostring(bool) .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
949 ply:SetNWBool("gElo_IsInPromos", bool);
950end
951
952---
953--- GetIsInPromos
954---
955function ELO:GetIsInPromos(ply)
956 if (not IsValid(ply)) then
957 return false;
958 end
959
960 return ply:GetNWBool("gElo_IsInPromos", false);
961end
962
963---
964--- IsLowestRank
965---
966function ELO:IsLowestRank(ply)
967 if (not IsValid(ply)) then
968 return false;
969 end
970
971 return ply:GetNWString("gElo_Rank", "Bronze") == "Bronze" and ply:GetNWInt("gElo_Division", 5) == 5;
972end
973
974---
975--- NotifyAboutPromo
976---
977function ELO:NotifyAboutPromo(ply, wins, losses)
978 if (wins == 1 and losses == 1) then
979 net.Start("gElo.SeriesInterface")
980 net.WriteString("svEloLastChance");
981 net.WriteString("svEloGoodLuck");
982 net.WriteBool(true);
983 net.Send(ply)
984
985 return true;
986 end
987
988 if (wins == 1 and losses == 0) then
989 net.Start("gElo.SeriesInterface")
990 net.WriteString("svEloOneMoreWin");
991 net.WriteString("svEloGoodLuck");
992 net.WriteBool(true);
993 net.Send(ply)
994
995 return true;
996 end
997
998 if (wins == 0 and losses == 1) then
999 net.Start("gElo.SeriesInterface")
1000 net.WriteString("svEloOneMoreLoss");
1001 net.WriteString("svEloGoodLuck");
1002 net.WriteBool(false);
1003 net.Send(ply)
1004
1005 return true;
1006 end
1007
1008 return false;
1009end
1010
1011---
1012--- GivePlayerRP
1013---
1014function ELO:GivePlayerRP(ply, rp)
1015 if (not IsValid(ply)) then
1016 return false;
1017 end
1018
1019 if (not isnumber(rp)) then
1020 return false;
1021 end
1022
1023 if (rp < 0) then
1024 rp = 0;
1025 end
1026
1027 if (self:GetIsInPromos(ply)) then
1028 gElo.DebugPrint("We're in promos so we don't need more RP");
1029 gElo.DebugPrint("Current RP: " .. ply:GetNWInt("gElo_RP"));
1030
1031 -- Since we're in promos, we're gonna add one win to our promos instead of giving RP, as RP is not needed when we're.. in promos.
1032 -- First we have to get how many we've won.
1033 local CurrentWins = sql.QueryRow("SELECT PromoWins FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1034 if (CurrentWins ~= false and CurrentWins ~= nil) then
1035 CurrentWins = tonumber(CurrentWins["PromoWins"]);
1036
1037 if (CurrentWins + 1 == 2) then
1038 self:SetIsInPromos(ply, false);
1039 self:PromotePlayer(ply);
1040 self:TakePlayerRP(ply, 100, true);
1041
1042 return true;
1043 end
1044
1045 sql.Query("UPDATE gElo_Stats SET PromoWins = PromoWins + '1' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1046
1047 local promoStatus = sql.QueryRow("SELECT PromoWins, PromoLoss FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1048 if (promoStatus ~= false and promoStatus ~= nil) then
1049 local wins = tonumber(promoStatus["PromoWins"]);
1050 local losses = tonumber(promoStatus["PromoLoss"]);
1051
1052 self:NotifyAboutPromo(ply, wins, losses);
1053 end
1054
1055 return true;
1056 end
1057
1058 return true;
1059 end
1060
1061 -- Reset the LossAtZeroRP Counter
1062 sql.Query("UPDATE gElo_Stats SET LossAtZeroRP = '0' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1063 sql.Query("UPDATE gElo_Stats SET PromoLoss = '0' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1064
1065 gElo.DebugPrint("We're not in promos.")
1066
1067 self.RP = (ply:GetNWInt("gElo_RP", 0) + rp);
1068 if (self.RP >= 100) then
1069 self.RP = 100;
1070
1071 sql.Query("UPDATE gElo_Stats SET RP = '" .. self.RP .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1072
1073 self:SetIsInPromos(ply, true);
1074 ply:SetNWInt("gElo_RP", self.RP);
1075
1076 net.Start("gElo.SeriesInterface")
1077 net.WriteString("svEloPromtionalSeries");
1078 net.WriteString("svEloGoodLuck");
1079 net.WriteBool(true);
1080 net.Send(ply)
1081
1082 gElo.DebugPrint("Our RP is 100 and we weren't in promos, we are now, though.");
1083
1084 return true;
1085 end
1086
1087 sql.Query("UPDATE gElo_Stats SET RP = '" .. self.RP .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1088 ply:SetNWInt("gElo_RP", self.RP);
1089
1090 gElo.DebugPrint("Our RP Is: " .. ply:GetNWInt("gElo_RP"));
1091 return true;
1092end
1093
1094---
1095--- TakePlayerRP
1096---
1097function ELO:TakePlayerRP(ply, rp, skipRaw)
1098 if (not IsValid(ply)) then
1099 return false;
1100 end
1101
1102 if (self:GetIsInPromos(ply)) then
1103 -- If we're in promos then we'll add one to our promo loss also.
1104 -- unless we've lost two times, if we have then we don't promote.
1105
1106 local CurrentLosses = sql.QueryRow("SELECT PromoLoss FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1107 if (CurrentLosses ~= false and CurrentLosses ~= nil) then
1108 CurrentLosses = tonumber(CurrentLosses["PromoLoss"]);
1109
1110 if (CurrentLosses + 1 == 2) then
1111 self:SetIsInPromos(ply, false);
1112 self:TakePlayerRP(ply, 50);
1113
1114 net.Start("gElo.SeriesInterface")
1115 net.WriteString("svEloUnsuccessfulSeries");
1116 net.WriteString("svEloBetterLuckNextTime");
1117 net.WriteBool(false);
1118 net.Send(ply)
1119
1120 return true;
1121 end
1122
1123 sql.Query("UPDATE gElo_Stats SET PromoLoss = PromoLoss + '1' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1124
1125 local promoStatus = sql.QueryRow("SELECT PromoWins, PromoLoss FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1126 if (promoStatus ~= false and promoStatus ~= nil) then
1127 local wins = tonumber(promoStatus["PromoWins"]);
1128 local losses = tonumber(promoStatus["PromoLoss"]);
1129
1130 self:NotifyAboutPromo(ply, wins, losses);
1131 end
1132
1133 return true;
1134 end
1135 end
1136
1137 self.RPRaw = ply:GetNWInt("gElo_RP", 0);
1138 self.RP = (ply:GetNWInt("gElo_RP", 0) - rp);
1139 if (self.RP < 0) then
1140 if (self.RPRaw == 0 and not self:IsLowestRank(ply) and not skipRaw) then
1141 sql.Query("UPDATE gElo_Stats SET LossAtZeroRP = LossAtZeroRP + '1' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1142 local zeroRP = sql.QueryRow("SELECT LossAtZeroRP FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1143
1144 if (zeroRP ~= false and zeroRP ~= nil) then
1145 if (tonumber(zeroRP["LossAtZeroRP"]) >= 2) then
1146
1147 self:DemotePlayer(ply);
1148 self:GivePlayerRP(ply, 75);
1149
1150 return true;
1151 end
1152 end
1153
1154 return true;
1155 end
1156
1157 self.RP = 0;
1158 end
1159
1160 sql.Query("UPDATE gElo_Stats SET RP = '" .. self.RP .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
1161 ply:SetNWInt("gElo_RP", self.RP);
1162
1163 gElo.DebugPrint("Successfully took " .. rp .. " from " .. ply:Nick());
1164 gElo.DebugPrint("Our RP Is: " .. ply:GetNWInt("gElo_RP"));
1165
1166 return true;
1167end
1168
1169---
1170--- SetRank
1171---
1172function ELO:SetRank(ply, elo, admin)
1173 local steamid;
1174 local storedPlayer;
1175
1176 if (isstring(ply)) then
1177 storedPlayer = player.GetBySteamID64(ply);
1178 end
1179
1180 if (IsValid(storedPlayer)) then
1181 steamid = storedPlayer:SteamID64();
1182 else
1183 if (isstring(ply)) then
1184 steamid = ply;
1185 else
1186 return false;
1187 end
1188 end
1189
1190 for k, v in ipairs(ELO.Ranks) do
1191 if (v.e == elo) then
1192 sql.Query(SQL:FormatSQL("UPDATE gElo_Stats SET Elo = '" .. v.e .. "', Rank = '" .. v.r .. "', Division = '" .. v.d .. "' WHERE SteamID = '%s'", steamid));
1193 sql.Query(SQL:FormatSQL("UPDATE gElo_Stats SET PromoWins = '0' WHERE SteamID = '%s'", steamid));
1194
1195 if (IsValid(storedPlayer)) then
1196 storedPlayer:SetNWString("gElo_Rank", v.r);
1197 storedPlayer:SetNWInt("gElo_Division", v.d);
1198 storedPlayer:SetNWInt("gElo_Elo", v.e);
1199
1200 if (IsValid(admin)) then
1201 gElo.ChatPrint("GLOBAL", "good", admin:Nick() .. " has set " .. storedPlayer:Nick() .. "'s rank to " .. v.r .. " " .. v.d .. " [" .. v.e .. "]");
1202 end
1203 end
1204
1205 return true;
1206 end
1207 end
1208
1209 return false;
1210end
1211
1212---
1213--- SetRP
1214---
1215function ELO:SetRP(ply, rp, admin)
1216 local steamid;
1217 local storedPlayer;
1218
1219 if (isstring(ply)) then
1220 storedPlayer = player.GetBySteamID64(ply);
1221 end
1222
1223 if (IsValid(storedPlayer)) then
1224 steamid = storedPlayer:SteamID64();
1225 else
1226 if (isstring(ply)) then
1227 steamid = ply;
1228 else
1229 return false;
1230 end
1231 end
1232
1233 if (isnumber(rp)) then
1234 sql.Query(SQL:FormatSQL("UPDATE gElo_Stats SET RP = '%s' WHERE SteamID = '%s'", rp, steamid));
1235
1236 if (IsValid(storedPlayer)) then
1237 storedPlayer:SetNWInt("gElo_RP", rp);
1238
1239 if (IsValid(admin)) then
1240 gElo.ChatPrint("GLOBAL", "good", admin:Nick() .. " has set " .. storedPlayer:Nick() .. "'s RP to " .. rp);
1241 end
1242 end
1243
1244 return true;
1245 end
1246
1247 return false;
1248end
1249
1250---
1251--- GetElo
1252---
1253function gElo.GetElo()
1254 return ELO;
1255end
1256
1257--[[------------------------------------------------------------------------------
1258 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
1259 * Unauthorized copying of this file, via any medium is strictly prohibited
1260 * Proprietary and confidential
1261--]]------------------------------------------------------------------------------
1262
1263local ELO = gElo.GetElo();
1264local history = gElo.GetHistory();
1265local CalculatedRP = {};
1266local canUpdate = false;
1267
1268---
1269--- ResetRPVariables
1270---
1271local function ResetRPVariables(ply)
1272 if (not IsValid(ply)) then return; end
1273
1274 CalculatedRP[ply:SteamID64()] = {};
1275 local CRP = CalculatedRP[ply:SteamID64()];
1276
1277 -- Reset everything;
1278 CRP["Kills"] = 0;
1279 CRP["DamageDealt"] = 0;
1280 CRP["FireDamageDealt"] = 0;
1281 CRP["Headshots"] = 0;
1282 CRP["MeleeKills"] = 0;
1283 CRP["WonRound"] = false;
1284 CRP["TeamKills"] = 0;
1285end
1286
1287---
1288--- GetCRP
1289---
1290local function GetCRP(ply)
1291 if (not IsValid(ply)) then return; end
1292
1293 if (CalculatedRP[ply:SteamID64()]) then
1294 return CalculatedRP[ply:SteamID64()];
1295 end
1296
1297 return false;
1298end
1299
1300hook.Add("PlayerInitialSpawn", "gElo.RetreiveRanking", function(ply)
1301 timer.Simple(1, function()
1302 if (not IsValid(ply) or ply:IsBot() and not gElo.UseDebug) then return; end
1303
1304 ResetRPVariables(ply);
1305
1306 local IsAuthed = ELO:SetCalculatedRank(ply);
1307 if (IsAuthed) then
1308 ply.gEloIsPlayerAuthed = true;
1309 else
1310 ply.gEloIsPlayerAuthed = false;
1311 end
1312
1313 local RP = sql.QueryRow("SELECT RP FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1314 if (RP == false or RP == nil) then
1315 ply.gEloIsPlayerAuthed = false;
1316 else
1317 ply:SetNWInt("gElo_RP", tonumber(RP["RP"]));
1318 ply.gEloIsPlayerAuthed = true;
1319 end
1320
1321 local Promos = sql.QueryRow("SELECT Promos FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1322 if (Promos == false or Promos == nil) then
1323 ply.gEloIsPlayerAuthed = false;
1324 else
1325 ply:SetNWBool("gElo_IsInPromos", tobool(Promos["Promos"]));
1326 ply.gEloIsPlayerAuthed = true;
1327 end
1328 end);
1329end);
1330
1331-- Here's where we calculate what to give the player.
1332hook.Add("PlayerDeath", "gElo.AddKillsToRP", function(victim, _, attacker)
1333 if (not IsValid(victim) or not IsValid(attacker)) then return; end
1334 if (not victim:IsPlayer() or not attacker:IsPlayer()) then return; end
1335 if (SpecDM and victim:IsGhost()) then return; end
1336 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
1337 if (victim:IsBot() and not gElo.UseDebug or attacker:IsBot() and not gElo.UseDebug) then return; end
1338
1339 local RP = GetCRP(attacker);
1340 if (not RP) then return; end
1341
1342 RP["Kills"] = RP["Kills"] + 1;
1343
1344 if (IsValid(attacker:GetActiveWeapon()) and attacker:GetActiveWeapon():GetHoldType() and attacker:GetActiveWeapon():GetHoldType() == "melee") then
1345 RP["MeleeKills"] = RP["MeleeKills"] + 1;
1346 end
1347
1348 if (victim:LastHitGroup() == HITGROUP_HEAD) then
1349 RP["Headshots"] = RP["Headshots"] + 1;
1350 end
1351
1352 if (victim:GetRole() == attacker:GetRole()) then
1353 RP["TeamKills"] = RP["TeamKills"] + 1;
1354 end
1355end);
1356
1357hook.Add("EntityTakeDamage", "gElo.AddDamageToRP", function(ent, dmg)
1358 if (not IsValid(ent) or not ent:IsPlayer()) then return; end
1359 if (SpecDM and ent:IsGhost()) then return; end
1360 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
1361 if (ent:IsBot() and not gElo.UseDebug) then return; end
1362
1363 local attacker = dmg:GetAttacker();
1364 if (not IsValid(attacker) or not attacker:IsPlayer()) then return; end
1365
1366 local damage = math.Round(dmg:GetDamage());
1367 local RP = GetCRP(attacker);
1368 if (not RP) then return; end
1369
1370 if (dmg:GetDamageType() == DMG_BURN) then
1371 RP["FireDamageDealt"] = RP["FireDamageDealt"] + damage;
1372 else
1373 RP["DamageDealt"] = RP["DamageDealt"] + damage;
1374 end
1375end);
1376
1377hook.Add("TTTBeginRound", "gElo.ResetRP", function()
1378 for _, v in ipairs(player.GetAll()) do
1379 if (not IsValid(v) or v:IsBot() and not gElo.UseDebug) then continue; end
1380
1381 ResetRPVariables(v);
1382 end
1383
1384 canUpdate = false;
1385end);
1386
1387hook.Add("TTTEndRound", "gElo.CalculateRPToGive", function(result)
1388 if (result == WIN_INNOCENT or result == WIN_TIMELIMIT) then
1389 for _, v in ipairs(player.GetAll()) do
1390 if (not IsValid(v) or not v.gEloCanAddStats or v:IsBot() and not gElo.UseDebug) then continue; end
1391
1392 local RP = GetCRP(v);
1393 if (not RP) then continue; end
1394
1395 if (v:IsTraitor()) then
1396 RP["WonRound"] = false;
1397 else
1398 RP["WonRound"] = true;
1399 end
1400 end
1401 elseif(result == WIN_TRAITOR) then
1402 for _, v in ipairs(player.GetAll()) do
1403 if (not IsValid(v) or not v.gEloCanAddStats or v:IsBot() and not gElo.UseDebug) then continue; end
1404
1405 local RP = GetCRP(v);
1406 if (not RP) then continue; end
1407
1408 if (v:IsTraitor()) then
1409 RP["WonRound"] = true;
1410 else
1411 RP["WonRound"] = false;
1412 end
1413 end
1414 end
1415
1416 for k, v in pairs(CalculatedRP) do
1417 local r = 0;
1418
1419 -- The reason why we do this is to balance out the RP,
1420 -- if the user dealt 10,000 damage that round then he would gain 100 RP and instantly get into promos
1421 -- fun ttt weapons deal 10000000000 damage instead of killing them the good way, this is also a fix for that
1422 -- This stops that, he can gain a max of 10 RP.
1423 if (v["DamageDealt"] > 2000) then
1424 v["DamageDealt"] = 2000;
1425 end
1426
1427 if (v["FireDamageDealt"] > 2000) then
1428 v["FireDamageDealt"] = 2000;
1429 end
1430
1431 local w = v["WonRound"];
1432 r = r + v["Kills"] * .5;
1433 r = r + v["DamageDealt"] * .005;
1434 r = r + v["FireDamageDealt"] * .06;
1435 r = r + v["Headshots"] * 1;
1436 r = r + (player.GetCount() * .1);
1437 r = r - (v["TeamKills"] * .5);
1438
1439 if (w) then
1440 if (v["TeamKills"] > 0) then
1441 r = math.Round(r);
1442 else
1443 r = math.Round(r * 2);
1444 end
1445 else
1446 local loseRatio = (player.GetCount() * .1);
1447 local toLose = 10 * loseRatio;
1448 toLose = toLose - r;
1449
1450 r = math.Round(toLose);
1451 end
1452
1453 local ply = player.GetBySteamID64(k);
1454 if (IsValid(ply) and ply.gEloCanAddStats) then
1455 if (w) then
1456 if (gElo.Config.EasyMode) then
1457 gElo.DebugPrint("Easy mode is enabled. We Won. Before: " .. r);
1458 r = r * 2;
1459 gElo.DebugPrint("After: " .. r);
1460 if (r < 0) then
1461 r = 0;
1462 end
1463 end
1464
1465 if (gElo.Config.MinPlayers > 0) then
1466 if (player.GetCount() >= gElo.Config.MinPlayers) then
1467 ELO:GivePlayerRP(ply, r);
1468 history:SetPlayerVariables(ply, "RP", r);
1469 else
1470 gElo.ChatPrint(ply, "warning", "You have not received your predicted rp of " .. r .. " this round due to minimum player limit not being reached.");
1471 end
1472 else
1473 ELO:GivePlayerRP(ply, r);
1474 history:SetPlayerVariables(ply, "RP", r);
1475 end
1476 else
1477 if (gElo.Config.EasyMode) then
1478 gElo.DebugPrint("Easy mode is enabled. We Lost. Before: " .. r);
1479 r = r / 2;
1480 gElo.DebugPrint("After: " .. r);
1481
1482 if (r < 0) then
1483 r = 0;
1484 end
1485 end
1486
1487 if (gElo.Config.MinPlayers > 0) then
1488 if (player.GetCount() >= gElo.Config.MinPlayers) then
1489 ELO:TakePlayerRP(ply, r);
1490 history:SetPlayerVariables(ply, "RP", -r);
1491 else
1492 gElo.ChatPrint(ply, "warning", "You have not received your predicted rp loss of " .. r .. " this round due to minimum player limit not being reached.");
1493 end
1494 else
1495 ELO:TakePlayerRP(ply, r);
1496 history:SetPlayerVariables(ply, "RP", -r);
1497 end
1498 end
1499 end
1500 end
1501
1502 canUpdate = true;
1503end);
1504
1505
1506--[[------------------------------------------------------------------------------
1507 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
1508 * Unauthorized copying of this file, via any medium is strictly prohibited
1509 * Proprietary and confidential
1510--]]------------------------------------------------------------------------------
1511
1512util.AddNetworkString("gElo.GetLeaderBoards");
1513util.AddNetworkString("gElo.SendLeaderBoards");
1514util.AddNetworkString("gElo.SendOldLeaderBoards");
1515
1516local SQL = gElo.GetSQL();
1517
1518net.Receive("gElo.GetLeaderBoards", function(_, ply)
1519 if (not IsValid(ply)) then return; end
1520
1521 local nextPage = net.ReadUInt(32);
1522 local sort = net.ReadUInt(8);
1523 local searchUser = net.ReadString();
1524 local canSkipCooldown = net.ReadBool();
1525 local toSort = "Elo";
1526 local shouldReplace = true;
1527
1528 if (ply.LeaderBoardsCooldown and ply.LeaderBoardsCooldown > CurTime() and not canSkipCooldown) then
1529 net.Start("gElo.SendOldLeaderBoards") net.Send(ply);
1530
1531 return;
1532 end
1533
1534 if (canSkipCooldown and ply.NextCooldown and ply.NextCooldown > CurTime()) then
1535 return;
1536 end
1537
1538 if (sort == 0) then
1539 toSort = "Elo";
1540 elseif(sort == 1) then
1541 toSort = "Kills";
1542 elseif(sort == 2) then
1543 toSort = "Deaths";
1544 elseif(sort == 3) then
1545 toSort = "TotalWins";
1546 elseif(sort == 4) then
1547 toSort = "TotalLosses"
1548 end
1549
1550 local users = {};
1551 local userCount = {};
1552 if (searchUser ~= "NULL") then
1553 if (searchUser:find("765611")) then
1554 users = sql.Query(SQL:FormatSQL("SELECT Name, SteamID, Elo, Rank, Kills, Deaths, TotalWins, TotalLosses, Division FROM gElo_Stats WHERE SteamID = '%s' LIMIT '%s' - 15, 14", searchUser, nextPage));
1555 userCount = ((users ~= false and users ~= nil) and #users or 0);
1556 shouldReplace = false;
1557 else
1558 users = sql.Query(SQL:FormatSQL("SELECT Name, SteamID, Elo, Rank, Kills, Deaths, TotalWins, TotalLosses, Division FROM gElo_Stats WHERE Name LIKE '%%%s%%' LIMIT '%s' - 15, 14", searchUser, nextPage));
1559 userCount = ((users ~= false and users ~= nil) and #users or 0);
1560 shouldReplace = false;
1561 end
1562 else
1563 users = sql.Query(SQL:FormatSQL("SELECT Name, SteamID, Elo, Rank, Kills, Deaths, TotalWins, TotalLosses, Division FROM gElo_Stats ORDER BY %s DESC LIMIT '%s' - 15, 14", toSort, nextPage));
1564 userCount = sql.QueryRow("SELECT Count(*) FROM gElo_Stats");
1565 userCount = tonumber(userCount["Count(*)"]);
1566 end
1567
1568 if (users == nil) then
1569 if (searchUser ~= "NULL") then
1570 net.Start("gElo.SendMenuError")
1571 net.WriteString("svLeaderUnableToFindUser;" .. tostring(searchUser));
1572 net.Send(ply)
1573 else
1574 net.Start("gElo.SendMenuError");
1575 net.WriteString("svEloNoMoreUsersFound");
1576 net.Send(ply)
1577 end
1578
1579 ply.NextCooldown = CurTime() + 2;
1580 return;
1581 end
1582
1583 local me = sql.QueryRow(SQL:FormatSQL("SELECT Name, Elo, Rank, Kills, Deaths, TotalWins, TotalLosses, Division FROM gElo_Stats WHERE SteamID = '%s' ORDER BY '%s'", ply:SteamID64(), toSort));
1584 local myPosition = -1;
1585
1586 -- I have no idea how I can achieve this in SQL, I've literally been stuck at this problem for one whole day.
1587 -- I can't do anything else unless this is fixed so I will be doing this for now, however, it will change on a later date... Hopefully... If I find the solution
1588 local tablePositions = sql.Query("SELECT Elo, SteamID FROM gElo_Stats ORDER BY Elo DESC");
1589 local count = table.Count(tablePositions);
1590
1591 for i = 1, count do
1592 local tbl = tablePositions[i];
1593
1594 if (ply:SteamID64() == tbl.SteamID) then
1595 myPosition = i;
1596
1597 break;
1598 end
1599 end
1600
1601 local userCountFound = 0;
1602 for i = 1, count do
1603 local tbl = tablePositions[i];
1604
1605 for s = 1, #users do
1606 local user = users[s];
1607
1608 if (user["SteamID"] == tbl.SteamID) then
1609 user["Position"] = i;
1610 userCountFound = userCountFound + 1;
1611 end
1612 end
1613
1614 if (userCountFound >= 15) then
1615 break;
1616 end
1617 end
1618
1619 net.Start("gElo.SendLeaderBoards")
1620 net.WriteBool(shouldReplace)
1621 net.WriteUInt(myPosition, 32);
1622 net.WriteTable(me);
1623 net.WriteTable(users);
1624 net.WriteUInt(userCount, 32);
1625 net.Send(ply)
1626
1627 if (canSkipCooldown) then
1628 ply.NextCooldown = CurTime() + 2;
1629 end
1630
1631 if (shouldReplace) then
1632 ply.LeaderBoardsCooldown = CurTime() + 600
1633 end
1634end);
1635
1636--[[------------------------------------------------------------------------------
1637 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
1638 * Unauthorized copying of this file, via any medium is strictly prohibited
1639 * Proprietary and confidential
1640--]]------------------------------------------------------------------------------
1641
1642local settings = {};
1643settings.default = {
1644 ["ui"] = {
1645 -- UI Settings
1646 ["language"] = "en",
1647 ["lang_fancy"] = "thisLanguage",
1648 --
1649
1650 -- Main
1651 ["main_outline"] = Color(57, 64, 78, 200),
1652 ["main_background"] = Color(255, 255, 255, 255),
1653 ["main_header"] = Color(255, 255, 255, 255),
1654 ["notifcation_text"] = Color(200, 200, 200, 200),
1655 ["elo_text"] = Color(0, 127, 255, 255),
1656 ["other_text"] = Color(230, 230, 230, 255),
1657
1658 -- Buttons
1659 ["main_button_background"] = Color(0, 0, 0, 50),
1660 ["main_button_text"] = Color(17, 154, 255),
1661 ["main_button_text_hover"] = Color(255, 255, 255, 255),
1662 ["main_button_outline"] = Color(255, 255, 255, 255),
1663 --
1664 --
1665
1666 -- Settings
1667 ["settings_footer"] = Color(36, 48, 64, 255),
1668 ["settings_containers"] = Color(57, 64, 78, 200),
1669 --
1670
1671 -- Side Bar
1672 ["button_hover"] = Color(230, 230, 230, 255),
1673 ["button_non_hover"] = Color(150, 150, 150, 255),
1674 --
1675
1676 -- Notifications
1677 ["notification_color"] = true,
1678 --
1679
1680 -- Menu Key
1681 ["gelo_menu"] = KEY_G,
1682 --
1683
1684 -- Size
1685 ["gelo_menu_size_x"] = 1200,
1686 ["gelo_menu_size_y"] = 750,
1687 --
1688
1689 }
1690}
1691
1692---
1693--- CreateDefaultSettings
1694---
1695function settings:CreateDefaultSettings()
1696 if (not IsValid(LocalPlayer())) then
1697 return false;
1698 end
1699
1700 if (file.Exists("gelo_settings.txt", "DATA")) then
1701 file.Delete("gelo_settings.txt");
1702 end
1703
1704 local json = util.TableToJSON(settings.default);
1705 file.Write("gelo_settings.txt", json);
1706
1707 return true;
1708end
1709
1710---
1711--- Exists
1712---
1713function settings:Exists()
1714 if (not IsValid(LocalPlayer())) then
1715 return false;
1716 end
1717
1718 if (file.Exists("gelo_settings.txt", "DATA")) then
1719 return true;
1720 end
1721
1722 return false;
1723end
1724
1725---
1726--- GetSettingsValue
1727---
1728function settings:GetSettingsValue(holder, value)
1729 if (not IsValid(LocalPlayer())) then
1730 return false;
1731 end
1732
1733 if (not self:Exists()) then
1734 self:CreateDefaultSettings();
1735 end
1736
1737 local settingsFile = file.Read("gelo_settings.txt", "DATA");
1738 local json = util.JSONToTable(settingsFile);
1739
1740 if (not json[holder]) then
1741 return false;
1742 end
1743
1744 if (not tostring(json[holder][value])) then
1745 return false;
1746 end
1747
1748 return json[holder][value], type(json[holder][value]);
1749end
1750
1751---
1752--- SetSettingsValue
1753---
1754function settings:SetSettingsValue(holder, value, set)
1755 if (not IsValid(LocalPlayer())) then
1756 return false;
1757 end
1758
1759 if (not self:Exists()) then
1760 self:CreateDefaultSettings();
1761 end
1762
1763 local settingsFile = file.Read("gelo_settings.txt", "DATA");
1764 local json = util.JSONToTable(settingsFile);
1765
1766 if (not json[holder]) then
1767 return false;
1768 end
1769
1770 if (not tostring(json[holder][value])) then
1771 return false;
1772 end
1773
1774 json[holder][value] = set;
1775
1776 -- Now that we've changed the value in the table
1777 -- We have to turn it into JSON again and write to data
1778
1779 file.Write("gelo_settings.txt", util.TableToJSON(json));
1780 return true;
1781end
1782
1783---
1784--- GetAllSettingsValues
1785---
1786function settings:GetAllSettingsValues()
1787 if (not IsValid(LocalPlayer())) then
1788 return false;
1789 end
1790
1791 if (not self:Exists()) then
1792 self:CreateDefaultSettings();
1793 end
1794
1795 local settingsFile = file.Read("gelo_settings.txt", "DATA");
1796 local json = util.JSONToTable(settingsFile);
1797
1798 return json;
1799end
1800
1801---
1802--- ValidateSettings
1803---
1804function settings:ValidateSettings()
1805 if (not IsValid(LocalPlayer())) then
1806 return false;
1807 end
1808
1809 if (not self:Exists()) then
1810 self:CreateDefaultSettings();
1811 end
1812
1813 local settingsFile = file.Read("gelo_settings.txt", "DATA");
1814 local json = util.JSONToTable(settingsFile);
1815
1816 if (not json or not next(json)) then
1817 self:CreateDefaultSettings();
1818
1819 return false;
1820 end
1821
1822 for k, v in pairs(settings.default) do
1823 for element, value in pairs(v) do
1824 if (not json[k][element]) then
1825 json[k][element] = value;
1826 end
1827 end
1828 end
1829
1830 file.Write("gelo_settings.txt", util.TableToJSON(json));
1831end
1832
1833---
1834--- GetSettings
1835---
1836function gElo.GetSettings()
1837 return settings;
1838end
1839
1840---
1841--- InitPostEntity
1842---
1843hook.Add("InitPostEntity", "gElo.CreateSettingsFile", function()
1844 if (settings:Exists()) then
1845 settings:ValidateSettings();
1846 return;
1847 end
1848
1849 settings:CreateDefaultSettings();
1850end);
1851
1852--[[------------------------------------------------------------------------------
1853 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
1854 * Unauthorized copying of this file, via any medium is strictly prohibited
1855 * Proprietary and confidential
1856--]]------------------------------------------------------------------------------
1857
1858util.AddNetworkString("gElo.GetProfileStats");
1859util.AddNetworkString("gElo.SendProfileStats");
1860util.AddNetworkString("gElo.LookupUserAll");
1861util.AddNetworkString("gElo.SendLookedupUsers");
1862util.AddNetworkString("gElo.SendMenuError");
1863
1864local SQL = gElo.GetSQL();
1865
1866net.Receive("gElo.GetProfileStats", function(_, ply)
1867 if (not IsValid(ply) or not ply.CanUpdateProfile) then return; end
1868
1869 local statsQuery = sql.QueryRow("SELECT * FROM gElo_Stats WHERE SteamID = '" .. ply:SteamID64() .. "'");
1870 local combat = {};
1871 local innocent = {};
1872 local detective = {};
1873 local traitor = {};
1874 local general = {};
1875
1876 -- Ugly way but only way as I want to sort them to my liking later on
1877 -- Since we're using a table inside of another table we can't use table.sort...
1878 -- u will get error,.
1879 for k, v in pairs(statsQuery) do
1880 if (k:lower():find("innocent")) then
1881 if (k == "InnocentKills") then
1882 innocent[1] = {stat = k, num = v};
1883 elseif(k == "InnocentDeaths") then
1884 innocent[2] = {stat = k, num = v};
1885 elseif(k == "InnocentWins") then
1886 innocent[3] = {stat = k, num = v};
1887 elseif(k == "InnocentLosses") then
1888 innocent[4] = {stat = k, num = v};
1889 else
1890 innocent[5] = {stat = k, num = v};
1891 end
1892 end
1893
1894 if (k:lower():find("detective")) then
1895 if (k == "DetectiveKills") then
1896 detective[1] = {stat = k, num = v};
1897 elseif(k == "DetectiveDeaths") then
1898 detective[2] = {stat = k, num = v};
1899 elseif(k == "DetectiveWins") then
1900 detective[3] = {stat = k, num = v};
1901 elseif(k == "DetectiveLosses") then
1902 detective[4] = {stat = k, num = v};
1903 else
1904 detective[5] = {stat = k, num = v};
1905 end
1906 end
1907
1908 if (k:lower():find("traitor")) then
1909 if (k == "TraitorKills") then
1910 traitor[1] = {stat = k, num = v};
1911 elseif(k == "TraitorDeaths") then
1912 traitor[2] = {stat = k, num = v};
1913 elseif(k == "TraitorWins") then
1914 traitor[3] = {stat = k, num = v};
1915 elseif(k == "TraitorLosses") then
1916 traitor[4] = {stat = k, num = v};
1917 else
1918 traitor[5] = {stat = k, num = v};
1919 end
1920 end
1921
1922 if (k == "Kills") then
1923 combat[1] = {stat = k, num = v};
1924 elseif(k == "Deaths") then
1925 combat[2] = {stat = k, num = v};
1926 elseif(k == "Headshots") then
1927 combat[3] = {stat = k, num = v};
1928 elseif(k == "FireDamageDealt") then
1929 combat[4] = {stat = k, num = v};
1930 elseif(k == "DamageDealt") then
1931 combat[5] = {stat = k, num = v};
1932 end
1933
1934 if (k == "TotalWins") then
1935 general[1] = {stat = k, num = v};
1936 elseif(k == "TotalLosses") then
1937 general[2] = {stat = k, num = v};
1938 elseif(k == "RoundsPlayed") then
1939 general[3] = {stat = k, num = v};
1940 elseif(k == "BulletsFired") then
1941 general[4] = {stat = k, num = v};
1942 elseif(k == "Elo") then
1943 general[5] = {stat = k, num = v};
1944 end
1945 end
1946
1947 net.Start("gElo.SendProfileStats");
1948 net.WriteTable(combat);
1949 net.WriteTable(innocent);
1950 net.WriteTable(detective);
1951 net.WriteTable(traitor);
1952 net.WriteTable(general);
1953 net.Send(ply);
1954
1955 ply.CanUpdateProfile = false;
1956end);
1957
1958net.Receive("gElo.LookupUserAll", function(_, ply)
1959 if (not gElo.Config.UIAdmin[ply:GetUserGroup()]) then return; end
1960
1961 local nextPage = net.ReadUInt(32);
1962 local sort = net.ReadUInt(8);
1963 local searchUser = net.ReadString();
1964 local toSort = "ID"
1965
1966 if (sort == 0) then
1967 toSort = "Elo"
1968 elseif (sort == 1) then
1969 toSort = "Kills"
1970 elseif(sort == 2) then
1971 toSort = "Deaths"
1972 elseif(sort == 3) then
1973 toSort = "TotalWins"
1974 elseif(sort == 4) then
1975 toSort = "TotalLosses"
1976 end
1977
1978 local users = {};
1979 local userCount = 0;
1980 if (searchUser ~= "NULL") then
1981 if (searchUser:find("765611")) then
1982 users = sql.Query(SQL:FormatSQL("SELECT * FROM gElo_Stats WHERE SteamID = '%s' LIMIT '%s' - 15, 14", searchUser, nextPage));
1983 userCount = ((users ~= false and users ~= nil) and #users or 0);
1984 else
1985 users = sql.Query(SQL:FormatSQL("SELECT * FROM gElo_Stats WHERE Name LIKE '%%%s%%' LIMIT '%s' - 15, 14", searchUser, nextPage));
1986 userCount = ((users ~= false and users ~= nil) and #users or 0);
1987 end
1988 else
1989 users = sql.Query(SQL:FormatSQL("SELECT * FROM gElo_Stats ORDER BY %s DESC LIMIT '%s' - 15, 14", toSort, nextPage));
1990 userCount = sql.QueryRow("SELECT Count(*) FROM gElo_Stats");
1991 userCount = tonumber(userCount["Count(*)"]);
1992 end
1993
1994 if (users == nil) then
1995 if (searchUser ~= "NULL") then
1996 net.Start("gElo.SendMenuError")
1997 net.WriteString("svLeaderUnableToFindUser;" .. tostring(searchUser));
1998 net.Send(ply)
1999 else
2000 net.Start("gElo.SendMenuError");
2001 net.WriteString("svLeaderMoreUsersFound");
2002 net.Send(ply)
2003 end
2004
2005 return;
2006 end
2007
2008 local tablePositions = sql.Query("SELECT Elo, SteamID FROM gElo_Stats ORDER BY Elo DESC");
2009 local count = table.Count(tablePositions);
2010
2011 local userCountFound = 0;
2012 for i = 1, count do
2013 local tbl = tablePositions[i];
2014
2015 for s = 1, #users do
2016 local user = users[s];
2017
2018 if (user["SteamID"] == tbl.SteamID) then
2019 user["Position"] = i;
2020 userCountFound = userCountFound + 1;
2021 end
2022 end
2023
2024 if (userCountFound >= 15) then
2025 break;
2026 end
2027 end
2028
2029 net.Start("gElo.SendLookedupUsers");
2030 net.WriteTable(users);
2031 net.WriteUInt(userCount, 32);
2032 net.Send(ply);
2033end);
2034
2035--[[------------------------------------------------------------------------------
2036 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
2037 * Unauthorized copying of this file, via any medium is strictly prohibited
2038 * Proprietary and confidential
2039--]]------------------------------------------------------------------------------
2040
2041local stats = {};
2042local queuedStats = {};
2043local Queue = gElo.GetQueue();
2044
2045---
2046--- AddStat
2047---
2048function stats:AddStat(ply, stat, num)
2049 if (not IsValid(ply)) then
2050 gElo.DebugPrint("[Stats][AddStat] -> Tried adding " .. stat .. " to player but player is not valid")
2051
2052 return false;
2053 end
2054
2055 table.insert(queuedStats, {Player = ply, Stat = stat, Num = num});
2056end
2057
2058---
2059--- GetStats
2060---
2061function gElo.GetStats()
2062 return stats;
2063end
2064
2065hook.Add("TTTBeginRound", "gElo.RemoveStats", function()
2066 table.Empty(queuedStats);
2067end);
2068
2069hook.Add("TTTEndRound", "gElo.AddStatsToQueue", function()
2070 timer.Simple(1, function()
2071 for k, v in ipairs(queuedStats) do
2072 local ply = v.Player;
2073 local stat = v.Stat;
2074 local num = v.Num;
2075
2076 if (IsValid(ply)) then
2077 Queue:AddSQLToQueue("UPDATE gElo_Stats SET " .. stat .. " = " .. stat .. " + '" .. num .. "' WHERE SteamID = '" .. ply:SteamID64() .. "'");
2078 end
2079 end
2080 end);
2081end);
2082
2083--[[------------------------------------------------------------------------------
2084 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
2085 * Unauthorized copying of this file, via any medium is strictly prohibited
2086 * Proprietary and confidential
2087--]]------------------------------------------------------------------------------
2088
2089local stats = gElo.GetStats();
2090local queuedStats = {};
2091
2092---
2093--- CheckStats
2094---
2095local function CheckStats(ply)
2096 if (not queuedStats[ply:SteamID64()]) then
2097 queuedStats[ply:SteamID64()] = {};
2098
2099 local stat = queuedStats[ply:SteamID64()];
2100 stat.DamageDealt = 0;
2101 stat.FireDamageDealt = 0;
2102 stat.BulletsFired = 0;
2103 stat.InnocentDamage = 0;
2104 stat.DetectiveDamage = 0;
2105 stat.TraitorDamage = 0;
2106 stat.Kills = 0;
2107 stat.InnocentKills = 0;
2108 stat.DetectiveKills = 0;
2109 stat.TraitorKills = 0;
2110 stat.Headshots = 0;
2111 stat.Deaths = 0;
2112 stat.InnocentDeaths = 0;
2113 stat.DetectiveDeaths = 0;
2114 stat.TraitorDeaths = 0;
2115
2116 return true;
2117 end
2118
2119 return true;
2120end
2121
2122---
2123--- AddStat
2124---
2125local function AddStat(ply, stat, num)
2126 queuedStats[ply:SteamID64()][stat] = queuedStats[ply:SteamID64()][stat] + num;
2127end
2128
2129hook.Add("PlayerInitialSpawn", "gElo.SetAddStatToFalse", function(ply)
2130 if (not IsValid(ply) or ply:IsBot() and not gElo.UseDebug) then return; end
2131
2132 ply.gEloCanAddStats = false;
2133end);
2134
2135hook.Add("PlayerDeath", "gElo.StatsAddKills", function(victim, _, attacker)
2136 if (not IsValid(attacker) or not IsValid(victim) or victim:IsBot() and not gElo.UseDebug) then return; end
2137 if (victim == attacker) then return; end
2138 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
2139
2140 -- if they use SpecDM check if the victim was a ghost
2141 -- No need to check if the attacker was a ghost because
2142 -- The only way a ghost dies is because of other ghosts or suicide.
2143 if (SpecDM and victim:IsGhost()) then
2144 return;
2145 end
2146
2147 -- The victim is always going to a player so no need to check if they are.
2148 AddStat(victim, "Deaths", 1);
2149
2150 -- Deaths
2151 if (not victim:IsTraitor() and not victim:IsDetective()) then
2152 AddStat(victim, "InnocentDeaths", 1);
2153 end
2154
2155 if (victim:IsDetective()) then
2156 AddStat(victim, "DetectiveDeaths", 1);
2157 end
2158
2159 if (victim:IsTraitor()) then
2160 AddStat(victim, "TraitorDeaths", 1);
2161 end
2162
2163 -- Have to make sure the attacker is player before we do anything with the attacker.
2164 if (attacker:IsPlayer()) then
2165
2166 -- Kills
2167 AddStat(attacker, "Kills", 1);
2168 if (not attacker:IsTraitor() and not attacker:IsDetective()) then
2169 AddStat(attacker, "InnocentKills", 1);
2170 end
2171
2172 if (attacker:IsDetective()) then
2173 AddStat(attacker, "DetectiveKills", 1);
2174 end
2175
2176 if (attacker:IsTraitor()) then
2177 AddStat(attacker, "TraitorKills", 1);
2178 end
2179
2180 if (victim:LastHitGroup() == HITGROUP_HEAD) then
2181 AddStat(attacker, "Headshots", 1);
2182 end
2183 end
2184end);
2185
2186hook.Add("EntityFireBullets", "gElo.StatsAddBullets", function(ent)
2187 if (not IsValid(ent) or not ent:IsPlayer()) then return; end
2188 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
2189 if (SpecDM and ent:IsGhost()) then return; end
2190
2191 AddStat(ent, "BulletsFired", 1);
2192end);
2193
2194hook.Add("EntityTakeDamage", "gElo.StatsAddDamage", function(ent, dmg)
2195 if (not IsValid(ent) or not ent:IsPlayer()) then return; end
2196 if (GetRoundState() ~= ROUND_ACTIVE) then return; end
2197 if (ent:IsBot() and not gElo.UseDebug) then return; end
2198
2199 local damage = math.Round(dmg:GetDamage());
2200 local att = dmg:GetAttacker();
2201
2202 if (IsValid(att) and att:IsPlayer()) then
2203 if (SpecDM and att:IsGhost()) then
2204 return;
2205 end
2206
2207 AddStat(att, "DamageDealt", damage);
2208
2209 if (dmg:GetDamageType() == DMG_BURN) then
2210 AddStat(att, "FireDamageDealt", damage);
2211 end
2212
2213 if (att:IsTraitor()) then
2214 AddStat(att, "TraitorDamage", damage);
2215 elseif(att:IsDetective()) then
2216 AddStat(att, "DetectiveDamage", damage);
2217 else
2218 AddStat(att, "InnocentDamage", damage);
2219 end
2220 end
2221end);
2222
2223hook.Add("TTTBeginRound", "gElo.SpecFix", function()
2224 table.Empty(queuedStats);
2225
2226 for _, v in ipairs(player.GetAll()) do
2227 if (not IsValid(v) or v:IsBot() and not gElo.UseDebug) then continue; end
2228 CheckStats(v);
2229
2230 if (v:Team() == TEAM_SPEC) then
2231 v.gEloCanAddStats = false;
2232
2233 continue;
2234 end
2235
2236 v.gEloCanAddStats = true;
2237 end
2238end);
2239
2240hook.Add("TTTEndRound", "gElo.StatsAdd", function(result)
2241 if (result == WIN_INNOCENT or result == WIN_TIMELIMIT) then
2242 for _, v in ipairs(player.GetAll()) do
2243 if (v:IsBot() and not gElo.UseDebug) then
2244 continue;
2245 end
2246
2247 v.CanUpdateProfile = true;
2248
2249 -- Don't want to add anything if they're spectating;
2250 if (not v.gEloCanAddStats) then
2251 continue;
2252 end
2253
2254 stats:AddStat(v, "RoundsPlayed", 1);
2255
2256 if (v:IsTraitor()) then
2257 stats:AddStat(v, "TraitorLosses", 1);
2258 stats:AddStat(v, "TotalLosses", 1);
2259
2260 continue;
2261 end
2262
2263 if (v:IsDetective()) then
2264 stats:AddStat(v, "DetectiveWins", 1);
2265 end
2266
2267 stats:AddStat(v, "InnocentWins", 1);
2268 stats:AddStat(v, "TotalWins", 1);
2269 end
2270 elseif(result == WIN_TRAITOR) then
2271 for _, v in ipairs(player.GetAll()) do
2272 if (v:IsBot() and not gElo.UseDebug) then
2273 continue;
2274 end
2275
2276 v.CanUpdateProfile = true;
2277
2278 -- Don't want to add anything if they're spectating;
2279 if (not v.gEloCanAddStats) then
2280 continue;
2281 end
2282
2283 stats:AddStat(v, "RoundsPlayed", 1);
2284
2285 if (not v:IsTraitor()) then
2286 stats:AddStat(v, "InnocentLosses", 1);
2287 stats:AddStat(v, "TotalLosses", 1);
2288
2289 if (v:IsDetective()) then
2290 stats:AddStat(v, "DetectiveLosses", 1);
2291 end
2292
2293 continue;
2294 end
2295
2296 stats:AddStat(v, "TraitorWins", 1);
2297 stats:AddStat(v, "TotalWins", 1);
2298 end
2299 end
2300
2301 for k, v in pairs(queuedStats) do
2302 local ply = player.GetBySteamID64(k);
2303 if (not IsValid(ply)) then continue; end
2304
2305 for stat, value in pairs(v) do
2306 if (value < 1) then continue; end
2307
2308 stats:AddStat(ply, stat, value);
2309 end
2310 end
2311end);
2312
2313--[[------------------------------------------------------------------------------
2314 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
2315 * Unauthorized copying of this file, via any medium is strictly prohibited
2316 * Proprietary and confidential
2317--]]------------------------------------------------------------------------------
2318
2319local panel = {};
2320
2321---
2322--- GetColors
2323---
2324function panel:GetColors()
2325 self.Colors = gElo.GetColorFromString("main_background");
2326end
2327
2328function panel:CreateNotification(db, desc)
2329 local main = self:GetParent();
2330 if (not IsValid(main)) then return; end
2331
2332 if (IsValid(self.Notification)) then
2333 return;
2334 end
2335
2336 self.Notification = main:Add("gElo.Notification");
2337 self.Notification:SetSize(400, 150);
2338 self.Notification:Center();
2339 self.Notification:SetDescription(gElo.L(desc));
2340 self.Notification.DoAcceptClick = function(s)
2341 net.Start("gElo.WipeDatabase")
2342 net.WriteUInt(db, 2);
2343 net.SendToServer()
2344
2345 if (IsValid(s)) then
2346 s:Remove();
2347 end
2348 end
2349 self.Notification.DoDeclineClick = function(s)
2350 if (IsValid(s)) then
2351 s:Remove();
2352 end
2353
2354 self.SideBar.SelectedButton = NULL;
2355 end
2356end
2357
2358---
2359--- Init
2360---
2361function panel:Init()
2362 self.BackgroundMaterial = Material("gelo/main_background.png");
2363 self:GetColors();
2364
2365 -- SideBar
2366 self.SideBar = self:Add("gElo.MainPanelSideBar");
2367
2368 -- Lookup Users
2369 self.SideBar:CreateSideTab(gElo.L("adminUsers"), "gelo/user.png", function()
2370 net.Start("gElo.LookupUserAll") net.WriteUInt(15, 32) net.WriteUInt(0, 8) net.WriteString("NULL"); net.SendToServer();
2371
2372 self.LookedupUsers = self:Add("gElo.MainUserLookupsPanel")
2373 self.SideBar.SelectedPanel = self.LookedupUsers;
2374
2375 if (IsValid(self.Notification)) then
2376 self.Notification:Remove();
2377 end
2378 end);
2379
2380 -- Wipe Stats Database
2381 self.SideBar:CreateSideTab(gElo.L("adminWipeStats"), "gelo/database.png", function()
2382 self:CreateNotification(1, "adminWipeStatsNotification");
2383 end);
2384
2385 -- Wipe History Database
2386 self.SideBar:CreateSideTab(gElo.L("adminWipeHistory"), "gelo/database.png", function()
2387 self:CreateNotification(2, "adminWipeHistoryNotification");
2388 end);
2389
2390 -- Wipe All Databases
2391 self.SideBar:CreateSideTab(gElo.L("adminWipeAll"), "gelo/database.png", function()
2392 self:CreateNotification(3, "adminAdminWipeAllNotification");
2393 end);
2394end
2395
2396---
2397--- PerformLayout
2398---
2399function panel:PerformLayout(w, h)
2400 self.SideBar:SetPos(0, 0);
2401 self.SideBar:SetSize(200, h);
2402
2403 if (IsValid(self.LookedupUsers)) then
2404 self.LookedupUsers:SetPos(self.SideBar:GetWide(), 0);
2405 self.LookedupUsers:SetSize(w - self.SideBar:GetWide(), h);
2406 end
2407end
2408
2409---
2410--- Paint
2411---
2412function panel:Paint(w, h)
2413 surface.SetDrawColor(self.Colors.main_background);
2414 surface.SetMaterial(self.BackgroundMaterial);
2415 surface.DrawTexturedRect(0, 0, w, h);
2416end
2417vgui.Register("gElo.MainAdminsPanel", panel, "EditablePanel");
2418
2419--[[------------------------------------------------------------------------------
2420 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
2421 * Unauthorized copying of this file, via any medium is strictly prohibited
2422 * Proprietary and confidential
2423--]]------------------------------------------------------------------------------
2424
2425local panel = {};
2426
2427AccessorFunc(panel, "CustomSteamID", "CustomSteamID", FORCE_STRING);
2428
2429---
2430--- GetColors
2431---
2432function panel:GetColors()
2433 self.Colors = gElo.GetColorFromString("main_background");
2434end
2435
2436---
2437--- SetUserRank
2438---
2439function panel:SetUserRank()
2440 self.SetRank = self:Add("DPanel")
2441 self.SetRank.Paint = function(s, w, h)
2442 surface.SetDrawColor(self.Colors.main_background);
2443 surface.SetMaterial(self.BackgroundMaterial);
2444 surface.DrawTexturedRect(0, 0, w, h);
2445 end
2446
2447 for k, v in ipairs(self.Ranks) do
2448 self:CreateUserOption(self.SetRank, v.r .. " " .. gElo.NumberToRoman(v.d), function(id)
2449 net.Start("gElo.AdminSetRank")
2450 net.WriteString(id);
2451 net.WriteUInt(v.e, 32);
2452 net.SendToServer()
2453 end);
2454 end
2455
2456 self.SideBar.SelectedPanel = self.SetRank;
2457end
2458
2459---
2460--- ResetUserAll
2461---
2462function panel:ResetUserAll()
2463 local parent = self:GetParent():GetParent();
2464
2465 if (not IsValid(parent)) then return; end
2466 self.Notification = parent:Add("gElo.Notification");
2467 self.Notification:SetSize(400, 150);
2468 self.Notification:Center();
2469 self.Notification:SetDescription(gElo.L("adminResetAllNotify"));
2470 self.Notification.DoAcceptClick = function(s)
2471 if (IsValid(s)) then
2472 s:Remove();
2473 end
2474
2475 net.Start("gElo.AdminResetUserAll")
2476 net.WriteString(self.CustomSteamID);
2477 net.SendToServer()
2478
2479 self.SideBar.SelectedButton = nil;
2480 end
2481 self.Notification.DoDeclineClick = function(s)
2482 if (IsValid(s)) then
2483 s:Remove();
2484 end
2485
2486 self.SideBar.SelectedButton = nil;
2487 end
2488
2489 self.SideBar.SelectedPanel = self.Notification;
2490end
2491
2492function panel:CreateUserOption(pnl, str, func)
2493 func = func or function() return; end
2494
2495 if (self.UserCount == 17) then
2496 self.xPos = self.xPos + 140;
2497 self.yPos = 5;
2498 self.UserCount = 0;
2499 end
2500
2501 self.UserOption = pnl:Add("gElo.Button");
2502 self.UserOption:SetPos(self.xPos, self.yPos);
2503 self.UserOption:SetSize(135, 34);
2504 self.UserOption:SetCustomText(str)
2505 self.UserOption.SetDoClick = function()
2506 func(self.CustomSteamID);
2507 end
2508
2509 self.UserCount = self.UserCount + 1;
2510 self.yPos = self.yPos + 39
2511end
2512
2513---
2514--- Init
2515---
2516function panel:Init()
2517 self.BackgroundMaterial = Material("gelo/main_background.png");
2518 self.UserCount = 0;
2519
2520 -- GetColors
2521 self:GetColors();
2522
2523 -- Ranks
2524 -- R = Rank; E = Elo; D = Division;
2525 self.Ranks = {
2526 {r = gElo.L("challenger"), e = 4000, d = 1},
2527 {r = gElo.L("masters"), e = 3000, d = 1},
2528
2529 -- Diamond
2530 {r = gElo.L("diamond"), e = 2800, d = 1},
2531 {r = gElo.L("diamond"), e = 2750, d = 2},
2532 {r = gElo.L("diamond"), e = 2700, d = 3},
2533 {r = gElo.L("diamond"), e = 2650, d = 4},
2534 {r = gElo.L("diamond"), e = 2600, d = 5},
2535
2536 -- Platinum
2537 {r = gElo.L("platinum"), e = 2550, d = 1},
2538 {r = gElo.L("platinum"), e = 2500, d = 2},
2539 {r = gElo.L("platinum"), e = 2450, d = 3},
2540 {r = gElo.L("platinum"), e = 2400, d = 4},
2541 {r = gElo.L("platinum"), e = 2350, d = 5},
2542
2543 -- Gold
2544 {r = gElo.L("gold"), e = 2300, d = 1},
2545 {r = gElo.L("gold"), e = 2250, d = 2},
2546 {r = gElo.L("gold"), e = 2200, d = 3},
2547 {r = gElo.L("gold"), e = 2150, d = 4},
2548 {r = gElo.L("gold"), e = 2100, d = 5},
2549
2550 -- Silver
2551 {r = gElo.L("silver"), e = 2050, d = 1},
2552 {r = gElo.L("silver"), e = 2000, d = 2},
2553 {r = gElo.L("silver"), e = 1950, d = 3},
2554 {r = gElo.L("silver"), e = 1900, d = 4},
2555 {r = gElo.L("silver"), e = 1850, d = 5},
2556
2557 -- Bronze
2558 {r = gElo.L("bronze"), e = 1800, d = 1},
2559 {r = gElo.L("bronze"), e = 1750, d = 2},
2560 {r = gElo.L("bronze"), e = 1700, d = 3},
2561 {r = gElo.L("bronze"), e = 1650, d = 4},
2562 {r = gElo.L("bronze"), e = 1600, d = 5},
2563 }
2564
2565 -- SideBar
2566 self.SideBar = self:Add("gElo.MainPanelSideBar");
2567
2568 -- Set Rank
2569 self.SideBar:CreateSideTab(gElo.L("setRank"), "gelo/user.png", function()
2570 self.xPos = 5;
2571 self.yPos = 5;
2572 self.UserCount = 0;
2573
2574 self:SetUserRank();
2575 end);
2576
2577 -- Set RP
2578 self.SideBar:CreateSideTab(gElo.L("setRP"), "gelo/user.png", function()
2579 Derma_StringRequest(gElo.L("setRP"), gElo.L("setRPInput"), "", function(rp)
2580 rp = tonumber(rp)
2581
2582 if (isnumber(rp) and rp > 0) then
2583 if (rp > 100) then
2584 local main = self:GetParent():GetParent();
2585
2586 if (IsValid(main)) then
2587 main:HeaderWarning(gElo.L("setRPLimit"), 3);
2588 end
2589 else
2590 net.Start("gElo.AdminSetRP")
2591 net.WriteString(self.CustomSteamID);
2592 net.WriteUInt(rp, 8);
2593 net.SendToServer()
2594 end
2595 end
2596
2597 self.SideBar.SelectedButton = nil;
2598 end,
2599
2600 function()
2601 self.SideBar.SelectedButton = nil;
2602 end);
2603
2604 if (IsValid(self.SideBar.SelectedPanel)) then
2605 self.SideBar.SelectedPanel:Remove();
2606 end
2607 end);
2608
2609 -- Completely Reset User
2610 self.SideBar:CreateSideTab(gElo.L("adminResetAll"), "gelo/user.png", function()
2611 self:ResetUserAll();
2612 end);
2613
2614 -- Set Name
2615 self.SideBar:CreateSideTab(gElo.L("adminResetNick"), "gelo/user.png", function()
2616 Derma_StringRequest(gElo.L("adminResetNick"), gElo.L("adminResetInfo"), "", function(name)
2617 if (name and name:len() > 40) then
2618 local main = self:GetParent():GetParent();
2619
2620 if (IsValid(main)) then
2621 main:HeaderWarning(gElo.L("adminResetNickError"), 5);
2622 end
2623 else
2624 net.Start("gElo.AdminSetName")
2625 net.WriteString(self.CustomSteamID);
2626 net.WriteString(name);
2627 net.SendToServer()
2628
2629 local main = self:GetParent():GetParent();
2630
2631 if (IsValid(main)) then
2632 main:HeaderWarning(gElo.L("adminResetSuccess"), 10);
2633 end
2634 end
2635
2636 self.SideBar.SelectedButton = nil;
2637 end,
2638
2639 function()
2640 self.SideBar.SelectedButton = nil;
2641 end);
2642 end);
2643end
2644
2645---
2646--- PerformLayout
2647---
2648function panel:PerformLayout(w, h)
2649 self.SideBar:SetPos(0, 0);
2650 self.SideBar:SetSize(200, h);
2651
2652 if (IsValid(self.SetRank)) then
2653 self.SetRank:SetPos(200, 0);
2654 self.SetRank:SetSize(w, h);
2655 end
2656end
2657
2658---
2659--- Paint
2660---
2661function panel:Paint(w, h)
2662 surface.SetDrawColor(self.Colors.main_background);
2663 surface.SetMaterial(self.BackgroundMaterial);
2664 surface.DrawTexturedRect(0, 0, w, h);
2665end
2666vgui.Register("gElo.MainAdminsSetPanel", panel, "EditablePanel");
2667
2668--[[------------------------------------------------------------------------------
2669 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
2670 * Unauthorized copying of this file, via any medium is strictly prohibited
2671 * Proprietary and confidential
2672--]]------------------------------------------------------------------------------
2673
2674local panel = {};
2675local users = {};
2676local userCount = 0;
2677local panelReference = nil;
2678
2679---
2680--- GetColors
2681---
2682function panel:GetColors()
2683 self.Colors = gElo.GetColorFromString("main_background", "main_outline", "other_text", "settings_containers");
2684end
2685
2686---
2687--- CreateHeader
2688---
2689function panel:CreateHeader()
2690 self.Header = self:Add("DPanel")
2691 self.Header.xPos = 0;
2692 self.Header.Paint = function(s, w, h)
2693 local x, y = self.Header:LocalToScreen();
2694
2695 BSHADOWS.BeginShadow()
2696 surface.SetDrawColor(self.Colors.settings_containers);
2697 surface.DrawRect(x, y, w, h);
2698 BSHADOWS.EndShadow(1, 2, 2);
2699 end
2700
2701 return self.Header;
2702end
2703
2704---
2705--- CreateHeaderChild
2706---
2707function panel:CreateHeaderChild(pnl, xSize, title, sortType)
2708 self.Child = pnl:Add("DButton");
2709 self.Child:SetPos(pnl.xPos, 0);
2710 if (xSize) then
2711 self.Child:SetSize(xSize, 35);
2712 else
2713 self.Child:SetSize(self.xSize, 35);
2714 end
2715 self.Child:SetText("");
2716 self.Child:SetCursor("arrow");
2717 self.Child.Paint = function(s, w, h)
2718 surface.SetDrawColor(s:IsHovered() and sortType ~= nil and self.Colors.main_outline or 0, 0, 0, 0);
2719 surface.DrawRect(0, 0, w, h);
2720
2721 draw.SimpleText(gElo.utf8upper(title), "gElo.18", w / 2, h / 2, self.Colors.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
2722
2723 surface.SetDrawColor(self.Colors.main_outline);
2724 surface.DrawRect(w - 1, 0, 1, h);
2725 end
2726
2727 self.Child.DoClick = function()
2728 if (not sortType or self.PageCooldown > CurTime()) then return; end
2729 self.SelectedSorting = sortType;
2730
2731 net.Start("gElo.LookupUserAll");
2732 net.WriteUInt(15, 32);
2733 net.WriteUInt(self.SelectedSorting, 8);
2734 net.WriteString("NULL");
2735 net.SendToServer();
2736
2737 self.PageCooldown = CurTime() + 1;
2738 end
2739
2740 if (xSize) then
2741 pnl.xPos = pnl.xPos + xSize;
2742 else
2743 pnl.xPos = pnl.xPos + self.xSize;
2744 end
2745end
2746
2747---
2748--- CreateUserRow
2749---
2750function panel:CreateUserRow(pnl, pos, name, rank, division, elo, kills, deaths, wins, losses, steamid)
2751 self.Match = pnl:Add("DPanel")
2752 self.Match:SetPos(0, self.yPos);
2753 self.Match:SetSize(977, 35);
2754 self.Match.xPos = 0;
2755 self.Match.Paint = function(s, w, h)
2756 surface.SetDrawColor(self.Colors.main_background);
2757 surface.SetMaterial(self.BackgroundMaterial);
2758 surface.DrawTexturedRect(0, 0, w, h);
2759
2760 surface.SetDrawColor(gElo.EloToColor(rank));
2761 surface.DrawRect(0, h - 1, w, 1);
2762 end
2763
2764 self:CreateUserRowChild(self.Match, 45, string.Comma(pos), nil, steamid);
2765 self:CreateUserRowChild(self.Match, 220, name, nil, steamid);
2766 self:CreateUserRowChild(self.Match, 105, gElo.L(rank:lower()) .. " " .. gElo.NumberToRoman(division), gElo.EloToColor(rank), steamid);
2767 self:CreateUserRowChild(self.Match, 80, elo, nil, steamid);
2768 self:CreateUserRowChild(self.Match, 80, kills, nil, steamid);
2769 self:CreateUserRowChild(self.Match, 80, deaths, nil, steamid);
2770 self:CreateUserRowChild(self.Match, 80, wins, nil, steamid);
2771 self:CreateUserRowChild(self.Match, 80, losses, nil, steamid);
2772
2773 self.yPos = self.yPos + 35;
2774end
2775
2776---
2777--- CreateUserRowChild
2778---
2779function panel:CreateUserRowChild(pnl, xSize, str, col, steamid)
2780 str = tostring(str);
2781
2782 if (#str > 26) then
2783 str = str:sub(0, 26) .. ".."
2784 end
2785
2786 col = col or self.Colors.other_text;
2787
2788 self.MatchChild = pnl:Add("DButton");
2789 self.MatchChild:SetPos(pnl.xPos, 0);
2790 if (xSize) then
2791 self.MatchChild:SetSize(xSize, 35);
2792 else
2793 self.MatchChild:SetSize(self.xSize, 35);
2794 end
2795 self.MatchChild:SetText("");
2796 self.MatchChild.ID = steamid;
2797 self.MatchChild:SetCursor("arrow");
2798 self.MatchChild.Paint = function(s, w, h)
2799 surface.SetDrawColor(0, 0, 0, 0);
2800 surface.DrawRect(0, 0, w, h);
2801
2802 draw.SimpleText(str, "gElo.16", w / 2, h / 2, col, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
2803
2804 surface.SetDrawColor(self.Colors.main_outline);
2805 surface.DrawRect(w - 1, 0, 1, h - 1);
2806 end
2807
2808 self.MatchChild.DoClick = function(s)
2809 local main = self:GetParent();
2810 if (IsValid(main)) then
2811 self:Remove();
2812
2813 local set = main:Add("gElo.MainAdminsSetPanel");
2814 set:SetPos(200, 0);
2815 set:SetSize(main:GetWide(), main:GetTall());
2816 set:SetCustomSteamID(steamid);
2817 end
2818 end
2819
2820 if (xSize) then
2821 pnl.xPos = pnl.xPos + xSize;
2822 else
2823 pnl.xPos = pnl.xPos + self.xSize;
2824 end
2825end
2826
2827function panel:ClearTheBoard()
2828 self.yPos = 0;
2829 self.xSize = 108;
2830 self.SelectedSorting = 0;
2831
2832 -- Clear the board.
2833 if (IsValid(self.ScrollPanel)) then
2834 self.ScrollPanel:Clear();
2835 end
2836end
2837
2838---
2839--- Init
2840---
2841function panel:Init()
2842 self.BackgroundMaterial = Material("gelo/main_background.png");
2843 self:GetColors();
2844 self.yPos = 0;
2845 self.xSize = 108;
2846 self.CurrentPage = 1;
2847 self.MaxPages = 1;
2848 self.CurrentPageRaw = 14;
2849 self.PageCooldown = CurTime();
2850 self.SelectedSorting = 0;
2851 self.LookupUserAllCooldown = CurTime();
2852
2853 self.ScrollPanel = self:Add("DScrollPanel")
2854 self.ScrollPanel.yPos = 12;
2855 self.ScrollPanel.Paint = function(s, w, h)
2856 surface.SetDrawColor(self.Colors.main_background);
2857 surface.SetMaterial(self.BackgroundMaterial);
2858 surface.DrawTexturedRect(0, 0, w, h);
2859 end
2860
2861 self.Head = self:CreateHeader();
2862 self:CreateHeaderChild(self.Head, 45, "#", 0);
2863 self:CreateHeaderChild(self.Head, 220, gElo.L("leaderName"));
2864 self:CreateHeaderChild(self.Head, 105, gElo.L("leaderRank"), 0);
2865 self:CreateHeaderChild(self.Head, 80, gElo.L("leaderElo"), 0);
2866 self:CreateHeaderChild(self.Head, 80, gElo.L("sqlKills"), 1);
2867 self:CreateHeaderChild(self.Head, 80, gElo.L("sqlDeaths"), 2);
2868 self:CreateHeaderChild(self.Head, 80, gElo.L("sqlWins"), 3);
2869 self:CreateHeaderChild(self.Head, 80, gElo.L("sqlLosses"), 4);
2870
2871 self.Back = self:Add("gElo.Button");
2872 self.Back:SetCustomText(gElo.L("adminBack"));
2873 self.Back.SetDoClick = function()
2874 if (self.CurrentPage <= 1 or self.LookupUserAllCooldown > CurTime()) then return; end
2875
2876 net.Start("gElo.LookupUserAll");
2877 net.WriteUInt(self.CurrentPageRaw - 15, 32);
2878 net.WriteUInt(self.SelectedSorting, 8);
2879 net.WriteString("NULL");
2880 net.SendToServer();
2881
2882 self.CurrentPage = self.CurrentPage - 1;
2883 self.CurrentPageRaw = self.CurrentPageRaw - 14;
2884 self.LookupUserAllCooldown = CurTime() + 2;
2885 end
2886
2887 self.Next = self:Add("gElo.Button");
2888 self.Next:SetCustomText(gElo.L("adminNext"));
2889 self.Next.SetDoClick = function()
2890 if (self.CurrentPage >= self.MaxPages or self.LookupUserAllCooldown > CurTime()) then return; end
2891
2892 net.Start("gElo.LookupUserAll");
2893 net.WriteUInt(self.CurrentPageRaw + 15, 32);
2894 net.WriteUInt(self.SelectedSorting, 8);
2895 net.WriteString("NULL");
2896 net.SendToServer();
2897
2898 self.CurrentPage = self.CurrentPage + 1;
2899 self.CurrentPageRaw = self.CurrentPageRaw + 14;
2900 self.LookupUserAllCooldown = CurTime() + 2;
2901 end
2902
2903 self.Search = self:Add("gElo.TextEntry");
2904 self.Search:SetBackgroundText(gElo.L("userSearch"))
2905 self.Search.OnCustomEnter = function()
2906 net.Start("gElo.LookupUserAll");
2907 net.WriteUInt(15, 32);
2908 net.WriteUInt(0, 8);
2909 net.WriteString(self.Search:GetValue());
2910 net.SendToServer();
2911
2912 self.CurrentPageRaw = 14;
2913 self.MaxPages = 1;
2914 self.CurrentPage = 1;
2915 self.LookupUserAllCooldown = CurTime() + 2;
2916 end
2917
2918 panelReference = self;
2919end
2920
2921---
2922--- PerformLayout
2923---
2924function panel:PerformLayout(w, h)
2925 self.Header:SetPos(0, 7);
2926 self.Header:SetSize(w, 35);
2927
2928 self.ScrollPanel:SetPos(0, 50);
2929 self.ScrollPanel:SetSize(w, h - 100);
2930
2931 self.Back:SetPos(25, h - 42);
2932 self.Back:SetSize(135, 34);
2933
2934 self.Next:SetPos(w - 160, h - 42);
2935 self.Next:SetSize(135, 34);
2936
2937 self.Search:SetPos(w - 320, h - 42);
2938 self.Search:SetSize(135, 34);
2939end
2940
2941---
2942--- Paint
2943---
2944function panel:Paint(w, h)
2945 surface.SetDrawColor(self.Colors.main_background);
2946 surface.SetMaterial(self.BackgroundMaterial);
2947 surface.DrawTexturedRect(0, 0, w, h);
2948
2949 draw.SimpleText(gElo.utf8upper(gElo.L("userPage") .. ": " .. self.CurrentPage .. "/" .. self.MaxPages), "gElo.16", 185, h - 21, self.Colors.other_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
2950end
2951vgui.Register("gElo.MainUserLookupsPanel", panel, "EditablePanel");
2952
2953net.Receive("gElo.SendLookedupUsers", function(_, ply)
2954 users = net.ReadTable();
2955 userCount = net.ReadUInt(32);
2956
2957 if (IsValid(panelReference)) then
2958 if (userCount > 15) then
2959 panelReference.MaxPages = math.Round(userCount / 15);
2960 else
2961 panelReference.MaxPages = 1;
2962 end
2963
2964 -- Reset variables.
2965 panelReference:ClearTheBoard();
2966 end
2967
2968 for k, v in ipairs(users or {}) do
2969 if (not IsValid(panelReference)) then return; end
2970
2971 panelReference:CreateUserRow(panelReference.ScrollPanel, k, v.Name, v.Rank, v.Division, v.Elo, v.Kills, v.Deaths, v.TotalWins, v.TotalLosses, v.SteamID);
2972 end
2973end);
2974
2975--[[------------------------------------------------------------------------------
2976 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
2977 * Unauthorized copying of this file, via any medium is strictly prohibited
2978 * Proprietary and confidential
2979--]]------------------------------------------------------------------------------
2980
2981local panel = {};
2982
2983---
2984--- GetColors
2985---
2986function panel:GetColors()
2987 self.Colors = gElo.GetColorFromString("main_background");
2988end
2989
2990---
2991--- Init
2992---
2993function panel:Init()
2994 self.BackgroundMaterial = Material("gelo/main_background.png");
2995 self:GetColors();
2996
2997 self.Forums = self:Add("HTML");
2998 self.Forums:OpenURL(gElo.Config.ForumURL);
2999
3000 panelReference = self;
3001end
3002
3003---
3004--- PerformLayout
3005---
3006function panel:PerformLayout(w, h)
3007 self.Forums:SetPos(0, 0);
3008 self.Forums:SetSize(w, h);
3009end
3010
3011---
3012--- Paint
3013---
3014function panel:Paint(w, h)
3015 surface.SetDrawColor(self.Colors.main_background);
3016 surface.SetMaterial(self.BackgroundMaterial);
3017 surface.DrawTexturedRect(0, 0, w, h);
3018end
3019vgui.Register("gElo.MainForumsPanel", panel, "EditablePanel");
3020
3021--[[------------------------------------------------------------------------------
3022 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
3023 * Unauthorized copying of this file, via any medium is strictly prohibited
3024 * Proprietary and confidential
3025--]]------------------------------------------------------------------------------
3026
3027local panel = {};
3028
3029---
3030--- GetColors
3031---
3032function panel:GetColors()
3033 self.Colors = gElo.GetColorFromString("main_background");
3034end
3035
3036---
3037--- CreateHelpText
3038---
3039function panel:CreateHelpText(title, desc, x, y, col)
3040 self.HelpText = self:Add("DPanel");
3041 self.HelpText:SetPos(x, y);
3042 self.HelpText:SetSize(767, 633);
3043 self.HelpText.Paint = function(s, width, tall)
3044 local x, y = s:LocalToScreen();
3045
3046 surface.SetDrawColor(self.Colors.main_background);
3047 surface.SetMaterial(self.BackgroundMaterial);
3048 surface.DrawTexturedRect(0, 0, width, tall);
3049
3050 surface.SetDrawColor(0, 0, 0, 50);
3051 surface.DrawRect(0, 0, width, tall);
3052
3053 BSHADOWS.BeginShadow();
3054 surface.DisableClipping(true);
3055 draw.SimpleText(gElo.utf8upper(title), "gElo.20", x + 20, y - 20, col or self.Colors.other_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
3056 surface.DisableClipping(false);
3057 BSHADOWS.EndShadow(1, 2, 2);
3058 draw.DrawText(gElo.textWrap(desc, "gElo.16", 750), "gElo.16", 5, 0, self.Colors.other_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
3059 end
3060
3061 return self.HelpText;
3062end
3063
3064---
3065--- Init
3066---
3067function panel:Init()
3068 self.BackgroundMaterial = Material("gelo/main_background.png");
3069 self:GetColors();
3070 self.yPos = 40;
3071
3072 -- SideBar
3073 self.SideBar = self:Add("gElo.MainPanelSideBar");
3074
3075 -- Promotion
3076 self.SideBar:CreateSideTab(gElo.L("helpPromote"), "gelo/help.png", function()
3077 local ui = self:CreateHelpText(gElo.L("helpPromote"), gElo.L("helpPromotions"), self.SideBar:GetWide() + 5, self.yPos);
3078 self.SideBar.SelectedPanel = ui;
3079 end);
3080
3081 -- Demotion
3082 self.SideBar:CreateSideTab(gElo.L("helpDemote"), "gelo/help.png", function()
3083 local ui = self:CreateHelpText(gElo.L("helpDemote"), gElo.L("helpDemotions"), self.SideBar:GetWide() + 5, self.yPos);
3084 self.SideBar.SelectedPanel = ui;
3085 end);
3086
3087 -- Rank Points
3088 self.SideBar:CreateSideTab(gElo.L("helpRP"), "gelo/help.png", function()
3089 local ui = self:CreateHelpText(gElo.L("helpRP"), gElo.L("helpRankPoints"), self.SideBar:GetWide() + 5, self.yPos);
3090 self.SideBar.SelectedPanel = ui;
3091 end);
3092
3093 -- History
3094 self.SideBar:CreateSideTab(gElo.L("helpHistory"), "gelo/help.png", function()
3095 local ui = self:CreateHelpText(gElo.L("helpHistory"), gElo.L("helpMatchHistory"), self.SideBar:GetWide() + 5, self.yPos);
3096 self.SideBar.SelectedPanel = ui;
3097 end);
3098
3099 -- Leaderboards
3100 self.SideBar:CreateSideTab(gElo.L("helpLeaderboards"), "gelo/help.png", function()
3101 local ui = self:CreateHelpText(gElo.L("helpLeaderboards"), gElo.L("helpLeaderboard"), self.SideBar:GetWide() + 5, self.yPos);
3102 self.SideBar.SelectedPanel = ui;
3103 end);
3104
3105 -- Language
3106 self.SideBar:CreateSideTab(gElo.L("helpLang"), "gelo/help.png", function()
3107 local ui = self:CreateHelpText(gElo.L("helpLang"), gElo.L("helpLanguage"), self.SideBar:GetWide() + 5, self.yPos);
3108 self.SideBar.SelectedPanel = ui;
3109 end);
3110
3111 -- Settings
3112 self.SideBar:CreateSideTab(gElo.L("helpSettings"), "gelo/help.png", function()
3113 local ui = self:CreateHelpText(gElo.L("helpSettings"), gElo.L("helpSetting"), self.SideBar:GetWide() + 5, self.yPos);
3114 self.SideBar.SelectedPanel = ui;
3115 end);
3116
3117 -- Errors
3118 self.SideBar:CreateSideTab(gElo.L("helpErrors"), "gelo/help.png", function()
3119 local ui = self:CreateHelpText(gElo.L("helpErrors"), gElo.L("helpError"), self.SideBar:GetWide() + 5, self.yPos);
3120 self.SideBar.SelectedPanel = ui;
3121 end);
3122
3123 if (gElo.Config.UIAdmin[LocalPlayer():GetUserGroup()]) then
3124 -- Administration Help
3125 self.SideBar:CreateSideTab(gElo.L("helpAdmin"), "gelo/help.png", function()
3126 local ui = self:CreateHelpText(gElo.L("helpAdmin"), gElo.L("helpAdministration"), self.SideBar:GetWide() + 5, self.yPos);
3127 self.SideBar.SelectedPanel = ui;
3128 end);
3129 end
3130end
3131
3132---
3133--- PerformLayout
3134---
3135function panel:PerformLayout(w, h)
3136 self.SideBar:SetPos(0, 0);
3137 self.SideBar:SetSize(200, h);
3138end
3139
3140---
3141--- Paint
3142---
3143function panel:Paint(w, h)
3144 surface.SetDrawColor(self.Colors.main_background);
3145 surface.SetMaterial(self.BackgroundMaterial);
3146 surface.DrawTexturedRect(0, 0, w, h);
3147end
3148vgui.Register("gElo.MainHelpPanel", panel, "EditablePanel");
3149
3150--[[------------------------------------------------------------------------------
3151 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
3152 * Unauthorized copying of this file, via any medium is strictly prohibited
3153 * Proprietary and confidential
3154--]]------------------------------------------------------------------------------
3155
3156local panel = {};
3157local matches = {};
3158local panelReference = nil
3159
3160---
3161--- GetColors
3162---
3163function panel:GetColors()
3164 self.Colors = gElo.GetColorFromString("main_background", "main_outline", "other_text", "settings_containers");
3165end
3166
3167---
3168--- GetRoleColor
3169---
3170function panel:GetRoleColor(role)
3171 role = string.lower(role);
3172
3173 local roles = {
3174 ["traitor"] = Color(150, 56, 50, 200),
3175 ["detective"] = Color(70, 134, 196, 200),
3176 ["innocent"] = Color(70, 196, 70, 200)
3177 }
3178
3179 return roles[role] or self.Colors.other_text;
3180end
3181
3182---
3183--- CreateHeader
3184---
3185function panel:CreateHeader()
3186 self.Header = self:Add("DPanel")
3187 self.Header.xPos = 0;
3188 self.Header.Paint = function(s, w, h)
3189 local x, y = self.Header:LocalToScreen();
3190
3191 BSHADOWS.BeginShadow()
3192 surface.SetDrawColor(self.Colors.settings_containers);
3193 surface.DrawRect(x, y, w, h);
3194 BSHADOWS.EndShadow(1, 2, 2);
3195 end
3196
3197 return self.Header;
3198end
3199
3200---
3201--- CreateHeaderChild
3202---
3203function panel:CreateHeaderChild(pnl, title, lastWasSpacer)
3204 self.Child = pnl:Add("DPanel");
3205 self.Child:SetPos(pnl.xPos, 0);
3206 self.Child:SetSize(self.xSize, 35);
3207 self.Child.Paint = function(s, w, h)
3208 surface.SetDrawColor(0, 0, 0, 0);
3209 surface.DrawRect(0, 0, w, h);
3210
3211 draw.SimpleText(gElo.utf8upper(title), "gElo.18", w / 2, h / 2, self.Colors.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
3212
3213 surface.SetDrawColor(self.Colors.main_outline);
3214 surface.DrawRect(w - 1, 0, 1, h);
3215
3216 if (lastWasSpacer) then
3217 surface.SetDrawColor(self.Colors.main_outline);
3218 surface.DrawRect(0, 0, 1, h);
3219 end
3220 end
3221
3222 pnl.xPos = pnl.xPos + self.xSize;
3223end
3224
3225---
3226--- CreateMatchChild
3227---
3228function panel:CreateMatchChild(pnl, str, col, lastWasSpacer)
3229 str = tostring(str);
3230
3231 if (#str > 13) then
3232 str = str:sub(0, 13) .. ".."
3233 end
3234
3235 col = col or self.Colors.other_text;
3236
3237 self.MatchChild = pnl:Add("DPanel");
3238 self.MatchChild:SetPos(pnl.xPos, 0);
3239 self.MatchChild:SetSize(self.xSize, 35);
3240 self.MatchChild.Paint = function(s, w, h)
3241 surface.SetDrawColor(0, 0, 0, 0);
3242 surface.DrawRect(0, 0, w, h);
3243
3244 draw.SimpleText(gElo.utf8upper(str), "gElo.16", w / 2, h / 2, col, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
3245
3246 surface.SetDrawColor(self.Colors.main_outline);
3247 surface.DrawRect(w - 1, 0, 1, h - 1);
3248
3249 if (lastWasSpacer) then
3250 surface.SetDrawColor(self.Colors.main_outline);
3251 surface.DrawRect(0, 0, 1, h - 1);
3252 end
3253 end
3254
3255 pnl.xPos = pnl.xPos + self.xSize;
3256end
3257
3258---
3259--- CreateMatch
3260---
3261function panel:CreateMatch(map, won, role, time, kills, rp, dmg, shots, date)
3262 self.Match = self:Add("DPanel")
3263 self.Match:SetPos(0, self.yPos);
3264 self.Match.xPos = 0;
3265 self.Match:SetSize(977, 35);
3266 self.Match.Paint = function(s, w, h)
3267 surface.SetDrawColor(self.Colors.main_background);
3268 surface.SetMaterial(self.BackgroundMaterial);
3269 surface.DrawTexturedRect(0, 0, w, h);
3270
3271 surface.SetDrawColor(won and Color(70, 134, 196, 100) or Color(150, 56, 50, 100));
3272 surface.DrawRect(0, h - 1, w, 1);
3273 end
3274
3275 self:CreateMatchChild(self.Match, map);
3276 self:CreateMatchChild(self.Match, gElo.utf8upper(won and gElo.L("historyVictory") or gElo.L("historyDefeat")), won and Color(70, 134, 196, 255) or Color(150, 56, 50, 255));
3277 self:CreateMatchChild(self.Match, gElo.SecondsToMinutes(time));
3278 self:CreateMatchChild(self.Match, gElo.L(role:lower()), self:GetRoleColor(role));
3279 self:CreateMatchChild(self.Match, string.Comma(kills));
3280 self:CreateMatchChild(self.Match, string.Comma(dmg));
3281 self:CreateMatchChild(self.Match, string.Comma(shots));
3282
3283 if (tonumber(rp) < 0) then
3284 self:CreateMatchChild(self.Match, rp, Color(150, 56, 50, 255));
3285 else
3286 self:CreateMatchChild(self.Match, rp, Color(70, 134, 196, 255));
3287 end
3288
3289 local date = os.date("*t", date);
3290 local today = os.date("*t");
3291 local dateString = "unknown"
3292
3293 if (date.day == today.day) then
3294 dateString = gElo.L("historyToday");
3295 elseif(today.day - 1 == date.day) then
3296 dateString = gElo.L("historyYesterday")
3297 else
3298 local y = string.Replace(date.year, "20", "");
3299 dateString = date.day .. "/" .. date.month .. "/" .. y;
3300 end
3301
3302 self:CreateMatchChild(self.Match, dateString);
3303 self.yPos = self.yPos + 35;
3304end
3305
3306---
3307--- PerformLayout
3308---
3309function panel:PerformLayout(w, h)
3310 self.Header:SetPos(0, 7);
3311 self.Header:SetSize(w, 35);
3312end
3313
3314---
3315--- Init
3316---
3317function panel:Init()
3318 self.BackgroundMaterial = Material("gelo/main_background.png");
3319 self:GetColors();
3320 self.yPos = 49;
3321 self.xSize = 108;
3322
3323 self.Head = self:CreateHeader();
3324 self:CreateHeaderChild(self.Head, gElo.L("historyMap"));
3325 self:CreateHeaderChild(self.Head, gElo.L("historyResult"));
3326 self:CreateHeaderChild(self.Head, gElo.L("historyTook"));
3327 self:CreateHeaderChild(self.Head, gElo.L("historyRole"));
3328 self:CreateHeaderChild(self.Head, gElo.L("sqlKills"));
3329 self:CreateHeaderChild(self.Head, gElo.L("historyDealt"));
3330 self:CreateHeaderChild(self.Head, gElo.L("historyFired"));
3331 self:CreateHeaderChild(self.Head, gElo.L("historyRP"));
3332 self:CreateHeaderChild(self.Head, gElo.L("historyPlayed"));
3333
3334 panelReference = self;
3335end
3336
3337---
3338--- Paint
3339---
3340function panel:Paint(w, h)
3341 surface.SetDrawColor(self.Colors.main_background);
3342 surface.SetMaterial(self.BackgroundMaterial);
3343 surface.DrawTexturedRect(0, 0, w, h);
3344end
3345vgui.Register("gElo.MainHistoryPanel", panel, "EditablePanel");
3346
3347net.Receive("gElo.SendMatchHistory", function()
3348 matches = net.ReadTable();
3349
3350 for k, v in ipairs(matches or {}) do
3351 if (not IsValid(panelReference)) then return; end
3352
3353 panelReference:CreateMatch(v.Map, tobool(v.Won), v.Role, v.RoundTime, v.Kills, v.RP, v.DamageDealt, v.Shots, v.Date);
3354 end
3355
3356 local main = panelReference:GetParent();
3357 if (IsValid(main)) then
3358 main:HeaderWarning(gElo.L("historyUpdated"), 3, Color(0, 150, 50, 200));
3359 end
3360end);
3361
3362net.Receive("gElo.SendOldHistory", function()
3363 for k, v in ipairs(matches or {}) do
3364 if (not IsValid(panelReference)) then return; end
3365
3366 panelReference:CreateMatch(v.Map, tobool(v.Won), v.Role, v.RoundTime, v.Kills, v.RP, v.DamageDealt, v.Shots, v.Date);
3367 end
3368end);
3369
3370--[[------------------------------------------------------------------------------
3371 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
3372 * Unauthorized copying of this file, via any medium is strictly prohibited
3373 * Proprietary and confidential
3374--]]------------------------------------------------------------------------------
3375
3376local panel = {};
3377local leaderboard = {};
3378local me = {};
3379local userCount = 0;
3380local panelReference = nil
3381local LeaderBoardsIsOnCD = CurTime();
3382local canBeBig = true;
3383local myPosition = -1;
3384
3385---
3386--- GetColors
3387---
3388function panel:GetColors()
3389 self.Colors = gElo.GetColorFromString("main_background", "main_outline", "other_text", "settings_containers");
3390end
3391
3392---
3393--- CreateHeader
3394---
3395function panel:CreateHeader()
3396 self.Header = self:Add("DPanel")
3397 self.Header.xPos = 0;
3398 self.Header.Paint = function(s, w, h)
3399 local x, y = self.Header:LocalToScreen();
3400
3401 BSHADOWS.BeginShadow()
3402 surface.SetDrawColor(self.Colors.settings_containers);
3403 surface.DrawRect(x, y, w, h);
3404 BSHADOWS.EndShadow(1, 2, 2);
3405 end
3406
3407 return self.Header;
3408end
3409
3410---
3411--- CreateHeaderChild
3412---
3413function panel:CreateHeaderChild(pnl, xSize, title, sortType)
3414 self.Child = pnl:Add("DButton");
3415 self.Child:SetPos(pnl.xPos, 0);
3416 if (xSize) then
3417 self.Child:SetSize(xSize, 35);
3418 else
3419 self.Child:SetSize(self.xSize, 35);
3420 end
3421 self.Child:SetText("");
3422 self.Child:SetCursor("arrow");
3423 self.Child.Paint = function(s, w, h)
3424 surface.SetDrawColor(s:IsHovered() and sortType ~= nil and self.Colors.main_outline or 0, 0, 0, 0);
3425 surface.DrawRect(0, 0, w, h);
3426
3427 draw.SimpleText(gElo.utf8upper(title), "gElo.18", w / 2, h / 2, self.Colors.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
3428
3429 surface.SetDrawColor(self.Colors.main_outline);
3430 surface.DrawRect(w - 1, 0, 1, h);
3431 end
3432
3433 self.Child.DoClick = function()
3434 if (not sortType or self.PageCooldown > CurTime()) then return; end
3435 self.SelectedSorting = sortType;
3436
3437 net.Start("gElo.GetLeaderBoards");
3438 net.WriteUInt(15, 32);
3439 net.WriteUInt(self.SelectedSorting, 8);
3440 net.WriteString("NULL");
3441 net.WriteBool(true);
3442 net.SendToServer();
3443
3444 self.PageCooldown = CurTime() + 3;
3445 end
3446
3447 if (xSize) then
3448 pnl.xPos = pnl.xPos + xSize;
3449 else
3450 pnl.xPos = pnl.xPos + self.xSize;
3451 end
3452end
3453
3454---
3455--- CreateLeaderRowChild
3456---
3457function panel:CreateLeaderRowChild(pnl, shouldBig, xSize, str, col)
3458 str = tostring(str);
3459
3460 if (#str > 26) then
3461 str = str:sub(0, 26) .. ".."
3462 end
3463
3464 col = col or self.Colors.other_text;
3465
3466 self.MatchChild = pnl:Add("DPanel");
3467 self.MatchChild:SetPos(pnl.xPos, 0);
3468 if (xSize) then
3469 if (canBeBig) then
3470 self.MatchChild:SetSize(xSize, 53);
3471 else
3472 self.MatchChild:SetSize(xSize, 35);
3473 end
3474 else
3475 if (canBeBig) then
3476 self.MatchChild:SetSize(self.xSize, 53);
3477 else
3478 self.MatchChild:SetSize(self.xSize, 35);
3479 end
3480 end
3481 self.MatchChild.Paint = function(s, w, h)
3482 surface.SetDrawColor(0, 0, 0, 0);
3483 surface.DrawRect(0, 0, w, h);
3484
3485 draw.SimpleText(str, shouldBig and "gElo.20" or "gElo.16", w / 2, h / 2, col, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
3486
3487 surface.SetDrawColor(self.Colors.main_outline);
3488 surface.DrawRect(w - 1, 0, 1, h - 1);
3489 end
3490
3491 if (xSize) then
3492 pnl.xPos = pnl.xPos + xSize;
3493 else
3494 pnl.xPos = pnl.xPos + self.xSize;
3495 end
3496end
3497
3498---
3499--- CreateLeaderRow
3500---
3501function panel:CreateLeaderRow(pnl, yPos, pos, name, rank, division, elo, kills, deaths, wins, losses)
3502 self.Match = pnl:Add("DPanel")
3503 if (yPos) then
3504 self.Match:SetPos(0, yPos);
3505 self.Match:SetSize(977, 53);
3506 else
3507 if (self.yPos == 35) then
3508 self.Match:SetPos(0, self.yPos + 18);
3509 self.Match:SetSize(977, 35);
3510 else
3511 self.Match:SetPos(0, self.yPos);
3512 self.Match:SetSize(977, 35);
3513 end
3514 end
3515 self.Match.xPos = 0;
3516 self.Match.Paint = function(s, w, h)
3517 surface.SetDrawColor(self.Colors.main_background);
3518 surface.SetMaterial(self.BackgroundMaterial);
3519 surface.DrawTexturedRect(0, 0, w, h);
3520
3521 surface.SetDrawColor(gElo.EloToColor(rank));
3522 surface.DrawRect(0, h - 1, w, 1);
3523 end
3524
3525 self:CreateLeaderRowChild(self.Match, canBeBig, 75, string.Comma(pos));
3526 self:CreateLeaderRowChild(self.Match, canBeBig, 208, name);
3527 self:CreateLeaderRowChild(self.Match, canBeBig, 150, gElo.L(rank:lower()) .. " " .. gElo.NumberToRoman(tonumber(division)), gElo.EloToColor(rank));
3528 self:CreateLeaderRowChild(self.Match, canBeBig, nil, elo);
3529 self:CreateLeaderRowChild(self.Match, canBeBig, nil, kills);
3530 self:CreateLeaderRowChild(self.Match, canBeBig, nil, deaths);
3531 self:CreateLeaderRowChild(self.Match, canBeBig, nil, wins);
3532 self:CreateLeaderRowChild(self.Match, canBeBig, nil, losses);
3533
3534 if (yPos == nil) then
3535 if (self.yPos == 35) then
3536 self.yPos = self.yPos + 53;
3537 else
3538 self.yPos = self.yPos + 35;
3539 end
3540 end
3541
3542 canBeBig = false;
3543end
3544
3545function panel:ClearTheBoard()
3546 self.yPos = 35;
3547 self.xSize = 108;
3548 self.SelectedSorting = 0;
3549 canBeBig = true;
3550
3551 -- Clear the board.
3552 if (IsValid(self.ScrollPanel)) then
3553 self.ScrollPanel:Clear();
3554 end
3555end
3556
3557---
3558--- Init
3559---
3560function panel:Init()
3561 self.BackgroundMaterial = Material("gelo/main_background.png");
3562 self:GetColors();
3563 self.yPos = 35;
3564 self.xSize = 108;
3565 self.CurrentPage = 1;
3566 self.MaxPages = 1;
3567 self.CurrentPageRaw = 14;
3568 self.PageCooldown = CurTime();
3569 self.SelectedSorting = 0;
3570 self.LookupUserAllCooldown = CurTime();
3571 self.PositionCount = 1;
3572
3573 -- Reset local variables.
3574 canBeBig = true;
3575
3576 self.ScrollPanel = self:Add("DScrollPanel")
3577 self.ScrollPanel.yPos = 12;
3578 self.ScrollPanel.Paint = function(s, w, h)
3579 surface.SetDrawColor(self.Colors.main_background);
3580 surface.SetMaterial(self.BackgroundMaterial);
3581 surface.DrawTexturedRect(0, 0, w, h);
3582 end
3583
3584 self.Head = self:CreateHeader();
3585 self:CreateHeaderChild(self.Head, 75, "#", 0);
3586 self:CreateHeaderChild(self.Head, 208, gElo.L("leaderName"));
3587 self:CreateHeaderChild(self.Head, 150, gElo.L("leaderRank"), 0);
3588 self:CreateHeaderChild(self.Head, nil, gElo.L("leaderElo"), 0);
3589 self:CreateHeaderChild(self.Head, nil, gElo.L("sqlKills"), 1);
3590 self:CreateHeaderChild(self.Head, nil, gElo.L("sqlDeaths"), 2);
3591 self:CreateHeaderChild(self.Head, nil, gElo.L("sqlWins"), 3);
3592 self:CreateHeaderChild(self.Head, nil, gElo.L("sqlLosses"), 4);
3593
3594 self.Back = self:Add("gElo.Button");
3595 self.Back:SetCustomText(gElo.L("adminBack"));
3596 self.Back.SetDoClick = function()
3597 if (self.CurrentPage <= 1 or self.LookupUserAllCooldown > CurTime()) then return; end
3598
3599 net.Start("gElo.GetLeaderBoards");
3600 net.WriteUInt(self.CurrentPageRaw - 15, 32);
3601 net.WriteUInt(self.SelectedSorting, 8);
3602 net.WriteString("NULL");
3603 net.WriteBool(true);
3604 net.SendToServer();
3605
3606 self.CurrentPage = self.CurrentPage - 1;
3607 self.CurrentPageRaw = self.CurrentPageRaw - 14;
3608 self.LookupUserAllCooldown = CurTime() + 2;
3609 end
3610
3611 self.Next = self:Add("gElo.Button");
3612 self.Next:SetCustomText(gElo.L("adminNext"));
3613 self.Next.SetDoClick = function()
3614 if (self.CurrentPage >= self.MaxPages or self.LookupUserAllCooldown > CurTime()) then return; end
3615
3616 net.Start("gElo.GetLeaderBoards");
3617 net.WriteUInt(self.CurrentPageRaw + 15, 32);
3618 net.WriteUInt(self.SelectedSorting, 8);
3619 net.WriteString("NULL");
3620 net.WriteBool(true);
3621 net.SendToServer();
3622
3623 self.CurrentPage = self.CurrentPage + 1;
3624 self.CurrentPageRaw = self.CurrentPageRaw + 14;
3625 self.LookupUserAllCooldown = CurTime() + 2;
3626 end
3627
3628 self.Search = self:Add("gElo.TextEntry");
3629 self.Search:SetBackgroundText(gElo.L("userSearch"))
3630 self.Search.OnCustomEnter = function()
3631 net.Start("gElo.GetLeaderBoards");
3632 net.WriteUInt(15, 32);
3633 net.WriteUInt(0, 8);
3634 net.WriteString(self.Search:GetValue());
3635 net.WriteBool(true);
3636 net.SendToServer();
3637
3638 self.CurrentPageRaw = 14;
3639 self.MaxPages = 1;
3640 self.CurrentPage = 1;
3641 self.LookupUserAllCooldown = CurTime() + 2;
3642 end
3643
3644 panelReference = self;
3645end
3646
3647---
3648--- PerformLayout
3649---
3650function panel:PerformLayout(w, h)
3651 self.Header:SetPos(0, 7);
3652 self.Header:SetSize(w, 35);
3653
3654 self.ScrollPanel:SetPos(0, 50);
3655 self.ScrollPanel:SetSize(w, h - 100);
3656
3657 self.Back:SetPos(25, h - 42);
3658 self.Back:SetSize(135, 34);
3659
3660 self.Next:SetPos(w - 160, h - 42);
3661 self.Next:SetSize(135, 34);
3662
3663 self.Search:SetPos(w - 320, h - 42);
3664 self.Search:SetSize(135, 34);
3665end
3666
3667---
3668--- Paint
3669---
3670function panel:Paint(w, h)
3671 surface.SetDrawColor(self.Colors.main_background);
3672 surface.SetMaterial(self.BackgroundMaterial);
3673 surface.DrawTexturedRect(0, 0, w, h);
3674
3675 draw.SimpleText(gElo.utf8upper(gElo.L("userPage") .. ": " .. self.CurrentPage .. "/" .. self.MaxPages), "gElo.16", 185, h - 21, self.Colors.other_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
3676end
3677vgui.Register("gElo.MainLeaderboardsPanel", panel, "EditablePanel");
3678
3679net.Receive("gElo.SendLeaderBoards", function()
3680 local shouldReplace = net.ReadBool();
3681 local tempTable = {};
3682
3683 myPosition = net.ReadUInt(32);
3684 me = net.ReadTable();
3685
3686 if (shouldReplace) then
3687 leaderboard = net.ReadTable();
3688 userCount = net.ReadUInt(32);
3689 else
3690 tempTable = net.ReadTable();
3691 end
3692
3693 if (IsValid(panelReference)) then
3694 if (shouldReplace) then
3695 if (userCount > 15) then
3696 panelReference.MaxPages = math.Round(userCount / 15);
3697 else
3698 panelReference.MaxPages = 1;
3699 end
3700 else
3701 panelReference.MaxPages = 1;
3702 panelReference.CurrentPage = 1;
3703 end
3704
3705 -- Reset variables.
3706 panelReference:ClearTheBoard();
3707 end
3708
3709 -- Make sure to create
3710 panelReference:CreateLeaderRow(panelReference.ScrollPanel, 0, myPosition, me["Name"], me["Rank"], me["Division"], me["Elo"], me["Kills"], me["Deaths"], me["TotalWins"], me["TotalLosses"]);
3711
3712 for k, v in ipairs(shouldReplace and leaderboard or tempTable) do
3713 if (not IsValid(panelReference)) then return; end
3714
3715 panelReference:CreateLeaderRow(panelReference.ScrollPanel, nil, v.Position, v.Name, v.Rank, v.Division, v.Elo, v.Kills, v.Deaths, v.TotalWins, v.TotalLosses);
3716 end
3717
3718 if (shouldReplace) then
3719 LeaderBoardsIsOnCD = CurTime() + 600;
3720 end
3721
3722 local main = panelReference:GetParent();
3723 if (IsValid(main)) then
3724 main:HeaderWarning(gElo.L("svLeaderUpdated"), 3, Color(0, 150, 50, 200));
3725 end
3726end);
3727
3728net.Receive("gElo.SendOldLeaderBoards", function()
3729 if (IsValid(panelReference)) then
3730 if (userCount > 15) then
3731 panelReference.MaxPages = math.Round(userCount / 15);
3732 else
3733 panelReference.MaxPages = 1;
3734 end
3735
3736 -- Reset variables.
3737 panelReference:ClearTheBoard();
3738 else
3739 return;
3740 end
3741
3742 panelReference:CreateLeaderRow(panelReference.ScrollPanel, 0, myPosition, me["Name"], me["Rank"], me["Division"], me["Elo"], me["Kills"], me["Deaths"], me["TotalWins"], me["TotalLosses"]);
3743
3744 for k, v in ipairs(leaderboard or {}) do
3745 if (not IsValid(panelReference)) then return; end
3746
3747 panelReference:CreateLeaderRow(panelReference.ScrollPanel, nil, v.Position, v.Name, v.Rank, v.Division, v.Elo, v.Kills, v.Deaths, v.TotalWins, v.TotalLosses);
3748 end
3749
3750 local main = panelReference:GetParent();
3751
3752 if (IsValid(main)) then
3753 main:HeaderWarning(gElo.L("leaderCooldown") .. string.NiceTime(LeaderBoardsIsOnCD - CurTime()) .. ".", 3);
3754 end
3755end);
3756
3757--[[------------------------------------------------------------------------------
3758 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
3759 * Unauthorized copying of this file, via any medium is strictly prohibited
3760 * Proprietary and confidential
3761--]]------------------------------------------------------------------------------
3762
3763local panel = {};
3764AccessorFunc(panel, "Description", "Description", FORCE_STRING);
3765
3766---
3767--- GetColors
3768---
3769function panel:GetColors()
3770 self.Colors = gElo.GetColorFromString("main_outline", "main_background", "notifcation_text");
3771end
3772
3773---
3774--- DoAcceptClick
3775---
3776function panel:DoAcceptClick()
3777 -- For Reference Later
3778end
3779
3780---
3781--- DoDeclineClick
3782---
3783function panel:DoDeclineClick()
3784 -- XD
3785end
3786
3787---
3788--- Init
3789---
3790function panel:Init()
3791 self.BackgroundMaterial = Material("gelo/main_background.png");
3792 self.ExitMat = Material("gelo/x.png", "noclamp smooth");
3793 self.Size = 0;
3794
3795 -- Colors
3796 self:GetColors();
3797
3798 -- Header
3799 self.Header = self:Add("gElo.MainPanelHeader");
3800 self.Header:SetUseSmallHeader(true);
3801
3802 -- Exit
3803 self.Exit = self:Add("DButton");
3804 self.Exit:SetText("");
3805 self.Exit:SetCursor("arrow");
3806 self.Exit.Paint = function(s, w, h)
3807 surface.SetDrawColor(0, 0, 0, 0);
3808 surface.DrawRect(0, 0, w, h);
3809
3810 surface.SetDrawColor(s:IsHovered() and Color(150, 150, 150, 200) or Color(100, 100, 100, 100));
3811 surface.SetMaterial(self.ExitMat);
3812 surface.DrawTexturedRect(w / 2, h / 2, w - 20, h - 20);
3813 end
3814
3815 self.Exit.DoClick = function()
3816 if (IsValid(self)) then
3817 self:Remove();
3818 self:DoDeclineClick(self);
3819 end
3820 end
3821
3822 self.Accept = self:Add("gElo.Button");
3823 self.Accept:SetCustomText(gElo.L("notificationAccept"));
3824 self.Accept.SetDoClick = function()
3825 self:DoAcceptClick(self);
3826 end
3827
3828 self.Decline = self:Add("gElo.Button");
3829 self.Decline:SetCustomText(gElo.L("notificationDecline"));
3830 self.Decline.SetDoClick = function()
3831 self:DoDeclineClick(self);
3832 end
3833end
3834
3835---
3836--- PerformLayout
3837---
3838function panel:PerformLayout(w, h)
3839 self.Header:SetPos(2, 2);
3840 self.Header:SetSize(w - 4, 68);
3841
3842 self.Exit:SetPos(w - 38, -8);
3843 self.Exit:SetSize(32, 32);
3844
3845 self.Accept:SetPos(25, (h - 34) - 21);
3846 self.Accept:SetSize(135, 34);
3847
3848 self.Decline:SetPos((25 + self.Accept:GetWide()) + 12, (h - 34) - 21);
3849 self.Decline:SetSize(135, 34);
3850
3851 if (#self.Description > 62) then
3852 local multiplier = 0.23;
3853
3854 if (self.Description:find("\n")) then
3855 local newLineCount = select(2, self.Description:gsub("%\n", ""));
3856
3857 multiplier = multiplier + (.05 * newLineCount);
3858 end
3859
3860 self.Size = (multiplier * (#self.Description - 62))
3861 end
3862
3863 self:SetSize(400, 150 + self.Size);
3864 self:Center();
3865end
3866
3867---
3868--- Paint
3869---
3870function panel:Paint(w, h)
3871 -- Main Background Image
3872 surface.SetDrawColor(self.Colors.main_background);
3873 surface.SetMaterial(self.BackgroundMaterial);
3874 surface.DrawTexturedRect(2, 2, w - 4, h - 4);
3875
3876 -- Black Outline
3877 surface.SetDrawColor(0, 0, 0, 255);
3878 surface.DrawOutlinedRect(0, 0, w, h)
3879
3880 -- Outline
3881 surface.SetDrawColor(self.Colors.main_outline);
3882 surface.DrawOutlinedRect(1, 1, w - 2, h - 2)
3883
3884 -- Description
3885 draw.DrawText(gElo.textWrap(self.Description, "gElo.16", w - 60), "gElo.16", 25, 35, self.Colors.notifcation_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
3886end
3887vgui.Register("gElo.Notification", panel, "EditablePanel");
3888
3889--[[------------------------------------------------------------------------------
3890 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
3891 * Unauthorized copying of this file, via any medium is strictly prohibited
3892 * Proprietary and confidential
3893--]]------------------------------------------------------------------------------
3894
3895local panel = {};
3896
3897---
3898--- GetColors
3899---
3900function panel:GetColors()
3901 self.Colors = gElo.GetColorFromString("main_background", "other_text");
3902end
3903
3904---
3905--- Init
3906---
3907function panel:Init()
3908 self.BackgroundMaterial = Material("gelo/main_background.png");
3909 self:GetColors();
3910end
3911
3912---
3913--- Paint
3914---
3915function panel:Paint(w, h)
3916 local x, y = self:LocalToScreen();
3917
3918 surface.SetDrawColor(self.Colors.main_background);
3919 surface.SetMaterial(self.BackgroundMaterial);
3920 surface.DrawTexturedRect(0, 0, w, h);
3921
3922 BSHADOWS.BeginShadow();
3923 draw.SimpleText(gElo.utf8upper(gElo.L("pluginsError")), "gElo.26", x + (w / 2), y + (h / 2) - 50, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
3924 BSHADOWS.EndShadow(1, 2, 2);
3925end
3926vgui.Register("gElo.MainPluginsPanel", panel, "EditablePanel");
3927
3928--[[------------------------------------------------------------------------------
3929 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
3930 * Unauthorized copying of this file, via any medium is strictly prohibited
3931 * Proprietary and confidential
3932--]]------------------------------------------------------------------------------
3933
3934local panel = {};
3935local combatStats = {};
3936local innocentStats = {};
3937local detectiveStats = {};
3938local traitorStats = {};
3939local general = {};
3940local panelReference = nil
3941
3942---
3943--- GetColors
3944---
3945function panel:GetColors()
3946 self.Colors = gElo.GetColorFromString("main_background", "settings_containers", "other_text", "main_outline");
3947end
3948
3949---
3950--- GetFancyName
3951---
3952function panel:GetFancyName(str)
3953 local converter = {
3954 ["kills"] = gElo.L("sqlKills"),
3955 ["deaths"] = gElo.L("sqlDeaths"),
3956 ["bulletsfired"] = gElo.L("sqlBulletsFired"),
3957 ["firedamagedealt"] = gElo.L("sqlFireDamageDealt"),
3958 ["damagedealt"] = gElo.L("sqlDamageDealt"),
3959 ["traitordeaths"] = gElo.L("sqlDeaths"),
3960 ["traitorkills"] = gElo.L("sqlKills"),
3961 ["detectivedeaths"] = gElo.L("sqlDeaths"),
3962 ["detectivekills"] = gElo.L("sqlKills"),
3963 ["innocentdeaths"] = gElo.L("sqlDeaths"),
3964 ["innocentkills"] = gElo.L("sqlKills"),
3965 ["traitorlosses"] = gElo.L("sqlLosses"),
3966 ["detectivelosses"] = gElo.L("sqlLosses"),
3967 ["innocentlosses"] = gElo.L("sqlLosses"),
3968 ["totallosses"] = gElo.L("sqlLosses"),
3969 ["totalwins"] = gElo.L("sqlWins"),
3970 ["traitorwins"] = gElo.L("sqlWins"),
3971 ["detectivewins"] = gElo.L("sqlWins"),
3972 ["innocentwins"] = gElo.L("sqlWins"),
3973 ["roundsplayed"] = gElo.L("sqlRoundsPlayed"),
3974 ["innocentdamage"] = gElo.L("sqlDamageDealt"),
3975 ["detectivedamage"] = gElo.L("sqlDamageDealt"),
3976 ["traitordamage"] = gElo.L("sqlDamageDealt"),
3977 }
3978
3979 if (converter[str]) then
3980 return converter[str];
3981 end
3982
3983 return str;
3984end
3985
3986---
3987--- CreateContainer
3988---
3989function panel:CreateContainer(title, x, y, col)
3990 self.Container = self:Add("DPanel");
3991 self.Container.xPos = 0;
3992 self.Container:SetPos(x, y);
3993 self.Container:SetSize(967, 35);
3994 self.Container.Paint = function(s, width, tall)
3995 local x, y = s:LocalToScreen();
3996
3997 surface.SetDrawColor(self.Colors.settings_containers);
3998 BSHADOWS.BeginShadow();
3999 surface.DrawRect(x, y, width, tall);
4000
4001 surface.DisableClipping(true);
4002 draw.SimpleText(gElo.utf8upper(title), "gElo.20", x + 20, y - 20, col or self.Colors.other_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
4003 surface.DisableClipping(false);
4004 BSHADOWS.EndShadow(1, 2, 2);
4005 end
4006
4007 self.yPos = self.yPos + 120;
4008 table.insert(self.CreatedContainers, self.Container);
4009
4010 return self.Container;
4011end
4012
4013---
4014--- CreateInfo
4015---
4016function panel:CreateInfo(pnl, title, value)
4017 self.Info = pnl:Add("DPanel");
4018 self.Info:SetPos(pnl.xPos, 0);
4019 self.Info:SetSize(210, self.Container:GetTall());
4020 self.Info.Paint = function(s, w, h)
4021 surface.SetDrawColor(0, 0, 0, 0);
4022 surface.DrawRect(0, 0, w, h);
4023
4024 draw.SimpleText(gElo.utf8upper(title), "gElo.18", (w / 2) + 9, 10, self.Colors.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4025 draw.SimpleText(string.Comma(value), "gElo.14", (w / 2) + 9, 25, self.Colors.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4026
4027 surface.SetDrawColor(self.Colors.main_outline);
4028 surface.DrawRect(w - 1, 0, 1, h);
4029 end
4030
4031 pnl.xPos = pnl.xPos + 190;
4032end
4033
4034---
4035--- CreateContainers
4036---
4037function panel:CreateContainers()
4038 self.Profile = self:CreateContainer(gElo.L("profileCombat"), 5, self.yPos);
4039 self.General = self:CreateContainer(gElo.L("profileOther"), 5, self.yPos);
4040 self.Innocent = self:CreateContainer(gElo.L("profileInnocent"), 5, self.yPos, Color(0, 200, 0, 200));
4041 self.Detective = self:CreateContainer(gElo.L("profileDetective"), 5, self.yPos, Color(0, 127, 255, 200));
4042 self.Traitor = self:CreateContainer(gElo.L("profileTraitor"), 5, self.yPos, Color(200, 0, 0, 200));
4043
4044 return true;
4045end
4046
4047---
4048--- CreateInfos
4049---
4050function panel:CreateInfos()
4051 for k, v in ipairs(self.CreatedContainers) do
4052 if (IsValid(v)) then
4053 v:Remove();
4054 end
4055 end
4056
4057 table.Empty(self.CreatedContainers);
4058 self.yPos = 40;
4059 self:CreateContainers();
4060
4061 for k, v in ipairs(combatStats) do
4062 self:CreateInfo(self.Profile, self:GetFancyName(v.stat:lower()), v.num);
4063 end
4064
4065 for k, v in ipairs(general) do
4066 self:CreateInfo(self.General, self:GetFancyName(v.stat:lower()), v.num);
4067 end
4068
4069 for k, v in ipairs(innocentStats) do
4070 self:CreateInfo(self.Innocent, self:GetFancyName(v.stat:lower()), v.num);
4071 end
4072
4073 for k, v in ipairs(detectiveStats) do
4074 self:CreateInfo(self.Detective, self:GetFancyName(v.stat:lower()), v.num);
4075 end
4076
4077 for k, v in ipairs(traitorStats) do
4078 self:CreateInfo(self.Traitor, self:GetFancyName(v.stat:lower()), v.num);
4079 end
4080
4081 return true;
4082end
4083
4084---
4085--- Init
4086---
4087function panel:Init()
4088 self.BackgroundMaterial = Material("gelo/main_background.png");
4089 self:GetColors();
4090 self.yPos = 40;
4091 self.CreatedContainers = {};
4092
4093 self:CreateContainers();
4094 self:CreateInfos();
4095
4096 panelReference = self;
4097end
4098
4099---
4100--- Paint
4101---
4102function panel:Paint(w, h)
4103 surface.SetDrawColor(self.Colors.main_background);
4104 surface.SetMaterial(self.BackgroundMaterial);
4105 surface.DrawTexturedRect(0, 0, w, h);
4106end
4107vgui.Register("gElo.MainProfilePanel", panel, "EditablePanel");
4108
4109net.Receive("gElo.SendProfileStats", function(_, ply)
4110 combatStats = net.ReadTable();
4111 innocentStats = net.ReadTable();
4112 detectiveStats = net.ReadTable();
4113 traitorStats = net.ReadTable();
4114 general = net.ReadTable();
4115
4116 if (IsValid(panelReference)) then
4117 panelReference:CreateInfos();
4118 end
4119end);
4120
4121--[[------------------------------------------------------------------------------
4122 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
4123 * Unauthorized copying of this file, via any medium is strictly prohibited
4124 * Proprietary and confidential
4125--]]------------------------------------------------------------------------------
4126
4127local panel = {};
4128
4129AccessorFunc(panel, "InterfaceHeader", "InterfaceHeader", FORCE_STRING);
4130AccessorFunc(panel, "InterfaceRank", "InterfaceRank", FORCE_STRING);
4131AccessorFunc(panel, "InterfaceDivision", "InterfaceDivision", FORCE_NUMBER);
4132AccessorFunc(panel, "InterfaceTexture", "InterfaceTexture");
4133AccessorFunc(panel, "WasPromoted", "WasPromoted", FORCE_BOOL);
4134
4135---
4136--- GetColors
4137---
4138function panel:GetColors()
4139 self.Colors = gElo.GetColorFromString("main_outline", "main_background", "other_text");
4140end
4141
4142---
4143--- Init
4144---
4145function panel:Init()
4146 self.BackgroundMaterial = Material("gelo/main_background.png");
4147 self.TextureCur = CurTime() + 1;
4148
4149 -- Retrieve Colors
4150 self:GetColors();
4151
4152 -- Header
4153 self.Header = self:Add("gElo.MainPanelHeader");
4154 self.Header:SetUseSmallHeader(true);
4155
4156 -- Once 10 seconds have passed we remove the notification.
4157 timer.Simple(10, function()
4158 if (IsValid(self)) then
4159 self.TextureCur = CurTime() + 2;
4160
4161 self:SizeTo(450, 0, 1, 0, -1, function()
4162 if (IsValid(self)) then
4163 self:Remove();
4164 end
4165 end);
4166 end
4167 end);
4168end
4169
4170---
4171--- PerformLayout
4172---
4173function panel:PerformLayout(w, h)
4174 self.Header:SetPos(2, 2);
4175 self.Header:SetSize(w - 4, 68);
4176end
4177
4178---
4179--- Paint
4180---
4181function panel:Paint(w, h)
4182 local x, y = self:LocalToScreen();
4183
4184 -- Main Background Image
4185 surface.SetDrawColor(self.Colors.main_background);
4186 surface.SetMaterial(self.BackgroundMaterial);
4187 surface.DrawTexturedRect(2, 2, w - 4, h - 4);
4188
4189 -- Black Outline
4190 surface.SetDrawColor(0, 0, 0, 255);
4191 surface.DrawOutlinedRect(0, 0, w, h)
4192
4193 -- Outline
4194 surface.SetDrawColor(self.Colors.main_outline);
4195 surface.DrawOutlinedRect(1, 1, w - 2, h - 2)
4196
4197 -- Rank
4198 local youHaveBeen = gElo.L("promotionsYouHaveBeen");
4199 youHaveBeen = gElo.utf8upper(youHaveBeen);
4200
4201 if (self.TextureCur < CurTime()) then
4202 BSHADOWS.BeginShadow();
4203 draw.SimpleText(youHaveBeen, "gElo.16", x + 225, y + 22, self.Colors.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4204 draw.SimpleText(gElo.utf8upper(self.InterfaceHeader), "gElo.30", x + 225, y + 45, self.WasPromoted and Color(70, 134, 196, 255) or Color(150, 56, 50, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4205 draw.SimpleText(gElo.utf8upper(self.InterfaceRank .. " " .. gElo.NumberToRoman(self.InterfaceDivision)), "gElo.26", x + 228, (y + h) - 18, gElo.EloToColor(self.InterfaceRank), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4206 BSHADOWS.EndShadow(1, 2, 1);
4207 end
4208
4209 -- Texture
4210 surface.SetDrawColor(255, 255, 255, 255);
4211 surface.SetMaterial(self.InterfaceTexture);
4212 if (self.TextureCur > CurTime()) then return; end
4213 surface.DrawTexturedRect((w / 2) - 73, (h / 2) - 64, 150, 150);
4214end
4215vgui.Register("gElo.RankChangePanel", panel, "EditablePanel");
4216
4217net.Receive("gElo.RankInterface", function()
4218 local rankType = net.ReadBool();
4219 local rank = net.ReadString();
4220 local division = net.ReadUInt(4);
4221
4222 local interface = vgui.Create("gElo.RankChangePanel");
4223 interface:SetSize(450, 0);
4224 interface:SizeTo(450, 225, 1, 0)
4225 interface:SetPos((ScrW() / 2) - 225, (ScrH() / 2) - 375);
4226
4227 if (rankType) then
4228 interface:SetInterfaceHeader(gElo.L("promotionsPromoted"));
4229 interface:SetWasPromoted(true);
4230 surface.PlaySound("gElo/promoted.wav");
4231 else
4232 interface:SetInterfaceHeader(gElo.L("promotionsDemoted"));
4233 interface:SetWasPromoted(false);
4234 end
4235
4236 interface:SetInterfaceRank(rank);
4237 interface:SetInterfaceDivision(division);
4238 interface:SetInterfaceTexture(Material("gElo/" .. rank .. ".png", "noclamp smooth"));
4239end);
4240
4241--[[------------------------------------------------------------------------------
4242 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
4243 * Unauthorized copying of this file, via any medium is strictly prohibited
4244 * Proprietary and confidential
4245--]]------------------------------------------------------------------------------
4246
4247local panel = {};
4248
4249AccessorFunc(panel, "InterfaceHeader", "InterfaceHeader", FORCE_STRING);
4250AccessorFunc(panel, "InterfaceFooter", "InterfaceFooter", FORCE_STRING);
4251AccessorFunc(panel, "UseBlueColor", "UseBlueColor", FORCE_BOOL);
4252
4253---
4254--- GetColors
4255---
4256function panel:GetColors()
4257 self.Colors = gElo.GetColorFromString("main_outline", "main_background", "other_text");
4258end
4259
4260---
4261--- Init
4262---
4263function panel:Init()
4264 self.BackgroundMaterial = Material("gelo/main_background.png");
4265 self.TextureCur = CurTime() + 1;
4266
4267 -- Retrieve Colors
4268 self:GetColors();
4269
4270 -- Header
4271 self.Header = self:Add("gElo.MainPanelHeader");
4272 self.Header:SetUseSmallHeader(true);
4273
4274 -- Once 10 seconds have passed we remove the notification.
4275 timer.Simple(10, function()
4276 if (IsValid(self)) then
4277 self.TextureCur = CurTime() + 1;
4278
4279 self:SizeTo(450, 0, 1, 0, -1, function()
4280 if (IsValid(self)) then
4281 self:Remove();
4282 end
4283 end);
4284 end
4285 end);
4286end
4287
4288---
4289--- PerformLayout
4290---
4291function panel:PerformLayout(w, h)
4292 self.Header:SetPos(2, 2);
4293 self.Header:SetSize(w - 4, 68);
4294end
4295
4296---
4297--- Paint
4298---
4299function panel:Paint(w, h)
4300 local x, y = self:LocalToScreen();
4301
4302 -- Main Background Image
4303 surface.SetDrawColor(self.Colors.main_background);
4304 surface.SetMaterial(self.BackgroundMaterial);
4305 surface.DrawTexturedRect(2, 2, w - 4, h - 4);
4306
4307 -- Black Outline
4308 surface.SetDrawColor(0, 0, 0, 255);
4309 surface.DrawOutlinedRect(0, 0, w, h)
4310
4311 -- Outline
4312 surface.SetDrawColor(self.Colors.main_outline);
4313 surface.DrawOutlinedRect(1, 1, w - 2, h - 2)
4314
4315 -- Rank
4316 if (self.TextureCur < CurTime()) then
4317 BSHADOWS.BeginShadow();
4318 draw.DrawText(gElo.textWrap(gElo.utf8upper(self.InterfaceHeader), "gElo.16", 400), "gElo.16", x + 225, y + 22, self.Colors.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4319 draw.SimpleText(gElo.utf8upper(self.InterfaceFooter), "gElo.30", x + 225, y + 85, self.UseBlueColor and Color(70, 134, 196, 255) or Color(150, 56, 50, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4320 BSHADOWS.EndShadow(1, 2, 1);
4321 end
4322end
4323vgui.Register("gElo.SeriesPanel", panel, "EditablePanel");
4324
4325net.Receive("gElo.SeriesInterface", function()
4326 local head = net.ReadString();
4327 local foot = net.ReadString();
4328 local blueColor = net.ReadBool();
4329
4330 local interface = vgui.Create("gElo.SeriesPanel");
4331 interface:SetSize(450, 0);
4332 interface:SizeTo(450, 125, 1, 0)
4333 interface:SetPos((ScrW() / 2) - 225, (ScrH() / 2) - 375);
4334 interface:SetInterfaceHeader(gElo.L(head));
4335 interface:SetInterfaceFooter(gElo.L(foot));
4336 interface:SetUseBlueColor(blueColor);
4337end);
4338
4339--[[------------------------------------------------------------------------------
4340 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
4341 * Unauthorized copying of this file, via any medium is strictly prohibited
4342 * Proprietary and confidential
4343--]]------------------------------------------------------------------------------
4344
4345local panel = {};
4346
4347---
4348--- GetColors
4349---
4350function panel:GetColors()
4351 self.ColorSettings = gElo.GetColorFromString("main_background", "settings_containers");
4352end
4353
4354---
4355--- CallGetColors
4356---
4357function panel:CallGetColors(pnl)
4358 if (not IsValid(pnl)) then
4359 return false;
4360 end
4361
4362 if (pnl:HasChildren()) then
4363 for _, v in ipairs(pnl:GetChildren()) do
4364 if (IsValid(v) and v.GetColors) then
4365 v:GetColors();
4366 end
4367
4368 if (v:HasChildren()) then
4369 self:CallGetColors(v);
4370 end
4371 end
4372 end
4373end
4374
4375---
4376--- CreateColorChanger
4377---
4378function panel:CreateColorChanger(title, element)
4379 local colCount = #self.Colors + 1
4380
4381 self.Colors[colCount] = self:Add("DPanel");
4382 self.Colors[colCount].Paint = function(s, w, h)
4383 local x, y = s:LocalToScreen();
4384
4385 BSHADOWS.BeginShadow();
4386 surface.SetDrawColor(self.ColorSettings.settings_containers);
4387 surface.DrawRect(x, y, w, h);
4388 BSHADOWS.EndShadow(1, 2, 1);
4389
4390 draw.SimpleText(gElo.utf8upper(title), "gElo.16", 10, 10, Color(230, 230, 230, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
4391 end
4392
4393 self.Colors[colCount].Slider = self.Colors[colCount]:Add("DNumSlider");
4394 self.Colors[colCount].Slider:SetMinMax(0, 360);
4395 self.Colors[colCount].Slider:SetDecimals(0);
4396 self.Colors[colCount].Slider:SetWidth(0);
4397 self.Colors[colCount].Slider.TextArea:SetVisible(false);
4398 self.Colors[colCount].Slider.Scratch:SetVisible(false);
4399 self.Colors[colCount].Slider:SetValue(select(1, ColorToHSV(gElo.GetSettings():GetSettingsValue("ui", element))));
4400 self.Colors[colCount].Slider.BackgroundColor = gElo.GetSettings():GetSettingsValue("ui", element);
4401 self.Colors[colCount].Slider.Slider.Paint = function(s, w, h)
4402 draw.RoundedBox(6, 0, 0, s:GetWide(), s:GetTall(), self.Colors[colCount].Slider.BackgroundColor);
4403 end
4404 self.Colors[colCount].Slider.OnValueChanged = function(s, num)
4405 local num = math.Round(num);
4406 local col = HSVToColor(num, 1, 1);
4407
4408 s.BackgroundColor = col;
4409 end
4410 self.Colors[colCount].Slider.Slider.Knob.Paint = function(s, w, h)
4411 surface.SetDrawColor(255, 255, 255, 255);
4412 surface.SetMaterial(self.Knob)
4413 surface.DrawTexturedRect(0, 0, w, h);
4414 end
4415
4416 local slider = self.Colors[colCount].Slider.Slider;
4417 function slider:OnMouseReleased()
4418 self:SetDragging(false);
4419 self:MouseCapture(false);
4420
4421 if (not IsValid(self:GetParent())) then return; end
4422 local value = math.Round(self:GetParent():GetValue());
4423 local col = HSVToColor(value, 1, 1);
4424 gElo.GetSettings():SetSettingsValue("ui", element, col);
4425
4426 -- Now that we've set the color in our settings we have to call GetColors() on all panels to refresh their colors.
4427 -- Ugly af but works..
4428 local main = self:GetParent():GetParent():GetParent():GetParent():GetParent()
4429 if (IsValid(main)) then
4430 -- For every children attached to main we call GetColors if the function exists.
4431 self:GetParent():GetParent():GetParent():CallGetColors(main);
4432
4433 -- Then we call GetColors on the main panel, we don't do this in the other function.
4434 main:GetColors();
4435 end
4436
4437 self:GetParent():GetParent():GetParent():GetColors();
4438 end
4439
4440 local knobOnRelease = slider.Knob.OnMouseReleased;
4441 local knob = slider.Knob;
4442 function knob:OnMouseReleased(...)
4443 knobOnRelease(self, ...);
4444 slider:OnMouseReleased();
4445 end
4446end
4447
4448---
4449--- RemoveAllChangers
4450---
4451function panel:RemoveAllChangers()
4452 for _, v in ipairs(self.Colors) do
4453 if (IsValid(v)) then
4454 v:Remove();
4455 end
4456 end
4457
4458 table.Empty(self.Colors)
4459end
4460
4461---
4462--- Init
4463---
4464function panel:Init()
4465 self.BackgroundMaterial = Material("gelo/main_background.png");
4466 self.Knob = Material("gelo/slider_knob.png");
4467 self.Colors = {};
4468
4469 -- Colors
4470 self:GetColors();
4471
4472 -- Side Bar
4473 self.SideBar = self:Add("gElo.MainPanelSideBar");
4474
4475 -- Side Bar Buttons
4476 self.SideBar:CreateSideTab(gElo.L("colorSideTabbMainElements"), "gelo/palette.png", function()
4477 self:RemoveAllChangers();
4478
4479 self:CreateColorChanger(gElo.L("colorBackground"), "main_background");
4480 self:CreateColorChanger(gElo.L("colorOutline"), "main_outline");
4481 self:CreateColorChanger(gElo.L("colorHeader"), "main_header");
4482 self:CreateColorChanger(gElo.L("colorFooter"), "settings_footer");
4483 end);
4484
4485 self.SideBar:CreateSideTab(gElo.L("colorSideTabButtons"), "gelo/palette.png", function()
4486 self:RemoveAllChangers();
4487
4488 self:CreateColorChanger(gElo.L("colorButtonBackground"), "main_button_background");
4489 self:CreateColorChanger(gElo.L("colorButtonText"), "main_button_text");
4490 self:CreateColorChanger(gElo.L("colorButtonTextHover"), "main_button_text_hover");
4491 self:CreateColorChanger(gElo.L("colorButtonOutline"), "main_button_outline");
4492 self:CreateColorChanger(gElo.L("colorSideButton"), "button_non_hover");
4493 self:CreateColorChanger(gElo.L("colorSideButtonHover"), "button_hover");
4494 end);
4495
4496 self.SideBar:CreateSideTab(gElo.L("colorSideTabOther"), "gelo/palette.png", function()
4497 self:RemoveAllChangers();
4498
4499 self:CreateColorChanger(gElo.L("colorNotification"), "notifcation_text");
4500 self:CreateColorChanger(gElo.L("colorElo"), "elo_text");
4501 self:CreateColorChanger(gElo.L("colorOther"), "other_text");
4502 self:CreateColorChanger(gElo.L("otherContainers"), "settings_containers");
4503 end);
4504
4505 gElo.GetSettings():SetSettingsValue("ui", "notification_color", false);
4506end
4507
4508---
4509--- PerformLayout
4510---
4511function panel:PerformLayout(w, h)
4512 self:SetPos(200, 0);
4513 self:SetSize(self:GetParent():GetWide(), self:GetParent():GetTall() - 60);
4514
4515 self.SideBar:SetPos(0, 0);
4516 self.SideBar:SetSize(219, h);
4517
4518 for i = 1, #self.Colors do
4519 local box = self.Colors[i];
4520
4521 box:SetPos(self.SideBar:GetWide() + 5, 55 * (i - 1) + 5);
4522 box:SetSize(260, 50);
4523
4524 -- Color Slider
4525 box.Slider:SetPos(-97, box:GetTall() - 21);
4526 box.Slider:SetSize(box:GetWide(), 10);
4527 end
4528end
4529
4530---
4531--- Paint
4532---
4533function panel:Paint(w, h)
4534 surface.SetDrawColor(self.ColorSettings.main_background);
4535 surface.SetMaterial(self.BackgroundMaterial);
4536 surface.DrawTexturedRect(0, 0, w, h);
4537end
4538vgui.Register("gElo.SettingsPanelColor", panel, "EditablePanel");
4539
4540--[[------------------------------------------------------------------------------
4541 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
4542 * Unauthorized copying of this file, via any medium is strictly prohibited
4543 * Proprietary and confidential
4544--]]------------------------------------------------------------------------------
4545
4546local panel = {};
4547
4548---
4549--- GetColors
4550---
4551function panel:GetColors()
4552 self.Colors = gElo.GetColorFromString("main_outline", "settings_footer");
4553end
4554
4555---
4556--- Init
4557---
4558function panel:Init()
4559 self.Settings = gElo.GetSettings();
4560 self:GetColors();
4561 self.Main = self:GetParent():GetParent();
4562
4563 self.RestoreToDefaults = self:Add("gElo.Button")
4564 self.RestoreToDefaults:SetCustomText(gElo.L("footerSetDefault"));
4565 self.RestoreToDefaults.SetDoClick = function()
4566 self.Notification = self.Main:Add("gElo.Notification");
4567 self.Notification:SetSize(400, 150);
4568 self.Notification:Center();
4569 self.Notification:SetDescription(gElo.L("footerNotification"));
4570 self.Notification.DoAcceptClick = function(s)
4571 if (IsValid(self.Main)) then
4572 self.Main:Remove();
4573 end
4574
4575 gElo.GetSettings():CreateDefaultSettings();
4576 end
4577 self.Notification.DoDeclineClick = function(s)
4578 if (IsValid(s)) then
4579 s:Remove();
4580 end
4581 end
4582 end
4583
4584 self.Done = self:Add("gElo.Button")
4585 self.Done:SetCustomText(gElo.L("footerDone"));
4586 self.Done.SetDoClick = function()
4587 if (IsValid(self.Main)) then
4588 self.Main:Remove();
4589 end
4590 end
4591end
4592
4593---
4594--- PerformLayout
4595---
4596function panel:PerformLayout(w, h)
4597 self.RestoreToDefaults:SetPos(25, (h / 2) - 17);
4598
4599 self.Done:SetPos(w - 150, (h / 2) - 17);
4600 self.Done:SetSize(135, 34);
4601end
4602
4603
4604---
4605--- Paint
4606---
4607function panel:Paint(w, h)
4608 surface.SetDrawColor(self.Colors.settings_footer);
4609 surface.DrawRect(0, 0, w, h);
4610
4611 surface.SetDrawColor(self.Colors.main_outline);
4612 surface.DrawRect(0, 0, w, 1);
4613end
4614vgui.Register("gElo.MainSettingsFooter", panel, "EditablePanel");
4615
4616--[[------------------------------------------------------------------------------
4617 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
4618 * Unauthorized copying of this file, via any medium is strictly prohibited
4619 * Proprietary and confidential
4620--]]------------------------------------------------------------------------------
4621
4622local panel = {};
4623
4624---
4625--- GetColors
4626---
4627function panel:GetColors()
4628 self.ColorSettings = gElo.GetColorFromString("main_background", "settings_containers", "main_outline", "other_text");
4629end
4630
4631function panel:CreateSettingsContainer(pnl, title, container, func)
4632 local containerCount = #container + 1;
4633 func = func or function() return; end
4634
4635 container[containerCount] = pnl:Add("DPanel")
4636 container[containerCount].Tall = 65;
4637 container[containerCount].Paint = function(s, w, h)
4638 local x, y = s:LocalToScreen();
4639
4640 BSHADOWS.BeginShadow();
4641 surface.SetDrawColor(self.ColorSettings.settings_containers);
4642 surface.DrawRect(x, y, w, h);
4643 BSHADOWS.EndShadow(1, 2, 1);
4644
4645 draw.SimpleText(gElo.utf8upper(title), "gElo.16", 10, 10, Color(230, 230, 230, 255), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
4646 end
4647
4648 func(container[containerCount]);
4649end
4650
4651---
4652--- Init
4653---
4654function panel:Init()
4655 self.BackgroundMaterial = Material("gelo/main_background.png");
4656
4657 -- Colors
4658 self:GetColors();
4659
4660 -- Side Bar
4661 self.SideBar = self:Add("gElo.MainPanelSideBar");
4662
4663 -- Exit Material
4664 self.ExitMat = Material("gelo/x.png", "noclamp smooth");
4665
4666 -- Side Bar Buttons
4667 self.SideBar:CreateSideTab(gElo.L("generalInterface"), "gelo/settings.png", function()
4668 self.OtherSettingsContainers = {};
4669 self.SettingsContainers = {};
4670
4671 self.Container = self:Add("DPanel")
4672 self.Container.Paint = function(s, w, h)
4673 surface.SetDrawColor(self.ColorSettings.main_background);
4674 surface.SetMaterial(self.BackgroundMaterial);
4675 surface.DrawTexturedRect(0, 0, w, h);
4676 end
4677
4678 self.SideBar.SelectedPanel = self.Container;
4679 self:CreateSettingsContainer(self.Container, gElo.L("generalCurrentLang", gElo.L(gElo.GetSettings():GetSettingsValue("ui", "lang_fancy"))), self.SettingsContainers, function(s)
4680 s.langSelector = s:Add("gElo.Button")
4681 s.langSelector:SetPos(10, 25);
4682 s.langSelector:SetSize(135, 34);
4683 s.langSelector:SetCustomText(gElo.L("generalSelectLang"));
4684 s.langSelector.SetDoClick = function()
4685 local main = self:GetParent();
4686 if (not IsValid(main)) then return; end
4687
4688 s.langPanel = main:Add("DPanel")
4689 s.langPanel:SetSize(500, 150);
4690 s.langPanel:SetPos((main:GetWide() / 2) - 303, (main:GetTall() / 2) - 109);
4691 s.children = 1;
4692 s.ychildren = 1;
4693 s.yPos = 13;
4694 s.langPanel.Paint = function(s, w, h)
4695 -- Main Background Image
4696 surface.SetDrawColor(self.ColorSettings.main_background);
4697 surface.SetMaterial(self.BackgroundMaterial);
4698 surface.DrawTexturedRect(2, 2, w - 4, h - 4);
4699
4700 -- Black Outline
4701 surface.SetDrawColor(0, 0, 0, 255);
4702 surface.DrawOutlinedRect(0, 0, w, h)
4703
4704 -- Outline
4705 surface.SetDrawColor(self.ColorSettings.main_outline);
4706 surface.DrawOutlinedRect(1, 1, w - 2, h - 2)
4707 end
4708
4709 s.Header = s.langPanel:Add("gElo.MainPanelHeader");
4710 s.Header:SetUseSmallHeader(true);
4711 s.Header:SetPos(2, 2);
4712 s.Header:SetSize(s.langPanel:GetWide() - 4, 68);
4713
4714 -- Exit
4715 s.Exit = s.langPanel:Add("DButton");
4716 s.Exit:SetText("");
4717 s.Exit:SetPos(s.langPanel:GetWide() - 38, -8);
4718 s.Exit:SetSize(32, 32);
4719 s.Exit:SetCursor("arrow");
4720 s.Exit.Paint = function(s, w, h)
4721 surface.SetDrawColor(0, 0, 0, 0);
4722 surface.DrawRect(0, 0, w, h);
4723
4724 surface.SetDrawColor(s:IsHovered() and Color(150, 150, 150, 200) or Color(100, 100, 100, 100));
4725 surface.SetMaterial(self.ExitMat);
4726 surface.DrawTexturedRect(w / 2, h / 2, w - 20, h - 20);
4727 end
4728
4729 s.Exit.DoClick = function()
4730 if (IsValid(s.langPanel)) then
4731 s.langPanel:Remove();
4732 end
4733
4734 if (IsValid(self)) then
4735 self:Remove();
4736 end
4737 end
4738
4739 for k, v in pairs(gElo.Languages) do
4740 if (s.children == 4) then
4741 s.yPos = s.yPos + 47;
4742
4743 s.children = 1;
4744 end
4745
4746 s.language = s.langPanel:Add("gElo.Button")
4747 s.language:SetPos(145 * (s.children - 1) + 5, s.yPos);
4748 s.language:SetSize(135, 34);
4749 s.language:SetCustomText(v.thisLanguage);
4750 s.language.SetDoClick = function()
4751 gElo.GetSettings():SetSettingsValue("ui", "language", k);
4752 local main = self:GetParent():GetParent();
4753 if (not IsValid(main)) then return; end
4754
4755 main:Remove();
4756 end
4757
4758 s.children = s.children + 1;
4759 end
4760 end
4761 end);
4762
4763 self:CreateSettingsContainer(self.Container, gElo.L("generalCurrentKey", gElo.GetTranslatedKey(gElo.GetSettings():GetSettingsValue("ui", "gelo_menu"))), self.SettingsContainers, function(s)
4764 local selectedKey = nil;
4765
4766 -- Current Selected Key
4767 local currentKey = gElo.GetSettings():GetSettingsValue("ui", "gelo_menu");
4768
4769 hook.Add("Move", "gElo.SelectKey", function(ply)
4770 for k, v in pairs(gElo.GetKeys()) do
4771 if (input.IsButtonDown(k)) then
4772 selectedKey = k;
4773 currentKey = v;
4774
4775 break;
4776 end
4777 end
4778 end);
4779
4780 s.keySelector = s:Add("gElo.Button")
4781 s.keySelector:SetPos(10, 25);
4782 s.keySelector:SetSize(135, 34);
4783 s.keySelector:SetCustomText(gElo.L("generalSelectKey"));
4784 s.keySelector.SetDoClick = function()
4785 local main = self:GetParent();
4786 if (not IsValid(main)) then return; end
4787
4788 s.keyPanel = main:Add("DPanel")
4789 s.keyPanel:SetSize(400, 150);
4790 s.keyPanel:SetPos((main:GetWide() / 2) - 303, (main:GetTall() / 2) - 109);
4791 s.keyPanel.Paint = function(s, w, h)
4792 -- Main Background Image
4793 surface.SetDrawColor(self.ColorSettings.main_background);
4794 surface.SetMaterial(self.BackgroundMaterial);
4795 surface.DrawTexturedRect(2, 2, w - 4, h - 4);
4796
4797 -- Black Outline
4798 surface.SetDrawColor(0, 0, 0, 255);
4799 surface.DrawOutlinedRect(0, 0, w, h)
4800
4801 -- Draw Key Information
4802 draw.DrawText(gElo.textWrap(gElo.utf8upper(gElo.L("settingsKeys")), "gElo.14", 370), "gElo.14", (w / 2) - 5, (h / 2) - 50, self.ColorSettings.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4803 draw.SimpleText(gElo.utf8upper(gElo.L("generalSelectedKey", gElo.GetTranslatedKey(currentKey))), "gElo.18", (w / 2) - 10, (h / 1) - 50, self.ColorSettings.other_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
4804
4805 -- Outline
4806 surface.SetDrawColor(self.ColorSettings.main_outline);
4807 surface.DrawOutlinedRect(1, 1, w - 2, h - 2)
4808 end
4809
4810 s.Header = s.keyPanel:Add("gElo.MainPanelHeader");
4811 s.Header:SetUseSmallHeader(true);
4812 s.Header:SetPos(2, 2);
4813 s.Header:SetSize(s.keyPanel:GetWide() - 4, 68);
4814
4815 -- Button To Accept New Key
4816 s.keyAccept = s.keyPanel:Add("gElo.Button")
4817 s.keyAccept:SetPos((s.keyPanel:GetWide() / 2) - 77, s.keyPanel:GetTall() - 39);
4818 s.keyAccept:SetSize(135, 34);
4819 s.keyAccept:SetCustomText(gElo.L("notificationAccept"));
4820 s.keyAccept.SetDoClick = function()
4821 if (selectedKey ~= nil and selectedKey ~= currentKey) then
4822 gElo.GetSettings():SetSettingsValue("ui", "gelo_menu", selectedKey);
4823 end
4824
4825 if (IsValid(s.keyPanel)) then
4826 s.keyPanel:Remove();
4827 end
4828
4829 if (IsValid(self)) then
4830 self:Remove();
4831 end
4832
4833 hook.Remove("Move", "gElo.SelectKey")
4834 end
4835 end
4836 end);
4837 end);
4838
4839 -- Containers
4840 self.OtherSettingsContainers = {};
4841 self.SettingsContainers = {};
4842end
4843
4844---
4845--- PerformLayout
4846---
4847function panel:PerformLayout(w, h)
4848 self:SetPos(200, 0);
4849 self:SetSize(self:GetParent():GetWide(), self:GetParent():GetTall() - 60);
4850
4851 self.SideBar:SetPos(0, 0);
4852 self.SideBar:SetSize(200, h);
4853
4854 if (IsValid(self.Container)) then
4855 self.Container:SetPos(self.SideBar:GetWide(), 0);
4856 self.Container:SetSize(w, h);
4857 end
4858
4859 if (IsValid(self.OtherContainer)) then
4860 self.OtherContainer:SetPos(self.SideBar:GetWide(), 0);
4861 self.OtherContainer:SetSize(w, h);
4862 end
4863
4864 for i = 1, #self.SettingsContainers do
4865 local container = self.SettingsContainers[i];
4866
4867 container:SetPos(5, (container.Tall + 5) * (i - 1) + 5);
4868 container:SetSize(250, container.Tall)
4869 end
4870
4871 for i = 1, #self.OtherSettingsContainers do
4872 local container = self.OtherSettingsContainers[i];
4873
4874 container:SetPos(5, (container.Tall + 5) * (i - 1) + 5);
4875 container:SetSize(250, container.Tall)
4876 end
4877end
4878
4879---
4880--- Paint
4881---
4882function panel:Paint(w, h)
4883 surface.SetDrawColor(self.ColorSettings.main_background);
4884 surface.SetMaterial(self.BackgroundMaterial);
4885 surface.DrawTexturedRect(0, 0, w, h);
4886end
4887vgui.Register("gElo.SettingsPanelGeneral", panel, "EditablePanel");
4888
4889--[[------------------------------------------------------------------------------
4890 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
4891 * Unauthorized copying of this file, via any medium is strictly prohibited
4892 * Proprietary and confidential
4893--]]------------------------------------------------------------------------------
4894
4895local panel = {};
4896
4897---
4898--- GetColors
4899---
4900function panel:GetColors()
4901 self.Colors = gElo.GetColorFromString("main_background");
4902end
4903
4904---
4905--- Init
4906---
4907function panel:Init()
4908 self.BackgroundMaterial = Material("gelo/main_background.png");
4909 self:GetColors();
4910
4911 -- SideBar
4912 self.SideBar = self:Add("gElo.MainPanelSideBar");
4913
4914 -- General Settings
4915 self.SideBar:CreateSideTab(gElo.L("settingsGeneral"), "gelo/settings.png", function()
4916 self.GeneralPanel = self:Add("gElo.SettingsPanelGeneral");
4917 self.SideBar.SelectedPanel = self.GeneralPanel;
4918
4919 if (IsValid(self.Notification)) then
4920 self.Notification:Remove();
4921 end
4922 end);
4923
4924 -- Color Settings
4925 self.SideBar:CreateSideTab(gElo.L("settingsSideTabColors"), "gelo/palette.png", function()
4926 local main = self:GetParent();
4927 if (not IsValid(main)) then return; end
4928
4929 if (IsValid(self.Notification)) then
4930 return;
4931 end
4932
4933 if (gElo.GetSettings():GetSettingsValue("ui", "notification_color")) then
4934 self.Notification = main:Add("gElo.Notification");
4935 self.Notification:SetSize(400, 150);
4936 self.Notification:Center();
4937 self.Notification:SetDescription(gElo.L("settingsNotification"));
4938 self.Notification.DoAcceptClick = function(s)
4939 if (IsValid(self)) then
4940 self.ColorPanel = self:Add("gElo.SettingsPanelColor");
4941 self.SideBar.SelectedPanel = self.ColorPanel;
4942 end
4943
4944 if (IsValid(s)) then
4945 s:Remove();
4946 end
4947 end
4948 self.Notification.DoDeclineClick = function(s)
4949 if (IsValid(s)) then
4950 s:Remove();
4951 end
4952
4953 self.SideBar.SelectedButton = NULL;
4954 end
4955 else
4956 self.ColorPanel = self:Add("gElo.SettingsPanelColor");
4957 self.SideBar.SelectedPanel = self.ColorPanel;
4958 end
4959 end);
4960
4961 -- Footer
4962 self.Footer = self:Add("gElo.MainSettingsFooter");
4963end
4964
4965---
4966--- PerformLayout
4967---
4968function panel:PerformLayout(w, h)
4969 self.Footer:SetPos(0, h - 60);
4970 self.Footer:SetSize(w, 60);
4971
4972 self.SideBar:SetPos(0, 0);
4973 self.SideBar:SetSize(200, h);
4974end
4975
4976---
4977--- Paint
4978---
4979function panel:Paint(w, h)
4980 surface.SetDrawColor(self.Colors.main_background);
4981 surface.SetMaterial(self.BackgroundMaterial);
4982 surface.DrawTexturedRect(0, 0, w, h);
4983end
4984vgui.Register("gElo.MainSettingsPanel", panel, "EditablePanel");
4985
4986--[[------------------------------------------------------------------------------
4987 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
4988 * Unauthorized copying of this file, via any medium is strictly prohibited
4989 * Proprietary and confidential
4990--]]------------------------------------------------------------------------------
4991
4992local panel = {};
4993AccessorFunc(panel, "CustomText", "CustomText", FORCE_STRING);
4994
4995---
4996--- GetColors
4997---
4998function panel:GetColors()
4999 self.Colors = gElo.GetColorFromString("main_button_background", "main_button_text", "main_button_text_hover", "main_button_outline");
5000end
5001
5002---
5003--- Init
5004---
5005function panel:Init()
5006 self.Rounded = Material("gelo/rounded.png");
5007
5008 -- Colors
5009 self:GetColors();
5010
5011 self:SetText("");
5012 self:SetCursor("arrow");
5013
5014 timer.Simple(0, function()
5015 if (#self.CustomText > 30) then
5016 local oldSize = self:GetWide();
5017 local oldTall = self:GetTall();
5018 self:SetSize(300, oldTall);
5019 end
5020 end);
5021end
5022
5023---
5024--- SetDoClick
5025---
5026function panel:SetDoClick()
5027 -- Just keep for refrence later.
5028end
5029
5030---
5031--- DoClick
5032---
5033function panel:DoClick()
5034 self:SetDoClick();
5035end
5036
5037function panel:PerformLayout(w, h)
5038 if (#self.CustomText >= 30) then
5039 self:SetSize((135 + #self.CustomText) + 95, 34);
5040 else
5041 self:SetSize(135, 34);
5042 end
5043end
5044
5045---
5046--- Paint
5047---
5048function panel:Paint(w, h)
5049 -- Actual rounded box of the button
5050 draw.RoundedBox(4, 0, 0, w, h, self:IsHovered() and ColorAlpha(self.Colors.main_button_background, self.Colors.main_button_background.a * 3) or self.Colors.main_button_background);
5051
5052 -- Rounded Texture
5053 surface.SetDrawColor(self.Colors.main_button_outline);
5054 surface.SetMaterial(self.Rounded);
5055 surface.DrawTexturedRect(0, 0, w, h);
5056
5057 -- Text Drawing
5058 draw.SimpleText(self.CustomText, "gElo.16", w / 2, h / 2, self:IsHovered() and self.Colors.main_button_text_hover or self.Colors.main_button_text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
5059end
5060vgui.Register("gElo.Button", panel, "DButton");
5061
5062--[[------------------------------------------------------------------------------
5063 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5064 * Unauthorized copying of this file, via any medium is strictly prohibited
5065 * Proprietary and confidential
5066--]]------------------------------------------------------------------------------
5067
5068local panel = {};
5069
5070AccessorFunc(panel, "DrawLine", "DrawLine", FORCE_BOOL);
5071AccessorFunc(panel, "UseSmallHeader", "UseSmallHeader", FORCE_BOOL);
5072
5073---
5074--- GetColors
5075---
5076function panel:GetColors()
5077 self.Colors = gElo.GetColorFromString("main_outline", "main_header");
5078end
5079
5080---
5081--- Init
5082---
5083function panel:Init()
5084 self.HeaderMaterial = Material("gelo/header.png", "noclamp smooth");
5085 self.SmallHeaderMaterial = Material("gelo/notification_header.png", "noclamp smooth");
5086
5087 -- Colors
5088 self:GetColors();
5089end
5090
5091---
5092--- Paint
5093---
5094function panel:Paint(w, h)
5095 surface.SetDrawColor(0, 0, 0, 0);
5096 surface.DrawRect(0, 0, w, h);
5097
5098 if (self.DrawLine) then
5099 surface.SetDrawColor(self.Colors.main_outline);
5100 surface.DrawRect(0, h - 1, w, 1);
5101 end
5102
5103 surface.SetDrawColor(self.Colors.main_header);
5104 if (self.UseSmallHeader) then
5105 surface.SetMaterial(self.SmallHeaderMaterial);
5106 else
5107 surface.SetMaterial(self.HeaderMaterial);
5108 end
5109 surface.DrawTexturedRect(0, 0, w, 8);
5110end
5111vgui.Register("gElo.MainPanelHeader", panel, "EditablePanel");
5112
5113--[[------------------------------------------------------------------------------
5114 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5115 * Unauthorized copying of this file, via any medium is strictly prohibited
5116 * Proprietary and confidential
5117--]]------------------------------------------------------------------------------
5118
5119local panel = {};
5120local mainPanel = nil;
5121
5122---
5123--- GetColors
5124---
5125function panel:GetColors()
5126 self.Colors = gElo.GetColorFromString("main_outline", "main_background", "elo_text", "other_text");
5127end
5128
5129---
5130--- CreateProfile
5131---
5132function panel:CreateProfile()
5133 net.Start("gElo.GetProfileStats") net.SendToServer()
5134
5135 self.ProfilePanel = self:Add("gElo.MainProfilePanel");
5136 self.SideBar.SelectedPanel = self.ProfilePanel;
5137end
5138
5139---
5140--- CreateMatchHistory
5141---
5142function panel:CreateMatchHistory()
5143 net.Start("gElo.GetMatchHistory") net.SendToServer()
5144
5145 self.HistoryPanel = self:Add("gElo.MainHistoryPanel");
5146 self.HistoryPanel:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5147 self.HistoryPanel:SetSize((self:GetWide() - self.SideBar:GetWide()) - 4, (self:GetTall() - self.Header:GetTall()) - 4);
5148
5149 self.SideBar.SelectedPanel = self.HistoryPanel;
5150end
5151
5152---
5153--- CreateLeaderBoard
5154---
5155function panel:CreateLeaderBoard()
5156 net.Start("gElo.GetLeaderBoards")
5157 net.WriteUInt(15, 32);
5158 net.WriteUInt(0, 8);
5159 net.WriteString("NULL");
5160 net.WriteBool(false);
5161 net.SendToServer()
5162
5163 self.LeaderboardsPanel = self:Add("gElo.MainLeaderboardsPanel");
5164 self.LeaderboardsPanel:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5165 self.LeaderboardsPanel:SetSize((self:GetWide() - self.SideBar:GetWide()) - 4, (self:GetTall() - self.Header:GetTall()) - 4);
5166
5167 self.SideBar.SelectedPanel = self.LeaderboardsPanel;
5168end
5169
5170---
5171--- CreateForums
5172---
5173function panel:CreateForums()
5174 self.ForumsPanel = self:Add("gElo.MainForumsPanel");
5175 self.ForumsPanel:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5176 self.ForumsPanel:SetSize((self:GetWide() - self.SideBar:GetWide()) - 4, (self:GetTall() - self.Header:GetTall()) - 4);
5177
5178 self.SideBar.SelectedPanel = self.ForumsPanel;
5179end
5180
5181---
5182--- CreateHelp
5183---
5184function panel:CreateHelp()
5185 self.HelpPanel = self:Add("gElo.MainHelpPanel")
5186 self.HelpPanel:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5187 self.HelpPanel:SetSize((self:GetWide() - self.SideBar:GetWide()) - 4, (self:GetTall() - self.Header:GetTall()) - 4);
5188
5189 self.SideBar.SelectedPanel = self.HelpPanel;
5190end
5191
5192---
5193--- CreateSettings
5194---
5195function panel:CreateSettings()
5196 self.SettingsPanel = self:Add("gElo.MainSettingsPanel")
5197 self.SettingsPanel:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5198 self.SettingsPanel:SetSize((self:GetWide() - self.SideBar:GetWide()) - 4, (self:GetTall() - self.Header:GetTall()) - 4);
5199
5200 self.SideBar.SelectedPanel = self.SettingsPanel;
5201end
5202
5203---
5204--- CreateAdministration
5205---
5206function panel:CreateAdministration()
5207 self.AdminPanel = self:Add("gElo.MainAdminsPanel")
5208 self.AdminPanel:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5209 self.AdminPanel:SetSize((self:GetWide() - self.SideBar:GetWide()) - 4, (self:GetTall() - self.Header:GetTall()) - 4);
5210
5211 self.SideBar.SelectedPanel = self.AdminPanel;
5212end
5213
5214---
5215--- CreatePlugins
5216---
5217function panel:CreatePlugins()
5218 self.Plugins = self:Add("gElo.MainPluginsPanel")
5219 self.Plugins:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5220 self.Plugins:SetSize((self:GetWide() - self.SideBar:GetWide()) - 4, (self:GetTall() - self.Header:GetTall()) - 4);
5221
5222 self.SideBar.SelectedPanel = self.Plugins;
5223end
5224
5225---
5226--- HeaderWarning
5227---
5228function panel:HeaderWarning(str, time, col)
5229 self.HeaderWarningString = str;
5230 self.HeaderWarningDisplayTime = CurTime() + time;
5231 self.HeaderWarningDisplayColor = col;
5232end
5233
5234---
5235--- Init
5236---
5237function panel:Init()
5238 self.BackgroundMaterial = Material("gelo/main_background.png");
5239 self.Time = SysTime();
5240 self.ExitMat = Material("gelo/x.png", "noclamp smooth");
5241 self.HeaderWarningString = "Warning";
5242
5243 -- Retrieve Colors
5244 self:GetColors();
5245
5246 -- Header
5247 self.Header = self:Add("gElo.MainPanelHeader");
5248 self.Header:SetDrawLine(true);
5249
5250 -- Main Side bar
5251 self.SideBar = self:Add("gElo.MainPanelSideBar");
5252 self:CreateProfile();
5253
5254 -- Profile
5255 local profile = self.SideBar:CreateSideTab(gElo.L("mainProfile"), "gelo/user.png", function()
5256 self:CreateProfile();
5257 end);
5258 self.SideBar.SelectedButton = profile;
5259
5260 -- Match History
5261 self.SideBar:CreateSideTab(gElo.L("mainHistory"), "gelo/history.png", function()
5262 self:CreateMatchHistory();
5263 end);
5264
5265 -- Leaderboards
5266 self.SideBar:CreateSideTab(gElo.L("mainLeaderboards"), "gelo/leaderboards.png", function()
5267 self:CreateLeaderBoard();
5268 end);
5269
5270 -- Forums
5271 self.SideBar:CreateSideTab(gElo.L("mainForums"), "gelo/forums.png", function()
5272 self:CreateForums();
5273 end);
5274
5275 -- Help
5276 self.SideBar:CreateSideTab(gElo.L("mainHelp"), "gelo/help.png", function()
5277 self:CreateHelp();
5278 end);
5279
5280 -- Plugins
5281 self.SideBar:CreateSideTab(gElo.L("mainPlugins"), "gelo/addons.png", function()
5282 -- We don't have any plugins yet.. WIP
5283 -- So this is just a error page so far, plugins will come later on.
5284 self:CreatePlugins();
5285 end);
5286
5287 -- Settings
5288 self.SideBar:CreateSideTab(gElo.L("mainSettings"), "gelo/settings.png", function()
5289 self:CreateSettings();
5290 end);
5291
5292 -- Administration
5293 if (gElo.Config.UIAdmin[LocalPlayer():GetUserGroup()]) then
5294 self.SideBar:CreateSideTab(gElo.L("mainAdmin"), "gelo/admin.png", function()
5295 self:CreateAdministration();
5296 end);
5297 end
5298
5299 -- Exit
5300 self.Exit = self:Add("DButton");
5301 self.Exit:SetText("");
5302 self.Exit:SetCursor("arrow");
5303 self.Exit.Paint = function(s, w, h)
5304 surface.SetDrawColor(0, 0, 0, 0);
5305 surface.DrawRect(0, 0, w, h);
5306
5307 surface.SetDrawColor(s:IsHovered() and Color(150, 150, 150, 200) or Color(100, 100, 100, 100));
5308 surface.SetMaterial(self.ExitMat);
5309 surface.DrawTexturedRect(w / 2, h / 2, w - 20, h - 20);
5310 end
5311
5312 self.Exit.DoClick = function()
5313 if (IsValid(self)) then
5314 self:Remove();
5315 end
5316
5317 if (hook.GetTable()["Move"] and hook.GetTable()["Move"]["gElo.SelectKey"]) then
5318 hook.Remove("Move", "gElo.SelectKey");
5319 end
5320 end
5321
5322 mainPanel = self;
5323end
5324
5325---
5326--- PerformLayout
5327---
5328function panel:PerformLayout(w, h)
5329 self.Header:SetPos(2, 2);
5330 self.Header:SetSize(w - 4, 68);
5331
5332 self.SideBar:SetPos(2, 70);
5333 self.SideBar:SetSize(219, h - 72);
5334
5335 self.Exit:SetPos(w - 38, -8);
5336 self.Exit:SetSize(32, 32);
5337
5338 if (IsValid(self.ProfilePanel)) then
5339 self.ProfilePanel:SetPos(self.SideBar:GetWide() + 2, self.Header:GetTall() + 2);
5340 self.ProfilePanel:SetSize((self:GetWide() - self.SideBar:GetWide() - 4), (self:GetTall() - self.Header:GetTall()) - 4);
5341 end
5342end
5343
5344---
5345--- Paint
5346---
5347function panel:Paint(w, h)
5348 -- Background Blur
5349 Derma_DrawBackgroundBlur(self, self.Time);
5350
5351 -- Main Background Image
5352 surface.SetDrawColor(self.Colors.main_background);
5353 surface.SetMaterial(self.BackgroundMaterial);
5354 surface.DrawTexturedRect(2, 2, w - 4, h - 4);
5355
5356 -- Black Outline
5357 surface.SetDrawColor(0, 0, 0, 255);
5358 surface.DrawOutlinedRect(0, 0, w, h)
5359
5360 -- Outline
5361 surface.SetDrawColor(self.Colors.main_outline);
5362 surface.DrawOutlinedRect(1, 1, w - 2, h - 2)
5363
5364 -- Player Nick
5365 draw.SimpleText(LocalPlayer():Nick(), "gElo.16", 10, 14, self.Colors.other_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
5366
5367 -- Elo
5368 draw.SimpleText(gElo.L("leaderRank") .. ": " .. gElo.L(LocalPlayer():GetNWString("gElo_Rank", "Unknown"):lower()) .. " " .. gElo.NumberToRoman(LocalPlayer():GetNWInt("gElo_Division", 5)), "gElo.16", 10, 34, gElo.EloToColor(LocalPlayer():GetNWString("gElo_Rank", "Bronze")), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
5369
5370 -- Elo
5371 draw.SimpleText(gElo.L("helpRP") .. ": " .. LocalPlayer():GetNWString("gElo_RP", "Unknown"), "gElo.16", 10, 54, self.Colors.elo_text, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
5372
5373 -- Warning
5374 if ((self.HeaderWarningDisplayTime or 0) >= CurTime()) then
5375 draw.DrawText(self.HeaderWarningString, "gElo.16", (w / 2) + 10, 15, self.HeaderWarningDisplayColor or Color(150, 50, 0, 200), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER);
5376 end
5377end
5378vgui.Register("gElo.MainPanel", panel, "EditablePanel");
5379
5380net.Receive("gElo.SendMenuError", function(_, ply)
5381 local reason = net.ReadString();
5382 if (reason:find(";")) then
5383 reason = string.Explode(";", reason);
5384 end
5385
5386 if (not IsValid(mainPanel)) then return; end
5387
5388 mainPanel.Notification = mainPanel:Add("gElo.Notification");
5389 mainPanel.Notification:SetSize(400, 150);
5390 mainPanel.Notification:Center();
5391
5392 if (type(reason) == "table") then
5393 mainPanel.Notification:SetDescription(gElo.L(reason[1]) .. " " .. reason[2]);
5394 else
5395 mainPanel.Notification:SetDescription(reason);
5396 end
5397 mainPanel.Notification.DoAcceptClick = function(s)
5398 if (IsValid(s)) then
5399 s:Remove();
5400 end
5401 end
5402 mainPanel.Notification.DoDeclineClick = function(s)
5403 if (IsValid(s)) then
5404 s:Remove();
5405 end
5406 end
5407end);
5408
5409net.Receive("gElo.SendHeaderError", function()
5410 local reason = net.ReadString();
5411
5412 if (not IsValid(mainPanel)) then return; end
5413
5414 mainPanel:HeaderWarning(gElo.L(reason), 3);
5415end);
5416
5417--[[------------------------------------------------------------------------------
5418 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5419 * Unauthorized copying of this file, via any medium is strictly prohibited
5420 * Proprietary and confidential
5421--]]------------------------------------------------------------------------------
5422
5423-- CL_SHADOWS.LUA IS CREATED BY 0V3RR1D3.
5424
5425--This code can be improved alot.
5426--Feel free to improve, use or modify in anyway altough credit would be apreciated.
5427
5428--Global table
5429if BSHADOWS == nil then
5430 BSHADOWS = {}
5431
5432 --The original drawing layer
5433 BSHADOWS.RenderTarget = GetRenderTarget("bshadows_original", ScrW(), ScrH())
5434
5435 --The shadow layer
5436 BSHADOWS.RenderTarget2 = GetRenderTarget("bshadows_shadow", ScrW(), ScrH())
5437
5438 --The matarial to draw the render targets on
5439 BSHADOWS.ShadowMaterial = CreateMaterial("bshadows","UnlitGeneric",{
5440 ["$translucent"] = 1,
5441 ["$vertexalpha"] = 1,
5442 ["alpha"] = 1
5443 })
5444
5445 --When we copy the rendertarget it retains color, using this allows up to force any drawing to be black
5446 --Then we can blur it to create the shadow effect
5447 BSHADOWS.ShadowMaterialGrayscale = CreateMaterial("bshadows_grayscale","UnlitGeneric",{
5448 ["$translucent"] = 1,
5449 ["$vertexalpha"] = 1,
5450 ["$alpha"] = 1,
5451 ["$color"] = "0 0 0",
5452 ["$color2"] = "0 0 0"
5453 })
5454
5455 --Call this to begin drawing a shadow
5456 BSHADOWS.BeginShadow = function()
5457
5458 --Set the render target so all draw calls draw onto the render target instead of the screen
5459 render.PushRenderTarget(BSHADOWS.RenderTarget)
5460
5461 --Clear is so that theres no color or alpha
5462 render.OverrideAlphaWriteEnable(true, true)
5463 render.Clear(0,0,0,0)
5464 render.OverrideAlphaWriteEnable(false, false)
5465
5466 --Start Cam2D as where drawing on a flat surface
5467 cam.Start2D()
5468
5469 --Now leave the rest to the user to draw onto the surface
5470 end
5471
5472 --This will draw the shadow, and mirror any other draw calls the happened during drawing the shadow
5473 BSHADOWS.EndShadow = function(intensity, spread, blur, opacity, direction, distance, _shadowOnly)
5474
5475 --Set default opcaity
5476 opacity = opacity or 255
5477 direction = direction or 0
5478 distance = distance or 0
5479 _shadowOnly = _shadowOnly or false
5480
5481 --Copy this render target to the other
5482 render.CopyRenderTargetToTexture(BSHADOWS.RenderTarget2)
5483
5484 --Blur the second render target
5485 if blur > 0 then
5486 render.OverrideAlphaWriteEnable(true, true)
5487 render.BlurRenderTarget(BSHADOWS.RenderTarget2, spread, spread, blur)
5488 render.OverrideAlphaWriteEnable(false, false)
5489 end
5490
5491 --First remove the render target that the user drew
5492 render.PopRenderTarget()
5493
5494 --Now update the material to what was drawn
5495 BSHADOWS.ShadowMaterial:SetTexture('$basetexture', BSHADOWS.RenderTarget)
5496
5497 --Now update the material to the shadow render target
5498 BSHADOWS.ShadowMaterialGrayscale:SetTexture('$basetexture', BSHADOWS.RenderTarget2)
5499
5500 --Work out shadow offsets
5501 local xOffset = math.sin(math.rad(direction)) * distance
5502 local yOffset = math.cos(math.rad(direction)) * distance
5503
5504 --Now draw the shadow
5505 BSHADOWS.ShadowMaterialGrayscale:SetFloat("$alpha", opacity/255) --set the alpha of the shadow
5506 render.SetMaterial(BSHADOWS.ShadowMaterialGrayscale)
5507 for i = 1 , math.ceil(intensity) do
5508 render.DrawScreenQuadEx(xOffset, yOffset, ScrW(), ScrH())
5509 end
5510
5511 if not _shadowOnly then
5512 --Now draw the original
5513 BSHADOWS.ShadowMaterial:SetTexture('$basetexture', BSHADOWS.RenderTarget)
5514 render.SetMaterial(BSHADOWS.ShadowMaterial)
5515 render.DrawScreenQuad()
5516 end
5517
5518 cam.End2D()
5519 end
5520
5521 --This will draw a shadow based on the texture you passed it.
5522 BSHADOWS.DrawShadowTexture = function(texture, intensity, spread, blur, opacity, direction, distance, shadowOnly)
5523
5524 --Set default opcaity
5525 opacity = opacity or 255
5526 direction = direction or 0
5527 distance = distance or 0
5528 shadowOnly = shadowOnly or false
5529
5530 --Copy the texture we wish to create a shadow for to the shadow render target
5531 render.CopyTexture(texture, BSHADOWS.RenderTarget2)
5532
5533 --Blur the second render target
5534 if blur > 0 then
5535 render.PushRenderTarget(BSHADOWS.RenderTarget2)
5536 render.OverrideAlphaWriteEnable(true, true)
5537 render.BlurRenderTarget(BSHADOWS.RenderTarget2, spread, spread, blur)
5538 render.OverrideAlphaWriteEnable(false, false)
5539 render.PopRenderTarget()
5540 end
5541
5542 --Now update the material to the shadow render target
5543 BSHADOWS.ShadowMaterialGrayscale:SetTexture('$basetexture', BSHADOWS.RenderTarget2)
5544
5545 --Work out shadow offsets
5546 local xOffset = math.sin(math.rad(direction)) * distance
5547 local yOffset = math.cos(math.rad(direction)) * distance
5548
5549 --Now draw the shadow
5550 BSHADOWS.ShadowMaterialGrayscale:SetFloat("$alpha", opacity/255) --Set the alpha
5551 render.SetMaterial(BSHADOWS.ShadowMaterialGrayscale)
5552 for i = 1 , math.ceil(intensity) do
5553 render.DrawScreenQuadEx(xOffset, yOffset, ScrW(), ScrH())
5554 end
5555 if not shadowOnly then
5556 --Now draw the original
5557 BSHADOWS.ShadowMaterial:SetTexture('$basetexture', texture)
5558 render.SetMaterial(BSHADOWS.ShadowMaterial)
5559 render.DrawScreenQuad()
5560 end
5561 end
5562end
5563
5564--[[------------------------------------------------------------------------------
5565 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5566 * Unauthorized copying of this file, via any medium is strictly prohibited
5567 * Proprietary and confidential
5568--]]------------------------------------------------------------------------------
5569
5570local panel = {};
5571
5572---
5573--- GetColors
5574---
5575function panel:GetColors()
5576 self.Colors = gElo.GetColorFromString("main_outline", "button_hover", "button_non_hover");
5577end
5578
5579---
5580--- CreateSideTab
5581---
5582function panel:CreateSideTab(title, mat, func)
5583 func = func or function() return; end
5584 mat = Material(mat, "noclamp smooth");
5585
5586 -- Total Tabs
5587 local tabCount = #self.SideTabs + 1;
5588
5589 self.SideTabs[tabCount] = self:Add("DButton");
5590 self.SideTabs[tabCount]:SetText("");
5591 self.SideTabs[tabCount]:SetCursor("arrow");
5592 self.SideTabs[tabCount].Paint = function(s, w, h)
5593 surface.SetDrawColor(((s:IsHovered() or self.SelectedButton == s) and Color(10, 10, 10, 100) or Color(0, 0, 0, 0)));
5594 surface.DrawRect(0, 0, w, h);
5595
5596 if (self.SelectedButton and self.SelectedButton == s) then
5597 surface.SetDrawColor(0, 174, 255, 255)
5598 surface.DrawRect(0, 0, 3, h);
5599 end
5600
5601 -- Title
5602 draw.SimpleText(title, "gElo.16", 61, h / 2, ((s:IsHovered() or self.SelectedButton == s) and self.Colors.button_hover or self.Colors.button_non_hover), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
5603
5604 -- Icon
5605 surface.SetDrawColor(255, 255, 255, 255);
5606 surface.SetMaterial(mat);
5607 surface.DrawTexturedRect(21, 8, 28, 28);
5608 end
5609
5610 self.SideTabs[tabCount].DoClick = function(s)
5611 if (self.SelectedButton and self.SelectedButton == s) then
5612 return;
5613 end
5614
5615 -- If we're already showing up a side panel then we just remove it before creating a new one.
5616 -- We don't need to do it, but it'll increase performance overtime.
5617 if (IsValid(self.SelectedPanel)) then
5618 self.SelectedPanel:Remove();
5619 end
5620
5621 self.SelectedButton = s;
5622 func(s, self);
5623 end
5624
5625 return self.SideTabs[tabCount];
5626end
5627
5628---
5629--- Init
5630---
5631function panel:Init()
5632 self.SideTabs = {};
5633 self.SelectedButton = nil;
5634 self.SelectedPanel = nil;
5635
5636 -- Colors
5637 self:GetColors();
5638
5639 -- Settings
5640 self.Settings = gElo.GetSettings();
5641end
5642
5643---
5644--- PerformLayout
5645---
5646function panel:PerformLayout(w, h)
5647 for i = 1, #self.SideTabs do
5648 local tab = self.SideTabs[i];
5649 tab:SetPos(0, 44 * (i - 1));
5650 tab:SetSize(w - 1, 44);
5651 end
5652
5653 if (IsValid(self.SettingsPanel)) then
5654 self.SettingsPanel:SetPos(219, h);
5655 self.SettingsPanel:SetSize(w, h);
5656 end
5657end
5658
5659---
5660--- Paint
5661---
5662function panel:Paint(w, h)
5663 surface.SetDrawColor(0, 0, 0, 150);
5664 surface.DrawRect(0, 0, w, h);
5665
5666 surface.SetDrawColor(self.Colors.main_outline);
5667 surface.DrawRect(w - 1, 0, 1, h);
5668end
5669vgui.Register("gElo.MainPanelSideBar", panel, "EditablePanel");
5670
5671local panel = {};
5672
5673AccessorFunc(panel, "BackgroundText", "BackgroundText", FORCE_STRING);
5674
5675---
5676--- GetColors
5677---
5678function panel:GetColors()
5679 self.Colors = gElo.GetColorFromString("other_text", "main_button_outline");
5680end
5681
5682---
5683--- OnCustomEnter
5684---
5685function panel:OnCustomEnter()
5686 -- Just keep for refrence later.
5687end
5688
5689---
5690--- OnEnter
5691---
5692function panel:OnEnter(s)
5693 self:OnCustomEnter(s);
5694
5695 self:SetText("");
5696end
5697
5698---
5699--- Init
5700---
5701function panel:Init()
5702 self:GetColors();
5703 self:SetFont("gElo.16");
5704
5705 self.Rounded = Material("gelo/rounded.png");
5706 self.CanDrawBackground = true;
5707end
5708
5709---
5710--- Paint
5711---
5712function panel:Paint(w, h)
5713 draw.RoundedBox(4, 0, 0, w, h, Color(14, 17, 22, 255));
5714 self:DrawTextEntryText(self.Colors.other_text, Color(30, 130, 255, 255), Color(255, 255, 255, 255));
5715
5716 surface.SetDrawColor(self.Colors.main_button_outline);
5717 surface.SetMaterial(self.Rounded);
5718 surface.DrawTexturedRect(0, 0, w, h);
5719
5720 if (self:GetValue() == "") then
5721 draw.SimpleText(self.BackgroundText, "gElo.12", 5, h / 2, Color(60, 60, 60, 200), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER);
5722 end
5723end
5724vgui.Register("gElo.TextEntry", panel, "DTextEntry")
5725
5726--[[------------------------------------------------------------------------------
5727 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5728 * Unauthorized copying of this file, via any medium is strictly prohibited
5729 * Proprietary and confidential
5730--]]------------------------------------------------------------------------------
5731
5732---
5733--- GetColorFromString
5734---
5735function gElo.GetColorFromString(...)
5736 local stringTable = {...};
5737 local settings = gElo.GetSettings():GetAllSettingsValues();
5738 local returnedColors = {};
5739
5740 for _, v in pairs(stringTable) do
5741 for str, clr in pairs(settings.ui) do
5742 if (v == str) then
5743 returnedColors[str] = clr;
5744 end
5745 end
5746 end
5747
5748 return returnedColors;
5749end
5750
5751hook.Add("PlayerButtonDown", "gElo.OpenMenuOnButton", function(ply, key)
5752 if (not IsValid(ply) or not IsFirstTimePredicted()) then return; end
5753
5754 -- Get Settings.
5755 local boundKey = gElo.GetSettings():GetSettingsValue("ui", "gelo_menu");
5756 if (boundKey ~= key) then return; end
5757
5758 net.Start("gElo.RequestgEloUI") net.SendToServer()
5759end);
5760
5761net.Receive("gElo.OpenUI", function(_, ply)
5762 local ui = vgui.Create("gElo.MainPanel");
5763 ui:SetSize(1200, 750);
5764 ui:Center();
5765 ui:MakePopup();
5766end);
5767
5768--[[------------------------------------------------------------------------------
5769 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5770 * Unauthorized copying of this file, via any medium is strictly prohibited
5771 * Proprietary and confidential
5772--]]------------------------------------------------------------------------------
5773
5774util.AddNetworkString("gElo.OpenUI");
5775util.AddNetworkString("gElo.RequestgEloUI");
5776
5777net.Receive("gElo.RequestgEloUI", function(_, ply)
5778 if (not IsValid(ply)) then return; end
5779 if (not ply.gEloIsPlayerAuthed) then return; end
5780
5781 net.Start("gElo.OpenUI") net.Send(ply)
5782end);
5783
5784hook.Add("PlayerSay", "gElo.ChatCommandMenu", function(ply, text)
5785 if (not IsValid(ply)) then return; end
5786 if (text:lower():sub(1, 1) ~= gElo.Config.UIPrefix or text:lower():sub(2, #gElo.Config.UIStr + 1) ~= gElo.Config.UIStr) then return; end
5787 if (not ply.gEloIsPlayerAuthed) then return; end
5788
5789 net.Start("gElo.OpenUI") net.Send(ply)
5790end);
5791
5792--[[------------------------------------------------------------------------------
5793 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5794 * Unauthorized copying of this file, via any medium is strictly prohibited
5795 * Proprietary and confidential
5796--]]------------------------------------------------------------------------------
5797
5798---
5799--- ChatPrint
5800---
5801function gElo.ChatPrint(Type, ...)
5802 local prefix, color;
5803
5804 if (gElo.Types[Type]) then
5805 prefix = gElo.Types[Type].prefix;
5806 color = gElo.Types[Type].color;
5807 else
5808 prefix = gElo.Types["neutral"].prefix;
5809 color = gElo.Types["neutral"].color;
5810 end
5811
5812 chat.AddText(gElo.Colors.Cyan, "[", color, prefix, gElo.Colors.Cyan, "] ", gElo.Colors.Neutral, tostring(...));
5813end
5814
5815net.Receive("gElo.ChatPrint", function(_, ply)
5816 local type = net.ReadString();
5817 local str = net.ReadString();
5818
5819 gElo.ChatPrint(type, str);
5820end);
5821
5822hook.Add("InitPostEntity", "gElo.GlobalNotification", function()
5823 timer.Create("gElo.gEloNotification", 300, 0, function()
5824 gElo.ChatPrint("good", gElo.L("chatAdvert", gElo.GetTranslatedKey(gElo.GetSettings():GetSettingsValue("ui", "gelo_menu"))));
5825 end);
5826end);
5827
5828--[[------------------------------------------------------------------------------
5829 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5830 * Unauthorized copying of this file, via any medium is strictly prohibited
5831 * Proprietary and confidential
5832--]]------------------------------------------------------------------------------
5833
5834gElo.Types = {
5835 ["good"] = {prefix = "$", color = gElo.Colors.Good},
5836 ["warning"] = {prefix = "?", color = gElo.Colors.Warning},
5837 ["bad"] = {prefix = "!", color = gElo.Colors.Bad},
5838 ["neutral"] = {prefix = "$", color = gElo.Colors.Neutral}
5839};
5840
5841---
5842--- ConsolePrint
5843---
5844function gElo.ConsolePrint(Type, str)
5845 local prefix, color;
5846
5847 if (gElo.Types[Type]) then
5848 prefix = gElo.Types[Type].prefix;
5849 color = gElo.Types[Type].color;
5850 else
5851 prefix = gElo.Types["neutral"].prefix;
5852 color = gElo.Types["neutral"].color;
5853 end
5854
5855 MsgC(gElo.Colors.Cyan, "[", color, prefix, gElo.Colors.Cyan, "] ", gElo.Colors.Neutral, tostring(str));
5856 MsgN("");
5857
5858 return true;
5859end
5860
5861---
5862--- FancyPrint
5863---
5864function gElo:FancyPrint()
5865 local fancy = [[
5866 ________
5867 ____ _/ ____/ /___
5868 / __ `/ __/ / / __ \
5869 / /_/ / /___/ / /_/ /
5870 \__, /_____/_/\____/
5871 /_____
5872 __ ________ ________
5873 / /_ __ __ / ____/ /_ __/ __/ __/_ __
5874 / __ \/ / / / / /_ / / / / / /_/ /_/ / / /
5875 / /_/ / /_/ / / __/ / / /_/ / __/ __/ /_/ /
5876 /_.___/\__, / /_/ /_/\__,_/_/ /_/ \__, /
5877 /____/ /____/
5878
5879 [*] Version: ]] .. gElo.Version .. "\n" .. [[
5880 [*] Loading...
5881 ]];
5882
5883 print(fancy);
5884end
5885
5886gElo:FancyPrint();
5887
5888--[[------------------------------------------------------------------------------
5889 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5890 * Unauthorized copying of this file, via any medium is strictly prohibited
5891 * Proprietary and confidential
5892--]]------------------------------------------------------------------------------
5893
5894util.AddNetworkString("gElo.ChatPrint");
5895
5896---
5897--- ChatPrint
5898---
5899function gElo.ChatPrint(Client, Type, ...)
5900 if (Client == "GLOBAL") then
5901 for _, v in ipairs(player.GetHumans()) do
5902 net.Start("gElo.ChatPrint");
5903 net.WriteString(Type);
5904 net.WriteString(...);
5905 net.Send(v);
5906 end
5907
5908 return true;
5909 end
5910
5911 if (not IsValid(Client)) then
5912 return false;
5913 end
5914
5915 net.Start("gElo.ChatPrint");
5916 net.WriteString(Type);
5917 net.WriteString(...);
5918 net.Send(Client);
5919
5920 return true;
5921end
5922
5923--[[------------------------------------------------------------------------------
5924 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5925 * Unauthorized copying of this file, via any medium is strictly prohibited
5926 * Proprietary and confidential
5927--]]------------------------------------------------------------------------------
5928
5929-- Start is 10, max is 32 we add 2 to start.
5930-- 10, 12, etc..
5931
5932hook.Add("Initialize", "gElo.FontCreations", function()
5933 for i = 10, 32, 2 do
5934 surface.CreateFont("gElo." .. i, {font = "Roboto", size = i, weight = 500});
5935 end
5936end);
5937
5938--[[------------------------------------------------------------------------------
5939 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5940 * Unauthorized copying of this file, via any medium is strictly prohibited
5941 * Proprietary and confidential
5942--]]------------------------------------------------------------------------------
5943
5944local lformat = string.format;
5945local gmatch = string.gmatch;
5946local replace = string.Replace;
5947
5948---
5949--- gElo.L
5950---
5951function gElo.L(key, ...)
5952 local cvlang = gElo.GetSettings():GetSettingsValue("ui", "language");
5953 local curLang = gElo.Languages[cvlang] or gElo.Languages["en"];
5954
5955 for m in gmatch(key, "%{%a+%}") do
5956 key = replace(key, m, gElo.L(m:sub(2, m:len() - 1)));
5957 end
5958
5959 if (curLang[key]) then
5960 return lformat(curLang[key], ...);
5961 else
5962 return key;
5963 end
5964end
5965
5966--[[------------------------------------------------------------------------------
5967 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
5968 * Unauthorized copying of this file, via any medium is strictly prohibited
5969 * Proprietary and confidential
5970--]]------------------------------------------------------------------------------
5971
5972---
5973--- charWrap
5974--- Credits to FPTje(STEAM_0:0:8944068 - 76561197978153864)
5975---
5976local function charWrap(text, pxWidth)
5977 local total = 0
5978
5979 text = text:gsub(".", function(char)
5980 total = total + surface.GetTextSize(char)
5981
5982 -- Wrap around when the max width is reached
5983 if total >= pxWidth then
5984 total = 0
5985 return "\n" .. char
5986 end
5987
5988 return char
5989 end)
5990
5991 return text, total
5992end
5993
5994---
5995--- textWrap
5996--- Credits to FPTje(STEAM_0:0:8944068 - 76561197978153864)
5997---
5998function gElo.textWrap(text, font, pxWidth)
5999 local total = 0
6000
6001 surface.SetFont(font)
6002
6003 local spaceSize = surface.GetTextSize(' ')
6004 text = text:gsub("(%s?[%S]+)", function(word)
6005 local char = string.sub(word, 1, 1)
6006 if char == "\n" or char == "\t" then
6007 total = 0
6008 end
6009
6010 local wordlen = surface.GetTextSize(word)
6011 total = total + wordlen
6012
6013 -- Wrap around when the max width is reached
6014 if wordlen >= pxWidth then -- Split the word if the word is too big
6015 local splitWord, splitPoint = charWrap(word, pxWidth - (total - wordlen))
6016 total = splitPoint
6017 return splitWord
6018 elseif total < pxWidth then
6019 return word
6020 end
6021
6022 -- Split before the word
6023 if char == ' ' then
6024 total = wordlen - spaceSize
6025 return '\n' .. string.sub(word, 2)
6026 end
6027
6028 total = wordlen
6029 return '\n' .. word
6030 end)
6031
6032 return text
6033end
6034
6035---
6036--- NumberToRoman
6037---
6038function gElo.NumberToRoman(num)
6039 local romanNumbers = {
6040 [5] = "V",
6041 [4] = "IV",
6042 [3] = "III",
6043 [2] = "II",
6044 [1] = "I"
6045 }
6046
6047 if (romanNumbers[num]) then
6048 return romanNumbers[num];
6049 end
6050
6051 return num;
6052end
6053
6054--[[------------------------------------------------------------------------------
6055 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
6056 * Unauthorized copying of this file, via any medium is strictly prohibited
6057 * Proprietary and confidential
6058--]]------------------------------------------------------------------------------
6059
6060gElo.Colors = gElo.Colors or {};
6061
6062gElo.Colors.Good = Color(0, 200, 0, 200);
6063gElo.Colors.Warning = Color(200, 200, 0, 200);
6064gElo.Colors.Bad = Color(200, 0, 0, 200);
6065gElo.Colors.Neutral = Color(200, 200, 200, 200);
6066gElo.Colors.Cyan = Color(0, 200, 200, 200);
6067
6068-- UI Colors
6069gElo.Colors.MainBlue = Color(29, 34, 44, 255);
6070gElo.Colors.UIOutline = Color(57, 64, 78, 200);
6071
6072--[[------------------------------------------------------------------------------
6073 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
6074 * Unauthorized copying of this file, via any medium is strictly prohibited
6075 * Proprietary and confidential
6076--]]------------------------------------------------------------------------------
6077
6078-- Only a handful of selected keys are we able to bound to.
6079local keys = {
6080 [KEY_A] = "A",
6081 [KEY_B] = "B",
6082 [KEY_C] = "C",
6083 [KEY_D] = "D",
6084 [KEY_E] = "E",
6085 [KEY_F] = "F",
6086 [KEY_G] = "G",
6087 [KEY_H] = "H",
6088 [KEY_I] = "I",
6089 [KEY_J] = "J",
6090 [KEY_K] = "K",
6091 [KEY_L] = "L",
6092 [KEY_M] = "M",
6093 [KEY_N] = "N",
6094 [KEY_O] = "O",
6095 [KEY_P] = "P",
6096 [KEY_Q] = "Q",
6097 [KEY_R] = "R",
6098 [KEY_S] = "S",
6099 [KEY_T] = "T",
6100 [KEY_U] = "U",
6101 [KEY_V] = "V",
6102 [KEY_W] = "W",
6103 [KEY_X] = "X",
6104 [KEY_Y] = "Y",
6105 [KEY_Z] = "Z",
6106 [KEY_F1] = "F1",
6107 [KEY_F2] = "F2",
6108 [KEY_F3] = "F3",
6109 [KEY_F4] = "F4",
6110 [KEY_F5] = "F5",
6111 [KEY_F6] = "F6",
6112 [KEY_F7] = "F7",
6113 [KEY_F8] = "F8",
6114 [KEY_F9] = "F9",
6115 [KEY_F10] = "F10",
6116 [KEY_F11] = "F11",
6117 [KEY_F12] = "F12",
6118 [KEY_RALT] = "ALT GR",
6119 [KEY_LALT] = "LEFT ALT",
6120 [KEY_PAD_0] = "NUMPAD 0",
6121 [KEY_PAD_1] = "NUMPAD 1",
6122 [KEY_PAD_2] = "NUMPAD 2",
6123 [KEY_PAD_3] = "NUMPAD 3",
6124 [KEY_PAD_4] = "NUMPAD 4",
6125 [KEY_PAD_5] = "NUMPAD 5",
6126 [KEY_PAD_6] = "NUMPAD 6",
6127 [KEY_PAD_7] = "NUMPAD 7",
6128 [KEY_PAD_8] = "NUMPAD 8",
6129 [KEY_PAD_9] = "NUMPAD 9",
6130}
6131
6132---
6133--- GetTranslatedKey
6134---
6135function gElo.GetTranslatedKey(key)
6136 if (keys[key]) then
6137 return keys[key];
6138 end
6139
6140 return key;
6141end
6142
6143---
6144--- GetKeys
6145---
6146function gElo.GetKeys()
6147 return keys;
6148end
6149
6150--[[------------------------------------------------------------------------------
6151 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
6152 * Unauthorized copying of this file, via any medium is strictly prohibited
6153 * Proprietary and confidential
6154--]]------------------------------------------------------------------------------
6155
6156---
6157--- gElo.SecondsToMinutes
6158---
6159function gElo.SecondsToMinutes(s)
6160 local s = tonumber(s)
6161 local hours = string.format("%02.f", math.floor(s / 3600));
6162 local minutes = string.format("%02.f", math.floor(s / 60 - (hours * 60)));
6163 local seconds = string.format("%02.f", math.floor(s - hours * 3600 - minutes * 60));
6164
6165 return minutes .. ":" .. seconds;
6166end
6167
6168--[[------------------------------------------------------------------------------
6169 * Copyright (C) Fluffy(76561197976769128 - STEAM_0:0:8251700) - All Rights Reserved
6170 * Unauthorized copying of this file, via any medium is strictly prohibited
6171 * Proprietary and confidential
6172--]]------------------------------------------------------------------------------
6173
6174-- UI:
6175 -- What should our prefix for our chat command be?
6176 -- Keep all of the prefixes inside of one string like I have below
6177 -- The current ones become "!gelo";
6178 gElo.Config.UIPrefix = "!";
6179
6180 -- What should our chat command be?
6181 gElo.Config.UIStr = "gelo";
6182
6183 -- What usergroups can access the administration panel side of the UI?
6184 -- These groups can also change people's RP, Rank, etc.
6185 -- They will not be able to wipe the databasse, only superadmins can do that, period.
6186 gElo.Config.UIAdmin = {["admin"] = true, ["superadmin"] = true};
6187
6188 -- Forums URL
6189 gElo.Config.ForumURL = "https://www.bds-gaming.de/forum/";
6190--
6191
6192-- Misc:
6193 -- Minimum players needed in order to receive RP.
6194 -- 0 is no limit.
6195 gElo.Config.MinPlayers = 0;
6196
6197 -- Should easy mode be enabled?
6198 -- If we win a round then our RP gained that round is multiplied by 2,
6199 -- so 20 * 2 = 40; however, if we lose that round then the rp lost is halved by two,
6200 -- so 20 / 2 = 10; ..easy mode.
6201 gElo.Config.EasyMode = false;
6202--