From 478b2db5ee54da13123fac0d46f9983a68963ca4 Mon Sep 17 00:00:00 2001 From: mluo24 Date: Thu, 14 Mar 2024 17:35:20 -0400 Subject: [PATCH 1/2] disconnect on back, loading text --- source/scenes/HostScene.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/source/scenes/HostScene.cpp b/source/scenes/HostScene.cpp index 71cde08f..9d3ac600 100644 --- a/source/scenes/HostScene.cpp +++ b/source/scenes/HostScene.cpp @@ -88,10 +88,11 @@ bool HostScene::init(const std::shared_ptr& assets, std::sha _backout = std::dynamic_pointer_cast(_assets->get("host_back")); _gameid = std::dynamic_pointer_cast(_assets->get("host_center_game_field_text")); _player = std::dynamic_pointer_cast(_assets->get("host_center_players_field_text")); - + // Program the buttons _backout->addListener([this](const std::string& name, bool down) { if (down) { + _network->disconnect(); _backClicked = true; } }); @@ -137,11 +138,9 @@ void HostScene::dispose() { void HostScene::setActive(bool value) { if (isActive() != value) { Scene2::setActive(value); - /** * TODO: if value is true, you need to activate the _backout button, and set the clicked variable to false. You need to also call the network controller to start a connection as a host. If the value is false, and reset all buttons and textfields to their original state. */ -#pragma mark BEGIN SOLUTION if (value) { _backout->activate(); _network->disconnect(); @@ -156,7 +155,6 @@ void HostScene::setActive(bool value) { _startgame->setDown(false); _backout->setDown(false); } -#pragma mark END SOLUTION } } @@ -178,8 +176,6 @@ void HostScene::updateText(const std::shared_ptr& button, const } -#pragma mark - -#pragma mark Student Methods /** * The method called to update the scene. * @@ -188,11 +184,7 @@ void HostScene::updateText(const std::shared_ptr& button, const * @param timestep The amount of time (in seconds) since the last frame */ void HostScene::update(float timestep) { - /** - * TODO: check for the status of `_network` (The NetworkController). If it is CONNECTED, you would need to update the scene nodes so that _gameId displays the id of the room (converted from hex to decimal) and _player displays the number of players. Additionally, you should check whether the `_startgame` button has been pressed and update its text. If it is not pressed yet, then its should display "Start Game" and be activated, otherwise, it should be deactivated and show "Starting". - */ -#pragma mark BEGIN SOLUTION - if(_network->getStatus() == NetEventController::Status::CONNECTED){ + if(_network->getStatus() == NetEventController::Status::CONNECTED) { if (!_startGameClicked) { updateText(_startgame, "Start Game"); _startgame->activate(); @@ -204,16 +196,15 @@ void HostScene::update(float timestep) { _gameid->setText(hex2dec(_network->getRoomID())); _player->setText(std::to_string(_network->getNumPlayers())); } -#pragma mark END SOLUTION + else if (_network->getStatus() == NetEventController::Status::CONNECTING) { + _gameid->setText("..."); + } } /** * This method prompts the network controller to start the game. */ void HostScene::startGame(){ - //TODO: call the network controller to start the game and set the _startGameClicked to true. -#pragma mark BEGIN SOLUTION _network->startGame(); _startGameClicked = true; -#pragma mark END SOLUTION } From 2df0aea45a1383238b2c64acdcbad98b47bb4323 Mon Sep 17 00:00:00 2001 From: mluo24 Date: Fri, 15 Mar 2024 01:53:16 -0400 Subject: [PATCH 2/2] client scene polish --- source/scenes/ClientScene.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/scenes/ClientScene.cpp b/source/scenes/ClientScene.cpp index c3b511a4..89736829 100644 --- a/source/scenes/ClientScene.cpp +++ b/source/scenes/ClientScene.cpp @@ -92,6 +92,7 @@ bool ClientScene::init(const std::shared_ptr& assets, std::s _startgame->addListener([=](const std::string& name, bool down) { if (down) { // This will call the _gameid listener + _gameid->requestFocus(); _gameid->releaseFocus(); } }); @@ -155,7 +156,6 @@ void ClientScene::setActive(bool value) { // If any were pressed, reset them _startgame->setDown(false); _backout->setDown(false); - } } } @@ -188,6 +188,9 @@ void ClientScene::update(float timestep) { if(_network->getStatus() == NetEventController::Status::CONNECTED || _network->getStatus() == NetEventController::Status::HANDSHAKE){ _player->setText(std::to_string(_network->getNumPlayers())); } + else { + _player->setText("..."); + } } /**