The Battle for Wesnoth  1.15.2+dev
unit_list.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 
16 #include "gettext.hpp"
19 #include "map/location.hpp"
20 #include "units/ptr.hpp"
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 class display;
27 
28 namespace gui2
29 {
30 namespace dialogs
31 {
32 
33 using unit_ptr_vector = std::vector<unit_const_ptr>;
34 
36 
37 class unit_list : public modal_dialog
38 {
39 public:
40  explicit unit_list(unit_ptr_vector& unit_list, map_location& scroll_to);
41 
42  static bool execute(unit_ptr_vector& units, map_location& scroll_to)
43  {
44  if(units.empty()) {
45  show_transient_message("", _("No units found."));
46  return false;
47  }
48 
49  return unit_list(units, scroll_to).show();
50  }
51 
52 private:
54 
56 
57  /** Callbacks */
59 
60  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
61  virtual const std::string& window_id() const override;
62 
63  /** Inherited from modal_dialog. */
64  virtual void pre_show(window& window) override;
65 
66  /** Inherited from modal_dialog. */
67  virtual void post_show(window& window) override;
68 };
69 
70 } // namespace dialogs
71 } // namespace gui2
virtual const std::string & window_id() const override
Inherited from modal_dialog, implemented by REGISTER_DIALOG.
unit_list(unit_ptr_vector &unit_list, map_location &scroll_to)
Definition: unit_list.cpp:48
virtual void post_show(window &window) override
Inherited from modal_dialog.
Definition: unit_list.cpp:190
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, const bool restore_background)
Shows a transient message to the user.
General purpose widgets.
void list_item_clicked(window &window)
Callbacks.
Definition: unit_list.cpp:177
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: unit_list.cpp:91
map_location & scroll_to_
Definition: unit_list.hpp:55
Generic file dialog.
Definition: field-fwd.hpp:22
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:91
Various uncategorised dialogs.
Encapsulates the map of the game.
Definition: location.hpp:42
unit_ptr_vector & unit_list_
Definition: unit_list.hpp:53
std::vector< unit_const_ptr > unit_ptr_vector
Definition: unit_list.hpp:33
Abstract base class for all modal dialogs.
static bool execute(unit_ptr_vector &units, map_location &scroll_to)
Definition: unit_list.hpp:42
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63