The Battle for Wesnoth  1.17.0-dev
unit_recruit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2021
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 
19 
20 class unit_type;
21 class team;
22 
23 namespace gui2::dialogs
24 {
25 
26 class unit_recruit : public modal_dialog
27 {
28 public:
29  /**
30  * @param recruit_map maps unit typs to strings. The strings are "" if the unit can be recalled and an error message string otherwise.
31  * @param team the team to recruit to.
32  */
33  unit_recruit(std::map<const unit_type*, t_string>& recruit_map, team& team);
34 
36  {
37  return selected_index_ < 0 ? nullptr : recruit_list_[selected_index_];
38  }
39 
40 private:
41  virtual const std::string& window_id() const override;
42 
43  virtual void pre_show(window& window) override;
44  virtual void post_show(window& window) override;
45 
46  void list_item_clicked();
47  void filter_text_changed(const std::string& text);
48 
49  void show_help();
50 
51  /** A vector of unit types in the order listed in the UI. Used by unit_recruit::post_show. */
52  std::vector<const unit_type*> recruit_list_;
53  std::map<const unit_type*, t_string>& recruit_map_;
54 
55  team& team_;
56 
58 
59  std::vector<std::string> last_words_;
60 };
61 
62 } // namespace dialogs
const unit_type * get_selected_unit_type() const
unit_recruit(std::map< const unit_type *, t_string > &recruit_map, team &team)
virtual const std::string & window_id() const override
The id of the window to build.
A single unit type that the player may recruit.
Definition: types.hpp:45
std::vector< const unit_type * > recruit_list_
A vector of unit types in the order listed in the UI.
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
void filter_text_changed(const std::string &text)
Abstract base class for all modal dialogs.
std::vector< std::string > last_words_
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
std::map< const unit_type *, t_string > & recruit_map_