Skip to content

Commit

Permalink
Faction Select: fixed changes persisting even if you cancel the dialog
Browse files Browse the repository at this point in the history
(cherry-picked from commit c2c6133)
  • Loading branch information
Vultraz committed Oct 7, 2018
1 parent a1a46b0 commit 9c9fbe4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -51,6 +51,8 @@
### Miscellaneous and bug fixes
* Added an advanced preference to enable experimental PRNG combat.
* Fixed MP admins being unable to observe private games.
* Fixed MP faction, leader, and leader gender changes persisting even if the
selection dialog is dismissed.

## Version 1.14.3
### AI
Expand Down
23 changes: 22 additions & 1 deletion src/gui/dialogs/multiplayer/faction_select.cpp
Expand Up @@ -46,6 +46,9 @@ faction_select::faction_select(ng::flg_manager& flg_manager, const std::string&
: flg_manager_(flg_manager)
, tc_color_(color)
, side_(side)
, last_faction_(flg_manager.current_faction_index())
, last_leader_(flg_manager.current_leader_index())
, last_gender_(flg_manager.current_gender_index())
{
}

Expand Down Expand Up @@ -184,7 +187,6 @@ void faction_select::on_leader_select(window& window)
{
flg_manager_.set_current_leader(find_widget<menu_button>(&window, "leader_menu", false).get_value());


// TODO: should we decouple this from the flg manager and instead just check the unit type directly?
// If that's done so, we'd need to come up with a different check for Random availability.
gender_toggle_.set_members_enabled([this](const std::string& gender)->bool {
Expand Down Expand Up @@ -214,5 +216,24 @@ void faction_select::update_leader_image(window& window)
find_widget<image>(&window, "leader_image", false).set_label(leader_image);
}

void faction_select::post_show(window& window)
{
//
// If we're canceling, restore the previous selections. It might be worth looking
// into only making selections at all here in post_show, but that would require a
// refactor of the flg_manager class.
//
// Also, note it's important to set these in the order of faction -> leader -> gender
// or the saved indices will be invalid!
//
// -- vultraz, 2018-06-16
//
if(get_retval() != retval::OK) {
flg_manager_.set_current_faction(last_faction_);
flg_manager_.set_current_leader(last_leader_);
flg_manager_.set_current_gender(last_gender_);
}
}

} // namespace dialogs
} // namespace gui2
5 changes: 5 additions & 0 deletions src/gui/dialogs/multiplayer/faction_select.hpp
Expand Up @@ -41,12 +41,17 @@ class faction_select : public modal_dialog

group<std::string> gender_toggle_;

const int last_faction_, last_leader_, last_gender_;

/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const override;

/** Inherited from modal_dialog. */
virtual void pre_show(window& window) override;

/** Inherited from modal_dialog. */
virtual void post_show(window& window) override;

/** Callbacks */
void on_faction_select(window& window);

Expand Down

0 comments on commit 9c9fbe4

Please sign in to comment.