The Battle for Wesnoth  1.15.2+dev
core_selection.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Mark de Wever <koraq@xs4all.nl>
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 
18 
20 #include "gui/widgets/image.hpp"
21 #include "gui/widgets/listbox.hpp"
24 #include "gui/widgets/settings.hpp"
25 #include "gui/widgets/window.hpp"
26 
27 #include "utils/functional.hpp"
28 
29 namespace gui2
30 {
31 namespace dialogs
32 {
33 
34 /*WIKI
35  * @page = GUIWindowDefinitionWML
36  * @order = 2_core_selection
37  *
38  * == Core selection ==
39  *
40  * This shows the dialog which allows the user to choose which core to
41  * play.
42  *
43  * @begin{table}{dialog_widgets}
44  *
45  * core_list & & listbox & m &
46  * A listbox that contains all available cores. $
47  *
48  * -icon & & image & o &
49  * The icon for the core. $
50  *
51  * -name & & styled_widget & o &
52  * The name of the core. $
53  *
54  * core_details & & multi_page & m &
55  * A multi page widget that shows more details for the selected
56  * core. $
57  *
58  * -image & & image & o &
59  * The image for the core. $
60  *
61  * -description & & styled_widget & o &
62  * The description of the core. $
63  *
64  * @end{table}
65  */
66 
67 REGISTER_DIALOG(core_selection)
68 
69 void core_selection::core_selected(window& window)
70 {
71  const int selected_row
72  = find_widget<listbox>(&window, "core_list", false)
73  .get_selected_row();
74 
75  multi_page& pages
76  = find_widget<multi_page>(&window, "core_details", false);
77 
78  pages.select_page(selected_row);
79 }
80 
82 {
83  /***** Setup core list. *****/
84  listbox& list = find_widget<listbox>(&window, "core_list", false);
85 
86  connect_signal_notify_modified(list, std::bind(&core_selection::core_selected, this, std::ref(window)));
87 
88  window.keyboard_capture(&list);
89 
90  /***** Setup core details. *****/
91  multi_page& pages
92  = find_widget<multi_page>(&window, "core_details", false);
93 
94  for(const auto & core : cores_)
95  {
96  /*** Add list item ***/
97  string_map list_item;
98  std::map<std::string, string_map> list_item_item;
99 
100  list_item["label"] = core["image"];
101  list_item_item.emplace("image", list_item);
102 
103  list_item["label"] = core["name"];
104  list_item_item.emplace("name", list_item);
105 
106  grid* grid = &list.add_row(list_item_item);
107  assert(grid);
108 
109  /*** Add detail item ***/
110  string_map detail_item;
111  std::map<std::string, string_map> detail_page;
112 
113  detail_item["label"] = core["description"];
114  detail_item["use_markup"] = "true";
115  detail_page.emplace("description", detail_item);
116 
117  pages.add_page(detail_page);
118  }
119  list.select_row(choice_, true);
120 
121  core_selected(window);
122 }
123 
125 {
126  choice_ = find_widget<listbox>(&window, "core_list", false)
127  .get_selected_row();
128 }
129 
130 } // namespace dialogs
131 } // namespace gui2
int choice_
The chosen core.
void core_selected(window &window)
Called when another core is selected.
grid & add_page(const string_map &item)
Adds single page to the grid.
Definition: multi_page.cpp:43
This file contains the window object, this object is a top level container which has the event manage...
virtual void post_show(window &window) override
Inherited from modal_dialog.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:250
Generic file dialog.
Definition: field-fwd.hpp:22
const std::vector< config > & cores_
Contains the config objects for all cores.
The listbox class.
Definition: listbox.hpp:40
Base container class.
Definition: grid.hpp:30
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:248
This file contains the settings handling of the widget library.
Various uncategorised dialogs.
void select_page(const unsigned page, const bool select=true)
Selectes a page.
Definition: multi_page.cpp:106
std::map< std::string, t_string > string_map
Definition: widget.hpp:24
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
The multi page class.
Definition: multi_page.hpp:35
virtual void pre_show(window &window) override
Inherited from modal_dialog.
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63