From 955aa0956d2728a4ccb3644f128ee4ecb93d1143 Mon Sep 17 00:00:00 2001 From: Kieran Kihn <114803508+kierankihn@users.noreply.github.com> Date: Wed, 10 Dec 2025 22:30:25 +0800 Subject: [PATCH] feat(ui): add `AFTER_GAME` state and restart flow in `GameUI` - Introduced `AFTER_GAME` state to handle post-game logic. - Updated `GameUI` to show restart prompt when the game ends. - Modified `StartPage` and `MainWindow` to support restart behavior. - Adjusted `endGame` method to transition to `AFTER_GAME`. --- src/game/GameState.cpp | 2 +- src/game/GameState.h | 2 +- src/ui/GameUI.cpp | 6 +++++- ui/MainWindow.slint | 2 ++ ui/StartPage.slint | 3 ++- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/game/GameState.cpp b/src/game/GameState.cpp index 92558db..ad5998f 100644 --- a/src/game/GameState.cpp +++ b/src/game/GameState.cpp @@ -179,7 +179,7 @@ namespace UNO::GAME { void ClientGameState::endGame() { - this->clientGameStage_ = ClientGameStage::PRE_GAME; + this->clientGameStage_ = ClientGameStage::AFTER_GAME; this->player_.clear(); } diff --git a/src/game/GameState.h b/src/game/GameState.h index 5e91b90..dbe791f 100644 --- a/src/game/GameState.h +++ b/src/game/GameState.h @@ -304,7 +304,7 @@ namespace UNO::GAME { } - enum class ClientGameStage { PENDING_CONNECTION, PRE_GAME, ACTIVE, IDLE }; + enum class ClientGameStage { PENDING_CONNECTION, PRE_GAME, ACTIVE, IDLE, AFTER_GAME }; class ClientGameState final : public GameState { private: diff --git a/src/ui/GameUI.cpp b/src/ui/GameUI.cpp index 12cc0db..94bbe5e 100644 --- a/src/ui/GameUI.cpp +++ b/src/ui/GameUI.cpp @@ -58,11 +58,15 @@ namespace UNO::UI { if (clientGameState->getClientGameStage() == GAME::ClientGameStage::PENDING_CONNECTION) { window_->set_active_page(PageType::ConnectPage); } - if (clientGameState->getClientGameStage() == GAME::ClientGameStage::PRE_GAME) { + if (clientGameState->getClientGameStage() == GAME::ClientGameStage::PRE_GAME + || clientGameState->getClientGameStage() == GAME::ClientGameStage::AFTER_GAME) { window_->set_active_page(PageType::StartPage); + window_->set_is_restart(clientGameState->getClientGameStage() == GAME::ClientGameStage::AFTER_GAME); } if (clientGameState->getClientGameStage() == GAME::ClientGameStage::ACTIVE || clientGameState->getClientGameStage() == GAME::ClientGameStage::IDLE) { + window_->set_is_ready(false); + window_->set_active_page(PageType::GamePage); auto players = clientGameState->getPlayers(); diff --git a/ui/MainWindow.slint b/ui/MainWindow.slint index 37968c1..95fdde3 100644 --- a/ui/MainWindow.slint +++ b/ui/MainWindow.slint @@ -16,6 +16,7 @@ export component MainWindow inherits Window { // StartPage in property is-ready; + in property is-restart; // GamePage in property <[OtherPlayer]> other-players; @@ -46,6 +47,7 @@ export component MainWindow inherits Window { } if root.active-page == PageType.StartPage: start-page := StartPage { is-ready: root.is-ready; + is-restart: root.is-restart; request-start => { root.request-start(); } diff --git a/ui/StartPage.slint b/ui/StartPage.slint index a91683e..172b317 100644 --- a/ui/StartPage.slint +++ b/ui/StartPage.slint @@ -2,6 +2,7 @@ import {Button} from "Components.slint"; export component StartPage inherits Window { in property is-ready; + in property is-restart; callback request-start; @@ -44,7 +45,7 @@ export component StartPage inherits Window { } Text { - text: "连接成功,所有玩家准备后开始游戏"; + text: is-restart ? "游戏结束,重新准备以重新开始游戏" : "连接成功,所有玩家准备后开始游戏"; font-size: 14px; color: #666666; horizontal-alignment: center;