The Battle for Wesnoth  1.19.7+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 
20 #include "gui/widgets/listbox.hpp"
22 #include "gui/widgets/window.hpp"
23 
24 #include <functional>
25 
26 namespace gui2::dialogs
27 {
28 
29 REGISTER_DIALOG(core_selection)
30 
31 void core_selection::core_selected()
32 {
33  const int selected_row
34  = find_widget<listbox>("core_list")
35  .get_selected_row();
36 
37  multi_page& pages
38  = find_widget<multi_page>("core_details");
39 
40  pages.select_page(selected_row);
41 }
42 
44 {
45  /***** Setup core list. *****/
46  listbox& list = find_widget<listbox>("core_list");
47 
49 
50  keyboard_capture(&list);
51 
52  /***** Setup core details. *****/
53  multi_page& pages
54  = find_widget<multi_page>("core_details");
55 
56  for(const auto & core : cores_)
57  {
58  /*** Add list item ***/
59  widget_item list_item;
60  widget_data list_item_item;
61 
62  list_item["label"] = core["image"];
63  list_item_item.emplace("image", list_item);
64 
65  list_item["label"] = core["name"];
66  list_item_item.emplace("name", list_item);
67 
68  grid* grid = &list.add_row(list_item_item);
69  assert(grid);
70 
71  /*** Add detail item ***/
72  widget_item detail_item;
73  widget_data detail_page;
74 
75  detail_item["label"] = core["description"];
76  detail_item["use_markup"] = "true";
77  detail_page.emplace("description", detail_item);
78 
79  pages.add_page(detail_page);
80  }
81  list.select_row(choice_, true);
82 
83  core_selected();
84 }
85 
87 {
88  choice_ = find_widget<listbox>("core_list")
89  .get_selected_row();
90 }
91 
92 } // namespace dialogs
const std::vector< config > & cores_
Contains the config objects for all cores.
virtual void post_show() override
Actions to be taken after the window has been shown.
virtual void pre_show() override
Actions to be taken before showing the window.
void core_selected()
Called when another core is selected.
Base container class.
Definition: grid.hpp:32
The listbox class.
Definition: listbox.hpp:41
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:92
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:280
grid & add_page(const widget_item &item)
Adds single page to the grid.
Definition: multi_page.cpp:58
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:119
void keyboard_capture(widget *widget)
Definition: window.cpp:1207
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(editor_edit_unit)
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:203
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
std::map< std::string, t_string > widget_item
Definition: widget.hpp:33