The Battle for Wesnoth
1.19.7+dev
gui
dialogs
depcheck_select_new.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2012 - 2024
3
by Boldizsár Lipka <lipkab@zoho.com>
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/depcheck_select_new.hpp
"
19
20
#include "
gui/widgets/window.hpp
"
21
#include "
gui/widgets/listbox.hpp
"
22
#include "
gettext.hpp
"
23
24
namespace
gui2::dialogs
25
{
26
27
REGISTER_DIALOG
(depcheck_select_new)
28
29
depcheck_select_new
::
depcheck_select_new
(
30
ng
::depcheck::
component_type
name,
31
const std::vector<std::
string
>& items)
32
:
modal_dialog
(window_id())
33
, items_(items)
34
, result_(-1)
35
{
36
std::string
message
;
37
38
switch
(name) {
39
case
ng::depcheck::SCENARIO
:
40
message
=
_
(
"The currently chosen scenario "
41
"is not compatible with your setup."
42
"\nPlease select a compatible one."
);
43
break
;
44
case
ng::depcheck::ERA
:
45
message
=
_
(
"The currently chosen era "
46
"is not compatible with your setup."
47
"\nPlease select a compatible one."
);
48
break
;
49
case
ng::depcheck::MODIFICATION
:
50
// currently this can't happen, but be prepared for anything...
51
message
=
_
(
"The currently chosen modification "
52
"is not compatible with your setup."
53
"\nPlease select a compatible one."
);
54
}
55
56
register_label(
"message"
,
false
,
message
);
57
}
58
59
void
depcheck_select_new::pre_show
()
60
{
61
listbox
& items = find_widget<listbox>(
"itemlist"
);
62
63
for
(
const
auto
& item :
items_
)
64
{
65
widget_data
data
;
66
data
[
"option"
][
"label"
] = item;
67
68
items.
add_row
(
data
);
69
}
70
71
items.
select_row
(0);
72
}
73
74
void
depcheck_select_new::post_show
()
75
{
76
if
(
get_retval
() ==
retval::OK
) {
77
listbox
& items = find_widget<listbox>(
"itemlist"
);
78
result_
= items.
get_selected_row
();
79
}
80
}
81
}
// namespace dialogs
gui2::dialogs::depcheck_select_new
Definition:
depcheck_select_new.hpp:27
gui2::dialogs::depcheck_select_new::pre_show
virtual void pre_show() override
Actions to be taken before showing the window.
Definition:
depcheck_select_new.cpp:59
gui2::dialogs::depcheck_select_new::result_
int result_
the index of the selected item
Definition:
depcheck_select_new.hpp:61
gui2::dialogs::depcheck_select_new::post_show
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition:
depcheck_select_new.cpp:74
gui2::dialogs::depcheck_select_new::items_
std::vector< std::string > items_
the options available
Definition:
depcheck_select_new.hpp:58
gui2::dialogs::message
Main class to show messages to the user.
Definition:
message.hpp:36
gui2::dialogs::modal_dialog
Abstract base class for all modal dialogs.
Definition:
modal_dialog.hpp:146
gui2::dialogs::modal_dialog::get_retval
int get_retval() const
Returns the cached window exit code.
Definition:
modal_dialog.hpp:176
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:280
gui2::listbox::get_selected_row
int get_selected_row() const
Returns the first selected row.
Definition:
listbox.cpp:305
depcheck_select_new.hpp
gettext.hpp
_
static std::string _(const char *str)
Definition:
gettext.hpp:93
window.hpp
This file contains the window object, this object is a top level container which has the event manage...
listbox.hpp
gui2::dialogs
Definition:
achievements_dialog.cpp:36
gui2::dialogs::REGISTER_DIALOG
REGISTER_DIALOG(editor_edit_unit)
gui2::widget_data
std::map< std::string, widget_item > widget_data
Definition:
widget.hpp:36
gui2::OK
@ OK
Dialog was closed with the OK button.
Definition:
retval.hpp:35
ng::depcheck::component_type
component_type
Definition:
depcheck.hpp:32
ng::depcheck::SCENARIO
@ SCENARIO
Definition:
depcheck.hpp:34
ng::depcheck::ERA
@ ERA
Definition:
depcheck.hpp:33
ng::depcheck::MODIFICATION
@ MODIFICATION
Definition:
depcheck.hpp:35
ng
Definition:
configure_engine.cpp:25
data
std::string_view data
Definition:
picture.cpp:178
Generated by
1.9.1