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

Fix tab menu credits exception #163

Merged
merged 2 commits into from
Nov 30, 2024
Merged
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
1 change: 0 additions & 1 deletion layout/hud/tab-menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</Panel>
<Panel class="hud-tab-menu-map-info__bottom">
<Panel id="HudTabMenuMapCredits" class="hud-tab-menu-map-info__credits">
<Label class="hud-tab-menu-map-info__credits-other-text" text="#Common_By" />
<!-- Author names inserted by JS -->
</Panel>
<Panel class="hud-tab-menu-map-info__stats">
Expand Down
8 changes: 7 additions & 1 deletion scripts/common/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ export function getTier(
: getTrack(staticData, gamemode, trackType, trackNum)?.tier;
}

/** Simplified credit object, derived from either a regular credit or a placeholder suggestion */
export interface SimpleMapCredit {
alias: string;
steamID?: string;
}

/**
* Get collection of simplified credits data, optionally filtered by type.
* If the map is in submission, placeholders suggestions are included, with steamID omitted.
*/
export function getAllCredits(staticData: MMap, type?: MapCreditType): Array<{ alias: string; steamID?: string }> {
export function getAllCredits(staticData: MMap, type?: MapCreditType): SimpleMapCredit[] {
const credits = [];

let normal = staticData.credits;
Expand Down
36 changes: 21 additions & 15 deletions scripts/hud/tab-menu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PanelHandler } from 'util/module-helpers';
import { EndOfRunShowReason } from 'common/timer';
import { GamemodeInfo, MapCredit, MapCreditType, MMap } from 'common/web';
import { GamemodeInfo, MapCreditType, MMap } from 'common/web';
import { getNumZones, getTrack } from 'common/leaderboard';
import { getAllCredits, SimpleMapCredit } from 'common/maps';

/**
* Class for the HUD tab menu panel, which contains the leaderboards, end of run, and zoning.
Expand Down Expand Up @@ -65,44 +66,49 @@ class HudTabMenuHandler {

if (mapData && isOfficial) {
this.setMapStats(mapData.staticData);
this.setMapAuthorCredits(mapData.staticData.credits);
this.setMapAuthorCredits(getAllCredits(mapData.staticData, MapCreditType.AUTHOR));
}
}

setMapAuthorCredits(credits: MapCredit[]) {
setMapAuthorCredits(credits: SimpleMapCredit[]) {
// Delete existing name labels
for (const label of this.panels.credits.Children().slice(1) || []) {
label.DeleteAsync(0);
this.panels.credits.Children()?.forEach((label) => label.DeleteAsync(0));

if (credits.length === 0) {
return;
}

const authorCredits = credits.filter(({ type }) => type === MapCreditType.AUTHOR);
$.CreatePanel('Label', this.panels.credits, '', {
class: 'hud-tab-menu-map-info__credits-other-text',
text: $.Localize('#CommonBy')
});

for (const credit of authorCredits) {
for (const [idx, { alias, steamID }] of credits.entries()) {
const namePanel = $.CreatePanel('Label', this.panels.credits, '', {
text: credit.user.alias
text: alias
});

namePanel.AddClass('hud-tab-menu-map-info__credits-name');

if (credit.user.steamID) {
// TODO: Perhaps better if left-click just loads momentum profile? Can access steam through that,
// and profile pages no longer require a login to view.
if (steamID) {
namePanel.AddClass('hud-tab-menu-map-info__credits-name--steam');

// TODO: Should be an onactivate (left click, not right), and open player card component,
// once that's made.
namePanel.SetPanelEvent('oncontextmenu', () => {
UiToolkitAPI.ShowSimpleContextMenu('', '', [
{
label: $.Localize('#Action_ShowSteamProfile'),
jsCallback: () => {
SteamOverlayAPI.OpenToProfileID(credit.user.steamID);
SteamOverlayAPI.OpenToProfileID(steamID);
}
}
]);
});
} else {
namePanel.AddClass('hud-tab-menu-map-info__credits-name--no-steam');
}

// hoped this would make contextmenu work but it doesn't
if (authorCredits.indexOf(credit) < authorCredits.length - 1) {
if (idx < credits.length - 1) {
const commaPanel = $.CreatePanel('Label', this.panels.credits, '');
commaPanel.AddClass('hud-tab-menu-map-info__credits-other-text');
commaPanel.text = ',';
Expand Down
12 changes: 8 additions & 4 deletions styles/hud/tab-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,16 @@
}

&__credits-name {
color: $mid-blue;
margin-left: 4px;
transition: color 0.1s ease-in-out 0s;
color: color.scale($mid-blue, $lightness: 75%);

&:hover:not(&--no-steam) {
color: color.scale($mid-blue, $lightness: 50%);
&--steam {
color: $mid-blue;
transition: color 0.1s ease-in-out 0s;

&:hover {
color: color.scale($mid-blue, $lightness: 50%);
}
}
}

Expand Down