The Battle for Wesnoth  1.15.3+dev
server_info_dialog.cpp
Go to the documentation of this file.
1 /*
2  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #define GETTEXT_DOMAIN "wesnoth-lib"
15 
17 
19 #include "gui/widgets/label.hpp"
20 #include "gui/widgets/listbox.hpp"
22 #include "gui/widgets/window.hpp"
23 
24 namespace gui2
25 {
26 namespace dialogs
27 {
28 
29 REGISTER_DIALOG(server_info)
30 
31 server_info::server_info(const std::string& info, const std::string& announcements)
32 : server_information_(info)
33 , announcements_(announcements)
34 {
35 
36 }
37 
39 {
40  find_widget<label>(&window, "server_information", false).set_label(server_information_);
41  find_widget<label>(&window, "announcements", false).set_label(announcements_);
42 
43  stacked_widget& pager = find_widget<stacked_widget>(&window, "tabs_container", false);
44  pager.select_layer(0);
45 
46  listbox& tab_bar = find_widget<listbox>(&window, "tab_bar", false);
47 
48  VALIDATE(tab_bar.get_item_count() == pager.get_layer_count(), "Tab bar and container size mismatch");
49 
50  connect_signal_notify_modified(tab_bar, std::bind(&server_info::tab_switch_callback, this, std::ref(window)));
51 }
52 
54 {
55  stacked_widget& pager = find_widget<stacked_widget>(&window, "tabs_container", false);
56  listbox& tab_bar = find_widget<listbox>(&window, "tab_bar", false);
57 
58  pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
59 }
60 
61 }
62 }
unsigned int get_layer_count() const
Gets the total number of layers.
logger & info()
Definition: log.cpp:90
This file contains the window object, this object is a top level container which has the event manage...
STL namespace.
void tab_switch_callback(window &window)
Generic file dialog.
Definition: field-fwd.hpp:22
The listbox class.
Definition: listbox.hpp:40
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:248
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
virtual void pre_show(window &window) override
Inherited from modal_dialog.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:131
Various uncategorised dialogs.
const std::string & server_information_
void select_layer(const int layer)
Selects and displays a particular layer.
const std::string & announcements_
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62