The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
server_info_dialog.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 - 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#define GETTEXT_DOMAIN "wesnoth-lib"
16
18
19#include "gui/widgets/label.hpp"
23
24#include "wml_exception.hpp"
25
26namespace gui2::dialogs
27{
28
29REGISTER_DIALOG(server_info)
30
31server_info::server_info(const std::string& info, const std::string& announcements)
32 : modal_dialog(window_id())
33 , server_information_(info)
34 , announcements_(announcements)
35{
36}
37
39{
40 find_widget<label>("server_information").set_label(server_information_);
41 find_widget<label>("announcements").set_label(announcements_);
42
43 stacked_widget& pager = find_widget<stacked_widget>("tabs_container");
44 pager.select_layer(0);
45
46 listbox& tab_bar = find_widget<listbox>("tab_bar");
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));
51}
52
54{
55 stacked_widget& pager = find_widget<stacked_widget>("tabs_container");
56 listbox& tab_bar = find_widget<listbox>("tab_bar");
57
58 pager.select_layer(std::max<int>(0, tab_bar.get_selected_row()));
59}
60
61}
Abstract base class for all modal dialogs.
const std::string & server_information_
virtual void pre_show() override
Actions to be taken before showing the window.
const std::string & announcements_
The listbox class.
Definition listbox.hpp:41
int get_selected_row() const
Returns the first selected row.
Definition listbox.cpp:290
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition listbox.cpp:153
unsigned int get_layer_count() const
Gets the total number of layers.
void select_layer(const int layer)
Selects and displays a particular layer.
virtual void set_label(const t_string &text)
This file contains the window object, this object is a top level container which has the event manage...
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
STL namespace.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.