cancel faction_select when the game starts
or when the hosts assigned control of that side to another player.
(cherry-picked from commit 2dd6557449
)
This commit is contained in:
parent
45fd7c9011
commit
745abef62d
5 changed files with 68 additions and 2 deletions
|
@ -52,11 +52,19 @@ faction_select::faction_select(ng::flg_manager& flg_manager, const std::string&
|
|||
, last_faction_(flg_manager.current_faction_index())
|
||||
, last_leader_(flg_manager.current_leader_index())
|
||||
, last_gender_(flg_manager.current_gender_index())
|
||||
, w_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void faction_select::cancel()
|
||||
{
|
||||
if(w_) {
|
||||
w_->set_retval(retval::CANCEL);
|
||||
}
|
||||
}
|
||||
void faction_select::pre_show(window& window)
|
||||
{
|
||||
w_ = &window;
|
||||
find_widget<label>(&window, "starting_pos", false).set_label(std::to_string(side_));
|
||||
|
||||
//
|
||||
|
|
|
@ -32,6 +32,9 @@ public:
|
|||
|
||||
DEFINE_SIMPLE_EXECUTE_WRAPPER(faction_select)
|
||||
|
||||
void cancel();
|
||||
|
||||
int get_side_num() const { return side_; }
|
||||
private:
|
||||
ng::flg_manager& flg_manager_;
|
||||
|
||||
|
@ -43,6 +46,7 @@ private:
|
|||
|
||||
const int last_faction_, last_leader_, last_gender_;
|
||||
|
||||
gui2::window* w_;
|
||||
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
|
||||
virtual const std::string& window_id() const override;
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "mp_ui_alerts.hpp"
|
||||
#include "statistics.hpp"
|
||||
#include "units/types.hpp"
|
||||
#include "utils/scope_exit.hpp"
|
||||
#include "wesnothd_connection.hpp"
|
||||
|
||||
|
||||
|
@ -72,6 +73,7 @@ mp_join_game::mp_join_game(saved_game& state, mp::lobby_info& lobby_info, wesnot
|
|||
, observe_game_(observe_game)
|
||||
, stop_updates_(false)
|
||||
, player_list_(nullptr)
|
||||
, open_flg_dialog_(nullptr)
|
||||
{
|
||||
set_show_even_without_video(true);
|
||||
}
|
||||
|
@ -350,9 +352,15 @@ void mp_join_game::show_flg_select(int side_num)
|
|||
|
||||
ng::flg_manager flg(era_factions, side_choice, lock_settings, use_map_settings, saved_game);
|
||||
|
||||
gui2::dialogs::faction_select dlg(flg, color, side_num);
|
||||
dlg.show();
|
||||
|
||||
gui2::dialogs::faction_select dlg(flg, color, side_num);
|
||||
|
||||
|
||||
{
|
||||
open_flg_dialog_ = &dlg;
|
||||
utils::scope_exit se([this](){ open_flg_dialog_ = nullptr; });
|
||||
dlg.show();
|
||||
}
|
||||
if(dlg.get_retval() != gui2::retval::OK) {
|
||||
return;
|
||||
}
|
||||
|
@ -518,11 +526,20 @@ void mp_join_game::network_handler(window& window)
|
|||
}
|
||||
|
||||
if(data["failed"].to_bool()) {
|
||||
if(open_flg_dialog_) {
|
||||
open_flg_dialog_->cancel();
|
||||
}
|
||||
window.set_retval(retval::CANCEL);
|
||||
} else if(data.child("start_game")) {
|
||||
if(open_flg_dialog_) {
|
||||
open_flg_dialog_->cancel();
|
||||
}
|
||||
level_["started"] = true;
|
||||
window.set_retval(retval::OK);
|
||||
} else if(data.child("leave_game")) {
|
||||
if(open_flg_dialog_) {
|
||||
open_flg_dialog_->cancel();
|
||||
}
|
||||
window.set_retval(retval::CANCEL);
|
||||
}
|
||||
|
||||
|
@ -537,6 +554,10 @@ void mp_join_game::network_handler(window& window)
|
|||
if(config& side_to_change = get_scenario().find_child("side", "side", change["side"])) {
|
||||
side_to_change.merge_with(change);
|
||||
}
|
||||
if(open_flg_dialog_ && open_flg_dialog_->get_side_num() == change["side"].to_int()) {
|
||||
open_flg_dialog_->cancel();
|
||||
}
|
||||
|
||||
} else if(data.has_child("scenario") || data.has_child("snapshot") || data.child("next_scenario")) {
|
||||
level_ = first_scenario_ ? data : data.child("next_scenario");
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class tree_view_node;
|
|||
|
||||
namespace dialogs
|
||||
{
|
||||
class faction_select;
|
||||
|
||||
class mp_join_game : public modal_dialog, private plugin_executor
|
||||
{
|
||||
|
@ -78,6 +79,8 @@ private:
|
|||
std::map<std::string, tree_view_node*> team_tree_map_;
|
||||
|
||||
std::unique_ptr<player_list_helper> player_list_;
|
||||
|
||||
gui2::dialogs::faction_select* open_flg_dialog_;
|
||||
};
|
||||
|
||||
} // namespace dialogs
|
||||
|
|
30
src/utils/scope_exit.hpp
Normal file
30
src/utils/scope_exit.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2018 the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace utils {
|
||||
|
||||
class scope_exit {
|
||||
//TODO: with c++17 we could make this a template class with 'F f_' instead of 'std::function<void ()> f_';
|
||||
std::function<void ()> f_;
|
||||
public:
|
||||
template<typename F>
|
||||
explicit scope_exit(F&& f) : f_(f) {}
|
||||
~scope_exit() { if(f_) { f_(); }}
|
||||
};
|
||||
} // namespace utils
|
Loading…
Add table
Reference in a new issue