From ce9acc373689ddd3ba3b74b6f19d215acf3c3823 Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Tue, 12 Mar 2024 04:35:48 -0400 Subject: [PATCH 1/2] Allow viewing the Local Leaderboard in the music wheel If the player does not have a groovestats account connected or groovestats is disabled, the player will still be able to view the Local Leaderboard Added a new preference (mainly oriented for public cabs) to prioritize displaying the local leaderboard before the the groovestats board. Always allow viewing the leaderboard in the sort menu. --- .../ScreenSelectMusic overlay/Leaderboard.lua | 120 ++++++++++++++++-- .../SortMenu/default.lua | 9 +- Languages/en.ini | 4 +- Scripts/99 SL-ThemePrefs.lua | 5 + metrics.ini | 3 +- 5 files changed, 120 insertions(+), 21 deletions(-) diff --git a/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua b/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua index aea5f65a6..4299a9837 100644 --- a/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua +++ b/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua @@ -16,6 +16,24 @@ local SetLeaderboardForPlayer = function(player_num, leaderboard, leaderboardDat local entryNum = 1 local rivalNum = 1 + + if leaderboardData["Disabled"] then + if leaderboardData["Name"] then + local name = leaderboardData["Name"]:gsub("ITL Online", "ITL") + leaderboard:GetChild("Header"):settext(name) + end + for j=1, NumEntries do + local entry = leaderboard:GetChild("LeaderboardEntry"..j) + if j == 1 then + SetEntryText("", "Disabled", "", "", entry) + else + -- Empty out the remaining rows. + SetEntryText("", "", "", "", entry) + end + end + return + end + -- Hide the rival and self highlights. -- They will be unhidden and repositioned as needed below. for i=1,3 do @@ -91,7 +109,38 @@ local SetLeaderboardForPlayer = function(player_num, leaderboard, leaderboardDat end end end - +local getLocalLeaderboard = function(pn) + if not GAMESTATE:IsPlayerEnabled(pn) then return {} end + local HighScores = PROFILEMAN:GetMachineProfile():GetHighScoreList(GAMESTATE:GetCurrentSong(),GAMESTATE:GetCurrentSteps(pn)):GetHighScores() + local profileName = PROFILEMAN:GetProfile(pn):GetLastUsedHighScoreName() + local localData = {} + if HighScores then + for i, highscore in ipairs(HighScores) do + local name = highscore:GetName() + local percentDP = highscore:GetPercentDP() + local score = tonumber(("%.0f"):format(percentDP * 10000)) + local date = highscore:GetDate() + local grade = highscore:GetGrade() + local isRival = false + local isSelf = name == profileName + local isFail = false + if grade == "Grade_Failed" then + isFail = true + end + local entry = { + name=name, + score=score, + date=date, + isRival=isRival, + isSelf=isSelf, + isFail=isFail, + rank=i + } + table.insert(localData, entry) + end + end + return localData +end local LeaderboardRequestProcessor = function(res, master) if master == nil then return end @@ -106,6 +155,14 @@ local LeaderboardRequestProcessor = function(res, master) for i=1, 2 do local pn = "P"..i local leaderboard = master:GetChild(pn.."Leaderboard") + local leaderboardList = master[pn]["Leaderboards"] + local localData = getLocalLeaderboard(pn) + leaderboardList[#leaderboardList + 1] = { + Name="Local Leaderboard", + Data=DeepCopy(localData), + IsEX=false + } + master[pn]["LeaderboardIndex"] = 1 for j=1, NumEntries do local entry = leaderboard:GetChild("LeaderboardEntry"..j) if j == 1 then @@ -129,7 +186,6 @@ local LeaderboardRequestProcessor = function(res, master) if data[playerStr] then master[pn].isRanked = data[playerStr]["isRanked"] - if SL["P"..i].ActiveModifiers.ShowEXScore then -- If the player is using EX scoring, then we want to display the EX leaderboard first. if data[playerStr]["exLeaderboard"] then @@ -183,6 +239,17 @@ local LeaderboardRequestProcessor = function(res, master) end end + -- Display the local leaderboard last if the preference is not set + if not ThemePrefs.Get("PrioritizeLocalLeaderboard") then + local localData = getLocalLeaderboard(pn) + leaderboardList[#leaderboardList + 1] = { + Name="Local Leaderboard", + Data=DeepCopy(localData), + IsEX=false + } + master[pn]["LeaderboardIndex"] = 1 + end + if #leaderboardList > 1 then leaderboard:GetChild("PaneIcons"):visible(true) else @@ -253,22 +320,51 @@ local af = Def.ActorFrame{ }, RequestResponseActor(17, 50)..{ SendLeaderboardRequestCommand=function(self) + -- If a player does not have an API key or chart hash just show the local leaderboard. + + for i=1,2 do + local pn = "P"..i + if SL[pn].ApiKey == "" or SL[pn].Streams.Hash == "" or ThemePrefs.Get("PrioritizeLocalLeaderboard") or not IsServiceAllowed(SL.GrooveStats.Leaderboard) then + local pn = "P"..i + local leaderboard = self:GetParent():GetChild(pn.."Leaderboard") + local leaderboardList = self:GetParent()[pn]["Leaderboards"] + local localData = getLocalLeaderboard(pn) + leaderboardList[#leaderboardList + 1] = { + Name="Local Leaderboard", + Data=DeepCopy(localData), + IsEX=false + } + self:GetParent()[pn]["LeaderboardIndex"] = 1 + end + end + -- Display the local leaderboard first if the preference is set + if ThemePrefs.Get("PrioritizeLocalLeaderboard") or not IsServiceAllowed(SL.GrooveStats.Leaderboard) then + for i=1, 2 do + local pn = "P"..i + local leaderboard = self:GetParent():GetChild(pn.."Leaderboard") + local leaderboardList = self:GetParent()[pn]["Leaderboards"] + local localData = getLocalLeaderboard(pn) + leaderboardList[#leaderboardList + 1] = { + Name="Local Leaderboard", + Data=DeepCopy(localData), + IsEX=false + } + self:GetParent()[pn]["LeaderboardIndex"] = 1 + end + end if not IsServiceAllowed(SL.GrooveStats.Leaderboard) then if SL.GrooveStats.IsConnected then -- If we disable the service from a previous request, surface it to the user here. - -- (Even though the Leaderboard option is already removed from the sort menu, so this is extra). for i=1, 2 do local pn = "P"..i local leaderboard = self:GetParent():GetChild(pn.."Leaderboard") - for j=1, NumEntries do - local entry = leaderboard:GetChild("LeaderboardEntry"..j) - if j == 1 then - SetEntryText("", "Disabled", "", "", entry) - else - -- Empty out the remaining rows. - SetEntryText("", "", "", "", entry) - end - end + local leaderboardList = self:GetParent()[pn]["Leaderboards"] + leaderboardList[#leaderboardList + 1] = { + Name="Groovestats", + Disabled=true, + IsEX=false + } + SetLeaderboardForPlayer(i, leaderboard, leaderboardList[1], false) end end return diff --git a/BGAnimations/ScreenSelectMusic overlay/SortMenu/default.lua b/BGAnimations/ScreenSelectMusic overlay/SortMenu/default.lua index 5c746c21d..32c30eb61 100644 --- a/BGAnimations/ScreenSelectMusic overlay/SortMenu/default.lua +++ b/BGAnimations/ScreenSelectMusic overlay/SortMenu/default.lua @@ -308,12 +308,9 @@ local t = Def.ActorFrame { table.insert(wheel_options, {"NeedMoreRam", "ViewDownloads"}) end - -- The relevant Leaderboard.lua actor is only added if these same conditions are met. - if IsServiceAllowed(SL.GrooveStats.Leaderboard) then - -- Also only add this if we're actually hovering over a song. - if GAMESTATE:GetCurrentSong() then - table.insert(wheel_options, {"GrooveStats", "Leaderboard"}) - end + -- Only add this if we're actually hovering over a song. + if GAMESTATE:GetCurrentSong() then + table.insert(wheel_options, {"GrooveStats", "Leaderboard"}) end if not GAMESTATE:IsCourseMode() then diff --git a/Languages/en.ini b/Languages/en.ini index c5a5d9eb0..3d03e1832 100644 --- a/Languages/en.ini +++ b/Languages/en.ini @@ -740,7 +740,7 @@ EditorShowBGChangesPlay=Show Backgrounds\n(and FGChanges) EnableGrooveStats=Enable GrooveStats AutoDownloadUnlocks=Auto-Download Unlocks SeparateUnlocksByPlayer=Separate Unlocks By Player - +PrioritizeLocalLeaderboard=Show Machine Scores First ############################################## # now we get into the longer explanations of options @@ -891,7 +891,7 @@ StepMania Credits=Celebrate those who made StepMania possible. EnableGrooveStats=Establish a connection to GrooveStats. AutoDownloadUnlocks=Auto-Download Unlocks for Online Events.\n\nNote: Unzipping the unlock can cause the game to stutter. SeparateUnlocksByPlayer=Separate Downloaded Unlocks for Each Profile. - +PrioritizeLocalLeaderboard=When viewing the leaderboard, Show the scores obtained on this machine first before showing any obtained from Groovestats. # ScreenPlayerOptions SpeedModType=Change the way arrows react to changing BPMs. diff --git a/Scripts/99 SL-ThemePrefs.lua b/Scripts/99 SL-ThemePrefs.lua index 1240aa0a1..b526fa577 100644 --- a/Scripts/99 SL-ThemePrefs.lua +++ b/Scripts/99 SL-ThemePrefs.lua @@ -298,6 +298,11 @@ SL_CustomPrefs.Get = function() Choices = { THEME:GetString("ThemePrefs","Yes"), THEME:GetString("ThemePrefs", "No") }, Values = { true, false } }, + PrioritizeLocalLeaderboard = { + Default = false, + Choices = { THEME:GetString("ThemePrefs","Yes"), THEME:GetString("ThemePrefs", "No") }, + Values = { true, false } + }, } end diff --git a/metrics.ini b/metrics.ini index 354d2b3b4..b9518cae5 100644 --- a/metrics.ini +++ b/metrics.ini @@ -1291,11 +1291,12 @@ ItemOnCommand=visible,false [ScreenGrooveStatsOptions] Fallback="ScreenOptionsServiceChild" -LineNames="EnableGrooveStats,AutoDownloadUnlocks,SeparateUnlocksByPlayer" +LineNames="EnableGrooveStats,AutoDownloadUnlocks,SeparateUnlocksByPlayer,PrioritizeLocalLeaderboard" LineEnableGrooveStats="lua,ThemePrefsRows.GetRow('EnableGrooveStats')" LineAutoDownloadUnlocks="lua,ThemePrefsRows.GetRow('AutoDownloadUnlocks')" LineSeparateUnlocksByPlayer="lua,ThemePrefsRows.GetRow('SeparateUnlocksByPlayer')" +LinePrioritizeLocalLeaderboard="lua,ThemePrefsRows.GetRow('PrioritizeLocalLeaderboard')" [ScreenTournamentModeOptions] From 69a22a8a51e6ec52baabe5417c5c9ac82810799d Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Tue, 31 Dec 2024 15:32:04 -0500 Subject: [PATCH 2/2] Rename Local Leaderboard --> Machine's Bests. Use 2 spaces to avoid crampness --- BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua b/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua index 4299a9837..c9ca79d61 100644 --- a/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua +++ b/BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua @@ -345,7 +345,7 @@ local af = Def.ActorFrame{ local leaderboardList = self:GetParent()[pn]["Leaderboards"] local localData = getLocalLeaderboard(pn) leaderboardList[#leaderboardList + 1] = { - Name="Local Leaderboard", + Name="Machine's Bests", Data=DeepCopy(localData), IsEX=false }