The Battle for Wesnoth  1.19.7+dev
unit_list.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 
17 #include "gettext.hpp"
20 #include "map/location.hpp"
21 #include "units/ptr.hpp"
22 
23 #include <string>
24 #include <vector>
25 
26 class display;
27 
28 namespace gui2::dialogs
29 {
31 
32 class unit_list : public modal_dialog
33 {
34 public:
35  explicit unit_list(std::vector<unit_const_ptr>& unit_list, map_location& scroll_to);
36 
37  static bool execute(std::vector<unit_const_ptr>& units, map_location& scroll_to)
38  {
39  if(units.empty()) {
40  show_transient_message("", _("No units found."));
41  return false;
42  }
43 
44  return unit_list(units, scroll_to).show();
45  }
46 
47 private:
48  std::vector<unit_const_ptr>& unit_list_;
49 
51 
52  /** Callbacks */
53  void list_item_clicked();
54 
55  virtual const std::string& window_id() const override;
56 
57  virtual void pre_show() override;
58 
59  virtual void post_show() override;
60 };
61 
62 } // namespace dialogs
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:97
Abstract base class for all modal dialogs.
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition: unit_list.cpp:177
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: unit_list.cpp:81
virtual const std::string & window_id() const override
The ID of the window to build.
unit_list(std::vector< unit_const_ptr > &unit_list, map_location &scroll_to)
Definition: unit_list.cpp:40
map_location & scroll_to_
Definition: unit_list.hpp:50
std::vector< unit_const_ptr > & unit_list_
Definition: unit_list.hpp:48
void list_item_clicked()
Callbacks.
Definition: unit_list.cpp:164
static bool execute(std::vector< unit_const_ptr > &units, map_location &scroll_to)
Definition: unit_list.hpp:37
static std::string _(const char *str)
Definition: gettext.hpp:93
void show_unit_list(display &gui)
Definition: unit_list.cpp:186
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:45