mirror of
https://github.com/kierankihn/uno-game.git
synced 2025-12-27 02:13:18 +08:00
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`.
This commit is contained in:
@@ -179,7 +179,7 @@ namespace UNO::GAME {
|
|||||||
|
|
||||||
void ClientGameState::endGame()
|
void ClientGameState::endGame()
|
||||||
{
|
{
|
||||||
this->clientGameStage_ = ClientGameStage::PRE_GAME;
|
this->clientGameStage_ = ClientGameStage::AFTER_GAME;
|
||||||
this->player_.clear();
|
this->player_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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<ClientPlayerState> {
|
class ClientGameState final : public GameState<ClientPlayerState> {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -58,11 +58,15 @@ namespace UNO::UI {
|
|||||||
if (clientGameState->getClientGameStage() == GAME::ClientGameStage::PENDING_CONNECTION) {
|
if (clientGameState->getClientGameStage() == GAME::ClientGameStage::PENDING_CONNECTION) {
|
||||||
window_->set_active_page(PageType::ConnectPage);
|
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_active_page(PageType::StartPage);
|
||||||
|
window_->set_is_restart(clientGameState->getClientGameStage() == GAME::ClientGameStage::AFTER_GAME);
|
||||||
}
|
}
|
||||||
if (clientGameState->getClientGameStage() == GAME::ClientGameStage::ACTIVE
|
if (clientGameState->getClientGameStage() == GAME::ClientGameStage::ACTIVE
|
||||||
|| clientGameState->getClientGameStage() == GAME::ClientGameStage::IDLE) {
|
|| clientGameState->getClientGameStage() == GAME::ClientGameStage::IDLE) {
|
||||||
|
window_->set_is_ready(false);
|
||||||
|
|
||||||
window_->set_active_page(PageType::GamePage);
|
window_->set_active_page(PageType::GamePage);
|
||||||
|
|
||||||
auto players = clientGameState->getPlayers();
|
auto players = clientGameState->getPlayers();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export component MainWindow inherits Window {
|
|||||||
|
|
||||||
// StartPage
|
// StartPage
|
||||||
in property <bool> is-ready;
|
in property <bool> is-ready;
|
||||||
|
in property <bool> is-restart;
|
||||||
|
|
||||||
// GamePage
|
// GamePage
|
||||||
in property <[OtherPlayer]> other-players;
|
in property <[OtherPlayer]> other-players;
|
||||||
@@ -46,6 +47,7 @@ export component MainWindow inherits Window {
|
|||||||
}
|
}
|
||||||
if root.active-page == PageType.StartPage: start-page := StartPage {
|
if root.active-page == PageType.StartPage: start-page := StartPage {
|
||||||
is-ready: root.is-ready;
|
is-ready: root.is-ready;
|
||||||
|
is-restart: root.is-restart;
|
||||||
request-start => {
|
request-start => {
|
||||||
root.request-start();
|
root.request-start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {Button} from "Components.slint";
|
|||||||
|
|
||||||
export component StartPage inherits Window {
|
export component StartPage inherits Window {
|
||||||
in property <bool> is-ready;
|
in property <bool> is-ready;
|
||||||
|
in property <bool> is-restart;
|
||||||
|
|
||||||
callback request-start;
|
callback request-start;
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ export component StartPage inherits Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: "连接成功,所有玩家准备后开始游戏";
|
text: is-restart ? "游戏结束,重新准备以重新开始游戏" : "连接成功,所有玩家准备后开始游戏";
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #666666;
|
color: #666666;
|
||||||
horizontal-alignment: center;
|
horizontal-alignment: center;
|
||||||
|
|||||||
Reference in New Issue
Block a user