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
Conversation
bt = k | ||
end | ||
end | ||
return bt > at |
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.
Couldn't this all be replaced by:
local function CompareRowsByName(rowa, rowb)
local plya = rowa:GetPlayer()
if not IsValid(plya) then return false end
local plyb = rowb:GetPlayer()
if not IsValid(plyb) then return true end
return plya:GetName() < plyb:GetName() -- might be >
end
@@ -91,6 +94,8 @@ CreateConVar("ttt_det_credits_starting", "1") | |||
CreateConVar("ttt_det_credits_traitorkill", "0") | |||
CreateConVar("ttt_det_credits_traitordead", "1") | |||
|
|||
-- Other | |||
CreateConVar("ttt_scoreboard_sorting", "1", FCVAR_NOTIFY + FCVAR_REPLICATED) |
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.
Instead of a ConVar, why not allow the clients to sort by clicking on the column headings or something?
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.
Good idea; but I believe I need to keep the ConVar as I could not find a shared object needed to host the variable. There may be one though; I'm not very familiar with the codebase.
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.
It could be a property of the scoreboard object
|
||
|
||
|
||
|
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.
You seem to have quite a bit of whitespace here and above.
|
||
local function CompareDeath(pa, pb) | ||
if not IsValid(pa) then return false end | ||
if not IsValid(pb) then return true end |
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.
The rows should always be valid at call time so these checks can be removed.
if not IsValid(pb) then return true end | ||
|
||
local a = pa:GetPlayer() | ||
local b = pb:GetPlayer() |
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.
Might want to use some more descriptive variable names for the rows and players. It took me longer to figure out the purpose of this code than if they had been properly labelled.
A few things: you should use bit.* operations for bit flags instead of normal arithmetic. In this case, CreateConVar actually supports sending in a table of flags that it will merge internally. Next, you should always test pull requests before submitting them; community feedback is great, but it works even better on working code. Also, why are you doing all of that extra sorting work in CompareAlpha? |
I just finished testing it; it works fine. I was not the one that created the initial code; I will work on cleaning it up now And sorting by clicking on column headers sounds like a fabulous idea. |
@DirkyJerky @Kefta I implemented clicking on scoreboard headings to sort. It supports swapping the sort direction by clicking a heading multiple times. It's just missing sorting by name. One quirk is that it sorts within ScoreGroups independently of each other, but it seems fine. |
TTT: Implement clicking on scoreboard headings to sort by that field
Great job @bmwalters :D |
It may even be useful to the end user; probably not
@@ -112,6 +112,23 @@ function PANEL:Init() | |||
|
|||
self.ply_groups = {} | |||
|
|||
concommand.Add( "ttt_scoreboard_setsort", function( _, _, args ) |
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.
i honestly don't think we need this
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.
A ConVar to store how the sorting should be in the scoreboard would be useful, wouldn't it?
return plya:GetRole() > plyb:GetRole() | ||
elseif self.sort_mode == "karma" then | ||
return plya:GetBaseKarma() < plyb:GetBaseKarma() | ||
else |
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.
Maybe add a hook, so you can also sort custom columnes too?
Alright I added two more buttons to click to sort on; and made the active sorting option get highlighted. |
Every option is working smoothly it seems. |
In my personal opinion; It would be a much better option to store the current sort option as a ConVar (with ARCHIVE flag set), because then it will be persistent across sessions. |
@DirkyJerky About the ConVar, I don't think the current sort option is something that needs to persist. It's trivial to interact with the headings to change the sorting back when wanted, and it's sort of needless complexity. Lastly, maybe the green from the "Terrorists (10)" heading background could be re-used for the text color. Nice job getting some stuff made; it's good to have working prototypes of these features. |
I did this once before but reverted it for some reason, I forget why. Works fine it seems
Done. |
Scratch that I found differing translations from different sources, so I bet an actual translator would know what works best. |
Don't put in empty translations; let it fall back to English |
No, I meant delete the translation from the other files. The code will automatically make it fall back to english. |
German Translation: |
Spanish is "Ordene por:" |
Can you squash? |
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.
Finally got around to testing this, and I did not get very far.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This use of sboard_panel
breaks things. UpdateSortCache
is called while initializing the scoreboard. At that point, sboard_panel
is nil (because the panel is still being created).
As a result, if 2+ players exist when you first open the scoreboard, then this sboard_panel.sort_table
access will of course break and throw your face full of errors.
Note that simply not sorting if sboard_panel == nil
probably will not work, because it will just leave the sort cache in an unsorted state until something triggers an update.
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.
Ugh I am bad I should have investigated this more earlier.
I had uncorrectly assumed that because existing code in sb_row.lua
and sb_team.lua
used that variable without any nil checks, that it was something out of the scope of this PR.
Which I see now was because it was used in instance methods
@Kefta, PRs can now be automatically Squashed when merging |
Ah, didn't know |
I believe the best but messy option is as follows:
Goal is the top Child #1 is Child #2 is just a (Target) Child #3 is one of the Everything seems to be working with the fix. Sorry for disappointing you @svdm ;-; |
Honestly it's cleaner to just move the |
Seems to still be working as intended. |
Reasoning:
--- It can take several seconds to find a specific person on it, especially if some of them are color coded.
Current status:
Pictures!: Name | Role - T | Role - D | Role - I | Score | Karma | Deaths | Ping | Custom column test