/
quit_confirmation.cpp
63 lines (52 loc) · 1.55 KB
/
quit_confirmation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Copyright (C) 2015 - 2017 by the Battle for Wesnoth Project
<http://www.wesnoth.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "quit_confirmation.hpp"
#include "game_end_exceptions.hpp"
#include "gettext.hpp"
#include "video.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/widgets/window.hpp"
#include <boost/range/adaptor/reversed.hpp>
std::vector<quit_confirmation*> quit_confirmation::blockers_ = std::vector<quit_confirmation*>();
bool quit_confirmation::open_ = false;
bool quit_confirmation::quit()
{
if(!open_) {
open_ = true;
for(quit_confirmation* blocker : boost::adaptors::reverse(blockers_))
{
if(!blocker->prompt_()) {
open_ = false;
return false;
}
}
open_ = false;
}
return true;
}
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::dialogs::message::yes_no_buttons) != gui2::window::CANCEL;
}
bool quit_confirmation::default_prompt()
{
return show_prompt(_("Do you really want to quit?"));
}