The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
gui
dialogs
core_selection.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2009 - 2025
3
by Mark de Wever <koraq@xs4all.nl>
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
16
#define GETTEXT_DOMAIN "wesnoth-lib"
17
18
#include "
gui/dialogs/core_selection.hpp
"
19
20
#include "
gui/widgets/listbox.hpp
"
21
#include "
gui/widgets/multi_page.hpp
"
22
#include "
gui/widgets/window.hpp
"
23
24
#include <functional>
25
26
namespace
gui2::dialogs
27
{
28
29
REGISTER_DIALOG
(core_selection)
30
31
void
core_selection
::core_selected()
32
{
33
const
int
selected_row
34
= find_widget<listbox>(
"core_list"
)
35
.get_selected_row();
36
37
multi_page
& pages
38
= find_widget<multi_page>(
"core_details"
);
39
40
pages.
select_page
(selected_row);
41
}
42
43
void
core_selection::pre_show
()
44
{
45
/***** Setup core list. *****/
46
listbox
& list = find_widget<listbox>(
"core_list"
);
47
48
connect_signal_notify_modified(list, std::bind(&
core_selection::core_selected
,
this
));
49
50
keyboard_capture
(&list);
51
52
/***** Setup core details. *****/
53
multi_page
& pages
54
= find_widget<multi_page>(
"core_details"
);
55
56
for
(
const
auto
& core :
cores_
)
57
{
58
/*** Add list item ***/
59
grid
*
grid
= &list.
add_row
(
widget_data
{
60
{
"image"
, {
61
{
"label"
, core[
"image"
].t_str() }
62
}},
63
{
"name"
, {
64
{
"label"
, core[
"name"
].t_str() }
65
}}
66
});
67
assert(
grid
);
68
69
/*** Add detail item ***/
70
pages.
add_page
({
71
{
"description"
, {
72
{
"label"
, core[
"description"
].t_str() },
73
{
"use_markup"
,
"true"
}
74
}}
75
});
76
}
77
list.
select_row
(
choice_
,
true
);
78
79
core_selected
();
80
}
81
82
void
core_selection::post_show
()
83
{
84
choice_
= find_widget<listbox>(
"core_list"
)
85
.get_selected_row();
86
}
87
88
}
// namespace dialogs
gui2::dialogs::core_selection
Definition
core_selection.hpp:26
gui2::dialogs::core_selection::cores_
const std::vector< config > & cores_
Contains the config objects for all cores.
Definition
core_selection.hpp:52
gui2::dialogs::core_selection::choice_
int choice_
The chosen core.
Definition
core_selection.hpp:55
gui2::dialogs::core_selection::post_show
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition
core_selection.cpp:82
gui2::dialogs::core_selection::pre_show
virtual void pre_show() override
Actions to be taken before showing the window.
Definition
core_selection.cpp:43
gui2::dialogs::core_selection::core_selected
void core_selected()
Called when another core is selected.
Definition
core_selection.cpp:31
gui2::grid
Base container class.
Definition
grid.hpp:32
gui2::listbox
The listbox class.
Definition
listbox.hpp:41
gui2::listbox::add_row
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition
listbox.cpp:92
gui2::listbox::select_row
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition
listbox.cpp:267
gui2::multi_page
Definition
multi_page.hpp:36
gui2::multi_page::add_page
grid & add_page(const widget_item &item)
Adds single page to the grid.
Definition
multi_page.cpp:58
gui2::multi_page::select_page
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition
multi_page.cpp:119
gui2::window::keyboard_capture
void keyboard_capture(widget *widget)
Definition
window.cpp:1197
core_selection.hpp
window.hpp
This file contains the window object, this object is a top level container which has the event manage...
listbox.hpp
REGISTER_DIALOG
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
Definition
modal_dialog.hpp:89
multi_page.hpp
gui2::dialogs
Definition
achievements_dialog.cpp:35
gui2::widget_data
std::map< std::string, widget_item > widget_data
Definition
widget.hpp:36
Generated by
1.9.8