-
-
Notifications
You must be signed in to change notification settings - Fork 988
/
core_selection.cpp
137 lines (111 loc) · 3.37 KB
/
core_selection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
Copyright (C) 2009 - 2017 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/core_selection.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/widgets/image.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
#else
#include "gui/widgets/listbox.hpp"
#endif
#include "gui/widgets/multi_page.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "serialization/string_utils.hpp"
#include "utils/functional.hpp"
namespace gui2
{
namespace dialogs
{
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_core_selection
*
* == Core selection ==
*
* This shows the dialog which allows the user to choose which core to
* play.
*
* @begin{table}{dialog_widgets}
*
* core_list & & listbox & m &
* A listbox that contains all available cores. $
*
* -icon & & image & o &
* The icon for the core. $
*
* -name & & styled_widget & o &
* The name of the core. $
*
* core_details & & multi_page & m &
* A multi page widget that shows more details for the selected
* core. $
*
* -image & & image & o &
* The image for the core. $
*
* -description & & styled_widget & o &
* The description of the core. $
*
* @end{table}
*/
REGISTER_DIALOG(core_selection)
void core_selection::core_selected(window& window)
{
const int selected_row
= find_widget<listbox>(&window, "core_list", false)
.get_selected_row();
multi_page& pages
= find_widget<multi_page>(&window, "core_details", false);
pages.select_page(selected_row);
}
void core_selection::pre_show(window& window)
{
/***** Setup core list. *****/
listbox& list = find_widget<listbox>(&window, "core_list", false);
connect_signal_notify_modified(list, std::bind(&core_selection::core_selected, this, std::ref(window)));
window.keyboard_capture(&list);
/***** Setup core details. *****/
multi_page& pages
= find_widget<multi_page>(&window, "core_details", false);
for(const auto & core : cores_)
{
/*** Add list item ***/
string_map list_item;
std::map<std::string, string_map> list_item_item;
list_item["label"] = core["image"];
list_item_item.emplace("image", list_item);
list_item["label"] = core["name"];
list_item_item.emplace("name", list_item);
grid* grid = &list.add_row(list_item_item);
assert(grid);
/*** Add detail item ***/
string_map detail_item;
std::map<std::string, string_map> detail_page;
detail_item["label"] = core["description"];
detail_item["use_markup"] = "true";
detail_page.emplace("description", detail_item);
pages.add_page(detail_page);
}
list.select_row(choice_, true);
core_selected(window);
}
void core_selection::post_show(window& window)
{
choice_ = find_widget<listbox>(&window, "core_list", false)
.get_selected_row();
}
} // namespace dialogs
} // namespace gui2