The Battle for Wesnoth
1.15.2+dev
gui
dialogs
depcheck_select_new.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2012 - 2018 by Boldizsár Lipka <lipkab@zoho.com>
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
17
#include "
gui/dialogs/depcheck_select_new.hpp
"
18
19
#include "
gui/auxiliary/find_widget.hpp
"
20
#include "
gui/widgets/settings.hpp
"
21
#include "
gui/widgets/window.hpp
"
22
#include "
gui/widgets/listbox.hpp
"
23
#include "
gettext.hpp
"
24
25
namespace
gui2
26
{
27
namespace
dialogs
28
{
29
30
/*WIKI
31
* @page = GUIWindowDefinitionWML
32
* @order = 2_depcheck_select_new
33
*
34
* == SP/MP Dependency Check: Select New ==
35
*
36
* Offers a list of compatible items if a currently selected one is
37
* incompatible. Currently used for switching era or map.
38
*
39
* @begin{table}{dialog_widgets}
40
*
41
* message & & label & m &
42
* displays the details of the required changes $
43
*
44
* itemlist & & listbox & m &
45
* displays the available items to choose from $
46
*
47
* cancel & & button & m &
48
* refuse to apply any changes $
49
*
50
* ok & & button & m &
51
* select the chosen item $
52
*
53
* @end{table}
54
*
55
*/
56
57
REGISTER_DIALOG
(depcheck_select_new)
58
59
depcheck_select_new
::
depcheck_select_new
(
60
ng
::depcheck::
component_type
name,
61
const
std
::vector<
std
::
string
>&
items
)
62
: items_(
items
), result_(-1)
63
{
64
65
std::string
message
;
66
67
switch
(name) {
68
case
ng::depcheck::SCENARIO
:
69
message =
_
(
"The currently chosen scenario "
70
"is not compatible with your setup."
71
"\nPlease select a compatible one."
);
72
break
;
73
case
ng::depcheck::ERA
:
74
message =
_
(
"The currently chosen era "
75
"is not compatible with your setup."
76
"\nPlease select a compatible one."
);
77
break
;
78
case
ng::depcheck::MODIFICATION
:
79
// currently this can't happen, but be prepared for anything...
80
message =
_
(
"The currently chosen modification "
81
"is not compatible with your setup."
82
"\nPlease select a compatible one."
);
83
}
84
85
register_label(
"message"
,
false
, message);
86
}
87
88
void
depcheck_select_new::pre_show
(
window
&
window
)
89
{
90
listbox
&
items
= find_widget<listbox>(&window,
"itemlist"
,
false
);
91
92
for
(
const
auto
&
item
:
items_
)
93
{
94
std::map<std::string, string_map> data;
95
data[
"option"
][
"label"
] =
item
;
96
97
items.
add_row
(data);
98
}
99
100
items.
select_row
(0);
101
}
102
103
void
depcheck_select_new::post_show
(
window
&
window
)
104
{
105
if
(
get_retval
() ==
retval::OK
) {
106
listbox
&
items
= find_widget<listbox>(&window,
"itemlist"
,
false
);
107
result_
= items.
get_selected_row
();
108
}
109
}
110
}
// namespace dialogs
111
}
// namespace gui2
REGISTER_DIALOG
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
Definition:
modal_dialog.hpp:89
gettext.hpp
ng::depcheck::MODIFICATION
Definition:
depcheck.hpp:33
find_widget.hpp
depcheck_select_new.hpp
gui2::dialogs::depcheck_select_new::result_
int result_
the index of the selected item
Definition:
depcheck_select_new.hpp:65
gui2::dialogs::message
Main class to show messages to the user.
Definition:
message.hpp:34
window.hpp
This file contains the window object, this object is a top level container which has the event manage...
std
STL namespace.
mp_ui_alerts::items
const std::vector< std::string > items
Definition:
mp_ui_alerts.cpp:53
gui2::listbox::get_selected_row
int get_selected_row() const
Returns the first selected row.
Definition:
listbox.cpp:272
ng
Definition:
configure_engine.cpp:27
gui2::listbox::select_row
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition:
listbox.cpp:250
gui2
Generic file dialog.
Definition:
field-fwd.hpp:22
gui2::listbox
The listbox class.
Definition:
listbox.hpp:40
_
static UNUSEDNOWARN std::string _(const char *str)
Definition:
gettext.hpp:91
settings.hpp
This file contains the settings handling of the widget library.
ng::depcheck::SCENARIO
Definition:
depcheck.hpp:32
gui2::dialogs::depcheck_select_new::items_
std::vector< std::string > items_
the options available
Definition:
depcheck_select_new.hpp:62
dialogs
Various uncategorised dialogs.
gui2::dialogs::depcheck_select_new
Definition:
depcheck_select_new.hpp:27
gui2::listbox::add_row
grid & add_row(const string_map &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:66
gui2::dialogs::depcheck_select_new::post_show
virtual void post_show(window &window) override
Inherited from modal_dialog.
Definition:
depcheck_select_new.cpp:103
gui2::dialogs::modal_dialog::get_retval
int get_retval() const
Definition:
modal_dialog.hpp:182
ng::depcheck::component_type
component_type
Definition:
depcheck.hpp:29
listbox.hpp
gui2::dialogs::depcheck_select_new::pre_show
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition:
depcheck_select_new.cpp:88
gui2::OK
Dialog was closed with the OK button.
Definition:
retval.hpp:34
gui2::window
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition:
window.hpp:62
help::item
std::pair< std::string, unsigned > item
Definition:
help_impl.hpp:371
ng::depcheck::ERA
Definition:
depcheck.hpp:31
Generated by
1.8.13