The Battle for Wesnoth  1.19.0-dev
core_selection.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
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()
36 {
37  const int selected_row
38  = find_widget<listbox>(this, "core_list", false)
39  .get_selected_row();
40 
41  multi_page& pages
42  = find_widget<multi_page>(this, "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  widget_item list_item;
64  widget_data 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  widget_item detail_item;
77  widget_data 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
This shows the dialog which allows the user to choose which core to play.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
const std::vector< config > & cores_
Contains the config objects for all cores.
void core_selected()
Called when another core is selected.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Base container class.
Definition: grid.hpp:32
The listbox class.
Definition: listbox.hpp:43
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:59
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:243
A multi page is a control that contains several 'pages' of which only one is visible.
Definition: multi_page.hpp:50
grid & add_page(const widget_item &item)
Adds single page to the grid.
Definition: multi_page.cpp:44
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:105
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:67
void keyboard_capture(widget *widget)
Definition: window.cpp:1225
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(tod_new_schedule)
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:205
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:35
std::map< std::string, t_string > widget_item
Definition: widget.hpp:32
This file contains the settings handling of the widget library.