The Battle for Wesnoth  1.15.2+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 text_box_base;
31 
32 namespace dialogs
33 {
34 
35 class unit_create : public modal_dialog
36 {
37 public:
38  unit_create();
39 
40  /** Unit type choice from the user. */
41  const std::string& choice() const
42  {
43  return choice_;
44  }
45 
46  /** Whether the user actually chose a unit type or not. */
47  bool no_choice() const
48  {
49  return choice_.empty();
50  }
51 
52  /** Gender choice from the user. */
54  {
55  return gender_;
56  }
57 
58 private:
59  std::vector<const unit_type*> units_;
60 
62 
63  std::string choice_;
64 
65  std::vector<std::string> last_words_;
66 
67  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
68  virtual const std::string& window_id() const override;
69 
70  /** Inherited from modal_dialog. */
71  virtual void pre_show(window& window) override;
72 
73  /** Inherited from modal_dialog. */
74  virtual void post_show(window& window) override;
75 
76  /** Callbacks */
78  void filter_text_changed(text_box_base* textbox, const std::string& text);
80 
81  void update_displayed_type() const;
82 
84 };
85 } // namespace dialogs
86 } // namespace gui2
Abstract base class for text items.
unit_race::GENDER gender()
Gender choice from the user.
Definition: unit_create.hpp:53
const std::string & choice() const
Unit type choice from the user.
Definition: unit_create.hpp:41
virtual void post_show(window &window) override
Inherited from modal_dialog.
group< unit_race::GENDER > gender_toggle
Definition: unit_create.hpp:83
A single unit type that the player may recruit.
Definition: types.hpp:42
void update_displayed_type() const
Generic file dialog.
Definition: field-fwd.hpp:22
unit_race::GENDER gender_
Definition: unit_create.hpp:61
virtual const std::string & window_id() const override
Inherited from modal_dialog, implemented by REGISTER_DIALOG.
void list_item_clicked(window &window)
Callbacks.
bool no_choice() const
Whether the user actually chose a unit type or not.
Definition: unit_create.hpp:47
std::vector< const unit_type * > units_
Definition: unit_create.hpp:59
Various uncategorised dialogs.
std::vector< std::string > last_words_
Definition: unit_create.hpp:65
void filter_text_changed(text_box_base *textbox, const std::string &text)
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: unit_create.cpp:85
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:62