The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
depcheck_select_new.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2016 by Boldizsár Lipka <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 
20 #include "gui/widgets/settings.hpp"
21 #include "gui/widgets/window.hpp"
22 #ifdef GUI2_EXPERIMENTAL_LISTBOX
23 #include "gui/widgets/list.hpp"
24 #else
25 #include "gui/widgets/listbox.hpp"
26 #endif
27 #include "gettext.hpp"
28 
29 namespace gui2
30 {
31 
32 /*WIKI
33  * @page = GUIWindowDefinitionWML
34  * @order = 2_depcheck_select_new
35  *
36  * == SP/MP Dependency Check: Select New ==
37  *
38  * Offers a list of compatible items if a currently selected one is
39  * incompatible. Currently used for switching era or map.
40  *
41  * @begin{table}{dialog_widgets}
42  *
43  * message & & label & m &
44  * displays the details of the required changes $
45  *
46  * itemlist & & listbox & m &
47  * displays the available items to choose from $
48  *
49  * cancel & & button & m &
50  * refuse to apply any changes $
51  *
52  * ok & & button & m &
53  * select the chosen item $
54  *
55  * @end{table}
56  *
57  */
58 
59 REGISTER_DIALOG(depcheck_select_new)
60 
62  ng::depcheck::component_type name,
63  const std::vector<std::string>& items)
64  : items_(items), result_(-1)
65 {
66 
68 
69  switch(name) {
71  message = _("The currently chosen scenario "
72  "is not compatible with your setup."
73  "\nPlease select a compatible one.");
74  break;
75  case ng::depcheck::ERA:
76  message = _("The currently chosen era "
77  "is not compatible with your setup."
78  "\nPlease select a compatible one.");
79  break;
81  // currently this can't happen, but be prepared for anything...
82  message = _("The currently chosen modification "
83  "is not compatible with your setup."
84  "\nPlease select a compatible one.");
85  }
86 
87  register_label("message", false, message);
88 }
89 
91 {
92  tlistbox& listbox = find_widget<tlistbox>(&window, "itemlist", false);
93 
94  for(const auto & item : items_)
95  {
96  string_map current;
97  current.insert(std::make_pair("label", item));
98 
99  listbox.add_row(current);
100  }
101 
102  listbox.select_row(0);
103 }
104 
106 {
107  if(get_retval() == twindow::OK) {
108  tlistbox& listbox = find_widget<tlistbox>(&window, "itemlist", false);
109  result_ = listbox.get_selected_row();
110  }
111 }
112 }
int get_retval() const
Definition: dialog.hpp:161
This file contains the window object, this object is a top level container which has the event manage...
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
STL namespace.
const std::vector< std::string > items
int result_
the index of the selected item
virtual void post_show(twindow &window)
Inherited from tdialog.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
Dialog is closed with ok button.
Definition: window.hpp:125
This file contains the settings handling of the widget library.
void 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:74
virtual void pre_show(twindow &window)
Inherited from tdialog.
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
std::vector< std::string > items_
the options available
The listbox class.
Definition: listbox.hpp:39
std::vector< expression_ptr > items_
Definition: formula.cpp:119
GLuint const GLchar * name
Definition: glew.h:1782
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:237
GLsizei const GLcharARB ** string
Definition: glew.h:4503