The Battle for Wesnoth  1.17.21+dev
unit_list.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2023
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 
17 #include "gettext.hpp"
20 #include "map/location.hpp"
21 #include "units/ptr.hpp"
22 
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 class display;
28 
29 namespace gui2::dialogs
30 {
32 
33 class unit_list : public modal_dialog
34 {
35 public:
36  explicit unit_list(std::vector<unit_const_ptr>& unit_list, map_location& scroll_to);
37 
38  static bool execute(std::vector<unit_const_ptr>& units, map_location& scroll_to)
39  {
40  if(units.empty()) {
41  show_transient_message("", _("No units found."));
42  return false;
43  }
44 
45  return unit_list(units, scroll_to).show();
46  }
47 
48 private:
49  std::vector<unit_const_ptr>& unit_list_;
50 
52 
53  /** Callbacks */
54  void list_item_clicked();
55 
56  virtual const std::string& window_id() const override;
57 
58  virtual void pre_show(window& window) override;
59 
60  virtual void post_show(window& window) override;
61 };
62 
63 } // namespace dialogs
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:87
Abstract base class for all modal dialogs.
virtual const std::string & window_id() const override
The ID of the window to build.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: unit_list.cpp:91
unit_list(std::vector< unit_const_ptr > &unit_list, map_location &scroll_to)
Definition: unit_list.cpp:47
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: unit_list.cpp:190
map_location & scroll_to_
Definition: unit_list.hpp:51
std::vector< unit_const_ptr > & unit_list_
Definition: unit_list.hpp:49
void list_item_clicked()
Callbacks.
Definition: unit_list.cpp:177
static bool execute(std::vector< unit_const_ptr > &units, map_location &scroll_to)
Definition: unit_list.hpp:38
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:67
static std::string _(const char *str)
Definition: gettext.hpp:93
void show_unit_list(display &gui)
Definition: unit_list.cpp:199
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
General purpose widgets.
Encapsulates the map of the game.
Definition: location.hpp:38