The Battle for Wesnoth  1.17.0-dev
core_selection.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
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 
19 
21 #include "gui/widgets/image.hpp"
22 #include "gui/widgets/listbox.hpp"
25 #include "gui/widgets/settings.hpp"
26 #include "gui/widgets/window.hpp"
27 
28 #include <functional>
29 
30 namespace gui2::dialogs
31 {
32 
33 REGISTER_DIALOG(core_selection)
34 
35 void core_selection::core_selected() const
36 {
37  const int selected_row
38  = find_widget<listbox>(get_window(), "core_list", false)
39  .get_selected_row();
40 
41  multi_page& pages
42  = find_widget<multi_page>(get_window(), "core_details", false);
43 
44  pages.select_page(selected_row);
45 }
46 
48 {
49  /***** Setup core list. *****/
50  listbox& list = find_widget<listbox>(&window, "core_list", false);
51 
53 
54  window.keyboard_capture(&list);
55 
56  /***** Setup core details. *****/
57  multi_page& pages
58  = find_widget<multi_page>(&window, "core_details", false);
59 
60  for(const auto & core : cores_)
61  {
62  /*** Add list item ***/
63  string_map list_item;
64  std::map<std::string, string_map> list_item_item;
65 
66  list_item["label"] = core["image"];
67  list_item_item.emplace("image", list_item);
68 
69  list_item["label"] = core["name"];
70  list_item_item.emplace("name", list_item);
71 
72  grid* grid = &list.add_row(list_item_item);
73  assert(grid);
74 
75  /*** Add detail item ***/
76  string_map detail_item;
77  std::map<std::string, string_map> detail_page;
78 
79  detail_item["label"] = core["description"];
80  detail_item["use_markup"] = "true";
81  detail_page.emplace("description", detail_item);
82 
83  pages.add_page(detail_page);
84  }
85  list.select_row(choice_, true);
86 
87  core_selected();
88 }
89 
91 {
92  choice_ = find_widget<listbox>(&window, "core_list", false)
93  .get_selected_row();
94 }
95 
96 } // namespace dialogs
int choice_
The chosen core.
grid & add_page(const string_map &item)
Adds single page to the grid.
Definition: multi_page.cpp:44
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
Actions to be taken after the window has been shown.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:252
const std::vector< config > & cores_
Contains the config objects for all cores.
The listbox class.
Definition: listbox.hpp:43
Base container class.
Definition: grid.hpp:31
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:187
This file contains the settings handling of the widget library.
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:107
std::map< std::string, t_string > string_map
Definition: widget.hpp:26
void core_selected() const
Called when another core is selected.
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:68
A multi page is a control that contains several &#39;pages&#39; of which only one is visible.
Definition: multi_page.hpp:49
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
This shows the dialog which allows the user to choose which core to play.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65