From a8c5d15f43bb0c568db7da9b0bb5805cdb977aa0 Mon Sep 17 00:00:00 2001 From: gfgtdf Date: Thu, 16 Mar 2023 13:02:07 +0100 Subject: [PATCH] Remove explicit enable button calls We improve can_execute_command for the entturn button, and replace button->enable calls with set_button_state/queue_rerender calls This is more robust in case someone else wants to update buttons. We remove a call to button->enable in playturn.cpp which probably had no effect since the linger mode for the clients automaticially ends there already. We create a new function to check set to gui to linger mode or not, in particular is removes the linger overlay in init_scenario, in case that we want to reset the replay from linger mode. --- src/hotkey/hotkey_handler_sp.cpp | 4 +++- src/playmp_controller.cpp | 33 ++---------------------------- src/playmp_controller.hpp | 4 +--- src/playsingle_controller.cpp | 35 ++++++++++++++++++-------------- src/playsingle_controller.hpp | 2 ++ src/playturn.cpp | 4 ---- 6 files changed, 28 insertions(+), 54 deletions(-) diff --git a/src/hotkey/hotkey_handler_sp.cpp b/src/hotkey/hotkey_handler_sp.cpp index 6e10ae826ed..a3ad8f72e12 100644 --- a/src/hotkey/hotkey_handler_sp.cpp +++ b/src/hotkey/hotkey_handler_sp.cpp @@ -224,7 +224,9 @@ bool playsingle_controller::hotkey_handler::can_execute_command(const hotkey::ho case hotkey::HOTKEY_RECALL: return (!browse() || whiteboard_manager_->is_active()) && !linger() && !events::commands_disabled; case hotkey::HOTKEY_ENDTURN: - return (!browse() || linger()) && !events::commands_disabled; + //TODO: Its unclear to me under which cirumstances the other clients can remain in linger mode + // when the host pressed scenario, some codes suggest that tha can be the case some don't. + return (!browse() || (linger() && playsingle_controller_.is_host())) && !events::commands_disabled; case hotkey::HOTKEY_DELAY_SHROUD: return !linger() diff --git a/src/playmp_controller.cpp b/src/playmp_controller.cpp index 7387ab4362b..0b68dcd071a 100644 --- a/src/playmp_controller.cpp +++ b/src/playmp_controller.cpp @@ -101,10 +101,6 @@ void playmp_controller::remove_blindfold() void playmp_controller::play_linger_turn() { - if(is_host()) { - end_turn_enable(true); - } - while( gamestate().in_phase(game_data::GAME_ENDED) && !end_turn_requested_) { config cfg; if(network_reader_.read(cfg)) { @@ -211,38 +207,15 @@ void playmp_controller::play_idle_loop() } } -void playmp_controller::set_end_scenario_button() -{ - // Modify the end-turn button - if(!is_host()) { - std::shared_ptr btn_end = gui_->find_action_button("button-endturn"); - btn_end->enable(false); - } - - gui_->get_theme().refresh_title2("button-endturn", "title2"); - gui_->queue_rerender(); -} - -void playmp_controller::reset_end_scenario_button() -{ - // revert the end-turn button text to its normal label - gui_->get_theme().refresh_title2("button-endturn", "title"); - gui_->queue_rerender(); - gui_->set_game_mode(game_display::RUNNING); -} - void playmp_controller::linger() { LOG_NG << "beginning end-of-scenario linger"; - // If we need to set the status depending on the completion state - // we're needed here. - gui_->set_game_mode(game_display::LINGER); - // End all unit moves gamestate().board_.set_all_units_user_end_turn(); - set_end_scenario_button(); + update_gui_linger(); + assert(is_regular_game_end()); if(get_end_level_data().transient.reveal_map) { @@ -283,8 +256,6 @@ void playmp_controller::linger() } } while(!quit); - reset_end_scenario_button(); - LOG_NG << "ending end-of-scenario linger"; } diff --git a/src/playmp_controller.hpp b/src/playmp_controller.hpp index 26b2872d315..8e5726d8232 100644 --- a/src/playmp_controller.hpp +++ b/src/playmp_controller.hpp @@ -61,13 +61,11 @@ protected: mutable bool network_processing_stopped_; virtual void on_not_observer() override; - bool is_host() const; + virtual bool is_host() const override; void remove_blindfold(); blindfold blindfold_; private: - void set_end_scenario_button(); - void reset_end_scenario_button(); void process_network_data(bool chat_only = false); mp_game_metadata* mp_info_; }; diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index 62da866323d..ef401b5bb5f 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -107,6 +107,8 @@ std::string playsingle_controller::describe_result() const void playsingle_controller::init_gui() { LOG_NG << "Initializing GUI... " << (SDL_GetTicks() - ticks()); + // If we are retarting replay from linger mode. + update_gui_linger(); play_controller::init_gui(); // Scroll to the starting position of the first team. If there is a @@ -587,25 +589,33 @@ void playsingle_controller::play_human_turn() } } +void playsingle_controller::update_gui_linger() +{ + if(is_linger_mode()) { + // If we need to set the status depending on the completion state + // the key to it is here. + gui_->set_game_mode(game_display::LINGER); + // change the end-turn button text from "End Turn" to "End Scenario" + gui_->get_theme().refresh_title2("button-endturn", "title2"); + } else { + gui_->set_game_mode(game_display::RUNNING); + // change the end-turn button text from "End Scenario" to "End Turn" + gui_->get_theme().refresh_title2("button-endturn", "title"); + } + // Also checcks whether the button can be pressed. + gui_->queue_rerender(); +} + void playsingle_controller::linger() { LOG_NG << "beginning end-of-scenario linger"; - // If we need to set the status depending on the completion state - // the key to it is here. - gui_->set_game_mode(game_display::LINGER); - // Make all of the able-to-move units' orbs consistently red gamestate().board_.set_all_units_user_end_turn(); - // change the end-turn button text to its alternate label - gui_->get_theme().refresh_title2("button-endturn", "title2"); - gui_->queue_rerender(); + update_gui_linger(); try { - // Same logic as single-player human turn, but - // *not* the same as multiplayer human turn. - end_turn_enable(true); while(!end_turn_requested_) { play_slice(); } @@ -615,11 +625,6 @@ void playsingle_controller::linger() throw; } - // revert the end-turn button text to its normal label - gui_->get_theme().refresh_title2("button-endturn", "title"); - gui_->queue_rerender(); - gui_->set_game_mode(game_display::RUNNING); - LOG_NG << "ending end-of-scenario linger"; } diff --git a/src/playsingle_controller.hpp b/src/playsingle_controller.hpp index 1cb5774f6fa..6cfcd4ea85e 100644 --- a/src/playsingle_controller.hpp +++ b/src/playsingle_controller.hpp @@ -54,6 +54,7 @@ public: virtual void check_objectives() override; virtual void on_not_observer() override {} + virtual bool is_host() const { return true; } virtual void maybe_linger(); void end_turn(); @@ -102,6 +103,7 @@ protected: /// non-null when replay mode in active, is used in singleplayer and for the "back to turn" feature in multiplayer. std::unique_ptr replay_controller_; void linger(); + void update_gui_linger(); void sync_end_turn() override; void update_viewing_player() override; void reset_replay(); diff --git a/src/playturn.cpp b/src/playturn.cpp index 1556a1af6e4..846750ae22b 100644 --- a/src/playturn.cpp +++ b/src/playturn.cpp @@ -365,10 +365,6 @@ turn_info::PROCESS_DATA_RESULT turn_info::process_network_data(const config& cfg if(chat_only) { return PROCESS_CANNOT_HANDLE; } - std::shared_ptr btn_end = display::get_singleton()->find_action_button("button-endturn"); - if(btn_end) { - btn_end->enable(true); - } return PROCESS_END_LINGER; }