New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TTT: Enable scoreboard to be sorted by different criteria other than score #1332
Changes from 71 commits
a94b8e3
c6a6cea
c512684
6d92af5
53dcb92
c82a4d0
6af889b
4793be8
0e74c2a
d8b7007
9dbeffe
b01837b
acad015
5d59fad
bd5a411
9ffde57
d785f17
ca2fd27
e9ddcee
d4cd44d
29e6e41
2307046
705ff0b
e66720c
5c9496f
8f7aa65
c988cac
f093512
a62d62a
9e54d20
f32611c
5711559
77e1c95
bd40d74
849e691
54b555f
2b602d8
1851aa7
0e2b959
aeaf2db
8c3363b
58f65f1
6f70cb8
52027fb
15b2986
2a8d2e7
f26c17a
02c8481
b26df01
a5942ae
745d5ca
b5a00d1
ae9b239
ab95202
553f3b4
23293d6
98d1b51
d055277
49d9e8a
b097d78
8b9902f
9d2a32b
e1849a4
2ac8002
b226ea1
a8d55c9
650381f
dab25a3
702e38d
ff9ab8d
7d9a8fe
865151b
7f51348
e5ee199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,6 @@ | |
|
||
include("sb_row.lua") | ||
|
||
local function CompareScore(pa, pb) | ||
if not IsValid(pa) then return false end | ||
if not IsValid(pb) then return true end | ||
|
||
local a = pa:GetPlayer() | ||
local b = pb:GetPlayer() | ||
|
||
if not IsValid(a) then return false end | ||
if not IsValid(b) then return true end | ||
|
||
if a:Frags() == b:Frags() then return a:Deaths() < b:Deaths() end | ||
|
||
return a:Frags() > b:Frags() | ||
end | ||
|
||
local PANEL = {} | ||
|
||
function PANEL:Init() | ||
|
@@ -116,11 +101,41 @@ end | |
|
||
function PANEL:UpdateSortCache() | ||
self.rows_sorted = {} | ||
for k,v in pairs(self.rows) do | ||
table.insert(self.rows_sorted, v) | ||
|
||
for _, row in pairs(self.rows) do | ||
table.insert(self.rows_sorted, row) | ||
end | ||
|
||
table.sort(self.rows_sorted, CompareScore) | ||
table.sort(self.rows_sorted, function(rowa, rowb) | ||
local plya = rowa:GetPlayer() | ||
local plyb = rowb:GetPlayer() | ||
|
||
if not IsValid(plya) then return false end | ||
if not IsValid(plyb) then return true end | ||
|
||
local comp = 0 -- Lua doesnt have an Ordering enumeration, I think? | ||
|
||
local sort_mode = GetConVar("ttt_scoreboard_sorting"):GetString() | ||
local sort_func = sboard_panel.sort_table[sort_mode] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This use of As a result, if 2+ players exist when you first open the scoreboard, then this Note that simply not sorting if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh I am bad I should have investigated this more earlier. I had uncorrectly assumed that because existing code in Which I see now was because it was used in instance methods |
||
|
||
if sort_func != nil then | ||
comp = sort_func(plya, plyb) | ||
end | ||
|
||
local ret = true | ||
|
||
if comp != 0 then | ||
ret = comp > 0 | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a hook, so you can also sort custom columnes too? |
||
ret = string.lower(plya:GetName()) > string.lower(plyb:GetName()) | ||
end | ||
|
||
if GetConVar("ttt_scoreboard_ascending"):GetBool() then | ||
ret = not ret | ||
end | ||
|
||
return ret | ||
end) | ||
end | ||
|
||
function PANEL:UpdatePlayerData() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To correspond with the two new parameters in the AddColumn function of sb_main
Unless the version of lua GMod uses is really screwed up the change won't make a lick of difference.