mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-26 05:20:24 +00:00
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.
This commit is contained in:
parent
045473dff5
commit
a8c5d15f43
@ -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()
|
||||
|
@ -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<gui::button> 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";
|
||||
}
|
||||
|
||||
|
@ -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_;
|
||||
};
|
||||
|
@ -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";
|
||||
}
|
||||
|
||||
|
@ -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> replay_controller_;
|
||||
void linger();
|
||||
void update_gui_linger();
|
||||
void sync_end_turn() override;
|
||||
void update_viewing_player() override;
|
||||
void reset_replay();
|
||||
|
@ -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<gui::button> btn_end = display::get_singleton()->find_action_button("button-endturn");
|
||||
if(btn_end) {
|
||||
btn_end->enable(true);
|
||||
}
|
||||
return PROCESS_END_LINGER;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user