Skip to content

Commit

Permalink
Add flag to quit_confirmation::quit() to only quit out of game
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Feb 23, 2016
1 parent f067332 commit ed9ead2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
13 changes: 2 additions & 11 deletions src/gui/dialogs/synced_choice_wait.cpp
Expand Up @@ -76,10 +76,8 @@ void tsynced_choice_wait::pre_show(CVideo& video, twindow& window)
tbutton& quit_button = find_widget<tbutton>(
&window, "btn_quit_game", false);

connect_signal_mouse_left_click(
quit_button,
boost::bind(&tsynced_choice_wait::on_btn_quit_game, this, boost::ref(video))
);
connect_signal_mouse_left_click(quit_button,
boost::bind(&quit_confirmation::quit, false));

message_->set_label(mgr_.wait_message());
if(mgr_.finished() || !mgr_.waiting()) {
Expand All @@ -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();
}
}

}
1 change: 0 additions & 1 deletion src/gui/dialogs/synced_choice_wait.hpp
Expand Up @@ -38,7 +38,6 @@ class tsynced_choice_wait : public tdialog, public events::observer
void pre_show(CVideo& video, twindow& window);

virtual void handle_generic_event(const std::string& event_name);
void on_btn_quit_game(CVideo& video);
};
}

Expand Down
8 changes: 1 addition & 7 deletions src/hotkey/command_executor.cpp
Expand Up @@ -316,7 +316,7 @@ bool command_executor::execute_command(const hotkey_command& cmd, int /*index*/
quit_confirmation::quit();
break;
case HOTKEY_QUIT_GAME:
quit_to_main_menu();
quit_confirmation::quit(false);
break;
default:
return false;
Expand Down Expand Up @@ -696,10 +696,4 @@ void command_executor_default::map_screenshot()
{
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();
}
}
}
1 change: 0 additions & 1 deletion src/hotkey/command_executor.hpp
Expand Up @@ -113,7 +113,6 @@ class command_executor
virtual void zoom_out() {}
virtual void zoom_default() {}
virtual void map_screenshot() {}
virtual void quit_to_main_menu() {}

virtual void set_button_state() {}
virtual void recalculate_minimap() {}
Expand Down
8 changes: 7 additions & 1 deletion src/quit_confirmation.cpp
Expand Up @@ -13,6 +13,7 @@
*/

#include "quit_confirmation.hpp"
#include "game_end_exceptions.hpp"
#include "gettext.hpp"
#include "video.hpp"
#include "gui/dialogs/message.hpp"
Expand All @@ -22,7 +23,7 @@
std::vector<quit_confirmation*> quit_confirmation::blockers_ = std::vector<quit_confirmation*>();
bool quit_confirmation::open_ = false;

void quit_confirmation::quit()
void quit_confirmation::quit(const bool full_exit)
{
if(!open_)
{
Expand All @@ -36,6 +37,11 @@ void quit_confirmation::quit()
}
open_ = false;
}

if(!full_exit) {
throw_quit_game_exception();
}

throw CVideo::quit();
}

Expand Down
9 changes: 7 additions & 2 deletions src/quit_confirmation.hpp
Expand Up @@ -31,17 +31,22 @@ class CVideo;
class quit_confirmation
{
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(); }

/**
* 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();
static void quit(const bool full_exit = true);
static bool default_prompt();

private:
//noncopyable
quit_confirmation( const quit_confirmation& );
Expand Down

0 comments on commit ed9ead2

Please sign in to comment.