mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-10 04:34:36 +00:00
Add requeue button to Ranked victory/defeat modal (#3121)
## Description: Adds a "Play Again" requeue button to the victory/defeat modal for Ranked 1v1 games. When clicked, it navigates the player back to the homepage and automatically opens the matchmaking modal to queue for another ranked match. Changes: - WinModal.ts: Added isRankedGame state, purple "Play Again" button (only shown for ranked 1v1), and _handleRequeue() method - Main.ts: Added ?requeue URL parameter handling to trigger matchmaking modal on page load - en.json: Added "requeue": "Play Again" translation string - added tests to WinModal.test.ts Note: temporarily set isRanked flag to true to get the modal to pop in a solo match on dev server and confirmed that ?requeue URL parameter called _handleRequeue() correctly, which opened the sign in process since actually signing in and queuing for a ranked match isn't possible on dev server. <img width="771" height="364" alt="play-again" src="https://github.com/user-attachments/assets/6e3f5a02-f1ae-465a-9b28-656126c11d3d" /> ## 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 - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: skigim
This commit is contained in:
@@ -755,6 +755,32 @@ class Client {
|
||||
if (decodedHash.startsWith("#refresh")) {
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
// Handle requeue parameter for ranked matchmaking
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
if (searchParams.has("requeue")) {
|
||||
// Remove only the requeue parameter, preserving other params and hash
|
||||
searchParams.delete("requeue");
|
||||
const newUrl =
|
||||
window.location.pathname +
|
||||
(searchParams.toString() ? "?" + searchParams.toString() : "") +
|
||||
window.location.hash;
|
||||
history.replaceState(null, "", newUrl);
|
||||
// Wait for matchmaking button to be defined, then trigger its click handler
|
||||
// This goes through username validation instead of bypassing it
|
||||
customElements.whenDefined("matchmaking-button").then(() => {
|
||||
const matchmakingButton = document.querySelector(
|
||||
"matchmaking-button button",
|
||||
) as HTMLButtonElement | null;
|
||||
if (matchmakingButton) {
|
||||
matchmakingButton.click();
|
||||
} else {
|
||||
console.warn(
|
||||
"Requeue requested, but matchmaking button not found in DOM.",
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async handleJoinLobby(event: CustomEvent<JoinLobbyEvent>) {
|
||||
|
||||
@@ -320,7 +320,7 @@ export class MatchmakingButton extends LitElement {
|
||||
window.showPage?.("page-account");
|
||||
}
|
||||
|
||||
private open() {
|
||||
public open() {
|
||||
this.matchmakingModal?.open();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "../../../client/Utils";
|
||||
import { ColorPalette, Pattern } from "../../../core/CosmeticSchemas";
|
||||
import { EventBus } from "../../../core/EventBus";
|
||||
import { RankedType } from "../../../core/game/Game";
|
||||
import { GameUpdateType } from "../../../core/game/GameUpdates";
|
||||
import { GameView } from "../../../core/game/GameView";
|
||||
import { getUserMe } from "../../Api";
|
||||
@@ -37,6 +38,9 @@ export class WinModal extends LitElement implements Layer {
|
||||
@state()
|
||||
private isWin = false;
|
||||
|
||||
@state()
|
||||
private isRankedGame = false;
|
||||
|
||||
@state()
|
||||
private patternContent: TemplateResult | null = null;
|
||||
|
||||
@@ -75,6 +79,16 @@ export class WinModal extends LitElement implements Layer {
|
||||
>
|
||||
${translateText("win_modal.exit")}
|
||||
</button>
|
||||
${this.isRankedGame
|
||||
? html`
|
||||
<button
|
||||
@click=${this._handleRequeue}
|
||||
class="flex-1 px-3 py-3 text-base cursor-pointer bg-purple-600 text-white border-0 rounded-sm transition-all duration-200 hover:bg-purple-500 hover:-translate-y-px active:translate-y-px"
|
||||
>
|
||||
${translateText("win_modal.requeue")}
|
||||
</button>
|
||||
`
|
||||
: null}
|
||||
<button
|
||||
@click=${this.hide}
|
||||
class="flex-1 px-3 py-3 text-base cursor-pointer bg-blue-500/60 text-white border-0 rounded-sm transition-all duration-200 hover:bg-blue-500/80 hover:-translate-y-px active:translate-y-px"
|
||||
@@ -251,6 +265,9 @@ export class WinModal extends LitElement implements Layer {
|
||||
async show() {
|
||||
crazyGamesSDK.gameplayStop();
|
||||
await this.loadPatternContent();
|
||||
// Check if this is a ranked game
|
||||
this.isRankedGame =
|
||||
this.game.config().gameConfig().rankedType === RankedType.OneVOne;
|
||||
this.isVisible = true;
|
||||
this.requestUpdate();
|
||||
setTimeout(() => {
|
||||
@@ -270,6 +287,12 @@ export class WinModal extends LitElement implements Layer {
|
||||
window.location.href = "/";
|
||||
}
|
||||
|
||||
private _handleRequeue() {
|
||||
this.hide();
|
||||
// Navigate to homepage and open matchmaking modal
|
||||
window.location.href = "/?requeue";
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
tick() {
|
||||
|
||||
Reference in New Issue
Block a user