The Battle for Wesnoth  1.17.0-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::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(window& window) override;
58 
59  virtual void post_show(window& window) override;
60 };
61 
62 } // namespace dialogs
virtual const std::string & window_id() const override
The id of the window to build.
void list_item_clicked()
Callbacks.
Definition: unit_list.cpp:175
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: unit_list.cpp:188
std::vector< unit_const_ptr > & unit_list_
Definition: unit_list.hpp:48
void show_unit_list(display &gui)
Definition: unit_list.cpp:197
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.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: unit_list.cpp:89
static std::string _(const char *str)
Definition: gettext.hpp:92
map_location & scroll_to_
Definition: unit_list.hpp:50
Encapsulates the map of the game.
Definition: location.hpp:37
static bool execute(std::vector< unit_const_ptr > &units, map_location &scroll_to)
Definition: unit_list.hpp:37
Abstract base class for all modal dialogs.
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64
unit_list(std::vector< unit_const_ptr > &unit_list, map_location &scroll_to)
Definition: unit_list.cpp:46