The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
quit_confirmation.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2015 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#include "quit_confirmation.hpp"
17#include "gettext.hpp"
18#include "video.hpp" // only for video::quit
19#include "resources.hpp"
20#include "playmp_controller.hpp"
24#include "utils/ranges.hpp"
25
27{
28 if(!open_) {
29 open_ = true;
31 {
32 if(!blocker->prompt_()) {
33 open_ = false;
34 return false;
35 }
36 }
37 open_ = false;
38 }
39
40 return true;
41}
42
47
49{
50 if(quit()) { throw video::quit(); }
51}
52
53bool quit_confirmation::show_prompt(const std::string& message)
54{
55 return gui2::show_message(_("Quit"), message,
57}
58
60{
62 std::size_t humans_notme_cnt = 0;
63
64 if(pmc != nullptr) {
65 for(const auto& t : pmc->get_teams()) {
66 if(t.is_network_human()) {
67 ++humans_notme_cnt;
68 }
69 }
70 }
71
72 if(!(pmc == nullptr || humans_notme_cnt < 1 || pmc->is_linger_mode() || pmc->is_observer())) {
74 sq.show();
75 int retval = sq.get_retval();
76 if(retval == 1)
77 {
79 return true;
80 }
81 else if(retval == 2)
82 {
83 return true;
84 }
85 else
86 {
87 return false;
88 }
89 } else {
90 return show_prompt(_("Do you really want to quit?"));
91 }
92}
double t
static display * get_singleton()
Returns the display object if a display object exists.
Definition display.hpp:102
std::size_t viewing_team_index() const
The viewing team is the team currently viewing the game.
Definition display.hpp:117
@ yes_no_buttons
Shows a yes and no button.
Definition message.hpp:81
bool show(const unsigned auto_close_time=0)
Shows the window.
This shows the dialog to confirm surrender and/or quitting the game.
int get_retval()
Definition window.hpp:394
bool is_observer() const
std::vector< team > & get_teams()
void surrender(int side_number)
Implements a quit confirmation dialog.
static bool default_prompt()
static bool show_prompt(const std::string &message)
static std::vector< quit_confirmation * > blockers_
static bool quit()
Shows the quit confirmation if needed.
static void quit_to_desktop()
static void quit_to_title()
Type that can be thrown as an exception to quit to desktop.
Definition video.hpp:328
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
void throw_quit_game_exception()
static std::string _(const char *str)
Definition gettext.hpp:100
void show_message(const std::string &title, const std::string &msg, const std::string &button_caption, const bool auto_close, const bool message_use_markup, const bool title_use_markup)
Shows a message to the user.
Definition message.cpp:148
@ CANCEL
Dialog was closed with the CANCEL button.
Definition retval.hpp:38
play_controller * controller
Definition resources.cpp:21
constexpr auto reverse
Definition ranges.hpp:44