From 46e3e154a5f3e4a2a05a14db9a2f7f8e832d588e Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Mon, 20 Nov 2017 15:11:27 +1100 Subject: [PATCH] Massive cleanup of GUI2 display/show and execute functions implementations and related CVideo arguments This a two part commit. First: ---------------------------------------------------------------------------------------------------- Added and deployed two new helper macros for the standard implementations of the static execute and display functions. I also made use of a variadic template in order greatly simplify code maintenance. Now, even if the dialog's ctor parameters change, no one has to worry about updating the associated execute/display functions (though of course, this only applies if the helper macros are used). \o/ I did not deploy the macro in cases where there were multiple overloads or the functions did more than just show their dialogs. I might add an additional __VA_ARGS_ parameter to the macros later. Do note for the end_credits dialog I moved the default empty-string parameter from the display function to the ctor. Second: ---------------------------------------------------------------------------------------------------- Another change is that modal_dialog::show and modeless_dialog::show no longer take CVideo arguments. Since the video argument couldn't be included in the parameter pack (maintaining the argument would have meant making it the first one, which would be just as much work), and using CVideo::get_singleton in the macros would require adding video.hpp includes in a whole bunch of files, I simply removed the argument. I had been intending to do this for a while anyway. This therefor also removes the CVideo argument from: * All dialog display/execute functions. * modal_dialog::show * modal_dialog::build_window * modeless_dialog::show * modeless_dialog::build_window * wml_exception::show * gui2::show_message * gui2::show_error_message * gui2::show_transient_message * gui2::show_transient_error_message * gui2::show_wml_message * gui2::build * gui2::window::window * gui2::dialogs::tip::show * Various GUI2-related Lua functions. The video_dispatch helper was also removed. * Any functions that took a CVideo argument for the sole purpose of passing it to one of the above. Ya know, all these damn CVideo arguments didn't actually do anything, besides an occasional check to CVideo::faked. At the end of the pipeline, they just got assigned to the video_ member of gui2::window. Huge code bloat for nothing. --- src/actions/advancement.cpp | 2 +- src/addon/client.cpp | 16 ++-- src/addon/manager_ui.cpp | 51 +++++++------ .../action/mouse/mouse_action_map_label.cpp | 2 +- src/editor/controller/editor_controller.cpp | 15 ++-- src/editor/map/context_manager.cpp | 60 +++++++-------- src/editor/palette/location_palette.cpp | 2 +- src/formula/debugger.cpp | 2 +- src/game_config_manager.cpp | 23 +++--- src/game_events/action_wml.cpp | 4 +- src/game_initialization/create_engine.cpp | 2 +- src/game_initialization/depcheck.cpp | 10 +-- src/game_initialization/multiplayer.cpp | 30 ++++---- src/game_initialization/multiplayer.hpp | 4 +- src/game_initialization/playcampaign.cpp | 22 +++--- src/game_initialization/singleplayer.cpp | 24 +++--- src/game_initialization/singleplayer.hpp | 6 +- src/game_launcher.cpp | 54 +++++++------ src/generators/default_map_generator.cpp | 2 +- src/gui/core/window_builder.cpp | 8 +- src/gui/core/window_builder.hpp | 4 +- src/gui/dialogs/addon/manager.cpp | 31 ++++---- src/gui/dialogs/advanced_graphics_options.hpp | 5 +- src/gui/dialogs/attack_predictions.hpp | 5 +- src/gui/dialogs/edit_label.hpp | 7 +- src/gui/dialogs/edit_text.hpp | 8 +- src/gui/dialogs/editor/custom_tod.cpp | 2 +- src/gui/dialogs/editor/custom_tod.hpp | 6 +- src/gui/dialogs/editor/edit_label.hpp | 14 +--- src/gui/dialogs/editor/edit_scenario.hpp | 20 +---- src/gui/dialogs/editor/edit_side.hpp | 7 +- src/gui/dialogs/editor/generator_settings.hpp | 7 +- src/gui/dialogs/editor/new_map.hpp | 7 +- src/gui/dialogs/editor/resize_map.hpp | 13 +--- src/gui/dialogs/end_credits.hpp | 7 +- src/gui/dialogs/file_dialog.cpp | 18 ++--- src/gui/dialogs/folder_create.hpp | 9 +-- src/gui/dialogs/game_cache_options.cpp | 20 ++--- src/gui/dialogs/game_cache_options.hpp | 9 +-- src/gui/dialogs/game_delete.hpp | 7 +- src/gui/dialogs/game_load.cpp | 2 +- src/gui/dialogs/game_load.hpp | 6 +- src/gui/dialogs/game_save.hpp | 21 +----- src/gui/dialogs/game_stats.hpp | 6 +- src/gui/dialogs/game_version.hpp | 5 +- src/gui/dialogs/gamestate_inspector.cpp | 2 +- src/gui/dialogs/help_browser.hpp | 5 +- src/gui/dialogs/label_settings.cpp | 4 +- src/gui/dialogs/label_settings.hpp | 2 +- src/gui/dialogs/loading_screen.cpp | 4 +- src/gui/dialogs/log_settings.hpp | 6 +- src/gui/dialogs/lua_interpreter.cpp | 10 +-- src/gui/dialogs/lua_interpreter.hpp | 4 +- src/gui/dialogs/message.cpp | 15 ++-- src/gui/dialogs/message.hpp | 14 +--- src/gui/dialogs/modal_dialog.cpp | 10 +-- src/gui/dialogs/modal_dialog.hpp | 75 ++++++++++++------- src/gui/dialogs/modeless_dialog.cpp | 12 ++- src/gui/dialogs/modeless_dialog.hpp | 9 +-- src/gui/dialogs/multiplayer/lobby.cpp | 10 +-- .../dialogs/multiplayer/mp_alerts_options.hpp | 5 +- src/gui/dialogs/multiplayer/mp_connect.cpp | 9 +-- src/gui/dialogs/multiplayer/mp_connect.hpp | 5 +- .../dialogs/multiplayer/mp_create_game.cpp | 10 +-- .../multiplayer/mp_host_game_prompt.hpp | 7 +- src/gui/dialogs/multiplayer/mp_join_game.cpp | 6 +- src/gui/dialogs/multiplayer/mp_join_game.hpp | 8 +- .../mp_join_game_password_prompt.hpp | 7 +- src/gui/dialogs/multiplayer/mp_staging.cpp | 6 +- src/gui/dialogs/multiplayer/mp_staging.hpp | 2 +- src/gui/dialogs/outro.hpp | 5 +- src/gui/dialogs/preferences_dialog.cpp | 40 +++++----- src/gui/dialogs/preferences_dialog.hpp | 4 +- src/gui/dialogs/screenshot_notification.hpp | 5 +- src/gui/dialogs/select_orb_colors.hpp | 5 +- src/gui/dialogs/sp_options_configure.hpp | 4 +- src/gui/dialogs/statistics_dialog.hpp | 5 +- src/gui/dialogs/story_viewer.hpp | 4 +- src/gui/dialogs/terrain_layers.hpp | 5 +- src/gui/dialogs/title_screen.cpp | 28 +++---- src/gui/dialogs/title_screen.hpp | 2 +- src/gui/dialogs/tooltip.cpp | 7 +- src/gui/dialogs/tooltip.hpp | 5 +- src/gui/dialogs/transient_message.cpp | 11 +-- src/gui/dialogs/transient_message.hpp | 8 +- src/gui/dialogs/unit_attack.cpp | 2 +- src/gui/dialogs/unit_list.cpp | 2 +- src/gui/dialogs/unit_list.hpp | 6 +- src/gui/dialogs/unit_recall.cpp | 2 +- src/gui/dialogs/wml_error.hpp | 10 +-- src/gui/dialogs/wml_message.cpp | 5 +- src/gui/dialogs/wml_message.hpp | 3 +- src/gui/widgets/label.cpp | 6 +- src/gui/widgets/menu_button.cpp | 2 +- src/gui/widgets/multimenu_button.cpp | 2 +- src/gui/widgets/window.cpp | 10 +-- src/gui/widgets/window.hpp | 4 +- src/help/help.cpp | 2 +- src/help/help_browser.cpp | 2 +- src/hotkey/command_executor.cpp | 10 +-- src/hotkey/hotkey_handler_sp.cpp | 4 +- src/menu_events.cpp | 68 ++++++++--------- src/mouse_events.cpp | 6 +- src/play_controller.cpp | 2 +- src/playsingle_controller.cpp | 7 +- src/playturn.cpp | 2 +- src/preferences/display.cpp | 10 +-- src/preferences/display.hpp | 4 +- src/quit_confirmation.cpp | 2 +- src/savegame.cpp | 38 +++++----- src/scripting/game_lua_kernel.cpp | 2 +- src/scripting/lua_gui2.cpp | 34 ++++----- src/scripting/lua_gui2.hpp | 16 ++-- src/scripting/lua_kernel_base.cpp | 31 +++----- src/scripting/lua_kernel_base.hpp | 4 - src/synced_user_choice.cpp | 2 +- src/tests/gui/test_gui2.cpp | 18 +---- src/wesnoth.cpp | 4 +- src/whiteboard/manager.cpp | 2 +- src/wml_exception.cpp | 4 +- src/wml_exception.hpp | 2 +- 121 files changed, 556 insertions(+), 744 deletions(-) diff --git a/src/actions/advancement.cpp b/src/actions/advancement.cpp index 9b804da65ddea..22ec3ce57db37 100644 --- a/src/actions/advancement.cpp +++ b/src/actions/advancement.cpp @@ -77,7 +77,7 @@ namespace if (previews.size() > 1 || always_display) { gui2::dialogs::unit_advance dlg(previews, num_real_advances); - dlg.show(CVideo::get_singleton()); + dlg.show(); if (dlg.get_retval() == gui2::window::OK) { return dlg.get_selected_index(); diff --git a/src/addon/client.cpp b/src/addon/client.cpp index 977dce3ed0298..09586475f6d18 100644 --- a/src/addon/client.cpp +++ b/src/addon/client.cpp @@ -252,13 +252,13 @@ bool addons_client::install_addon(config& archive_cfg, const addon_info& info) i18n_symbols["addon_title"] = font::escape_text(info.title); if(!check_names_legal(archive_cfg)) { - gui2::show_error_message(v_, + gui2::show_error_message( vgettext("The add-on $addon_title has an invalid file or directory " "name and cannot be installed.", i18n_symbols)); return false; } if(!check_case_insensitive_duplicates(archive_cfg)){ - gui2::show_error_message(v_, + gui2::show_error_message( vgettext("The add-on $addon_title has file or directory names " "with case conflicts. This may cause problems.", i18n_symbols)); } @@ -315,7 +315,7 @@ bool addons_client::try_fetch_addon(const addon_info & addon) )) { const std::string& server_error = get_last_server_error(); if(!server_error.empty()) { - gui2::show_error_message(v_, + gui2::show_error_message( _("The server responded with an error:") + "\n" + server_error); } return false; @@ -365,7 +365,7 @@ addons_client::install_result addons_client::do_resolve_addon_dependencies(const broken_deps_report += "\n " + font::unicode_bullet + " " + make_addon_title(broken_dep_id); } - if(gui2::show_message(v_, _("Broken Dependencies"), broken_deps_report, gui2::dialogs::message::yes_no_buttons) != gui2::window::OK) { + if(gui2::show_message(_("Broken Dependencies"), broken_deps_report, gui2::dialogs::message::yes_no_buttons) != gui2::window::OK) { result.outcome = install_outcome::abort; return result; // canceled by user } @@ -384,7 +384,7 @@ addons_client::install_result addons_client::do_resolve_addon_dependencies(const } gui2::dialogs::install_dependencies dlg(options); - bool cont = dlg.show(v_); + bool cont = dlg.show(); if(!cont) { return result; // the user has chosen to continue without installing anything. } @@ -412,7 +412,7 @@ addons_client::install_result addons_client::do_resolve_addon_dependencies(const "The following dependencies could not be installed. Do you still wish to continue?", failed_titles.size()) + std::string("\n\n") + utils::bullet_list(failed_titles); - result.outcome = gui2::show_message(v_, _("Dependencies Installation Failed"), failed_deps_report, gui2::dialogs::message::yes_no_buttons) == gui2::window::OK ? install_outcome::success : install_outcome::abort; // If the user cancels, return abort. Otherwise, return success, since the user chose to ignore the failure. + result.outcome = gui2::show_message(_("Dependencies Installation Failed"), failed_deps_report, gui2::dialogs::message::yes_no_buttons) == gui2::window::OK ? install_outcome::success : install_outcome::abort; // If the user cancels, return abort. Otherwise, return success, since the user chose to ignore the failure. return result; } @@ -449,7 +449,7 @@ bool addons_client::do_check_before_overwriting_addon(const addon_info& addon) text += utils::bullet_list(extra_items) + "\n\n"; text += _("Do you really wish to continue?"); - return gui2::show_message(v_, _("Confirm"), text, gui2::dialogs::message::yes_no_buttons) == gui2::window::OK; + return gui2::show_message(_("Confirm"), text, gui2::dialogs::message::yes_no_buttons) == gui2::window::OK; } addons_client::install_result addons_client::install_addon_with_checks(const addons_list& addons, const addon_info& addon) @@ -550,7 +550,7 @@ void addons_client::wait_for_transfer_done(const std::string& status_message, bo stat_->set_connection_data(*cd); } - if(!stat_->show(v_)) { + if(!stat_->show()) { // Notify the caller chain that the user aborted the operation. throw user_exit(); } diff --git a/src/addon/manager_ui.cpp b/src/addon/manager_ui.cpp index 78d067cfe6d25..0ca8a4c607a48 100644 --- a/src/addon/manager_ui.cpp +++ b/src/addon/manager_ui.cpp @@ -74,18 +74,18 @@ bool addons_manager_ui(CVideo& v, const std::string& remote_address) client.connect(); gui2::dialogs::addon_manager dlg(client); - dlg.show(v); + dlg.show(); need_wml_cache_refresh = dlg.get_need_wml_cache_refresh(); } catch(const config::error& e) { ERR_CFG << "config::error thrown during transaction with add-on server; \""<< e.message << "\"" << std::endl; - gui2::show_error_message(v, _("Network communication error.")); + gui2::show_error_message(_("Network communication error.")); } catch(const network_asio::error& e) { ERR_NET << "network_asio::error thrown during transaction with add-on server; \""<< e.what() << "\"" << std::endl; - gui2::show_error_message(v, _("Remote host disconnected.")); + gui2::show_error_message(_("Remote host disconnected.")); } catch(const filesystem::io_exception& e) { ERR_FS << "filesystem::io_exception thrown while installing an addon; \"" << e.what() << "\"" << std::endl; - gui2::show_error_message(v, _("A problem occurred when trying to create the files necessary to install this add-on.")); + gui2::show_error_message(_("A problem occurred when trying to create the files necessary to install this add-on.")); } catch(const invalid_pbl_exception& e) { ERR_CFG << "could not read .pbl file " << e.path << ": " << e.message << std::endl; @@ -93,28 +93,27 @@ bool addons_manager_ui(CVideo& v, const std::string& remote_address) symbols["path"] = e.path; symbols["msg"] = e.message; - gui2::show_error_message(v, + gui2::show_error_message( vgettext("A local file with add-on publishing information could not be read.\n\nFile: $path\nError message: $msg", symbols)); } catch(wml_exception& e) { - e.show(v); + e.show(); } catch(const addons_client::user_exit&) { LOG_AC << "initial connection canceled by user\n"; } catch(const addons_client::invalid_server_address&) { - gui2::show_error_message(v, _("The add-ons server address specified is not valid.")); + gui2::show_error_message(_("The add-ons server address specified is not valid.")); } return need_wml_cache_refresh; } -bool uninstall_local_addons(CVideo& v) +bool uninstall_local_addons() { const std::string list_lead = "\n\n"; const std::vector& addons = installed_addons(); if(addons.empty()) { - gui2::show_error_message(v, - _("You have no add-ons installed.")); + gui2::show_error_message(_("You have no add-ons installed.")); return false; } @@ -151,7 +150,7 @@ bool uninstall_local_addons(CVideo& v) do { gui2::dialogs::addon_uninstall_list dlg(addon_titles_map); - dlg.show(v); + dlg.show(); remove_ids = dlg.selected_addons(); if(remove_ids.empty()) { @@ -169,8 +168,8 @@ bool uninstall_local_addons(CVideo& v) "Are you sure you want to remove the following installed add-ons?", remove_ids.size()) + list_lead + utils::bullet_list(remove_names); - res = gui2::show_message(v - , _("Confirm") + res = gui2::show_message( + _("Confirm") , confirm_message , gui2::dialogs::message::yes_no_buttons); } while (res != gui2::window::OK); @@ -196,11 +195,11 @@ bool uninstall_local_addons(CVideo& v) skipped_names.size()); gui2::show_error_message( - v, dlg_msg + list_lead + utils::bullet_list(skipped_names)); + dlg_msg + list_lead + utils::bullet_list(skipped_names)); } if(!failed_names.empty()) { - gui2::show_error_message(v, _n( + gui2::show_error_message(_n( "The following add-on could not be deleted properly:", "The following add-ons could not be deleted properly:", failed_names.size()) + list_lead + utils::bullet_list(failed_names)); @@ -215,7 +214,7 @@ bool uninstall_local_addons(CVideo& v) succeeded_names.size()); gui2::show_transient_message( - v, dlg_title, + dlg_title, dlg_msg + list_lead + utils::bullet_list(succeeded_names), "", false, false, true); return true; @@ -236,7 +235,7 @@ bool manage_addons(CVideo& v) const bool have_addons = !installed_addons().empty(); gui2::dialogs::addon_connect addon_dlg(host_name, have_addons); - addon_dlg.show(v); + addon_dlg.show(); int res = addon_dlg.get_retval(); if(res == gui2::window::OK) { @@ -247,7 +246,7 @@ bool manage_addons(CVideo& v) case addon_download: return addons_manager_ui(v, host_name); case addon_uninstall: - return uninstall_local_addons(v); + return uninstall_local_addons(); default: return false; } @@ -266,7 +265,7 @@ bool ad_hoc_addon_fetch_session(CVideo& v, const std::vector& addon addons_list addons; if(!get_addons_list(client, addons)) { - gui2::show_error_message(v, _("An error occurred while downloading the add-ons list from the server.")); + gui2::show_error_message(_("An error occurred while downloading the add-ons list from the server.")); return false; } @@ -280,7 +279,7 @@ bool ad_hoc_addon_fetch_session(CVideo& v, const std::vector& addon } else { utils::string_map symbols; symbols["addon_id"] = addon_id; - gui2::show_error_message(v, vgettext("Could not find an add-on matching id $addon_id on the add-on server.", symbols)); + gui2::show_error_message(vgettext("Could not find an add-on matching id $addon_id on the add-on server.", symbols)); return_value = false; } } @@ -289,13 +288,13 @@ bool ad_hoc_addon_fetch_session(CVideo& v, const std::vector& addon } catch(const config::error& e) { ERR_CFG << "config::error thrown during transaction with add-on server; \""<< e.message << "\"" << std::endl; - gui2::show_error_message(v, _("Network communication error.")); + gui2::show_error_message(_("Network communication error.")); } catch(const network_asio::error& e) { ERR_NET << "network_asio::error thrown during transaction with add-on server; \""<< e.what() << "\"" << std::endl; - gui2::show_error_message(v, _("Remote host disconnected.")); + gui2::show_error_message(_("Remote host disconnected.")); } catch(const filesystem::io_exception& e) { ERR_FS << "io_exception thrown while installing an addon; \"" << e.what() << "\"" << std::endl; - gui2::show_error_message(v, _("A problem occurred when trying to create the files necessary to install this add-on.")); + gui2::show_error_message(_("A problem occurred when trying to create the files necessary to install this add-on.")); } catch(const invalid_pbl_exception& e) { ERR_CFG << "could not read .pbl file " << e.path << ": " << e.message << std::endl; @@ -303,14 +302,14 @@ bool ad_hoc_addon_fetch_session(CVideo& v, const std::vector& addon symbols["path"] = e.path; symbols["msg"] = e.message; - gui2::show_error_message(v, + gui2::show_error_message( vgettext("A local file with add-on publishing information could not be read.\n\nFile: $path\nError message: $msg", symbols)); } catch(wml_exception& e) { - e.show(v); + e.show(); } catch(const addons_client::user_exit&) { LOG_AC << "initial connection canceled by user\n"; } catch(const addons_client::invalid_server_address&) { - gui2::show_error_message(v, _("The add-ons server address specified is not valid.")); + gui2::show_error_message(_("The add-ons server address specified is not valid.")); } return false; diff --git a/src/editor/action/mouse/mouse_action_map_label.cpp b/src/editor/action/mouse/mouse_action_map_label.cpp index 4ea72de6192dd..2568c9f6e7c24 100644 --- a/src/editor/action/mouse/mouse_action_map_label.cpp +++ b/src/editor/action/mouse/mouse_action_map_label.cpp @@ -83,7 +83,7 @@ editor_action* mouse_action_map_label::up_left(editor_display& disp, int x, int gui2::dialogs::editor_edit_label d(label, immutable, visible_fog, visible_shroud, color, category); editor_action* a = nullptr; - if(d.show(disp.video())) { + if(d.show()) { a = new editor_action_label(hex, label, team_name, color , visible_fog, visible_shroud, immutable, category); update_brush_highlights(disp, hex); diff --git a/src/editor/controller/editor_controller.cpp b/src/editor/controller/editor_controller.cpp index ef2bd1d36635a..9e9822322a194 100644 --- a/src/editor/controller/editor_controller.cpp +++ b/src/editor/controller/editor_controller.cpp @@ -174,10 +174,10 @@ EXIT_STATUS editor_controller::main_loop() play_slice(); } } catch (editor_exception& e) { - gui2::show_transient_message(gui().video(), _("Fatal error"), e.what()); + gui2::show_transient_message(_("Fatal error"), e.what()); return EXIT_ERROR; } catch (wml_exception& e) { - e.show(gui().video()); + e.show(); } return quit_mode_; } @@ -192,7 +192,7 @@ void editor_controller::do_screenshot(const std::string& screenshot_filename /* ERR_ED << "Screenshot creation failed!\n"; } } catch (wml_exception& e) { - e.show(gui().video()); + e.show(); } } @@ -216,14 +216,13 @@ bool editor_controller::quit_confirm() void editor_controller::custom_tods_dialog() { if (tods_.empty()) { - gui2::show_error_message(gui().video(), - _("No editor time-of-day found.")); + gui2::show_error_message(_("No editor time-of-day found.")); return; } tod_manager& manager = *get_current_map_context().get_time_manager(); - if(gui2::dialogs::custom_tod::execute(manager.times(), manager.get_current_time(), gui().video())) { + if(gui2::dialogs::custom_tod::execute(manager.times(), manager.get_current_time())) { // TODO save the new tod here } @@ -1143,7 +1142,7 @@ void editor_controller::change_unit_id() if(un != units.end()) { std::string id = un->id(); - if (gui2::dialogs::edit_text::execute(title, label, id, gui_->video())) { + if (gui2::dialogs::edit_text::execute(title, label, id)) { un->set_id(id); } } @@ -1160,7 +1159,7 @@ void editor_controller::rename_unit() if(un != units.end()) { std::string name = un->name(); - if(gui2::dialogs::edit_text::execute(title, label, name, gui_->video())) { + if(gui2::dialogs::edit_text::execute(title, label, name)) { //TODO we may not want a translated name here. un->set_name(name); } diff --git a/src/editor/map/context_manager.cpp b/src/editor/map/context_manager.cpp index 6bca1509d1fee..2e9261126d157 100644 --- a/src/editor/map/context_manager.cpp +++ b/src/editor/map/context_manager.cpp @@ -214,7 +214,7 @@ void context_manager::load_map_dialog(bool force_same_context /* = false */) dlg.set_title(_("Load Map")) .set_path(fn); - if(dlg.show(gui_.video())) { + if(dlg.show()) { load_map(dlg.path(), !force_same_context); } } @@ -235,7 +235,7 @@ void context_manager::edit_side_dialog(int side_index) editor_team_info team_info(t); - if(gui2::dialogs::editor_edit_side::execute(team_info, gui_.video())) { + if(gui2::dialogs::editor_edit_side::execute(team_info)) { get_map_context().set_side_setup(team_info); } } @@ -258,7 +258,7 @@ void context_manager::edit_scenario_dialog() bool random = context.random_start_time(); const bool ok = gui2::dialogs::editor_edit_scenario::execute( - id, name, description, turns, xp_mod, victory, random, gui_.video() + id, name, description, turns, xp_mod, victory, random ); if(!ok) { @@ -277,7 +277,7 @@ void context_manager::new_map_dialog() int w = get_map().w(); int h = get_map().h(); - if(gui2::dialogs::editor_new_map::execute(_("New Map"), w, h, gui_.video())) { + if(gui2::dialogs::editor_new_map::execute(_("New Map"), w, h)) { const t_translation::terrain_code& fill = get_selected_bg_terrain(); new_map(w, h, fill, true); } @@ -288,7 +288,7 @@ void context_manager::new_scenario_dialog() int w = get_map().w(); int h = get_map().h(); - if(gui2::dialogs::editor_new_map::execute(_("New Scenario"), w, h, gui_.video())) { + if(gui2::dialogs::editor_new_map::execute(_("New Scenario"), w, h)) { const t_translation::terrain_code& fill = get_selected_bg_terrain(); new_scenario(w, h, fill, true); } @@ -472,16 +472,16 @@ void context_manager::apply_mask_dialog() dlg.set_title(_("Apply Mask")) .set_path(fn); - if(dlg.show(gui_.video())) { + if(dlg.show()) { try { map_context mask(game_config_, dlg.path()); editor_action_apply_mask a(mask.get_map()); perform_refresh(a); } catch (editor_map_load_exception& e) { - gui2::show_transient_message(gui_.video(), _("Error loading mask"), e.what()); + gui2::show_transient_message(_("Error loading mask"), e.what()); return; } catch (editor_action_exception& e) { - gui2::show_error_message(gui_.video(), e.what()); + gui2::show_error_message(e.what()); return; } } @@ -498,7 +498,7 @@ void context_manager::rename_area_dialog() int active_area = get_map_context().get_active_area(); std::string name = get_map_context().get_time_manager()->get_area_ids()[active_area]; - if(gui2::dialogs::edit_text::execute(N_("Rename Area"), N_("Identifier:"), name, gui_.video())) { + if(gui2::dialogs::edit_text::execute(N_("Rename Area"), N_("Identifier:"), name)) { get_map_context().get_time_manager()->set_area_id(active_area, name); } } @@ -515,16 +515,16 @@ void context_manager::create_mask_to_dialog() dlg.set_title(_("Choose Target Map")) .set_path(fn); - if(dlg.show(gui_.video())) { + if(dlg.show()) { try { map_context map(game_config_, dlg.path()); editor_action_create_mask a(map.get_map()); perform_refresh(a); } catch (editor_map_load_exception& e) { - gui2::show_transient_message(gui_.video(), _("Error loading map"), e.what()); + gui2::show_transient_message(_("Error loading map"), e.what()); return; } catch (editor_action_exception& e) { - gui2::show_error_message(gui_.video(), e.what()); + gui2::show_error_message(e.what()); return; } } @@ -577,7 +577,7 @@ void context_manager::resize_map_dialog() gui2::dialogs::editor_resize_map::EXPAND_DIRECTION dir = gui2::dialogs::editor_resize_map::EXPAND_DIRECTION(); bool copy = false; - if(!gui2::dialogs::editor_resize_map::execute(w, h, dir, copy, gui_.video())) { + if(!gui2::dialogs::editor_resize_map::execute(w, h, dir, copy)) { return; } @@ -650,7 +650,7 @@ void context_manager::save_map_as_dialog() .set_path(input_name) .set_extension(".map"); - if(!dlg.show(gui_.video())) { + if(!dlg.show()) { return; } @@ -671,7 +671,7 @@ void context_manager::save_scenario_as_dialog() .set_path(input_name) .set_extension(".cfg"); - if(!dlg.show(gui_.video())) { + if(!dlg.show()) { return; } @@ -698,13 +698,13 @@ void context_manager::init_map_generators(const config& game_config) void context_manager::generate_map_dialog() { if(map_generators_.empty()) { - gui2::show_error_message(gui_.video(), _("No random map generators found.")); + gui2::show_error_message(_("No random map generators found.")); return; } gui2::dialogs::editor_generate_map dialog(map_generators_); dialog.select_map_generator(last_map_generator_); - dialog.show(gui_.video()); + dialog.show(); if(dialog.get_retval() == gui2::window::OK) { std::string map_string; @@ -712,12 +712,12 @@ void context_manager::generate_map_dialog() try { map_string = map_generator->create_map(dialog.get_seed()); } catch (mapgen_exception& e) { - gui2::show_transient_message(gui_.video(), _("Map creation failed."), e.what()); + gui2::show_transient_message(_("Map creation failed."), e.what()); return; } if(map_string.empty()) { - gui2::show_transient_message(gui_.video(), "", _("Map creation failed.")); + gui2::show_transient_message("", _("Map creation failed.")); } else { editor_map new_map(game_config_, map_string); editor_action_whole_map a(new_map); @@ -732,7 +732,7 @@ void context_manager::generate_map_dialog() bool context_manager::confirm_discard() { if(get_map_context().modified()) { - const int res = gui2::show_message(gui_.video(), _("Unsaved Changes"), + const int res = gui2::show_message(_("Unsaved Changes"), _("Do you want to discard all changes made to the map since the last save?"), gui2::dialogs::message::yes_no_buttons); return gui2::window::CANCEL != res; } @@ -789,7 +789,7 @@ bool context_manager::save_scenario_as(const std::string& filename) { size_t is_open = check_open_map(filename); if(is_open < map_contexts_.size() && is_open != static_cast(current_context_index_)) { - gui2::show_transient_message(gui_.video(), _("This scenario is already open."), filename); + gui2::show_transient_message(_("This scenario is already open."), filename); return false; } @@ -812,7 +812,7 @@ bool context_manager::save_map_as(const std::string& filename) { size_t is_open = check_open_map(filename); if(is_open < map_contexts_.size() && is_open != static_cast(current_context_index_)) { - gui2::show_transient_message(gui_.video(), _("This map is already open."), filename); + gui2::show_transient_message(_("This map is already open."), filename); return false; } @@ -836,10 +836,10 @@ bool context_manager::write_scenario(bool display_confirmation) try { get_map_context().save_scenario(); if(display_confirmation) { - gui2::show_transient_message(gui_.video(), "", _("Scenario saved.")); + gui2::show_transient_message("", _("Scenario saved.")); } } catch (editor_map_save_exception& e) { - gui2::show_transient_message(gui_.video(), "", e.what()); + gui2::show_transient_message("", e.what()); return false; } @@ -851,10 +851,10 @@ bool context_manager::write_map(bool display_confirmation) try { get_map_context().save_map(); if(display_confirmation) { - gui2::show_transient_message(gui_.video(), "", _("Map saved.")); + gui2::show_transient_message("", _("Map saved.")); } } catch (editor_map_save_exception& e) { - gui2::show_transient_message(gui_.video(), "", e.what()); + gui2::show_transient_message("", e.what()); return false; } @@ -875,7 +875,7 @@ bool context_manager::check_switch_open_map(const std::string& fn) { size_t i = check_open_map(fn); if(i < map_contexts_.size()) { - gui2::show_transient_message(gui_.video(), _("This map is already open."), fn); + gui2::show_transient_message(_("This map is already open."), fn); switch_context(i); return true; } @@ -909,7 +909,7 @@ void context_manager::load_map(const std::string& filename, bool new_context) if(get_map_context().is_embedded()) { const std::string& msg = _("Loaded embedded map data"); - gui2::show_transient_message(gui_.video(), _("Map loaded from scenario"), msg); + gui2::show_transient_message(_("Map loaded from scenario"), msg); } else { if(get_map_context().get_filename() != filename) { if(get_map_context().get_map_data_key().empty()) { @@ -922,14 +922,14 @@ void context_manager::load_map(const std::string& filename, bool new_context) const std::string& msg = _("Loaded referenced map file:\n$new"); symbols["new"] = get_map_context().get_filename(); symbols["map_data"] = get_map_context().get_map_data_key(); - gui2::show_transient_message(gui_.video(), _("Map loaded from scenario"), + gui2::show_transient_message(_("Map loaded from scenario"), //TODO: msg is already translated does vgettext make sense? vgettext(msg.c_str(), symbols)); } } } } catch (editor_map_load_exception& e) { - gui2::show_transient_message(gui_.video(), _("Error loading map"), e.what()); + gui2::show_transient_message(_("Error loading map"), e.what()); return; } } diff --git a/src/editor/palette/location_palette.cpp b/src/editor/palette/location_palette.cpp index ca51c3535840b..0ab4274335d32 100644 --- a/src/editor/palette/location_palette.cpp +++ b/src/editor/palette/location_palette.cpp @@ -254,7 +254,7 @@ void location_palette::adjust_size(const SDL_Rect& target) })); button_add_.reset(new location_palette_button(video(), SDL_Rect{ target.x , bottom -= button_y, target.w - 10, button_height }, _("Add"), [this]() { std::string newid; - if (gui2::dialogs::edit_text::execute(_("New Location Identifer"), "", newid, video())) { + if (gui2::dialogs::edit_text::execute(_("New Location Identifer"), "", newid)) { add_item(newid); } })); diff --git a/src/formula/debugger.cpp b/src/formula/debugger.cpp index c41aef1d9fce8..ab55fe5e1bc41 100644 --- a/src/formula/debugger.cpp +++ b/src/formula/debugger.cpp @@ -159,7 +159,7 @@ void formula_debugger::show_gui() } if (game_config::debug) { gui2::dialogs::formula_debugger debug_dialog(*this); - debug_dialog.show(resources::screen->video()); + debug_dialog.show(); } else { WRN_FDB << "do not showing debug window due to disabled --new-widgets"<< std::endl; } diff --git a/src/game_config_manager.cpp b/src/game_config_manager.cpp index d2b098e03e8ff..e8c4b35fe05b4 100644 --- a/src/game_config_manager.cpp +++ b/src/game_config_manager.cpp @@ -196,8 +196,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, gui2::dialogs::wml_error::display( _("Error validating data core."), _("Found a core without id attribute.") - + '\n' + _("Skipping the core."), - video_); + + '\n' + _("Skipping the core.")); }); continue; } @@ -207,8 +206,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, _("Error validating data core."), _("Core ID: ") + id + '\n' + _("The ID is already in use.") - + '\n' + _("Skipping the core."), - video_); + + '\n' + _("Skipping the core.")); }); continue; } @@ -221,8 +219,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, _("Core ID: ") + id + '\n' + _("Core Path: ") + path + '\n' + _("File not found.") - + '\n' + _("Skipping the core."), - video_); + + '\n' + _("Skipping the core.")); }); continue; } @@ -244,8 +241,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, _("Error loading core data."), _("Core ID: ") + preferences::core_id() + '\n' + _("Error loading the core with named id.") - + '\n' + _("Falling back to the default core."), - video_); + + '\n' + _("Falling back to the default core.")); }); preferences::set_core_id("default"); } @@ -256,8 +252,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, gui2::dialogs::wml_error::display( _("Error loading core data."), _("Can't locate the default core.") - + '\n' + _("The game will now exit."), - video_); + + '\n' + _("The game will now exit.")); }); throw; } @@ -318,14 +313,14 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, events::call_in_main_thread([&]() { gui2::dialogs::wml_error::display( _("Error loading custom game configuration files. The game will try without loading add-ons."), - e.message, video_); + e.message); }); load_game_config(force_reload, classification); } else if (preferences::core_id() != "default") { events::call_in_main_thread([&]() { gui2::dialogs::wml_error::display( _("Error loading custom game configuration files. The game will fallback to the default core files."), - e.message, video_); + e.message); }); preferences::set_core_id("default"); game_config::no_addons = false; @@ -334,7 +329,7 @@ void game_config_manager::load_game_config(FORCE_RELOAD_CONFIG force_reload, events::call_in_main_thread([&]() { gui2::dialogs::wml_error::display( _("Error loading default core game configuration files. The game will now exit."), - e.message, video_); + e.message); }); throw; } @@ -470,7 +465,7 @@ void game_config_manager::load_addons_cfg() const std::string& report = utils::join(error_log, "\n\n"); events::call_in_main_thread([&]() { - gui2::dialogs::wml_error::display(msg1, msg2, error_addons, report, video_); + gui2::dialogs::wml_error::display(msg1, msg2, error_addons, report); }); } } diff --git a/src/game_events/action_wml.cpp b/src/game_events/action_wml.cpp index 4c7fa94511812..877f0448b9b8a 100644 --- a/src/game_events/action_wml.cpp +++ b/src/game_events/action_wml.cpp @@ -608,7 +608,7 @@ WML_HANDLER_FUNCTION(replace_map,, cfg) lg::wml_error() << "replace_map: Unable to load map " << log_map_name << std::endl; return; } catch(wml_exception& e) { - e.show(resources::screen->video()); + e.show(); return; } @@ -873,7 +873,7 @@ WML_HANDLER_FUNCTION(terrain_mask,, cfg) ERR_NG << "terrain mask is in the incorrect format, and couldn't be applied" << std::endl; return; } catch(wml_exception& e) { - e.show(resources::screen->video()); + e.show(); return; } diff --git a/src/game_initialization/create_engine.cpp b/src/game_initialization/create_engine.cpp index 7ad927bc261c5..38e3e6a1996c1 100644 --- a/src/game_initialization/create_engine.cpp +++ b/src/game_initialization/create_engine.cpp @@ -467,7 +467,7 @@ std::string create_engine::select_campaign_difficulty(int set_value) // We don't pass the difficulties vector here because additional data is required // to constrict the dialog gui2::dialogs::campaign_difficulty dlg(current_level().data()); - dlg.show(video_); + dlg.show(); selected_campaign_difficulty_ = dlg.selected_difficulty(); diff --git a/src/game_initialization/depcheck.cpp b/src/game_initialization/depcheck.cpp index f7e0e7808257d..71deab819685f 100644 --- a/src/game_initialization/depcheck.cpp +++ b/src/game_initialization/depcheck.cpp @@ -442,7 +442,7 @@ bool manager::enable_mods_dialog(const std::vector& mods, const std } gui2::dialogs::depcheck_confirm_change dialog(true, items, requester); - return dialog.show(video_); + return dialog.show(); } bool manager::disable_mods_dialog(const std::vector& mods, const std::string& requester) @@ -453,7 +453,7 @@ bool manager::disable_mods_dialog(const std::vector& mods, const st } gui2::dialogs::depcheck_confirm_change dialog(false, items, requester); - return dialog.show(video_); + return dialog.show(); } std::string manager::change_era_dialog(const std::vector& eras) @@ -465,7 +465,7 @@ std::string manager::change_era_dialog(const std::vector& eras) gui2::dialogs::depcheck_select_new dialog(ERA, items); - if(dialog.show(video_)) { + if(dialog.show()) { return eras[dialog.result()]; } @@ -480,7 +480,7 @@ std::string manager::change_scenario_dialog(const std::vector& scen } gui2::dialogs::depcheck_select_new dialog(SCENARIO, items); - if(dialog.show(video_)) { + if(dialog.show()) { return scenarios[dialog.result()]; } @@ -489,7 +489,7 @@ std::string manager::change_scenario_dialog(const std::vector& scen void manager::failure_dialog(const std::string& msg) { - gui2::show_message(video_, _("Failed to resolve dependencies"), msg, _("OK")); + gui2::show_message(_("Failed to resolve dependencies"), msg, _("OK")); } void manager::insert_element(component_type type, const config& data, int index) diff --git a/src/game_initialization/multiplayer.cpp b/src/game_initialization/multiplayer.cpp index 0a671c703d83b..c6445993ad643 100644 --- a/src/game_initialization/multiplayer.cpp +++ b/src/game_initialization/multiplayer.cpp @@ -209,7 +209,7 @@ std::pair open_connection(CVideo& video, std::s warning_msg += "\n\n"; warning_msg += _("Do you want to continue?"); - if(gui2::show_message(video, _("Warning"), warning_msg, gui2::dialogs::message::yes_no_buttons) != gui2::window::OK) { + if(gui2::show_message(_("Warning"), warning_msg, gui2::dialogs::message::yes_no_buttons) != gui2::window::OK) { return std::make_pair(wesnothd_connection_ptr(), config()); } } @@ -223,7 +223,7 @@ std::pair open_connection(CVideo& video, std::s std::string password = preferences::password(host, login); bool fall_through = (*error)["force_confirmation"].to_bool() ? - (gui2::show_message(video, _("Confirm"), (*error)["message"], gui2::dialogs::message::ok_cancel_buttons) == gui2::window::CANCEL) : + (gui2::show_message(_("Confirm"), (*error)["message"], gui2::dialogs::message::ok_cancel_buttons) == gui2::window::CANCEL) : false; const bool is_pw_request = !((*error)["password_request"].empty()) && !(password.empty()); @@ -323,7 +323,7 @@ std::pair open_connection(CVideo& video, std::s gui2::dialogs::mp_login dlg(host, error_message, !((*error)["password_request"].empty())); // Need to show the dialog from the main thread or it won't appear. - events::call_in_main_thread([&dlg, &video]() { dlg.show(video); }); + events::call_in_main_thread([&dlg, &video]() { dlg.show(); }); switch(dlg.get_retval()) { //Log in with password @@ -414,11 +414,11 @@ void enter_wait_mode(mp_workflow_helper_ptr helper, int game_id, bool observe) { gui2::dialogs::mp_join_game dlg(helper->state, *helper->lobby_info, *helper->connection, true, observe); - if(!dlg.fetch_game_config(helper->video)) { + if(!dlg.fetch_game_config()) { return; } - dlg.show(helper->video); + dlg.show(); dlg_ok = dlg.get_retval() == gui2::window::OK; } @@ -449,7 +449,7 @@ void enter_staging_mode(mp_workflow_helper_ptr helper) ng::connect_engine_ptr connect_engine(new ng::connect_engine(helper->state, true, campaign_info.get())); gui2::dialogs::mp_staging dlg(*connect_engine, *helper->lobby_info, helper->connection); - dlg.show(helper->video); + dlg.show(); dlg_ok = dlg.get_retval() == gui2::window::OK; } // end connect_engine_ptr, dlg scope @@ -474,7 +474,7 @@ void enter_create_mode(mp_workflow_helper_ptr helper) mp::user_info* host_info = helper->lobby_info->get_user(preferences::login()); gui2::dialogs::mp_create_game dlg(helper->game_config, helper->state, local_mode, host_info); - dlg_cancel = !dlg.show(helper->video); + dlg_cancel = !dlg.show(); } if(!dlg_cancel) { @@ -516,7 +516,7 @@ bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vectorgame_config, li, *helper->connection); - dlg.show(helper->video); + dlg.show(); dlg_retval = dlg.get_retval(); dlg_joined_game_id = dlg.get_joined_game_id(); } @@ -527,7 +527,7 @@ bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vectorvideo, error.message); + gui2::show_error_message(error.message); } // Update lobby content @@ -544,7 +544,7 @@ bool enter_lobby_mode(mp_workflow_helper_ptr helper, const std::vectorvideo, error.message); + gui2::show_error_message(error.message); } // Update lobby content @@ -616,21 +616,21 @@ void start_client(CVideo& video, const config& game_config, saved_game& state, c } while(re_enter); } -bool goto_mp_connect(CVideo& video, ng::connect_engine& engine, const config& game_config, wesnothd_connection* connection) +bool goto_mp_connect(ng::connect_engine& engine, const config& game_config, wesnothd_connection* connection) { lobby_info li(game_config, {}); gui2::dialogs::mp_staging dlg(engine, li, connection); - return dlg.show(video); + return dlg.show(); } -bool goto_mp_wait(CVideo& video, saved_game& state, const config& game_config, wesnothd_connection* connection, bool observe) +bool goto_mp_wait(saved_game& state, const config& game_config, wesnothd_connection* connection, bool observe) { lobby_info li(game_config, std::vector()); gui2::dialogs::mp_join_game dlg(state, li, *connection, false, observe); - if(!dlg.fetch_game_config(video)) { + if(!dlg.fetch_game_config()) { return false; } @@ -638,7 +638,7 @@ bool goto_mp_wait(CVideo& video, saved_game& state, const config& game_config, w return true; } - return dlg.show(video); + return dlg.show(); } void start_local_game(CVideo& video, const config& game_config, saved_game& state) diff --git a/src/game_initialization/multiplayer.hpp b/src/game_initialization/multiplayer.hpp index 4985657927dea..68c5a045e87af 100644 --- a/src/game_initialization/multiplayer.hpp +++ b/src/game_initialization/multiplayer.hpp @@ -60,13 +60,13 @@ void start_client(CVideo& video, const config& game_config, * Opens mp::connect screen and sets game state according to the * changes made. */ -bool goto_mp_connect(CVideo& video, ng::connect_engine& engine, +bool goto_mp_connect(ng::connect_engine& engine, const config& game_config, wesnothd_connection* connection); /** * Opens mp::wait screen and sets game state according to the * changes made. */ -bool goto_mp_wait(CVideo& video, saved_game& state, const config& game_config, wesnothd_connection* connection, bool observe); +bool goto_mp_wait(saved_game& state, const config& game_config, wesnothd_connection* connection, bool observe); } diff --git a/src/game_initialization/playcampaign.cpp b/src/game_initialization/playcampaign.cpp index 8350e91829887..604deb22deeab 100644 --- a/src/game_initialization/playcampaign.cpp +++ b/src/game_initialization/playcampaign.cpp @@ -180,7 +180,7 @@ void campaign_controller::show_carryover_message(playsingle_controller& playcont } if (end_level.transient.carryover_report) { - gui2::show_transient_message(video_, title, report.str(), "", true); + gui2::show_transient_message(title, report.str(), "", true); } } @@ -288,24 +288,24 @@ LEVEL_RESULT campaign_controller::play_game() res = playmp_scenario(end_level); } } catch(game::load_game_failed& e) { - gui2::show_error_message(video_, _("The game could not be loaded: ") + e.message); + gui2::show_error_message(_("The game could not be loaded: ") + e.message); return LEVEL_RESULT::QUIT; } catch(quit_game_exception&) { LOG_NG << "The game was aborted\n"; return LEVEL_RESULT::QUIT; } catch(game::game_error& e) { - gui2::show_error_message(video_, _("Error while playing the game: ") + e.message); + gui2::show_error_message(_("Error while playing the game: ") + e.message); return LEVEL_RESULT::QUIT; } catch(incorrect_map_format_error& e) { - gui2::show_error_message(video_, _("The game map could not be loaded: ") + e.message); + gui2::show_error_message(_("The game map could not be loaded: ") + e.message); return LEVEL_RESULT::QUIT; } catch (mapgen_exception& e) { - gui2::show_error_message(video_, _("Map generator error: ") + e.message); + gui2::show_error_message(_("Map generator error: ") + e.message); } catch(config::error& e) { - gui2::show_error_message(video_, _("Error while reading the WML: ") + e.message); + gui2::show_error_message(_("Error while reading the WML: ") + e.message); return LEVEL_RESULT::QUIT; } catch(wml_exception& e) { - e.show(video_); + e.show(); return LEVEL_RESULT::QUIT; } @@ -339,7 +339,7 @@ LEVEL_RESULT campaign_controller::play_game() } else if(res == LEVEL_RESULT::OBSERVER_END && mp_info_ && !mp_info_->is_host) { - const int dlg_res = gui2::show_message(video_, _("Game Over"), + const int dlg_res = gui2::show_message(_("Game Over"), _("This scenario has ended. Do you want to continue the campaign?"), gui2::dialogs::message::yes_no_buttons); @@ -350,7 +350,7 @@ LEVEL_RESULT campaign_controller::play_game() if (mp_info_ && !mp_info_->is_host) { // Opens join game dialog to get a new gamestate. - if(!mp::goto_mp_wait(video_, state_, game_config_, &mp_info_->connection, res == LEVEL_RESULT::OBSERVER_END)) { + if(!mp::goto_mp_wait(state_, game_config_, &mp_info_->connection, res == LEVEL_RESULT::OBSERVER_END)) { return LEVEL_RESULT::QUIT; } @@ -372,7 +372,7 @@ LEVEL_RESULT campaign_controller::play_game() if (!connect_engine->can_start_game() || (game_config::debug && game_type == game_classification::CAMPAIGN_TYPE::MULTIPLAYER)) { // Opens staging dialog to allow users to make an adjustments for scenario. - if(!mp::goto_mp_connect(video_, *connect_engine, game_config_, mp_info_ ? &mp_info_->connection : nullptr)) { + if(!mp::goto_mp_connect(*connect_engine, game_config_, mp_info_ ? &mp_info_->connection : nullptr)) { return LEVEL_RESULT::QUIT; } } else { @@ -409,7 +409,7 @@ LEVEL_RESULT campaign_controller::play_game() utils::string_map symbols; symbols["scenario"] = state_.get_scenario_id(); message = utils::interpolate_variables_into_string(message, &symbols); - gui2::show_error_message(video_, message); + gui2::show_error_message(message); return LEVEL_RESULT::QUIT; } diff --git a/src/game_initialization/singleplayer.cpp b/src/game_initialization/singleplayer.cpp index 6bae01a5bc28b..803be82477417 100644 --- a/src/game_initialization/singleplayer.cpp +++ b/src/game_initialization/singleplayer.cpp @@ -26,7 +26,7 @@ static lg::log_domain log_engine("engine"); namespace sp { -bool enter_create_mode(CVideo& video, const config& game_config, saved_game& state, jump_to_campaign_info jump_to_campaign) +bool enter_create_mode(const config& game_config, saved_game& state, jump_to_campaign_info jump_to_campaign) { bool configure_canceled = false; @@ -39,7 +39,7 @@ bool enter_create_mode(CVideo& video, const config& game_config, saved_game& sta create_eng.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN); if(campaigns.empty()) { - gui2::show_error_message(video, _("No campaigns are available.")); + gui2::show_error_message(_("No campaigns are available.")); return false; } @@ -50,9 +50,9 @@ bool enter_create_mode(CVideo& video, const config& game_config, saved_game& sta gui2::dialogs::campaign_selection dlg(create_eng); try { - dlg.show(video); + dlg.show(); } catch(wml_exception& e) { - e.show(video); + e.show(); return false; } @@ -92,7 +92,7 @@ bool enter_create_mode(CVideo& video, const config& game_config, saved_game& sta } // Canceled difficulty dialog, relaunch the campaign selection dialog - return enter_create_mode(video, game_config, state, jump_to_campaign); + return enter_create_mode(game_config, state, jump_to_campaign); } create_eng.prepare_for_era_and_mods(); @@ -109,14 +109,14 @@ bool enter_create_mode(CVideo& video, const config& game_config, saved_game& sta return false; } - configure_canceled = !enter_configure_mode(video, game_config_manager::get()->game_config(), state, create_eng); + configure_canceled = !enter_configure_mode(game_config_manager::get()->game_config(), state, create_eng); } while (configure_canceled); return true; } -bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& state, ng::create_engine& create_eng) +bool enter_configure_mode(const config& game_config, saved_game& state, ng::create_engine& create_eng) { // We create the config engine here in order to ensure values like use_map_settings are set correctly // TODO: should this be passed to this function instead of created here? @@ -125,19 +125,19 @@ bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& // TODO: needed? config_eng.update_initial_cfg(create_eng.current_level().data()); - if(!gui2::dialogs::sp_options_configure::execute(create_eng, config_eng, video)) { + if(!gui2::dialogs::sp_options_configure::execute(create_eng, config_eng)) { return false; } create_eng.get_parameters(); create_eng.prepare_for_new_level(); - enter_connect_mode(video, game_config, state); + enter_connect_mode(game_config, state); return true; } -bool enter_connect_mode(CVideo& /*video*/, const config& /*game_config*/, saved_game& state) +bool enter_connect_mode(const config& /*game_config*/, saved_game& state) { ng::connect_engine connect_eng(state, true, nullptr); @@ -147,11 +147,11 @@ bool enter_connect_mode(CVideo& /*video*/, const config& /*game_config*/, saved_ lobby_info li(game_config, std::vector()); gui2::dialogs::mp_staging dlg(connect_eng, li); - dlg.show(video); + dlg.show(); if(dlg.get_retval() != gui2::window::OK) { // TODO: enable the workflow loops from GUI1 - //return enter_create_mode(video, game_config, state, jump_to_campaign_info(false, -1, "", "")); + //return enter_create_mode(game_config, state, jump_to_campaign_info(false, -1, "", "")); return false; } diff --git a/src/game_initialization/singleplayer.hpp b/src/game_initialization/singleplayer.hpp index b42a6e243adbb..070eebdf31b3d 100644 --- a/src/game_initialization/singleplayer.hpp +++ b/src/game_initialization/singleplayer.hpp @@ -21,13 +21,13 @@ namespace sp { -bool enter_create_mode(CVideo& video, const config& game_config, +bool enter_create_mode(const config& game_config, saved_game& state, jump_to_campaign_info jump_to); -bool enter_configure_mode(CVideo& video, const config& game_config, +bool enter_configure_mode(const config& game_config, saved_game& state, ng::create_engine& create_eng); -bool enter_connect_mode(CVideo& video, const config& game_config, +bool enter_connect_mode(const config& game_config, saved_game& state); } // end namespace sp diff --git a/src/game_launcher.cpp b/src/game_launcher.cpp index ef342751a2dec..a40fba3a94f47 100644 --- a/src/game_launcher.cpp +++ b/src/game_launcher.cpp @@ -442,7 +442,7 @@ bool game_launcher::init_lua_script() return true; } catch (std::exception & e) { - gui2::show_error_message(video(), std::string("When loading a plugin, error:\n") + e.what()); + gui2::show_error_message(std::string("When loading a plugin, error:\n") + e.what()); error = true; } } @@ -641,28 +641,28 @@ bool game_launcher::load_game() } catch(config::error& e) { if(e.message.empty()) { - gui2::show_error_message(video(), _("The file you have tried to load is corrupt")); + gui2::show_error_message(_("The file you have tried to load is corrupt")); } else { - gui2::show_error_message(video(), _("The file you have tried to load is corrupt: '") + e.message + '\''); + gui2::show_error_message(_("The file you have tried to load is corrupt: '") + e.message + '\''); } return false; } catch(wml_exception& e) { - e.show(video()); + e.show(); return false; } catch(filesystem::io_exception& e) { if(e.message.empty()) { - gui2::show_error_message(video(), _("File I/O Error while reading the game")); + gui2::show_error_message(_("File I/O Error while reading the game")); } else { - gui2::show_error_message(video(), _("File I/O Error while reading the game: '") + e.message + '\''); + gui2::show_error_message(_("File I/O Error while reading the game: '") + e.message + '\''); } return false; } catch(game::error& e) { if(e.message.empty()) { - gui2::show_error_message(video(), _("The file you have tried to load is corrupt")); + gui2::show_error_message(_("The file you have tried to load is corrupt")); } else { - gui2::show_error_message(video(), _("The file you have tried to load is corrupt: '") + e.message + '\''); + gui2::show_error_message(_("The file you have tried to load is corrupt: '") + e.message + '\''); } return false; } @@ -717,7 +717,7 @@ bool game_launcher::new_campaign() state_.mp_settings().show_connect = false; play_replay_ = false; - return sp::enter_create_mode(video(), game_config_manager::get()->game_config(), + return sp::enter_create_mode(game_config_manager::get()->game_config(), state_, jump_to_campaign_); } @@ -815,7 +815,7 @@ bool game_launcher::play_multiplayer(mp_selection res) start_wesnothd(); } catch(game::mp_server_error&) { - preferences::show_wesnothd_server_search(video()); + preferences::show_wesnothd_server_search(); try { start_wesnothd(); @@ -830,7 +830,7 @@ bool game_launcher::play_multiplayer(mp_selection res) // If a server address wasn't specified, prompt for it now. if(res != MP_LOCAL && multiplayer_server_.empty()) { - if(!gui2::dialogs::mp_connect::execute(CVideo::get_singleton())) { + if(!gui2::dialogs::mp_connect::execute()) { return false; } @@ -858,39 +858,37 @@ bool game_launcher::play_multiplayer(mp_selection res) } } catch(game::mp_server_error& e) { - gui2::show_error_message(video(), _("Error while starting server: ") + e.message); + gui2::show_error_message(_("Error while starting server: ") + e.message); } catch(game::load_game_failed& e) { - gui2::show_error_message(video(), _("The game could not be loaded: ") + e.message); + gui2::show_error_message(_("The game could not be loaded: ") + e.message); } catch(game::game_error& e) { - gui2::show_error_message(video(), _("Error while playing the game: ") + e.message); + gui2::show_error_message(_("Error while playing the game: ") + e.message); } catch (mapgen_exception& e) { - gui2::show_error_message(video(), _("Map generator error: ") + e.message); + gui2::show_error_message(_("Map generator error: ") + e.message); } catch(wesnothd_error& e) { if(!e.message.empty()) { ERR_NET << "caught network error: " << e.message << std::endl; - gui2::show_transient_message(video() - , "" - , translation::gettext(e.message.c_str())); + gui2::show_transient_message("", translation::gettext(e.message.c_str())); } else { ERR_NET << "caught network error" << std::endl; } } catch(config::error& e) { if(!e.message.empty()) { ERR_CONFIG << "caught config::error: " << e.message << std::endl; - gui2::show_transient_message(video(), "", e.message); + gui2::show_transient_message("", e.message); } else { ERR_CONFIG << "caught config::error" << std::endl; } } catch(incorrect_map_format_error& e) { - gui2::show_error_message(video(), _("The game map could not be loaded: ") + e.message); + gui2::show_error_message(_("The game map could not be loaded: ") + e.message); } catch (savegame::load_game_exception & e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded } catch(wml_exception& e) { - e.show(video()); + e.show(); } catch (game::error & e) { std::cerr << "caught game::error...\n"; - gui2::show_error_message(video(), _("Error: ") + e.message); + gui2::show_error_message(_("Error: ") + e.message); } return false; @@ -923,7 +921,7 @@ bool game_launcher::play_multiplayer_commandline() bool game_launcher::change_language() { gui2::dialogs::language_selection dlg; - dlg.show(video()); + dlg.show(); if (dlg.get_retval() != gui2::window::OK) return false; if (!(cmdline_opts_.nogui || cmdline_opts_.headless_unit_test)) { @@ -968,19 +966,19 @@ void game_launcher::launch_game(RELOAD_GAME_DATA reload) if(result == LEVEL_RESULT::VICTORY && !state_.classification().is_normal_mp_game()) { preferences::add_completed_campaign(state_.classification().campaign, state_.classification().difficulty); - gui2::dialogs::outro::display(state_.classification().end_text, state_.classification().end_text_duration, video()); + gui2::dialogs::outro::display(state_.classification().end_text, state_.classification().end_text_duration); if(state_.classification().end_credits) { - gui2::dialogs::end_credits::display(video(), state_.classification().campaign); + gui2::dialogs::end_credits::display(state_.classification().campaign); } } } catch (savegame::load_game_exception &e) { load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded } catch(wml_exception& e) { - e.show(video()); + e.show(); } catch(mapgen_exception& e) { - gui2::show_error_message(video(), _("Map generator error: ") + e.message); + gui2::show_error_message(_("Map generator error: ") + e.message); } } @@ -994,7 +992,7 @@ void game_launcher::play_replay() load_data_.reset(new savegame::load_game_metadata(std::move(e.data_))); //this will make it so next time through the title screen loop, this game is loaded } catch(wml_exception& e) { - e.show(video()); + e.show(); } } diff --git a/src/generators/default_map_generator.cpp b/src/generators/default_map_generator.cpp index d1f62ea5f06f8..f619b81dca33c 100644 --- a/src/generators/default_map_generator.cpp +++ b/src/generators/default_map_generator.cpp @@ -60,7 +60,7 @@ bool default_map_generator::allow_user_config() const { return true; } void default_map_generator::user_config() { - gui2::dialogs::generator_settings::execute(data_, CVideo::get_singleton()); + gui2::dialogs::generator_settings::execute(data_); } std::string default_map_generator::name() const { return "default"; } diff --git a/src/gui/core/window_builder.cpp b/src/gui/core/window_builder.cpp index 8ed9bd25dc8f8..9ccc90f66b0f4 100644 --- a/src/gui/core/window_builder.cpp +++ b/src/gui/core/window_builder.cpp @@ -68,11 +68,11 @@ static std::map& builder_widget_lookup() * be tuned. This page will describe what can be tuned. * */ -window* build(CVideo& video, const builder_window::window_resolution* definition) +window* build(const builder_window::window_resolution* definition) { // We set the values from the definition since we can only determine the // best size (if needed) after all widgets have been placed. - window* win = new window(video, definition); + window* win = new window(definition); assert(win); for(const auto& lg : definition->linked_groups) { @@ -102,10 +102,10 @@ window* build(CVideo& video, const builder_window::window_resolution* definition return win; } -window* build(CVideo& video, const std::string& type) +window* build(const std::string& type) { const builder_window::window_resolution& definition = get_window_builder(type); - window* window = build(video, &definition); + window* window = build(&definition); window->set_id(type); return window; } diff --git a/src/gui/core/window_builder.hpp b/src/gui/core/window_builder.hpp index 8e046ea7395a6..d64b52a08a56f 100644 --- a/src/gui/core/window_builder.hpp +++ b/src/gui/core/window_builder.hpp @@ -36,7 +36,7 @@ class window; * @param type The type id string of the window, this window * must be registered at startup. */ -window* build(CVideo& video, const std::string& type); +window* build(const std::string& type); /** Contains the info needed to instantiate a widget. */ struct builder_widget @@ -231,6 +231,6 @@ class builder_window /** * Builds a window. */ -window* build(CVideo& video, const builder_window::window_resolution* res); +window* build(const builder_window::window_resolution* res); } // namespace gui2 diff --git a/src/gui/dialogs/addon/manager.cpp b/src/gui/dialogs/addon/manager.cpp index 68209c2e32239..d065cf037e917 100644 --- a/src/gui/dialogs/addon/manager.cpp +++ b/src/gui/dialogs/addon/manager.cpp @@ -437,7 +437,7 @@ void addon_manager::fetch_addons_list(window& window) { client_.request_addons_list(cfg_); if(!cfg_) { - show_error_message(window.video(), _("An error occurred while downloading the add-ons list from the server.")); + gui2::show_error_message(_("An error occurred while downloading the add-ons list from the server.")); window.close(); } } @@ -471,7 +471,7 @@ void addon_manager::load_addon_list(window& window) } if(addons_.empty()) { - show_transient_message(window.video(), _("No Add-ons Available"), _("There are no add-ons available for download from this server.")); + show_transient_message(_("No Add-ons Available"), _("There are no add-ons available for download from this server.")); window.close(); } @@ -616,7 +616,7 @@ void addon_manager::install_addon(const addon_info& addon, window& window) void addon_manager::uninstall_addon(const addon_info& addon, window& window) { if(have_addon_pbl_info(addon.id) || have_addon_in_vcs_tree(addon.id)) { - show_error_message(window.video(), + show_error_message( _("The following add-on appears to have publishing or version control information stored locally, and will not be removed:") + " " + addon.display_title()); return; @@ -625,7 +625,7 @@ void addon_manager::uninstall_addon(const addon_info& addon, window& window) bool success = remove_local_addon(addon.id); if(!success) { - show_error_message(window.video(), _("The following add-on could not be deleted properly:") + " " + addon.display_title()); + gui2::show_error_message(_("The following add-on could not be deleted properly:") + " " + addon.display_title()); } else { need_wml_cache_refresh_ = true; @@ -671,7 +671,7 @@ void addon_manager::publish_addon(const addon_info& addon, window& window) const version_info& version_to_publish = cfg["version"].str(); if(version_to_publish <= tracking_info_[addon_id].remote_version) { - const int res = gui2::show_message(window.video(), _("Warning"), + const int res = gui2::show_message(_("Warning"), _("The remote version of this add-on is greater or equal to the version being uploaded. Do you really wish to continue?"), gui2::dialogs::message::yes_no_buttons); @@ -681,11 +681,11 @@ void addon_manager::publish_addon(const addon_info& addon, window& window) } if(!::image::exists(cfg["icon"].str())) { - gui2::show_error_message(window.video(), _("Invalid icon path. Make sure the path points to a valid image.")); + gui2::show_error_message(_("Invalid icon path. Make sure the path points to a valid image.")); } else if(!client_.request_distribution_terms(server_msg)) { - gui2::show_error_message(window.video(), + gui2::show_error_message( _("The server responded with an error:") + "\n" + client_.get_last_server_error()); - } else if(gui2::show_message(window.video(), _("Terms"), server_msg, gui2::dialogs::message::ok_cancel_buttons, true) == gui2::window::OK) { + } else if(gui2::show_message(_("Terms"), server_msg, gui2::dialogs::message::ok_cancel_buttons, true) == gui2::window::OK) { if(!client_.upload_addon(addon_id, server_msg, cfg)) { const std::string& msg = _("The server responded with an error:") + "\n\n" + client_.get_last_server_error(); @@ -697,12 +697,12 @@ void addon_manager::publish_addon(const addon_info& addon, window& window) // stuff (having a scroll container is especially // important since a long list can cause the dialog to // overflow). - gui2::show_error_message(window.video(), msg + "\n\n" + extra_data, true); + gui2::show_error_message(msg + "\n\n" + extra_data, true); } else { - gui2::show_error_message(window.video(), msg, true); + gui2::show_error_message(msg, true); } } else { - gui2::show_transient_message(window.video(), _("Response"), server_msg); + gui2::show_transient_message(_("Response"), server_msg); fetch_addons_list(window); reload_list_and_reselect_item(addon_id, window); } @@ -718,8 +718,7 @@ void addon_manager::delete_addon(const addon_info& addon, window& window) {{"addon", make_addon_title(addon_id)}} // FIXME: need the real title! ); - const int res = gui2::show_message( - window.video(), _("Confirm"), text, gui2::dialogs::message::yes_no_buttons); + const int res = gui2::show_message(_("Confirm"), text, gui2::dialogs::message::yes_no_buttons); if(res != gui2::window::OK) { return; @@ -727,10 +726,10 @@ void addon_manager::delete_addon(const addon_info& addon, window& window) std::string server_msg; if(!client_.delete_remote_addon(addon_id, server_msg)) { - gui2::show_error_message(window.video(), _("The server responded with an error:") + "\n" + client_.get_last_server_error()); + gui2::show_error_message(_("The server responded with an error:") + "\n" + client_.get_last_server_error()); } else { // FIXME: translation needed! - gui2::show_transient_message(window.video(), _("Response"), server_msg); + gui2::show_transient_message(_("Response"), server_msg); fetch_addons_list(window); reload_list_and_reselect_item(addon_id, window); } @@ -746,7 +745,7 @@ void addon_manager::execute_default_action(const addon_info& addon, window& wind case ADDON_INSTALLED: if(!tracking_info_[addon.id].can_publish) { utils::string_map symbols{ { "addon", addon.display_title() } }; - int res = gui2::show_message(window.video(), _("Uninstall add-on"), + int res = gui2::show_message(_("Uninstall add-on"), vgettext("Do you want to uninstall '$addon|'?", symbols), gui2::dialogs::message::ok_cancel_buttons); if(res == gui2::window::OK) { diff --git a/src/gui/dialogs/advanced_graphics_options.hpp b/src/gui/dialogs/advanced_graphics_options.hpp index b24d84f2de455..737bee2606efb 100644 --- a/src/gui/dialogs/advanced_graphics_options.hpp +++ b/src/gui/dialogs/advanced_graphics_options.hpp @@ -34,10 +34,7 @@ class advanced_graphics_options : public modal_dialog * * See @ref modal_dialog for more information. */ - static void display(CVideo& video) - { - advanced_graphics_options().show(video); - } + DEFINE_SIMPLE_DISPLAY_WRAPPER(advanced_graphics_options) // These names must match the infixes of the widget ids in advanced_graphics_options.cfg static const std::vector scale_cases; diff --git a/src/gui/dialogs/attack_predictions.hpp b/src/gui/dialogs/attack_predictions.hpp index e3e0043aa8ac5..6a066ddcf9bcd 100644 --- a/src/gui/dialogs/attack_predictions.hpp +++ b/src/gui/dialogs/attack_predictions.hpp @@ -40,10 +40,7 @@ class attack_predictions : public modal_dialog public: attack_predictions(battle_context& bc, const unit& attacker, const unit& defender); - static void display(battle_context& bc, const unit& attacker, const unit& defender, CVideo& video) - { - attack_predictions(bc, attacker, defender).show(video); - } + DEFINE_SIMPLE_DISPLAY_WRAPPER(attack_predictions) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/edit_label.hpp b/src/gui/dialogs/edit_label.hpp index 3db8664215e07..e94ebf58f7482 100644 --- a/src/gui/dialogs/edit_label.hpp +++ b/src/gui/dialogs/edit_label.hpp @@ -41,11 +41,8 @@ class edit_label : public modal_dialog */ edit_label(std::string& label, bool& team_only); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(std::string& label, bool& team_only, CVideo& video) - { - return edit_label(label, team_only).show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(edit_label) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/edit_text.hpp b/src/gui/dialogs/edit_text.hpp index 3a6696324ab4c..c61102c5c9824 100644 --- a/src/gui/dialogs/edit_text.hpp +++ b/src/gui/dialogs/edit_text.hpp @@ -49,13 +49,7 @@ class edit_text : public modal_dialog * if this method returns @a true, undefined * otherwise. */ - static bool execute(const std::string& title, - const std::string& label, - std::string& text, - CVideo& video) - { - return edit_text(title, label, text).show(video); - } + DEFINE_SIMPLE_EXECUTE_WRAPPER(edit_text) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/editor/custom_tod.cpp b/src/gui/dialogs/editor/custom_tod.cpp index 258fa84768e47..1bbcf10e441d0 100644 --- a/src/gui/dialogs/editor/custom_tod.cpp +++ b/src/gui/dialogs/editor/custom_tod.cpp @@ -205,7 +205,7 @@ void custom_tod::select_file(window& window, const std::string& default_dir) .set_path(dn) .set_read_only(true); - if(dlg.show(window.video())) { + if(dlg.show()) { dn = dlg.path(); if(data.first == "image") { diff --git a/src/gui/dialogs/editor/custom_tod.hpp b/src/gui/dialogs/editor/custom_tod.hpp index 0d81c5474332a..16678fb2568d7 100644 --- a/src/gui/dialogs/editor/custom_tod.hpp +++ b/src/gui/dialogs/editor/custom_tod.hpp @@ -35,10 +35,8 @@ class custom_tod : public modal_dialog public: custom_tod(const std::vector& times, int current_time); - static bool execute(const std::vector& times, int current_time, CVideo& video) - { - return custom_tod(times, current_time).show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(custom_tod) using string_pair = std::pair; using tod_attribute_getter = std::function; diff --git a/src/gui/dialogs/editor/edit_label.hpp b/src/gui/dialogs/editor/edit_label.hpp index 50168d116c386..0fc899ab9c5c7 100644 --- a/src/gui/dialogs/editor/edit_label.hpp +++ b/src/gui/dialogs/editor/edit_label.hpp @@ -41,18 +41,8 @@ class editor_edit_label : public modal_dialog color_t& color, std::string& category); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(std::string& text, - bool& immutable, - bool& visible_fog, - bool& visible_shroud, - color_t& color, - std::string& category, - CVideo& video) - { - return editor_edit_label(text, immutable, visible_fog, visible_shroud, color, category) - .show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(editor_edit_label) private: color_t& color_store; diff --git a/src/gui/dialogs/editor/edit_scenario.hpp b/src/gui/dialogs/editor/edit_scenario.hpp index 7b71f3962339d..53074fb2bfd52 100644 --- a/src/gui/dialogs/editor/edit_scenario.hpp +++ b/src/gui/dialogs/editor/edit_scenario.hpp @@ -32,24 +32,8 @@ class editor_edit_scenario : public modal_dialog bool& victory_when_enemies_defeated, bool& random_start_time); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(std::string& id, - std::string& name, - std::string& description, - int& turns, - int& experience_modifier, - bool& victory_when_enemies_defeated, - bool& random_start_time, - CVideo& video) - { - return editor_edit_scenario(id, - name, - description, - turns, - experience_modifier, - victory_when_enemies_defeated, - random_start_time).show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(editor_edit_scenario) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/editor/edit_side.hpp b/src/gui/dialogs/editor/edit_side.hpp index 82548002f5bfc..65ff44dcd521a 100644 --- a/src/gui/dialogs/editor/edit_side.hpp +++ b/src/gui/dialogs/editor/edit_side.hpp @@ -32,11 +32,8 @@ class editor_edit_side : public modal_dialog public: explicit editor_edit_side(editor::editor_team_info& info); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(editor::editor_team_info& info, CVideo& video) - { - return editor_edit_side(info).show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(editor_edit_side) private: virtual void pre_show(window& window) override; diff --git a/src/gui/dialogs/editor/generator_settings.hpp b/src/gui/dialogs/editor/generator_settings.hpp index bc50756ca003f..e887e9b6c9b63 100644 --- a/src/gui/dialogs/editor/generator_settings.hpp +++ b/src/gui/dialogs/editor/generator_settings.hpp @@ -30,11 +30,8 @@ class generator_settings : public modal_dialog public: explicit generator_settings(generator_data& data); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(generator_data& data, CVideo& video) - { - return generator_settings(data).show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(generator_settings) private: virtual void pre_show(window& window) override; diff --git a/src/gui/dialogs/editor/new_map.hpp b/src/gui/dialogs/editor/new_map.hpp index 52817d4298f36..f42d969913a43 100644 --- a/src/gui/dialogs/editor/new_map.hpp +++ b/src/gui/dialogs/editor/new_map.hpp @@ -43,11 +43,8 @@ class editor_new_map : public modal_dialog */ editor_new_map(const t_string& title, int& width, int& height); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(const t_string& title, int& width, int& height, CVideo& video) - { - return editor_new_map(title, width, height).show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(editor_new_map) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/editor/resize_map.hpp b/src/gui/dialogs/editor/resize_map.hpp index 6e5c7f4cd72cd..a5d50137de220 100644 --- a/src/gui/dialogs/editor/resize_map.hpp +++ b/src/gui/dialogs/editor/resize_map.hpp @@ -72,17 +72,8 @@ class editor_resize_map : public modal_dialog EXPAND_DIRECTION& expand_direction, bool& copy_edge_terrain); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(int& width, - int& height, - EXPAND_DIRECTION& expand_direction, - bool& copy_edge_terrain, - CVideo& video) - { - return editor_resize_map( - width, height, expand_direction, copy_edge_terrain) - .show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(editor_resize_map) private: /** The currently selected width. */ diff --git a/src/gui/dialogs/end_credits.hpp b/src/gui/dialogs/end_credits.hpp index 33c3919aa938c..1b5331302e6e5 100644 --- a/src/gui/dialogs/end_credits.hpp +++ b/src/gui/dialogs/end_credits.hpp @@ -32,12 +32,9 @@ namespace dialogs class end_credits : public modal_dialog { public: - explicit end_credits(const std::string& campaign); + explicit end_credits(const std::string& campaign = ""); - static void display(CVideo& video, const std::string& campaign = "") - { - end_credits(campaign).show(video); - } + DEFINE_SIMPLE_DISPLAY_WRAPPER(end_credits) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/file_dialog.cpp b/src/gui/dialogs/file_dialog.cpp index f2c28cf0f364a..3bb6b9274535d 100644 --- a/src/gui/dialogs/file_dialog.cpp +++ b/src/gui/dialogs/file_dialog.cpp @@ -296,7 +296,7 @@ bool file_dialog::is_selection_type_acceptable(file_dialog::SELECTION_TYPE stype : stype == SELECTION_IS_FILE; } -bool file_dialog::confirm_overwrite(window& window, file_dialog::SELECTION_TYPE stype) +bool file_dialog::confirm_overwrite(window& /*window*/, file_dialog::SELECTION_TYPE stype) { // TODO: Adapt for implementing directory selection mode. if(stype != SELECTION_IS_FILE) { @@ -305,7 +305,7 @@ bool file_dialog::confirm_overwrite(window& window, file_dialog::SELECTION_TYPE const std::string& message = _("The file already exists. Do you wish to overwrite it?"); - return gui2::show_message(window.video(), _("Confirm"), message, message::yes_no_buttons) != gui2::window::CANCEL; + return gui2::show_message(_("Confirm"), message, message::yes_no_buttons) != gui2::window::CANCEL; } bool file_dialog::process_submit_common(window& window, const std::string& name) @@ -328,13 +328,13 @@ bool file_dialog::process_submit_common(window& window, const std::string& name) // We get here in save mode or not. Use the file creation language only in // save mode. if(save_mode_) { - show_transient_error_message(window.video(), vgettext("The file or folder $path cannot be created.", {{"path", name}})); + show_transient_error_message(vgettext("The file or folder $path cannot be created.", {{"path", name}})); break; } FALLTHROUGH; case SELECTION_NOT_FOUND: // We only get here if we aren't in save mode. - show_transient_error_message(window.video(), vgettext("The file or folder $path does not exist.", {{"path", name}})); + show_transient_error_message(vgettext("The file or folder $path does not exist.", {{"path", name}})); break; case SELECTION_IS_FILE: // TODO: Adapt for implementing directory selection mode. @@ -656,7 +656,7 @@ void file_dialog::on_bookmark_add_cmd(window& window) std::string label = default_label; - const bool confirm = bookmark_create::execute(label, window.video()); + const bool confirm = bookmark_create::execute(label); if(!confirm) { return; } @@ -705,11 +705,11 @@ void file_dialog::on_dir_create_cmd(window& window) { std::string new_dir_name; - if(folder_create::execute(new_dir_name, window.video())) { + if(folder_create::execute(new_dir_name)) { const std::string& new_path = concat_path(current_dir_, new_dir_name); if(!fs::make_directory(new_path)) { - show_transient_error_message(window.video(), + show_transient_error_message( vgettext("Could not create a new folder at $path|. Make sure you have the appropriate permissions to write to this location.", {{"path", new_path}})); } else { @@ -732,7 +732,7 @@ void file_dialog::on_file_delete_cmd(window& window) : _("The following file will be permanently deleted:")) + "\n\n" + selection + "\n\n" + _("Do you wish to continue?"); - if(gui2::show_message(window.video(), _("Confirm"), message, message::yes_no_buttons) == gui2::window::CANCEL) { + if(gui2::show_message(_("Confirm"), message, message::yes_no_buttons) == gui2::window::CANCEL) { return; } @@ -741,7 +741,7 @@ void file_dialog::on_file_delete_cmd(window& window) : fs::delete_file(selection); if(!result) { - show_transient_error_message(window.video(), + show_transient_error_message( vgettext("Could not delete $path|. Make sure you have the appropriate permissions to write to this location.", {{"path", selection}})); } else { diff --git a/src/gui/dialogs/folder_create.hpp b/src/gui/dialogs/folder_create.hpp index bd509da7a8919..8046a681a6c64 100644 --- a/src/gui/dialogs/folder_create.hpp +++ b/src/gui/dialogs/folder_create.hpp @@ -37,10 +37,7 @@ class folder_create : public modal_dialog folder_create(std::string& folder_name); /** The execute function; see @ref modal_dialog for more information. */ - static bool execute(std::string& folder_name, CVideo& video) - { - return folder_create(folder_name).show(video); - } + DEFINE_SIMPLE_EXECUTE_WRAPPER(folder_create) private: friend class bookmark_create; @@ -65,9 +62,9 @@ class bookmark_create { public: /** The execute function; see @ref modal_dialog for more information. */ - static bool execute(std::string& bookmark_name, CVideo& video) + static bool execute(std::string& bookmark_name) { - return folder_create(bookmark_name).enable_bookmark_mode().show(video); + return folder_create(bookmark_name).enable_bookmark_mode().show(); } }; diff --git a/src/gui/dialogs/game_cache_options.cpp b/src/gui/dialogs/game_cache_options.cpp index c598f075da559..c1b0f4d6a8458 100644 --- a/src/gui/dialogs/game_cache_options.cpp +++ b/src/gui/dialogs/game_cache_options.cpp @@ -113,13 +113,11 @@ void game_cache_options::pre_show(window& window) connect_signal_mouse_left_click(*clean_button_, std::bind(&game_cache_options::clean_cache_callback, - this, - std::ref(window.video()))); + this)); connect_signal_mouse_left_click(*purge_button_, std::bind(&game_cache_options::purge_cache_callback, - this, - std::ref(window.video()))); + this)); } void game_cache_options::post_show(window& /*window*/) @@ -158,15 +156,14 @@ void game_cache_options::browse_cache_callback() desktop::open_object(cache_path_); } -void game_cache_options::clean_cache_callback(CVideo& video) +void game_cache_options::clean_cache_callback() { if(clean_cache()) { - show_message(video, + show_message( _("Cache Cleaned"), _("The game data cache has been cleaned.")); } else { - show_error_message(video, - _("The game data cache could not be completely cleaned.")); + show_error_message(_("The game data cache could not be completely cleaned.")); } update_cache_size_display(); @@ -178,15 +175,14 @@ bool game_cache_options::clean_cache() return game_config::config_cache::instance().clean_cache(); } -void game_cache_options::purge_cache_callback(CVideo& video) +void game_cache_options::purge_cache_callback() { if(purge_cache()) { - show_message(video, + show_message( _("Cache Purged"), _("The game data cache has been purged.")); } else { - show_error_message(video, - _("The game data cache could not be purged.")); + show_error_message(_("The game data cache could not be purged.")); } update_cache_size_display(); diff --git a/src/gui/dialogs/game_cache_options.hpp b/src/gui/dialogs/game_cache_options.hpp index 2de2357d68b00..a7ce67986eb26 100644 --- a/src/gui/dialogs/game_cache_options.hpp +++ b/src/gui/dialogs/game_cache_options.hpp @@ -34,10 +34,7 @@ class game_cache_options : public modal_dialog * * See @ref modal_dialog for more information. */ - static void display(CVideo& video) - { - game_cache_options().show(video); - } + DEFINE_SIMPLE_DISPLAY_WRAPPER(game_cache_options) private: std::string cache_path_; @@ -46,10 +43,10 @@ class game_cache_options : public modal_dialog button* purge_button_; label* size_label_; - void clean_cache_callback(CVideo& video); + void clean_cache_callback(); bool clean_cache(); - void purge_cache_callback(CVideo& video); + void purge_cache_callback(); bool purge_cache(); void copy_to_clipboard_callback(); diff --git a/src/gui/dialogs/game_delete.hpp b/src/gui/dialogs/game_delete.hpp index 3b711007e5515..5cc9c448f1a5c 100644 --- a/src/gui/dialogs/game_delete.hpp +++ b/src/gui/dialogs/game_delete.hpp @@ -26,11 +26,8 @@ class game_delete : public modal_dialog public: game_delete(); - /** The execute function see @ref modal_dialog for more information. */ - static bool execute(CVideo& video) - { - return game_delete().show(video); - } + /** The execute function. See @ref modal_dialog for more information. */ + DEFINE_SIMPLE_EXECUTE_WRAPPER(game_delete) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/game_load.cpp b/src/gui/dialogs/game_load.cpp index 35fa8b9198b9e..4a56b7d92b4bf 100644 --- a/src/gui/dialogs/game_load.cpp +++ b/src/gui/dialogs/game_load.cpp @@ -364,7 +364,7 @@ void game_load::delete_button_callback(window& window) // See if we should ask the user for deletion confirmation if(preferences::ask_delete_saves()) { - if(!gui2::dialogs::game_delete::execute(window.video())) { + if(!gui2::dialogs::game_delete::execute()) { return; } } diff --git a/src/gui/dialogs/game_load.hpp b/src/gui/dialogs/game_load.hpp index a174840ac98ba..94327b02265b6 100644 --- a/src/gui/dialogs/game_load.hpp +++ b/src/gui/dialogs/game_load.hpp @@ -37,14 +37,14 @@ class game_load : public modal_dialog public: game_load(const config& cache_config, savegame::load_game_metadata& data); - static bool execute(const config& cache_config, savegame::load_game_metadata& data, CVideo& video) + static bool execute(const config& cache_config, savegame::load_game_metadata& data) { if(savegame::get_saves_list().empty()) { - gui2::show_transient_message(video, _("No Saved Games"), _("There are no save files to load")); + gui2::show_transient_message(_("No Saved Games"), _("There are no save files to load")); return false; } - return game_load(cache_config, data).show(video); + return game_load(cache_config, data).show(); } private: diff --git a/src/gui/dialogs/game_save.hpp b/src/gui/dialogs/game_save.hpp index db0ee936969f0..39b58fb6415cb 100644 --- a/src/gui/dialogs/game_save.hpp +++ b/src/gui/dialogs/game_save.hpp @@ -27,9 +27,9 @@ class game_save : public modal_dialog game_save(std::string& filename, const std::string& title); static bool - execute(std::string& filename, const std::string& title, CVideo& video) + execute(std::string& filename, const std::string& title) { - return game_save(filename, title).show(video); + return game_save(filename, title).show(); } private: @@ -44,13 +44,7 @@ class game_save_message : public modal_dialog const std::string& title, const std::string& message); - static bool execute(std::string& filename, - const std::string& title, - const std::string& message, - CVideo& video) - { - return game_save_message(filename, title, message).show(video); - } + DEFINE_SIMPLE_EXECUTE_WRAPPER(game_save_message) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ @@ -65,14 +59,7 @@ class game_save_oos : public modal_dialog const std::string& title, const std::string& message); - static bool execute(bool& ignore_all, - std::string& filename, - const std::string& title, - const std::string& message, - CVideo& video) - { - return game_save_oos(ignore_all, filename, title, message).show(video); - } + DEFINE_SIMPLE_EXECUTE_WRAPPER(game_save_oos) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/game_stats.hpp b/src/gui/dialogs/game_stats.hpp index bdf000e16de71..ecd1a0fc686e0 100644 --- a/src/gui/dialogs/game_stats.hpp +++ b/src/gui/dialogs/game_stats.hpp @@ -37,14 +37,14 @@ class game_stats : public modal_dialog public: game_stats(const display_context& board, const int viewing_team, int& selected_index); - static bool execute(game_board& board, const int viewing_team, int& selected_index, CVideo& video) + static bool execute(game_board& board, const int viewing_team, int& selected_index) { if(std::all_of(board.teams().begin(), board.teams().end(), [](team& team) { return team.hidden(); })) { - show_transient_message(video, "", _("No visible sides found.")); + show_transient_message("", _("No visible sides found.")); return false; } - return game_stats(board, viewing_team, selected_index).show(video); + return game_stats(board, viewing_team, selected_index).show(); } private: diff --git a/src/gui/dialogs/game_version.hpp b/src/gui/dialogs/game_version.hpp index 78440c47cf481..5ac05bd06cdf3 100644 --- a/src/gui/dialogs/game_version.hpp +++ b/src/gui/dialogs/game_version.hpp @@ -48,10 +48,7 @@ class game_version : public modal_dialog * * See @ref modal_dialog for more information. */ - static void display(CVideo& video) - { - game_version().show(video); - } + DEFINE_SIMPLE_DISPLAY_WRAPPER(game_version) private: const std::string path_wid_stem_; diff --git a/src/gui/dialogs/gamestate_inspector.cpp b/src/gui/dialogs/gamestate_inspector.cpp index c7c254636cdca..31a6e5cd77b79 100644 --- a/src/gui/dialogs/gamestate_inspector.cpp +++ b/src/gui/dialogs/gamestate_inspector.cpp @@ -348,7 +348,7 @@ class gamestate_inspector::controller void handle_lua_button_clicked(window& window) { - lua_interpreter::display(window.video(), lua_interpreter::GAME); + lua_interpreter::display(lua_interpreter::GAME); // The game state could've changed, so reset the dialog callbacks.clear(); controllers.clear(); diff --git a/src/gui/dialogs/help_browser.hpp b/src/gui/dialogs/help_browser.hpp index 88e64c639edfd..9258bf8282d40 100644 --- a/src/gui/dialogs/help_browser.hpp +++ b/src/gui/dialogs/help_browser.hpp @@ -30,10 +30,7 @@ class help_browser : public modal_dialog public: help_browser(); - static void display(CVideo& video) - { - help_browser().show(video); - } + DEFINE_SIMPLE_DISPLAY_WRAPPER(help_browser) private: std::string initial_topic_; diff --git a/src/gui/dialogs/label_settings.cpp b/src/gui/dialogs/label_settings.cpp index 01fa09aae91c1..1f99394312b6b 100644 --- a/src/gui/dialogs/label_settings.cpp +++ b/src/gui/dialogs/label_settings.cpp @@ -113,9 +113,9 @@ void label_settings::pre_show(window& window) { } } -bool label_settings::execute(display_context& dc, CVideo& video) { +bool label_settings::execute(display_context& dc) { label_settings window(dc); - if(!window.show(video)) return false; + if(!window.show()) return false; std::vector hidden_categories; for(auto lbl : window.all_labels) { if(lbl.second == false) { diff --git a/src/gui/dialogs/label_settings.hpp b/src/gui/dialogs/label_settings.hpp index 835c02f84e009..8f570906b0ca8 100644 --- a/src/gui/dialogs/label_settings.hpp +++ b/src/gui/dialogs/label_settings.hpp @@ -32,7 +32,7 @@ class label_settings : public modal_dialog { * * See @ref modal_dialog for more information. */ - static bool execute(display_context& dc, CVideo& video); + static bool execute(display_context& dc); private: std::map all_labels; std::map labels_display; diff --git a/src/gui/dialogs/loading_screen.cpp b/src/gui/dialogs/loading_screen.cpp index 69640fd297edb..26040a1627d00 100644 --- a/src/gui/dialogs/loading_screen.cpp +++ b/src/gui/dialogs/loading_screen.cpp @@ -220,9 +220,9 @@ void loading_screen::display(CVideo& video, std::function f) if(current_load || video.faked()) { f(); } else if(use_loadingscreen_animation) { - loading_screen(f).show(video); + loading_screen(f).show(); } else { - loading_screen(std::function()).show(video); + loading_screen(std::function()).show(); f(); } } diff --git a/src/gui/dialogs/log_settings.hpp b/src/gui/dialogs/log_settings.hpp index b8388882b07f9..81d6ffff9f3cc 100644 --- a/src/gui/dialogs/log_settings.hpp +++ b/src/gui/dialogs/log_settings.hpp @@ -35,11 +35,7 @@ class log_settings : public modal_dialog * * See @ref modal_dialog for more information. */ - static void display(CVideo& video) - { - log_settings().show(video); - } - + DEFINE_SIMPLE_DISPLAY_WRAPPER(log_settings) private: void set_logger(const std::basic_string log_domain); diff --git a/src/gui/dialogs/lua_interpreter.cpp b/src/gui/dialogs/lua_interpreter.cpp index edc02feb202c9..7c1c905531110 100644 --- a/src/gui/dialogs/lua_interpreter.cpp +++ b/src/gui/dialogs/lua_interpreter.cpp @@ -675,7 +675,7 @@ void lua_interpreter::controller::search(int direction) // Dialog implementation /** Display a new console, using given video and lua kernel */ -void lua_interpreter::display(CVideo& video, lua_kernel_base * lk) { +void lua_interpreter::display(lua_kernel_base * lk) { #ifndef ALWAYS_HAVE_LUA_CONSOLE if(!game_config::debug) { return; @@ -686,15 +686,15 @@ void lua_interpreter::display(CVideo& video, lua_kernel_base * lk) { return; } - lua_interpreter(*lk).show(video); + lua_interpreter(*lk).show(); } /** Helper function to assist those callers which don't want to include resources.hpp */ -void lua_interpreter::display(CVideo& video, lua_interpreter::WHICH_KERNEL which) { +void lua_interpreter::display(lua_interpreter::WHICH_KERNEL which) { if (which == lua_interpreter::APP) { - display(video, plugins_manager::get()->get_kernel_base()); + display(plugins_manager::get()->get_kernel_base()); } else if (which == lua_interpreter::GAME) { - display(video, resources::lua_kernel); + display(resources::lua_kernel); } } diff --git a/src/gui/dialogs/lua_interpreter.hpp b/src/gui/dialogs/lua_interpreter.hpp index 45b2ef5f954a4..93f3f3dd062e1 100644 --- a/src/gui/dialogs/lua_interpreter.hpp +++ b/src/gui/dialogs/lua_interpreter.hpp @@ -37,8 +37,8 @@ class lua_interpreter : public modal_dialog virtual void pre_show(window& window) override; enum WHICH_KERNEL { APP, GAME }; - static void display(CVideo& video, lua_kernel_base * lk); - static void display(CVideo& video, WHICH_KERNEL which); + static void display(lua_kernel_base * lk); + static void display(WHICH_KERNEL which); private: const std::unique_ptr controller_; diff --git a/src/gui/dialogs/message.cpp b/src/gui/dialogs/message.cpp index b6597bc364eff..8f9ec2ba3a38b 100644 --- a/src/gui/dialogs/message.cpp +++ b/src/gui/dialogs/message.cpp @@ -149,8 +149,7 @@ message::button_status::button_status() using namespace dialogs; -void show_message(CVideo& video, - const std::string& title, +void show_message(const std::string& title, const std::string& msg, const std::string& button_caption, const bool auto_close, @@ -159,11 +158,10 @@ void show_message(CVideo& video, { message dlg(title, msg, auto_close, message_use_markup, title_use_markup); dlg.set_button_caption(message::ok, button_caption); - dlg.show(video); + dlg.show(); } -int show_message(CVideo& video, - const std::string& title, +int show_message(const std::string& title, const std::string& msg, const message::button_style button_style, bool message_use_markup, @@ -200,16 +198,15 @@ int show_message(CVideo& video, break; } - dlg.show(video); + dlg.show(); return dlg.get_retval(); } -void show_error_message(CVideo& video, - const std::string& msg, +void show_error_message(const std::string& msg, bool message_use_markup) { LOG_STREAM(err, lg::general()) << msg << '\n'; - (void) show_message(video, + (void) show_message( _("Error"), msg, message::ok_button, diff --git a/src/gui/dialogs/message.hpp b/src/gui/dialogs/message.hpp index 2712edaf3cb67..b435d509f5aed 100644 --- a/src/gui/dialogs/message.hpp +++ b/src/gui/dialogs/message.hpp @@ -166,7 +166,6 @@ class message : public modal_dialog * Normally the dialog won't have a button only when the text doesn't fit in * the dialog and a scrollbar is used the button will be shown. * - * @param video The video which contains the surface to draw upon. * @param title The title of the dialog. * @param message The message to show in the dialog. * @param button_caption The caption of the close button. @@ -176,8 +175,7 @@ class message : public modal_dialog * @param message_use_markup Use markup for the message? * @param title_use_markup Use markup for the title? */ -void show_message(CVideo& video, - const std::string& title, +void show_message(const std::string& title, const std::string& message, const std::string& button_caption = "", const bool auto_close = true, @@ -190,8 +188,6 @@ void show_message(CVideo& video, * @note this function is rather untested, and the API might change in the * near future. * - * @param video The video which contains the surface to draw - * upon. * @param title The title of the dialog. * @param message The message to show in the dialog. * @param button_style The style of the button(s) shown. @@ -200,8 +196,7 @@ void show_message(CVideo& video, * * @returns The retval of the dialog shown. */ -int show_message(CVideo& video, - const std::string& title, +int show_message(const std::string& title, const std::string& message, const dialogs::message::button_style button_style, bool message_use_markup = false, @@ -210,13 +205,10 @@ int show_message(CVideo& video, /** * Shows an error message to the user. * - * @param video The video which contains the surface to draw - * upon. * @param message The message to show in the dialog. * @param message_use_markup Use markup for the message? */ -void show_error_message(CVideo& video, - const std::string& message, +void show_error_message(const std::string& message, bool message_use_markup = false); } // namespace gui2 diff --git a/src/gui/dialogs/modal_dialog.cpp b/src/gui/dialogs/modal_dialog.cpp index 22537251abdc9..792877b6165c8 100644 --- a/src/gui/dialogs/modal_dialog.cpp +++ b/src/gui/dialogs/modal_dialog.cpp @@ -54,9 +54,9 @@ namespace { }; } -bool modal_dialog::show(CVideo& video, const unsigned auto_close_time) +bool modal_dialog::show(const unsigned auto_close_time) { - if(video.faked() && !show_even_without_video_) { + if(CVideo::get_singleton().faked() && !show_even_without_video_) { if(!allow_plugin_skip_) { return false; } @@ -73,7 +73,7 @@ bool modal_dialog::show(CVideo& video, const unsigned auto_close_time) return false; } - window_.reset(build_window(video)); + window_.reset(build_window()); assert(window_.get()); post_build(*window_); @@ -216,9 +216,9 @@ field_label* modal_dialog::register_label(const std::string& id, return field; } -window* modal_dialog::build_window(CVideo& video) const +window* modal_dialog::build_window() const { - return build(video, window_id()); + return build(window_id()); } void modal_dialog::post_build(window& /*window*/) diff --git a/src/gui/dialogs/modal_dialog.hpp b/src/gui/dialogs/modal_dialog.hpp index 0bc632ad1fd70..6cb6993f1358e 100644 --- a/src/gui/dialogs/modal_dialog.hpp +++ b/src/gui/dialogs/modal_dialog.hpp @@ -27,7 +27,6 @@ namespace gui2 { namespace dialogs { - /** * Registers a window. * @@ -41,23 +40,21 @@ namespace dialogs * the same window so the id doesn't need to be * unique. */ -#define REGISTER_WINDOW(id) \ - namespace \ - { \ - \ - namespace ns_##id \ - { \ - \ - struct register_helper \ - { \ - register_helper() \ - { \ - register_window(#id); \ - } \ - }; \ - \ - struct register_helper register_helper; \ - } \ +#define REGISTER_WINDOW(id) \ + namespace \ + { \ + namespace ns_##id \ + { \ + struct register_helper \ + { \ + register_helper() \ + { \ + register_window(#id); \ + } \ + }; \ + \ + struct register_helper register_helper; \ + } \ } /** @@ -79,11 +76,11 @@ namespace dialogs * the same window so the id doesn't need to be * unique. */ -#define REGISTER_DIALOG2(type, id) \ - REGISTER_WINDOW(id) const std::string& type::window_id() const \ - { \ - static const std::string result(#id); \ - return result; \ +#define REGISTER_DIALOG2(type, id) \ + REGISTER_WINDOW(id) const std::string& type::window_id() const \ + { \ + static const std::string result(#id); \ + return result; \ } /** @@ -93,6 +90,34 @@ namespace dialogs */ #define REGISTER_DIALOG(window_id) REGISTER_DIALOG2(window_id, window_id) +/** + * Adds a bare-bones static `display` function to a dialog class that immediately + * invokes the dialogs's @ref modal_dialog::show function. If more complex behavior + * is desired, the function should be defined manually. + * + * See the @ref modal_dialog documentation (below) for more info. + */ +#define DEFINE_SIMPLE_DISPLAY_WRAPPER(dialog) \ + template \ + static void display(T&&... args) \ + { \ + dialog(std::forward(args)...).show(); \ + } + +/** + * Adds a bare-bonesstatic `execute` function to a dialog class that immediately + * invokes and return the result of the dialogs's @ref modal_dialog::show function. + * If more complex behavior is desired, the function should be defined manually. + * + * See the @ref modal_dialog documentation (below) for more info. + */ +#define DEFINE_SIMPLE_EXECUTE_WRAPPER(dialog) \ + template \ + static bool execute(T&&... args) \ + { \ + return dialog(std::forward(args)...).show(); \ + } + /** * Abstract base class for all modal dialogs. * @@ -147,7 +172,7 @@ class modal_dialog * * @returns Whether the final retval_ == window::OK */ - bool show(CVideo& video, const unsigned auto_close_time = 0); + bool show(const unsigned auto_close_time = 0); /***** ***** ***** setters / getters for members ***** ****** *****/ @@ -372,7 +397,7 @@ class modal_dialog * upon. * @returns The window to show. */ - window* build_window(CVideo& video) const; + window* build_window() const; /** * Actions to be taken directly after the window is build. diff --git a/src/gui/dialogs/modeless_dialog.cpp b/src/gui/dialogs/modeless_dialog.cpp index 2c065e8ea9335..ab609cd1f9829 100644 --- a/src/gui/dialogs/modeless_dialog.cpp +++ b/src/gui/dialogs/modeless_dialog.cpp @@ -33,17 +33,15 @@ modeless_dialog::~modeless_dialog() hide(); } -void modeless_dialog::show(CVideo& video, - const bool allow_interaction, - const unsigned /*auto_close_time*/) +void modeless_dialog::show(const bool allow_interaction, const unsigned /*auto_close_time*/) { - if(video.faked()) { + if(CVideo::get_singleton().faked()) { return; } hide(); - window_.reset(build_window(video)); + window_.reset(build_window()); post_build(*window_); @@ -69,9 +67,9 @@ void modeless_dialog::hide() window_.reset(nullptr); } } -window* modeless_dialog::build_window(CVideo& video) const +window* modeless_dialog::build_window() const { - return build(video, window_id()); + return build(window_id()); } void modeless_dialog::post_build(window& /*window*/) diff --git a/src/gui/dialogs/modeless_dialog.hpp b/src/gui/dialogs/modeless_dialog.hpp index 3f629c06c2da2..48d9017aeab32 100644 --- a/src/gui/dialogs/modeless_dialog.hpp +++ b/src/gui/dialogs/modeless_dialog.hpp @@ -59,8 +59,6 @@ class modeless_dialog /** * Shows the window. * - * @param video The video which contains the surface to draw - * upon. * @param allow_interaction Does the dialog allow interaction? * * true a non modal window is shown * * false a tooltip window is shown @@ -70,8 +68,7 @@ class modeless_dialog * there's no guarantee about how fast it closes * after the minimum. */ - void show(CVideo& video, - const bool allow_interaction = false, + void show(const bool allow_interaction = false, const unsigned auto_close_time = 0); @@ -102,11 +99,9 @@ class modeless_dialog * Every dialog shows it's own kind of window, this function should return * the window to show. * - * @param video The video which contains the surface to draw - * upon. * @returns The window to show. */ - window* build_window(CVideo& video) const; + window* build_window() const; /** * Actions to be taken directly after the window is build. diff --git a/src/gui/dialogs/multiplayer/lobby.cpp b/src/gui/dialogs/multiplayer/lobby.cpp index e52bba87178dd..708b52808cb2b 100644 --- a/src/gui/dialogs/multiplayer/lobby.cpp +++ b/src/gui/dialogs/multiplayer/lobby.cpp @@ -245,7 +245,7 @@ bool handle_addon_requirements_gui(CVideo& v, const std::vector 0); - if(gui2::show_message(v, e_title, err_msg, message::yes_no_buttons, true) == gui2::window::OK) { + if(gui2::show_message(e_title, err_msg, message::yes_no_buttons, true) == gui2::window::OK) { // Begin download session ad_hoc_addon_fetch_session(v, needs_download); @@ -950,7 +950,7 @@ void mp_lobby::enter_game(const mp::game_info& game, JOIN_MODE mode) // Prompt user to download this game's required addons if its requirements have not been met if(game.addons_outcome != mp::game_info::SATISFIED) { if(game.required_addons.empty()) { - gui2::show_error_message(window.video(), _("Something is wrong with the addon version check database supporting the multiplayer lobby. Please report this at http://bugs.wesnoth.org.")); + gui2::show_error_message(_("Something is wrong with the addon version check database supporting the multiplayer lobby. Please report this at http://bugs.wesnoth.org.")); return; } @@ -973,7 +973,7 @@ void mp_lobby::enter_game(const mp::game_info& game, JOIN_MODE mode) if(!join_data.empty() && try_join && game.password_required) { std::string password; - if(!gui2::dialogs::mp_join_game_password_prompt::execute(password, window.video())) { + if(!gui2::dialogs::mp_join_game_password_prompt::execute(password)) { return; } @@ -1114,7 +1114,7 @@ void mp_lobby::user_dialog_callback(mp::user_info* info) lobby_delay_gamelist_update_guard g(*this); - dlg.show(get_window()->video()); + dlg.show(); delay_playerlist_update_ = true; diff --git a/src/gui/dialogs/multiplayer/mp_alerts_options.hpp b/src/gui/dialogs/multiplayer/mp_alerts_options.hpp index 200991f3eefb8..a2c99dbcc1eb2 100644 --- a/src/gui/dialogs/multiplayer/mp_alerts_options.hpp +++ b/src/gui/dialogs/multiplayer/mp_alerts_options.hpp @@ -33,10 +33,7 @@ class mp_alerts_options : public modal_dialog * * See @ref modal_dialog for more information. */ - static void display(CVideo& video) - { - mp_alerts_options().show(video); - } + DEFINE_SIMPLE_DISPLAY_WRAPPER(mp_alerts_options) private: /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */ diff --git a/src/gui/dialogs/multiplayer/mp_connect.cpp b/src/gui/dialogs/multiplayer/mp_connect.cpp index 3aede09cff237..6eb6b25f9a316 100644 --- a/src/gui/dialogs/multiplayer/mp_connect.cpp +++ b/src/gui/dialogs/multiplayer/mp_connect.cpp @@ -152,12 +152,12 @@ void mp_server_list::post_show(window& window) REGISTER_DIALOG(mp_connect) static void -show_server_list(CVideo& video, window& window, field_text* host_name) +show_server_list(window& window, field_text* host_name) { assert(host_name); mp_server_list dlg; - dlg.show(video); + dlg.show(); if(dlg.get_retval() == window::OK) { host_name->set_widget_value(window, dlg.host_name()); @@ -182,10 +182,7 @@ void mp_connect::pre_show(window& win) if(button* btn = find_widget