MP Create: improved handling of campaign difficulty selection
Instead of showing the difficulty dialog in post_show and setting the retval to twindow::NONE if the dialog was canceled, we add a custom exit hook that fires when double clicking the games list or pressing the Create Game button that shows the dialog instead, and returns if canceled. This is much cleaner.
This commit is contained in:
parent
1195c01508
commit
90c3c05af4
6 changed files with 54 additions and 21 deletions
|
@ -1216,6 +1216,7 @@
|
|||
definition = "default"
|
||||
|
||||
horizontal_scrollbar_mode = "never"
|
||||
vertical_scrollbar_mode = "auto"
|
||||
[/scroll_label]
|
||||
|
||||
[/column]
|
||||
|
@ -1275,8 +1276,10 @@
|
|||
horizontal_grow = "true"
|
||||
|
||||
[toggle_panel]
|
||||
id = "game_list_panel"
|
||||
definition = "default"
|
||||
return_value_id = "ok"
|
||||
# We don't use return_value_id since we have a custom double click hook that handles
|
||||
# campaign difficulty and closes the dialog itself.
|
||||
|
||||
[grid]
|
||||
|
||||
|
@ -1608,7 +1611,9 @@
|
|||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
[button]
|
||||
id = "ok"
|
||||
# We don't use id = 'ok' since we have a custom double click hook that handles
|
||||
# campaign difficulty and closes the dialog itself.
|
||||
id = "create_game"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Create Game"
|
||||
|
|
|
@ -407,7 +407,8 @@ create_engine::create_engine(CVideo& v, saved_game& state) :
|
|||
state_(state),
|
||||
video_(v),
|
||||
dependency_manager_(nullptr),
|
||||
generator_(nullptr)
|
||||
generator_(nullptr),
|
||||
selected_campaign_difficulty_()
|
||||
{
|
||||
DBG_MP << "restoring game config\n";
|
||||
|
||||
|
@ -544,8 +545,10 @@ void create_engine::prepare_for_campaign(const std::string& difficulty)
|
|||
{
|
||||
DBG_MP << "preparing data for campaign by reloading game config\n";
|
||||
|
||||
if (difficulty != "") {
|
||||
if(difficulty != "") {
|
||||
state_.classification().difficulty = difficulty;
|
||||
} else if(!selected_campaign_difficulty_.empty()) {
|
||||
state_.classification().difficulty = selected_campaign_difficulty_;
|
||||
}
|
||||
|
||||
state_.classification().campaign = current_level().data()["id"].str();
|
||||
|
@ -619,7 +622,14 @@ std::string create_engine::select_campaign_difficulty(int set_value)
|
|||
gui2::tcampaign_difficulty dlg(current_level().data());
|
||||
dlg.show(video_);
|
||||
|
||||
return dlg.selected_difficulty();
|
||||
selected_campaign_difficulty_ = dlg.selected_difficulty();
|
||||
|
||||
return selected_campaign_difficulty_;
|
||||
}
|
||||
|
||||
std::string create_engine::get_selected_campaign_difficulty()
|
||||
{
|
||||
return selected_campaign_difficulty_;
|
||||
}
|
||||
|
||||
void create_engine::prepare_for_saved_game()
|
||||
|
|
|
@ -204,12 +204,13 @@ public:
|
|||
void prepare_for_new_level();
|
||||
void prepare_for_era_and_mods();
|
||||
void prepare_for_scenario();
|
||||
void prepare_for_campaign(const std::string& difficulty);
|
||||
void prepare_for_campaign(const std::string& difficulty = "");
|
||||
void prepare_for_saved_game();
|
||||
//random maps, user maps
|
||||
void prepare_for_other();
|
||||
|
||||
std::string select_campaign_difficulty(int set_value = -1);
|
||||
std::string get_selected_campaign_difficulty();
|
||||
|
||||
void apply_level_filter(const std::string& name);
|
||||
void apply_level_filter(int players);
|
||||
|
@ -309,6 +310,8 @@ private:
|
|||
std::unique_ptr<depcheck::manager> dependency_manager_;
|
||||
|
||||
std::unique_ptr<map_generator> generator_;
|
||||
|
||||
std::string selected_campaign_difficulty_;
|
||||
};
|
||||
|
||||
} // end namespace ng
|
||||
|
|
|
@ -529,9 +529,7 @@ static void enter_create_mode(CVideo& video, const config& game_config,
|
|||
|
||||
gui2::tmp_create_game dlg(game_config, create_eng);
|
||||
|
||||
do {
|
||||
dlg.show(video);
|
||||
} while(dlg.get_retval() == gui2::twindow::NONE);
|
||||
dlg.show(video);
|
||||
|
||||
if(dlg.get_retval() == gui2::twindow::OK) {
|
||||
enter_connect_mode(video, game_config, state, wesnothd_connection, local_players_only);
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "gui/widgets/slider.hpp"
|
||||
#include "gui/widgets/stacked_widget.hpp"
|
||||
#include "gui/widgets/toggle_button.hpp"
|
||||
#include "gui/widgets/toggle_panel.hpp"
|
||||
#include "gui/widgets/text_box.hpp"
|
||||
#include "gui/widgets/tree_view.hpp"
|
||||
#include "gui/widgets/tree_view_node.hpp"
|
||||
|
@ -123,6 +124,11 @@ void tmp_create_game::pre_show(twindow& window)
|
|||
find_widget<tbutton>(&window, "random_map_settings", false),
|
||||
std::bind(&tmp_create_game::show_generator_settings, this, std::ref(window)));
|
||||
|
||||
// Custom dialog close hook
|
||||
connect_signal_mouse_left_click(
|
||||
find_widget<tbutton>(&window, "create_game", false),
|
||||
std::bind(tmp_create_game::dialog_exit_hook, this, std::ref(window)));
|
||||
|
||||
tlistbox& list = find_widget<tlistbox>(&window, "games_list", false);
|
||||
#ifdef GUI2_EXPERIMENTAL_LISTBOX
|
||||
connect_signal_notify_modified(list,
|
||||
|
@ -319,10 +325,12 @@ void tmp_create_game::display_games_of_type(twindow& window, ng::level::TYPE typ
|
|||
item["label"] = game.get()->name();
|
||||
data.emplace("game_name", item);
|
||||
|
||||
list.add_row(data);
|
||||
tgrid* row_grid = &list.add_row(data);
|
||||
|
||||
find_widget<ttoggle_panel>(row_grid, "game_list_panel", false).set_callback_mouse_left_double_click(
|
||||
std::bind(&tmp_create_game::dialog_exit_hook, this, std::ref(window)));
|
||||
}
|
||||
|
||||
// TODO: move to click handler?
|
||||
const bool is_random_map = type == ng::level::TYPE::RANDOM_MAP;
|
||||
|
||||
find_widget<tbutton>(&window, "random_map_regenerate", false).set_active(is_random_map);
|
||||
|
@ -331,6 +339,18 @@ void tmp_create_game::display_games_of_type(twindow& window, ng::level::TYPE typ
|
|||
update_details(window);
|
||||
}
|
||||
|
||||
void tmp_create_game::dialog_exit_hook(twindow& window) {
|
||||
if(create_engine_.current_level_type() == ng::level::TYPE::CAMPAIGN ||
|
||||
create_engine_.current_level_type() == ng::level::TYPE::SP_CAMPAIGN) {
|
||||
|
||||
if(create_engine_.select_campaign_difficulty() == "CANCEL") {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
window.set_retval(twindow::OK);
|
||||
}
|
||||
|
||||
void tmp_create_game::on_mod_select(twindow& window)
|
||||
{
|
||||
create_engine_.set_current_mod_index(find_widget<tlistbox>(&window, "mod_list", false).get_selected_row());
|
||||
|
@ -639,14 +659,8 @@ void tmp_create_game::post_show(twindow& window)
|
|||
create_engine_.prepare_for_era_and_mods();
|
||||
|
||||
if(create_engine_.current_level_type() == ng::level::TYPE::CAMPAIGN ||
|
||||
create_engine_.current_level_type() == ng::level::TYPE::SP_CAMPAIGN) {
|
||||
|
||||
std::string difficulty = create_engine_.select_campaign_difficulty();
|
||||
if(difficulty == "CANCEL") {
|
||||
window.set_retval(twindow::NONE);
|
||||
}
|
||||
|
||||
create_engine_.prepare_for_campaign(difficulty);
|
||||
create_engine_.current_level_type() == ng::level::TYPE::SP_CAMPAIGN) {
|
||||
create_engine_.prepare_for_campaign();
|
||||
} else if(create_engine_.current_level_type() == ng::level::TYPE::SCENARIO) {
|
||||
create_engine_.prepare_for_scenario();
|
||||
} else {
|
||||
|
|
|
@ -24,8 +24,9 @@ class config;
|
|||
|
||||
namespace gui2
|
||||
{
|
||||
|
||||
|
||||
class ttree_view;
|
||||
class ttoggle_panel;
|
||||
class twidget;
|
||||
|
||||
class tmp_create_game : public tdialog
|
||||
|
@ -82,11 +83,13 @@ private:
|
|||
void on_era_select(twindow& window);
|
||||
|
||||
void on_mod_toggle(const int index, twidget&);
|
||||
|
||||
|
||||
void display_custom_options(ttree_view& options_tree, std::string&& type, const std::string& id, const config& data);
|
||||
|
||||
void update_options_list(twindow& window);
|
||||
|
||||
void dialog_exit_hook(twindow& window);
|
||||
|
||||
public:
|
||||
// another map selected
|
||||
void update_details(twindow& window);
|
||||
|
|
Loading…
Add table
Reference in a new issue