[UI/UX] Add Username to Stats Screen (#6270)

* [Feature] Add Username to Stats Screen

* [Feature] username fallback to "Guest"

* [UI/UX] Update display name fallback to use translation for guest user

* Update locales submodule

* [Fix] Username updates without refresh

* Update locales submodule

---------

Co-authored-by: Wlowscha <54003515+Wlowscha@users.noreply.github.com>
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
G Sai Nikhilesh 2025-08-18 02:32:29 +05:30 committed by GitHub
parent 432f505f65
commit bf9f0880b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions

@ -1 +1 @@
Subproject commit 38d7c1baa2367582770d62b3f4b0239874c1c7e5 Subproject commit 7fa231e7239ed23e17a026670c007c97c3cd9e4a

View File

@ -1,7 +1,9 @@
import { loggedInUser } from "#app/account";
import { globalScene } from "#app/global-scene"; import { globalScene } from "#app/global-scene";
import { speciesStarterCosts } from "#balance/starters"; import { speciesStarterCosts } from "#balance/starters";
import { Button } from "#enums/buttons"; import { Button } from "#enums/buttons";
import { DexAttr } from "#enums/dex-attr"; import { DexAttr } from "#enums/dex-attr";
import { PlayerGender } from "#enums/player-gender";
import { TextStyle } from "#enums/text-style"; import { TextStyle } from "#enums/text-style";
import { UiTheme } from "#enums/ui-theme"; import { UiTheme } from "#enums/ui-theme";
import type { GameData } from "#system/game-data"; import type { GameData } from "#system/game-data";
@ -227,6 +229,9 @@ export class GameStatsUiHandler extends UiHandler {
private arrowUp: Phaser.GameObjects.Sprite; private arrowUp: Phaser.GameObjects.Sprite;
private arrowDown: Phaser.GameObjects.Sprite; private arrowDown: Phaser.GameObjects.Sprite;
/** Logged in username */
private headerText: Phaser.GameObjects.Text;
/** Whether the UI is single column mode */ /** Whether the UI is single column mode */
private get singleCol(): boolean { private get singleCol(): boolean {
const resolvedLang = i18next.resolvedLanguage ?? "en"; const resolvedLang = i18next.resolvedLanguage ?? "en";
@ -296,6 +301,23 @@ export class GameStatsUiHandler extends UiHandler {
return GameStatsUiHandler.ROWS_PER_PAGE * this.columnCount; return GameStatsUiHandler.ROWS_PER_PAGE * this.columnCount;
} }
/**
* Returns the username of logged in user. If the username is hidden, the trainer name based on gender will be displayed.
* @returns The username of logged in user
*/
private getUsername(): string {
const usernameReplacement =
globalScene.gameData.gender === PlayerGender.FEMALE
? i18next.t("trainerNames:player_f")
: i18next.t("trainerNames:player_m");
const displayName = !globalScene.hideUsername
? (loggedInUser?.username ?? i18next.t("common:guest"))
: usernameReplacement;
return i18next.t("gameStatsUiHandler:stats", { username: displayName });
}
// #endregion Columnar-specific properties // #endregion Columnar-specific properties
setup() { setup() {
@ -316,11 +338,11 @@ export class GameStatsUiHandler extends UiHandler {
const headerBg = addWindow(0, 0, sWidth - 2, 24).setOrigin(0); const headerBg = addWindow(0, 0, sWidth - 2, 24).setOrigin(0);
const headerText = addTextObject(0, 0, i18next.t("gameStatsUiHandler:stats"), TextStyle.HEADER_LABEL) this.headerText = addTextObject(0, 0, this.getUsername(), TextStyle.HEADER_LABEL)
.setOrigin(0) .setOrigin(0)
.setPositionRelative(headerBg, 8, 4); .setPositionRelative(headerBg, 8, 4);
this.gameStatsContainer.add([headerBg, headerText]); this.gameStatsContainer.add([headerBg, this.headerText]);
const colWidth = this.colWidth; const colWidth = this.colWidth;
@ -368,6 +390,10 @@ export class GameStatsUiHandler extends UiHandler {
show(args: any[]): boolean { show(args: any[]): boolean {
super.show(args); super.show(args);
// show updated username on every render
this.headerText.setText(this.getUsername());
this.gameStatsContainer.setActive(true).setVisible(true); this.gameStatsContainer.setActive(true).setVisible(true);
this.arrowUp.setActive(true).play("prompt").setVisible(false); this.arrowUp.setActive(true).play("prompt").setVisible(false);