fix quit confirmation promt in editor

previously it showed the default "do you want to quit the game" message
when leaving the editor. using the red cross in the corner.

This also changes some dublication of the "Do you really want to quit?"
translatable string in the c++ code.
This commit is contained in:
gfgtdf 2016-02-23 20:32:12 +01:00
parent df45dd9aab
commit 0484fdd414
9 changed files with 50 additions and 44 deletions

View file

@ -54,7 +54,7 @@ namespace hotkey { class command_executor; }
namespace soundsource { class manager; }
class controller_base : public events::sdl_handler, quit_confirmation
class controller_base : public events::sdl_handler
{
public:
controller_base(const config& game_config, CVideo& video);

View file

@ -63,6 +63,7 @@ namespace editor {
editor_controller::editor_controller(const config &game_config, CVideo& video)
: controller_base(game_config, video)
, mouse_handler_base()
, quit_confirmation(boost::bind(&editor_controller::quit_confirm, this))
, active_menu_(editor::MAP)
, reports_(new reports())
, gui_(new editor_display(editor::get_dummy_display_context(), video, *reports_, controller_base::get_theme(game_config, "editor"), config()))
@ -199,7 +200,7 @@ void editor_controller::do_screenshot(const std::string& screenshot_filename /*
}
}
void editor_controller::quit_confirm(EXIT_STATUS mode)
bool editor_controller::quit_confirm()
{
std::string modified;
size_t amount = context_manager_->modified_maps(modified);
@ -213,11 +214,7 @@ void editor_controller::quit_confirm(EXIT_STATUS mode)
message = _("Do you really want to quit? The following maps were modified and all changes since the last save will be lost:");
message += modified;
}
const int res = gui2::show_message(gui().video(), _("Quit"), message, gui2::tmessage::yes_no_buttons);
if(res != gui2::twindow::CANCEL) {
do_quit_ = true;
quit_mode_ = mode;
}
return gui2::show_message(gui().video(), _("Quit"), message, gui2::tmessage::yes_no_buttons) != gui2::twindow::CANCEL;
}
void editor_controller::custom_tods_dialog()
@ -720,10 +717,16 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
return true;
case HOTKEY_QUIT_GAME:
quit_confirm(EXIT_NORMAL);
if(quit_confirm()) {
do_quit_ = true;
quit_mode_ = EXIT_NORMAL;
}
return true;
case HOTKEY_QUIT_TO_DESKTOP:
quit_confirm(EXIT_QUIT_TO_DESKTOP);
if(quit_confirm()) {
do_quit_ = true;
quit_mode_ = EXIT_QUIT_TO_DESKTOP;
}
return true;
case TITLE_SCREEN__RELOAD_WML:
context_manager_->save_all_maps(true);

View file

@ -72,7 +72,8 @@ enum menu_type {
class editor_controller : public controller_base,
public hotkey::command_executor_default,
public events::mouse_handler_base,
private boost::noncopyable
private boost::noncopyable,
quit_confirmation
{
public:
/**
@ -94,8 +95,8 @@ class editor_controller : public controller_base,
/** Process a hotkey quit command */
void hotkey_quit();
/** Show a quit confirmation dialog and if confirmed quit with the given exit status */
void quit_confirm(EXIT_STATUS status);
/** Show a quit confirmation dialog and returns true if the user pressed 'yes' */
bool quit_confirm();
/** Display the settings dialog, used to control e.g. the lighting settings */
void custom_tods_dialog();

View file

@ -19,7 +19,7 @@
#include "gui/widgets/button.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "quit_confirmation.hpp"
#include "message.hpp"
#include "../../game_end_exceptions.hpp"
@ -97,11 +97,9 @@ void tsynced_choice_wait::handle_generic_event(const std::string& event_name)
}
}
void tsynced_choice_wait::on_btn_quit_game(CVideo& video)
void tsynced_choice_wait::on_btn_quit_game(CVideo&)
{
const int res = gui2::show_message(video, _("Quit"),
_("Do you really want to quit?"), gui2::tmessage::yes_no_buttons);
if (res != gui2::twindow::CANCEL) {
if (quit_confirmation::default_promt()) {
throw_quit_game_exception();
}
}

View file

@ -30,6 +30,7 @@
#include "preferences.hpp"
#include "game_end_exceptions.hpp"
#include "display.hpp"
#include "quit_confirmation.hpp"
#include <boost/function.hpp>
#include <boost/bind.hpp>
@ -697,7 +698,7 @@ void command_executor_default::map_screenshot()
}
void command_executor_default::quit_to_desktop()
{
if(gui2::show_message(get_video(), _("Quit"), _("Do you really want to quit?"), gui2::tmessage::yes_no_buttons) != gui2::twindow::CANCEL) {
if(quit_confirmation::default_promt()) {
throw CVideo::quit();
}
}
@ -707,7 +708,7 @@ void command_executor::quit_to_desktop()
}
void command_executor_default::quit_to_main_menu()
{
if(gui2::show_message(get_video(), _("Quit"), _("Do you really want to quit?"), gui2::tmessage::yes_no_buttons) != gui2::twindow::CANCEL) {
if(quit_confirmation::default_promt()) {
throw_quit_game_exception();
}
}

View file

@ -152,6 +152,7 @@ play_controller::play_controller(const config& level, saved_game& state_of_game,
: controller_base(game_config, video)
, observer()
, savegame_config()
, quit_confirmation()
, ticks_(SDL_GetTicks())
, tdata_(tdata)
, gamestate_()

View file

@ -80,7 +80,7 @@ namespace wb {
// Holds gamestate related objects
class game_state;
class play_controller : public controller_base, public events::observer, public savegame::savegame_config
class play_controller : public controller_base, public events::observer, public savegame::savegame_config, quit_confirmation
{
public:
play_controller(const config& level, saved_game& state_of_game,

View file

@ -19,31 +19,27 @@
#include "gui/widgets/window.hpp"
#include "resources.hpp"
int quit_confirmation::count_ = 0;
std::vector<quit_confirmation*> quit_confirmation::blockers_ = std::vector<quit_confirmation*>();
bool quit_confirmation::open_ = false;
void quit_confirmation::quit()
{
if(count_ != 0 && !open_)
if(!open_)
{
quit(CVideo::get_singleton());
}
else
{
throw CVideo::quit();
open_ = true;
BOOST_REVERSE_FOREACH(quit_confirmation* blocker, blockers_)
{
if(!blocker->promt_()) {
open_ = false;
return;
}
}
open_ = false;
}
throw CVideo::quit();
}
void quit_confirmation::quit(CVideo& video)
bool quit_confirmation::default_promt()
{
assert(!open_);
open_ = true;
const int res = gui2::show_message(video, _("Quit"),
_("Do you really want to quit?"), gui2::tmessage::yes_no_buttons);
open_ = false;
if(res != gui2::twindow::CANCEL) {
throw CVideo::quit();
} else {
return;
}
return gui2::show_message(CVideo::get_singleton(), _("Quit"), _("Do you really want to quit?"), gui2::tmessage::yes_no_buttons) != gui2::twindow::CANCEL;
}

View file

@ -18,6 +18,9 @@
class CVideo;
#include <cassert>
#include <vector>
#include <boost/function.hpp>
#include <boost/bind.hpp>
/**
* Implements a quit confirmation dialog.
@ -28,9 +31,8 @@ class CVideo;
class quit_confirmation
{
public:
quit_confirmation() { ++count_; }
quit_confirmation(const quit_confirmation&) { ++count_; }
~quit_confirmation() { --count_; assert(count_ >= 0); }
quit_confirmation(const boost::function<bool()>& promt = &quit_confirmation::default_promt) : promt_(promt) { blockers_.push_back(this); }
~quit_confirmation() { blockers_.pop_back(); }
/**
* Shows the quit confirmation if needed.
@ -39,11 +41,15 @@ public:
* displayed.
*/
static void quit();
static void quit(CVideo& video );
static bool default_promt();
private:
static int count_;
//noncopyable
quit_confirmation( const quit_confirmation& );
const quit_confirmation& operator=( const quit_confirmation& );
static std::vector<quit_confirmation*> blockers_;
static bool open_;
boost::function<bool()> promt_;
};
#endif