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