The Battle for Wesnoth  1.15.12+dev
unit_create.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Iris Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
18 #include "gui/widgets/group.hpp"
19 #include "units/race.hpp"
20 
21 #include <string>
22 #include <vector>
23 
24 class display;
25 class unit_type;
26 
27 namespace gui2
28 {
29 
30 class menu_button;
31 class text_box_base;
32 
33 namespace dialogs
34 {
35 
36 /**
37  * @ingroup GUIWindowDefinitionWML
38  *
39  * This shows the debug-mode dialog to create new units on the map.
40  * Key |Type |Mandatory|Description
41  * ------------------|---------------|---------|-----------
42  * male_toggle | toggle_button |yes |Option button to select the "male" gender for created units.
43  * female_toggle | toggle_button |yes |Option button to select the "female" gender for created units.
44  * unit_type_list | @ref listbox |yes |Listbox displaying existing unit types sorted by name and race.
45  * unit_type | control |yes |Widget which shows the unit type name label.
46  * race | control |yes |Widget which shows the unit race name label.
47  */
48 class unit_create : public modal_dialog
49 {
50 public:
51  unit_create();
52 
53  /** Unit type choice from the user. */
54  const std::string& choice() const
55  {
56  return choice_;
57  }
58 
59  /** Whether the user actually chose a unit type or not. */
60  bool no_choice() const
61  {
62  return choice_.empty();
63  }
64 
65  /** Gender choice from the user. */
67  {
68  return gender_;
69  }
70 
71  /** Variation choice from the user. */
72  std::string variation() const
73  {
74  return variation_;
75  }
76 
77 private:
78  std::vector<const unit_type*> units_;
79 
81 
82  std::string choice_;
83 
84  std::string variation_;
85 
86  std::vector<std::string> last_words_;
87 
88  virtual const std::string& window_id() const override;
89 
90  virtual void pre_show(window& window) override;
91 
92  virtual void post_show(window& window) override;
93 
94  /** Callbacks */
95  void list_item_clicked();
96  void filter_text_changed(const std::string& text);
99 
100  void update_displayed_type() const;
101 
103 };
104 } // namespace dialogs
105 } // namespace gui2
unit_race::GENDER gender()
Gender choice from the user.
Definition: unit_create.hpp:66
const std::string & choice() const
Unit type choice from the user.
Definition: unit_create.hpp:54
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:44
void update_displayed_type() const
Generic file dialog.
Definition: field-fwd.hpp:22
unit_race::GENDER gender_
Definition: unit_create.hpp:80
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:60
std::vector< const unit_type * > units_
Definition: unit_create.hpp:78
Various uncategorised dialogs.
std::vector< std::string > last_words_
Definition: unit_create.hpp:86
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: unit_create.cpp:58
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:64
This shows the debug-mode dialog to create new units on the map.
Definition: unit_create.hpp:48
std::string variation() const
Variation choice from the user.
Definition: unit_create.hpp:72