Skip to content

Commit

Permalink
MP Create: make use of window exit hook for showing the difficulty di…
Browse files Browse the repository at this point in the history
…alog
  • Loading branch information
Vultraz committed Sep 7, 2016
1 parent d858c6b commit 969018f
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
3 changes: 1 addition & 2 deletions data/gui/window/mp_create_game.cfg
Expand Up @@ -732,8 +732,7 @@
[toggle_panel]
id = "game_list_panel"
definition = "default"
# We don't use return_value_id since we have a custom double click hook that handles
# campaign difficulty and closes the dialog itself.
return_value_id = "ok"

[grid]

Expand Down
4 changes: 1 addition & 3 deletions data/gui/window/mp_create_game/default_resolution.cfg
Expand Up @@ -378,9 +378,7 @@
border_size = 5
horizontal_alignment = "right"
[button]
# 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"
id = "ok"
definition = "default"

label = _ "Create Game"
Expand Down
4 changes: 1 addition & 3 deletions data/gui/window/mp_create_game/small_resolution.cfg
Expand Up @@ -346,9 +346,7 @@
border_size = 5
horizontal_alignment = "right"
[button]
# 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"
id = "ok"
definition = "default"

label = _ "Create Game"
Expand Down
4 changes: 1 addition & 3 deletions data/gui/window/mp_create_game/tiny_resolution.cfg
Expand Up @@ -311,9 +311,7 @@
border_size = 5
horizontal_alignment = "right"
[button]
# 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"
id = "ok"
definition = "default"

label = _ "Create Game"
Expand Down
17 changes: 6 additions & 11 deletions src/gui/dialogs/multiplayer/mp_create_game.cpp
Expand Up @@ -132,9 +132,7 @@ void tmp_create_game::pre_show(twindow& window)
std::bind(&tmp_create_game::load_game_callback, 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)));
window.set_exit_hook_ok_only([this](twindow& w)->bool { return dialog_exit_hook(w); });

//
// Set up the options manager. Needs to be done before selecting an initial tab
Expand Down Expand Up @@ -511,10 +509,7 @@ void tmp_create_game::display_games_of_type(twindow& window, ng::level::TYPE typ
item["label"] = game.get()->name();
data.emplace("game_name", item);

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)));
list.add_row(data);
}

// Recalculate which rows should be visisble
Expand Down Expand Up @@ -573,7 +568,7 @@ void tmp_create_game::load_game_callback(twindow& window)

create_engine_.prepare_for_saved_game();

dialog_exit_hook(window);
window.set_retval(twindow::OK);
} catch(config::error&) {}
}

Expand Down Expand Up @@ -701,16 +696,16 @@ void tmp_create_game::update_map_settings(twindow& window)
}
}

void tmp_create_game::dialog_exit_hook(twindow& window) {
bool tmp_create_game::dialog_exit_hook(twindow&) {
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;
return false;
}
}

window.set_retval(twindow::OK);
return true;
}

void tmp_create_game::post_show(twindow& window)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/multiplayer/mp_create_game.hpp
Expand Up @@ -122,7 +122,7 @@ class tmp_create_game : public tdialog, private plugin_executor
void update_details(twindow& window);
void update_map_settings(twindow& window);

void dialog_exit_hook(twindow& window);
bool dialog_exit_hook(twindow&);

int convert_to_game_filtered_index(const int initial_index);

Expand Down

0 comments on commit 969018f

Please sign in to comment.