Add flag to quit_confirmation::quit() to only quit out of game

This commit is contained in:
Charles Dang 2016-02-24 10:30:48 +11:00
parent f067332d0f
commit ed9ead2ac9
6 changed files with 17 additions and 23 deletions

View file

@ -76,10 +76,8 @@ void tsynced_choice_wait::pre_show(CVideo& video, twindow& window)
tbutton& quit_button = find_widget<tbutton>( tbutton& quit_button = find_widget<tbutton>(
&window, "btn_quit_game", false); &window, "btn_quit_game", false);
connect_signal_mouse_left_click( connect_signal_mouse_left_click(quit_button,
quit_button, boost::bind(&quit_confirmation::quit, false));
boost::bind(&tsynced_choice_wait::on_btn_quit_game, this, boost::ref(video))
);
message_->set_label(mgr_.wait_message()); message_->set_label(mgr_.wait_message());
if(mgr_.finished() || !mgr_.waiting()) { if(mgr_.finished() || !mgr_.waiting()) {
@ -97,11 +95,4 @@ void tsynced_choice_wait::handle_generic_event(const std::string& event_name)
} }
} }
void tsynced_choice_wait::on_btn_quit_game(CVideo&)
{
if (quit_confirmation::default_prompt()) {
throw_quit_game_exception();
}
}
} }

View file

@ -38,7 +38,6 @@ private:
void pre_show(CVideo& video, twindow& window); void pre_show(CVideo& video, twindow& window);
virtual void handle_generic_event(const std::string& event_name); virtual void handle_generic_event(const std::string& event_name);
void on_btn_quit_game(CVideo& video);
}; };
} }

View file

@ -316,7 +316,7 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/
quit_confirmation::quit(); quit_confirmation::quit();
break; break;
case HOTKEY_QUIT_GAME: case HOTKEY_QUIT_GAME:
quit_to_main_menu(); quit_confirmation::quit(false);
break; break;
default: default:
return false; return false;
@ -696,10 +696,4 @@ void command_executor_default::map_screenshot()
{ {
make_screenshot(_("Map-Screenshot"), get_video(), boost::bind(&display::screenshot, &get_display(), _1, true)); make_screenshot(_("Map-Screenshot"), get_video(), boost::bind(&display::screenshot, &get_display(), _1, true));
} }
void command_executor_default::quit_to_main_menu()
{
if(quit_confirmation::default_prompt()) {
throw_quit_game_exception();
}
}
} }

View file

@ -113,7 +113,6 @@ public:
virtual void zoom_out() {} virtual void zoom_out() {}
virtual void zoom_default() {} virtual void zoom_default() {}
virtual void map_screenshot() {} virtual void map_screenshot() {}
virtual void quit_to_main_menu() {}
virtual void set_button_state() {} virtual void set_button_state() {}
virtual void recalculate_minimap() {} virtual void recalculate_minimap() {}

View file

@ -13,6 +13,7 @@
*/ */
#include "quit_confirmation.hpp" #include "quit_confirmation.hpp"
#include "game_end_exceptions.hpp"
#include "gettext.hpp" #include "gettext.hpp"
#include "video.hpp" #include "video.hpp"
#include "gui/dialogs/message.hpp" #include "gui/dialogs/message.hpp"
@ -22,7 +23,7 @@
std::vector<quit_confirmation*> quit_confirmation::blockers_ = std::vector<quit_confirmation*>(); std::vector<quit_confirmation*> quit_confirmation::blockers_ = std::vector<quit_confirmation*>();
bool quit_confirmation::open_ = false; bool quit_confirmation::open_ = false;
void quit_confirmation::quit() void quit_confirmation::quit(const bool full_exit)
{ {
if(!open_) if(!open_)
{ {
@ -36,6 +37,11 @@ void quit_confirmation::quit()
} }
open_ = false; open_ = false;
} }
if(!full_exit) {
throw_quit_game_exception();
}
throw CVideo::quit(); throw CVideo::quit();
} }

View file

@ -31,17 +31,22 @@ class CVideo;
class quit_confirmation class quit_confirmation
{ {
public: public:
quit_confirmation(const boost::function<bool()>& prompt = &quit_confirmation::default_prompt) : prompt_(prompt) { blockers_.push_back(this); } quit_confirmation(const boost::function<bool()>& promt = &quit_confirmation::default_prompt)
: prompt_(promt) { blockers_.push_back(this); }
~quit_confirmation() { blockers_.pop_back(); } ~quit_confirmation() { blockers_.pop_back(); }
/** /**
* Shows the quit confirmation if needed. * 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 * @throws CVideo::quit If the user chooses to quit or no prompt was
* displayed. * displayed.
*/ */
static void quit(); static void quit(const bool full_exit = true);
static bool default_prompt(); static bool default_prompt();
private: private:
//noncopyable //noncopyable
quit_confirmation( const quit_confirmation& ); quit_confirmation( const quit_confirmation& );