The Battle for Wesnoth  1.15.12+dev
unit_recruit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
18 
19 class unit_type;
20 class team;
21 
22 namespace gui2::dialogs
23 {
24 
25 class unit_recruit : public modal_dialog
26 {
27 public:
28  /**
29  * @param recruit_map maps unit typs to strings. The strings are "" if the unit can be recalled and an error message string otherwise.
30  * @param team the team to recruit to.
31  */
32  unit_recruit(std::map<const unit_type*, t_string>& recruit_map, team& team);
33 
35  {
36  return selected_index_ < 0 ? nullptr : recruit_list_[selected_index_];
37  }
38 
39 private:
40  virtual const std::string& window_id() const override;
41 
42  virtual void pre_show(window& window) override;
43  virtual void post_show(window& window) override;
44 
45  void list_item_clicked();
46  void filter_text_changed(const std::string& text);
47 
48  void show_help();
49 
50  /** A vector of unit types in the order listed in the UI. Used by unit_recruit::post_show. */
51  std::vector<const unit_type*> recruit_list_;
52  std::map<const unit_type*, t_string>& recruit_map_;
53 
54  team& team_;
55 
57 
58  std::vector<std::string> last_words_;
59 };
60 
61 } // 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:44
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:44
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:64
std::map< const unit_type *, t_string > & recruit_map_