The Battle for Wesnoth  1.19.1+dev
unit_recruit.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
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 
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 
55 
57 
58  std::vector<std::string> last_words_;
59 };
60 
61 } // namespace dialogs
Abstract base class for all modal dialogs.
virtual const std::string & window_id() const override
The ID of the window to build.
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.
std::map< const unit_type *, t_string > & recruit_map_
void filter_text_changed(const std::string &text)
std::vector< std::string > last_words_
const unit_type * get_selected_unit_type() const
unit_recruit(std::map< const unit_type *, t_string > &recruit_map, team &team)
std::vector< const unit_type * > recruit_list_
A vector of unit types in the order listed in the UI.
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:74
A single unit type that the player may recruit.
Definition: types.hpp:43