The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
core_selection.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Mark de Wever <[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/dialogs/helper.hpp"
21 #include "gui/widgets/image.hpp"
22 #ifdef GUI2_EXPERIMENTAL_LISTBOX
23 #include "gui/widgets/list.hpp"
24 #else
25 #include "gui/widgets/listbox.hpp"
26 #endif
29 #include "gui/widgets/settings.hpp"
30 #include "gui/widgets/window.hpp"
32 
33 #include "utils/functional.hpp"
34 
35 namespace gui2
36 {
37 
38 /*WIKI
39  * @page = GUIWindowDefinitionWML
40  * @order = 2_core_selection
41  *
42  * == Core selection ==
43  *
44  * This shows the dialog which allows the user to choose which core to
45  * play.
46  *
47  * @begin{table}{dialog_widgets}
48  *
49  * core_list & & listbox & m &
50  * A listbox that contains all available cores. $
51  *
52  * -icon & & image & o &
53  * The icon for the core. $
54  *
55  * -name & & control & o &
56  * The name of the core. $
57  *
58  * core_details & & multi_page & m &
59  * A multi page widget that shows more details for the selected
60  * core. $
61  *
62  * -image & & image & o &
63  * The image for the core. $
64  *
65  * -description & & control & o &
66  * The description of the core. $
67  *
68  * @end{table}
69  */
70 
71 REGISTER_DIALOG(core_selection)
72 
73 void tcore_selection::core_selected(twindow& window)
74 {
75  const int selected_row
76  = find_widget<tlistbox>(&window, "core_list", false)
77  .get_selected_row();
78 
79  tmulti_page& multi_page
80  = find_widget<tmulti_page>(&window, "core_details", false);
81 
82  multi_page.select_page(selected_row);
83 }
84 
86 {
87  /***** Setup core list. *****/
88  tlistbox& list = find_widget<tlistbox>(&window, "core_list", false);
89 #ifdef GUI2_EXPERIMENTAL_LISTBOX
91  list,
93  this,
94  std::ref(window)));
95 #else
99 #endif
100  window.keyboard_capture(&list);
101 
102  /***** Setup core details. *****/
103  tmulti_page& multi_page
104  = find_widget<tmulti_page>(&window, "core_details", false);
105 
106  for(const auto & core : cores_)
107  {
108  /*** Add list item ***/
109  string_map list_item;
110  std::map<std::string, string_map> list_item_item;
111 
112  list_item["label"] = core["image"];
113  list_item_item.insert(std::make_pair("image", list_item));
114 
115  list_item["label"] = core["name"];
116  list_item_item.insert(std::make_pair("name", list_item));
117 
118  list.add_row(list_item_item);
119 
120  tgrid* grid = list.get_row_grid(list.get_item_count() - 1);
121  assert(grid);
122 
123  /*** Add detail item ***/
124  string_map detail_item;
125  std::map<std::string, string_map> detail_page;
126 
127  detail_item["label"] = core["description"];
128  detail_item["use_markup"] = "true";
129  detail_page.insert(std::make_pair("description", detail_item));
130 
131  multi_page.add_page(detail_page);
132  }
133  list.select_row(choice_, true);
134 
135  core_selected(window);
136 }
137 
139 {
140  choice_ = find_widget<tlistbox>(&window, "core_list", false)
141  .get_selected_row();
142 }
143 
144 } // namespace gui2
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
const std::vector< config > & cores_
Contains the config objects for all cores.
void core_selected(twindow &window)
Called when another core is selected.
void connect_signal_notify_modified(tdispatcher &dispatcher, const tsignal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.hpp:725
Base container class.
Definition: grid.hpp:29
This file contains the window object, this object is a top level container which has the event manage...
void pre_show(twindow &window)
Inherited from tdialog.
bool select_row(const unsigned row, const bool select=true)
Selectes a row.
Definition: listbox.cpp:228
REGISTER_DIALOG(label_settings)
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
This file contains the settings handling of the widget library.
unsigned get_item_count() const
Returns the number of items in the listbox.
Definition: listbox.cpp:138
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
void add_page(const string_map &item)
Adds single page to the grid.
Definition: multi_page.cpp:42
The multi page class.
Definition: multi_page.hpp:37
int choice_
The chosen core.
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
The listbox class.
Definition: listbox.hpp:39
void select_page(const unsigned page, const bool select=true)
Selectes a page.
Definition: multi_page.cpp:84
GLenum GLint ref
Definition: glew.h:1813
void post_show(twindow &window)
Inherited from tdialog.
void set_callback_value_change(const std::function< void(twidget &)> &callback)
Definition: listbox.hpp:225
void dialog_callback(twidget &caller)
Template for dialog callbacks.
Definition: helper.hpp:31
const tgrid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:215