Skip to content
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

Add the Local Leaderboard as a viewable Leaderboard #527

Open
wants to merge 2 commits into
base: itgmania-beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 108 additions & 12 deletions BGAnimations/ScreenSelectMusic overlay/Leaderboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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="Machine's Bests",
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
Expand Down
9 changes: 3 additions & 6 deletions BGAnimations/ScreenSelectMusic overlay/SortMenu/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Languages/en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions Scripts/99 SL-ThemePrefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion metrics.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down