Bunch of refactoring of editor quit handling
This commit is contained in:
parent
27d4091ec5
commit
7d0a02ec7d
7 changed files with 36 additions and 28 deletions
|
@ -49,6 +49,8 @@
|
|||
#include "../../unit.hpp"
|
||||
#include "../../unit_animation_component.hpp"
|
||||
|
||||
#include "quit_confirmation.hpp"
|
||||
|
||||
#include "halo.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -214,7 +216,7 @@ bool editor_controller::quit_confirm()
|
|||
message = _("Do you really want to quit? The following maps were modified and all changes since the last save will be lost:");
|
||||
message += modified;
|
||||
}
|
||||
return gui2::show_message(gui().video(), _("Quit"), message, gui2::tmessage::yes_no_buttons) != gui2::twindow::CANCEL;
|
||||
return quit_confirmation::show_prompt(message);
|
||||
}
|
||||
|
||||
void editor_controller::custom_tods_dialog()
|
||||
|
@ -717,16 +719,13 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
|
|||
return true;
|
||||
|
||||
case HOTKEY_QUIT_GAME:
|
||||
if(quit_confirm()) {
|
||||
if(quit_confirmation::quit()) {
|
||||
do_quit_ = true;
|
||||
quit_mode_ = EXIT_NORMAL;
|
||||
}
|
||||
return true;
|
||||
case HOTKEY_QUIT_TO_DESKTOP:
|
||||
if(quit_confirm()) {
|
||||
do_quit_ = true;
|
||||
quit_mode_ = EXIT_QUIT_TO_DESKTOP;
|
||||
}
|
||||
quit_confirmation::quit_to_desktop();
|
||||
return true;
|
||||
case TITLE_SCREEN__RELOAD_WML:
|
||||
context_manager_->save_all_maps(true);
|
||||
|
|
|
@ -499,7 +499,7 @@ void pump()
|
|||
#ifndef __APPLE__
|
||||
case SDL_KEYDOWN: {
|
||||
if(event.key.keysym.sym == SDLK_F4 && (event.key.keysym.mod == KMOD_RALT || event.key.keysym.mod == KMOD_LALT)) {
|
||||
quit_confirmation::quit();
|
||||
quit_confirmation::quit_to_desktop();
|
||||
continue; // this event is already handled
|
||||
}
|
||||
break;
|
||||
|
@ -522,7 +522,7 @@ void pump()
|
|||
#endif
|
||||
|
||||
case SDL_QUIT: {
|
||||
quit_confirmation::quit();
|
||||
quit_confirmation::quit_to_desktop();
|
||||
continue; //this event is already handled.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ void tsynced_choice_wait::pre_show(CVideo& video, twindow& window)
|
|||
&window, "btn_quit_game", false);
|
||||
|
||||
connect_signal_mouse_left_click(quit_button,
|
||||
boost::bind(&quit_confirmation::quit, false));
|
||||
boost::bind(&quit_confirmation::quit_to_title));
|
||||
|
||||
message_->set_label(mgr_.wait_message());
|
||||
if(mgr_.finished() || !mgr_.waiting()) {
|
||||
|
|
|
@ -313,10 +313,10 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/
|
|||
map_screenshot();
|
||||
break;
|
||||
case HOTKEY_QUIT_TO_DESKTOP:
|
||||
quit_confirmation::quit();
|
||||
quit_confirmation::quit_to_desktop();
|
||||
break;
|
||||
case HOTKEY_QUIT_GAME:
|
||||
quit_confirmation::quit(false);
|
||||
quit_confirmation::quit_to_title();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -23,30 +23,40 @@
|
|||
std::vector<quit_confirmation*> quit_confirmation::blockers_ = std::vector<quit_confirmation*>();
|
||||
bool quit_confirmation::open_ = false;
|
||||
|
||||
void quit_confirmation::quit(const bool full_exit)
|
||||
bool quit_confirmation::quit()
|
||||
{
|
||||
if(!open_)
|
||||
{
|
||||
if(!open_) {
|
||||
open_ = true;
|
||||
BOOST_REVERSE_FOREACH(quit_confirmation* blocker, blockers_)
|
||||
{
|
||||
if(!blocker->prompt_()) {
|
||||
open_ = false;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
open_ = false;
|
||||
}
|
||||
|
||||
if(!full_exit) {
|
||||
throw_quit_game_exception();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
throw CVideo::quit();
|
||||
void quit_confirmation::quit_to_title()
|
||||
{
|
||||
if(quit()) { throw_quit_game_exception(); }
|
||||
}
|
||||
|
||||
void quit_confirmation::quit_to_desktop()
|
||||
{
|
||||
if(quit()) { throw CVideo::quit(); }
|
||||
}
|
||||
|
||||
bool quit_confirmation::show_prompt(const std::string& message)
|
||||
{
|
||||
return gui2::show_message(CVideo::get_singleton(), _("Quit"), message,
|
||||
gui2::tmessage::yes_no_buttons) != gui2::twindow::CANCEL;
|
||||
}
|
||||
|
||||
bool quit_confirmation::default_prompt()
|
||||
{
|
||||
return gui2::show_message(CVideo::get_singleton(), _("Quit"), _("Do you really want to quit?"),
|
||||
gui2::tmessage::yes_no_buttons) != gui2::twindow::CANCEL;
|
||||
return show_prompt(_("Do you really want to quit?"));
|
||||
}
|
||||
|
|
|
@ -39,12 +39,14 @@ public:
|
|||
/**
|
||||
* Shows the quit confirmation if needed.
|
||||
*
|
||||
* @param full_exit Whether to quit fully to the desktop or simply
|
||||
* exit game. Defaults to true.
|
||||
* @throws CVideo::quit If the user chooses to quit or no prompt was
|
||||
* displayed.
|
||||
*/
|
||||
static void quit(const bool full_exit = true);
|
||||
static bool quit();
|
||||
static void quit_to_title();
|
||||
static void quit_to_desktop();
|
||||
|
||||
static bool show_prompt(const std::string& message);
|
||||
static bool default_prompt();
|
||||
|
||||
private:
|
||||
|
|
|
@ -861,10 +861,7 @@ static int do_gameloop(const std::vector<std::string>& args)
|
|||
image::flush_cache();
|
||||
continue;
|
||||
} else if(res == gui2::ttitle_screen::START_MAP_EDITOR) {
|
||||
///@todo editor can ask the game to quit completely
|
||||
if (game->start_editor() == editor::EXIT_QUIT_TO_DESKTOP) {
|
||||
return 0;
|
||||
}
|
||||
game->start_editor();
|
||||
continue;
|
||||
}
|
||||
game->launch_game(should_reload);
|
||||
|
|
Loading…
Add table
Reference in a new issue