The Battle for Wesnoth  1.19.0-dev
synced_choice_wait.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by Iris Morelle <shadowm2006@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
17 
19 #include "gui/widgets/label.hpp"
20 #include "gui/widgets/button.hpp"
21 #include "gui/widgets/settings.hpp"
22 #include "gui/widgets/window.hpp"
23 #include "quit_confirmation.hpp"
24 
25 #include "gui/dialogs/message.hpp"
26 #include "game_end_exceptions.hpp"
27 #include "gettext.hpp"
28 
29 
30 #include <functional>
31 
32 namespace gui2::dialogs
33 {
34 
35 REGISTER_DIALOG(synched_choice_wait)
36 
38  : modal_dialog(window_id())
39  , mgr_(mgr)
40  , message_()
41 {
42  mgr_.changed_event_.attach_handler(this);
43 }
44 
46 {
48 }
49 
51 {
52  message_ = find_widget<label>(&window, "lblMessage", false, true);
53 
54 
55  button& quit_button = find_widget<button>(
56  &window, "btn_quit_game", false);
57 
60 
62  if(mgr_.finished() || !mgr_.waiting()) {
63  window.close();
64  }
65 }
66 
67 void synched_choice_wait::handle_generic_event(const std::string& event_name)
68 {
69  assert(event_name == "user_choice_update");
70  assert(message_);
72  if(mgr_.finished() || !mgr_.waiting()) {
73  get_window()->close();
74  }
75 }
76 
77 } // namespace dialogs
virtual bool detach_handler(observer *obs)
Simple push button.
Definition: button.hpp:36
Abstract base class for all modal dialogs.
window * get_window()
Returns a pointer to the dialog's window.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
virtual void handle_generic_event(const std::string &event_name) override
virtual void set_label(const t_string &text)
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:67
void close()
Requests to close the window.
Definition: window.hpp:227
static void quit_to_title()
events::generic_event changed_event_
bool waiting() const
Note: currently finished() does not imply !waiting() so you may need to check both.
const std::string & wait_message() const
Contains the exception interfaces used to signal completion of a scenario, campaign or turn.
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(tod_new_schedule)
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:179
This file contains the settings handling of the widget library.