From 312b38fda5363d2df34dfd1b9fb211ffead72873 Mon Sep 17 00:00:00 2001 From: Ryan <7389646+ryanbarlow97@users.noreply.github.com> Date: Fri, 5 Jun 2026 22:18:31 +0100 Subject: [PATCH] Disable game buttons (clan tag + username) (#4170) ## Description: disables buttons, instead of emitting a warning image image ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory ## Please put your Discord username so you can be contacted if a bug or regression is found: w.o.n --- src/client/GameModeSelector.ts | 39 ++++++++++++++++++++++++++++------ src/client/Main.ts | 2 +- src/client/UsernameInput.ts | 37 +++++++++++++------------------- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/client/GameModeSelector.ts b/src/client/GameModeSelector.ts index 660dd222a..b1dc74cb0 100644 --- a/src/client/GameModeSelector.ts +++ b/src/client/GameModeSelector.ts @@ -34,6 +34,7 @@ const CARD_BG = "bg-surface"; export class GameModeSelector extends LitElement { @state() private lobbies: PublicGames | null = null; @state() private mapAspectRatios: Map = new Map(); + @state() private inputValid: boolean = true; private serverTimeOffset: number = 0; private defaultLobbyTime: number = 0; @@ -45,28 +46,44 @@ export class GameModeSelector extends LitElement { return this; } - /** - * Validates username input and shows error message if invalid. - * Returns true if valid, false otherwise. - */ + // Silent backstop; the buttons are already disabled while input is invalid. private validateUsername(): boolean { const usernameInput = document.querySelector( "username-input", ) as UsernameInput | null; - return usernameInput ? usernameInput.validateOrShowError() : true; + return usernameInput ? usernameInput.canPlay() : true; } connectedCallback() { super.connectedCallback(); this.lobbySocket.start(); this.defaultLobbyTime = ClientEnv.gameCreationRate() / 1000; + window.addEventListener( + "username-validity-change", + this.handleValidityChange, + ); + // Pick up the current value in case username-input validated before us. + const usernameInput = document.querySelector( + "username-input", + ) as UsernameInput | null; + if (usernameInput) { + this.inputValid = usernameInput.canPlay(); + } } disconnectedCallback() { this.stop(); + window.removeEventListener( + "username-validity-change", + this.handleValidityChange, + ); super.disconnectedCallback(); } + private handleValidityChange = (e: Event) => { + this.inputValid = (e as CustomEvent).detail?.isValid ?? true; + }; + public stop() { this.lobbySocket.stop(); } @@ -259,7 +276,11 @@ export class GameModeSelector extends LitElement { return html` @@ -305,7 +326,11 @@ export class GameModeSelector extends LitElement { return html`