show confirmation dialog when quitting
when quitting (for example by clicking on the red cross in the corner) the game now asks for a confirmation, if there is currently a (re-)play or the editor running.
This commit is contained in:
parent
8db92e9af3
commit
0abde389dc
7 changed files with 58 additions and 2 deletions
|
@ -1104,6 +1104,7 @@ set(libwesnoth-game_STAT_SRC
|
|||
preferences.cpp
|
||||
preferences_display.cpp
|
||||
race.cpp
|
||||
quit_confirmation.cpp
|
||||
reports.cpp
|
||||
show_dialog.cpp
|
||||
simple_rng.cpp
|
||||
|
|
|
@ -117,6 +117,7 @@ libwesnoth_sources = Split("""
|
|||
pathutils.cpp
|
||||
preferences.cpp
|
||||
preferences_display.cpp
|
||||
quit_confirmation.cpp
|
||||
race.cpp
|
||||
reports.cpp
|
||||
show_dialog.cpp
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "hotkey/hotkey_command.hpp"
|
||||
#include "joystick.hpp"
|
||||
#include "key.hpp"
|
||||
#include "quit_confirmation.hpp"
|
||||
|
||||
class CVideo;
|
||||
class display;
|
||||
|
@ -53,7 +54,7 @@ namespace hotkey { class command_executor; }
|
|||
|
||||
namespace soundsource { class manager; }
|
||||
|
||||
class controller_base : public events::sdl_handler
|
||||
class controller_base : public events::sdl_handler, quit_confirmation
|
||||
{
|
||||
public:
|
||||
controller_base(const config& game_config, CVideo& video);
|
||||
|
|
|
@ -229,6 +229,8 @@ display::display(const display_context * dc, CVideo& video, boost::weak_ptr<wb::
|
|||
, do_reverse_memcpy_workaround_(false)
|
||||
#endif
|
||||
{
|
||||
//The following assertion fails when starting a campaign
|
||||
//assert(singleton_ == NULL);
|
||||
singleton_ = this;
|
||||
|
||||
resources::fake_units = fake_unit_man_.get();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "events.hpp"
|
||||
#include "log.hpp"
|
||||
#include "sound.hpp"
|
||||
#include "quit_confirmation.hpp"
|
||||
#include "video.hpp"
|
||||
#if defined _WIN32
|
||||
#include "desktop/windows_tray_notification.hpp"
|
||||
|
@ -415,7 +416,7 @@ void pump()
|
|||
#endif
|
||||
|
||||
case SDL_QUIT: {
|
||||
throw CVideo::quit();
|
||||
quit_confirmation::quit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
35
src/quit_confirmation.cpp
Normal file
35
src/quit_confirmation.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
#include "quit_confirmation.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "display.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "resources.hpp"
|
||||
|
||||
int quit_confirmation::count_ = 0;
|
||||
bool quit_confirmation::open_ = false;
|
||||
void quit_confirmation::quit()
|
||||
{
|
||||
if(count_ != 0 && display::get_singleton() && !open_)
|
||||
{
|
||||
quit(display::get_singleton()->video());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw CVideo::quit();
|
||||
}
|
||||
}
|
||||
|
||||
void quit_confirmation::quit(CVideo& video)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
15
src/quit_confirmation.hpp
Normal file
15
src/quit_confirmation.hpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
class CVideo;
|
||||
|
||||
class quit_confirmation
|
||||
{
|
||||
public:
|
||||
quit_confirmation() { ++count_; }
|
||||
quit_confirmation(const quit_confirmation&) { ++count_; }
|
||||
~quit_confirmation() { --count_; }
|
||||
static void quit();
|
||||
static void quit(CVideo& video );
|
||||
private:
|
||||
static int count_;
|
||||
static bool open_;
|
||||
};
|
Loading…
Add table
Reference in a new issue