Skip to content

Commit

Permalink
feat: Add button to sync primary track with the current leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Panzerhandschuh committed Jan 13, 2025
1 parent 1cf0d64 commit 7ad6be1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions layout/pages/leaderboards/leaderboards.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
<Panel id="placeholder" /> <!-- This is needed to unfuck the dynamic dropdown -->
</DropDown>

<TooltipPanel tooltip="#Leaderboards_SyncTrackButton" class="v-align-center">
<Button id="SyncTrackButton" class="button leaderboards__button" onactivate="LeaderboardsHandler.syncTrackWithLeaderboard();">
<Image class="button__icon" src="file://{images}/refresh.svg" textureheight="32" />
</Button>
</TooltipPanel>

<TooltipPanel tooltip="#Leaderboards_EndOfRunButton" class="v-align-center">
<Button id="EndOfRunButton" class="button leaderboards__button" onactivate="LeaderboardsHandler.showEndOfRun();">
<Image class="button__icon button__icon--left" src="file://{images}/arrow-thick-right.svg" textureheight="64" />
Expand Down
22 changes: 22 additions & 0 deletions scripts/pages/leaderboards/leaderboards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LeaderboardsHandler {
lobbyButton: $<Button>('#TimesListLobby'),
timesContainer: $<Panel>('#LeaderboardTimesContainer'),
emptyWarningText: $<Label>('#LeaderboardEmptyWarningText'),
syncTrackButton: $<Button>('#SyncTrackButton'),
endOfRunButton: $<Button>('#EndOfRunButton'),
tracksDropdown: $<DropDown>('#TracksDropdown'),
radioButtons: {
Expand Down Expand Up @@ -164,6 +165,24 @@ class LeaderboardsHandler {
}
}

syncTrackWithLeaderboard() {
const selected = this.panels.tracksDropdown.GetSelected();
const trackType = selected.GetAttributeInt('trackType', TrackType.MAIN as number);
const trackNum = selected.GetAttributeInt('trackNum', 1);

switch (trackType) {
case TrackType.MAIN:
GameInterfaceAPI.ConsoleCommand('mom_main');
break;
case TrackType.STAGE:
GameInterfaceAPI.ConsoleCommand(`mom_stage ${trackNum}`);
break;
case TrackType.BONUS:
GameInterfaceAPI.ConsoleCommand(`mom_bonus ${trackNum}`);
break;
}
}

showEndOfRun() {
$.DispatchEvent('EndOfRun_Show', EndOfRunShowReason.MANUALLY_SHOWN);
}
Expand All @@ -183,6 +202,7 @@ class LeaderboardsHandler {
*/
onMapLoad(isOfficial: boolean) {
this.panels.endOfRunButton.visible = false;
this.panels.syncTrackButton.visible = false;

if (isOfficial) {
return; // Load official leaderboard tracks instead
Expand All @@ -191,6 +211,8 @@ class LeaderboardsHandler {
// Try to load tracks from local zones
const mapZoneData = MomentumTimerAPI.GetActiveZoneDefs();
if (mapZoneData) {
this.panels.syncTrackButton.visible = true;

// Main track
{
const trackStr = $.Localize('#Leaderboards_Tracks_Main');
Expand Down

0 comments on commit 7ad6be1

Please sign in to comment.