The Battle for Wesnoth  1.19.0-dev
unit_create.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Iris Morelle <shadowm2006@gmail.com>
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 #pragma once
17 
19 #include "gui/widgets/group.hpp"
20 #include "units/race.hpp"
21 
22 #include <string>
23 #include <vector>
24 
25 class unit_type;
26 
27 namespace gui2
28 {
29 
30 
31 namespace dialogs
32 {
33 
34 /**
35  * @ingroup GUIWindowDefinitionWML
36  *
37  * This shows the debug-mode dialog to create new units on the map.
38  * Key |Type |Mandatory|Description
39  * ------------------|---------------|---------|-----------
40  * male_toggle | toggle_button |yes |Option button to select the "male" gender for created units.
41  * female_toggle | toggle_button |yes |Option button to select the "female" gender for created units.
42  * unit_type_list | @ref listbox |yes |Listbox displaying existing unit types sorted by name and race.
43  * unit_type | control |yes |Widget which shows the unit type name label.
44  * race | control |yes |Widget which shows the unit race name label.
45  */
46 class unit_create : public modal_dialog
47 {
48 public:
49  unit_create();
50 
51  /** Unit type choice from the user. */
52  const std::string& choice() const
53  {
54  return choice_;
55  }
56 
57  /** Whether the user actually chose a unit type or not. */
58  bool no_choice() const
59  {
60  return choice_.empty();
61  }
62 
63  /** Gender choice from the user. */
65  {
66  return gender_;
67  }
68 
69  /** Variation choice from the user. */
70  std::string variation() const
71  {
72  return variation_;
73  }
74 
75 private:
76  std::vector<const unit_type*> units_;
77 
79 
80  std::string choice_;
81 
82  std::string variation_;
83 
84  std::vector<std::string> last_words_;
85 
86  virtual const std::string& window_id() const override;
87 
88  virtual void pre_show(window& window) override;
89 
90  virtual void post_show(window& window) override;
91 
92  /** Callbacks */
93  void list_item_clicked();
94  void filter_text_changed(const std::string& text);
97 
98  void update_displayed_type();
99 
101 };
102 } // namespace dialogs
103 } // namespace gui2
Abstract base class for all modal dialogs.
This shows the debug-mode dialog to create new units on the map.
Definition: unit_create.hpp:47
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
unit_race::GENDER gender_
Definition: unit_create.hpp:78
group< unit_race::GENDER > gender_toggle
unit_race::GENDER gender()
Gender choice from the user.
Definition: unit_create.hpp:64
bool no_choice() const
Whether the user actually chose a unit type or not.
Definition: unit_create.hpp:58
std::vector< std::string > last_words_
Definition: unit_create.hpp:84
void list_item_clicked()
Callbacks.
std::string variation() const
Variation choice from the user.
Definition: unit_create.hpp:70
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: unit_create.cpp:53
void filter_text_changed(const std::string &text)
void gender_toggle_callback(const unit_race::GENDER val)
const std::string & choice() const
Unit type choice from the user.
Definition: unit_create.hpp:52
std::vector< const unit_type * > units_
Definition: unit_create.hpp:76
virtual const std::string & window_id() const override
The ID of the window to build.
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:63
A single unit type that the player may recruit.
Definition: types.hpp:43
Various uncategorised dialogs.
Generic file dialog.