The Battle for Wesnoth  1.17.4+dev
unit_preview_pane.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2022
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 #include <string>
21 
22 class unit;
23 class unit_type;
24 
25 namespace gui2
26 {
27 
28 // ------------ WIDGET -----------{
29 
30 class button;
31 class drawing;
32 class image;
33 class label;
34 class tree_view;
35 class tree_view_node;
36 
37 namespace implementation
38 {
39  struct builder_unit_preview_pane;
40 }
41 
43 {
45 
46 public:
48 
49  /** Displays the stats of a specified unit type */
50  void set_displayed_type(const unit_type& type);
51 
52  /** Displays the stats of a specific unit */
53  void set_displayed_unit(const unit& u);
54 
55  /** Sets the facing of the unit image */
56  void set_image_mods(const std::string& mods);
57 
58  /** Callback for the profile button */
59  void profile_button_callback();
60 
61  /** See @ref styled_widget::set_active. */
62  virtual void set_active(const bool active) override;
63 
64  /** See @ref styled_widget::get_active. */
65  virtual bool get_active() const override;
66 
67  /** See @ref styled_widget::get_state. */
68  virtual unsigned get_state() const override;
69 
70 protected:
71  /**
72  * Initializes the internal sub-widget pointers.
73  * Should be called when building the window, so the pointers
74  * are initialized when set_displayed_type() is called.
75  */
76  void finalize_setup();
77 
78 private:
80 
84 
88 
91 
93 
94  std::string image_mods_;
95 
96  template<typename T> // This is only a template to avoid including units/attack.hpp
97  void print_attack_details(T attacks, tree_view_node& parent_node);
98 
99  enum state_t {
100  ENABLED
101  };
102 
103 public:
104  /** Static type getter that does not rely on the widget being constructed. */
105  static const std::string& type();
106 
107 private:
108  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
109  virtual const std::string& get_control_type() const override;
110 
111  /** See @ref container_base::set_self_active. */
112  virtual void set_self_active(const bool active) override;
113 
114 };
115 
116 // }---------- DEFINITION ---------{
117 
119 {
120 
121  explicit unit_preview_pane_definition(const config& cfg);
122 
124  {
125  explicit resolution(const config& cfg);
126 
128  };
129 };
130 
131 // }---------- BUILDER -----------{
132 
133 namespace implementation
134 {
135 
137 {
138 public:
139  explicit builder_unit_preview_pane(const config& cfg);
140 
142 
143  virtual std::unique_ptr<widget> build() const override;
144 
145 private:
146  const std::string image_mods_;
147 };
148 
149 } // namespace implementation
150 
151 // }------------ END --------------
152 
153 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
utils::optional_reference< const unit_type > current_type_
This class represents a single unit of a specific type.
Definition: unit.hpp:120
A drawing is widget with a fixed size and gives access to the canvas of the widget in the window inst...
Definition: drawing.hpp:52
styled_widget * label_details_
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:57
A single unit type that the player may recruit.
Definition: types.hpp:45
Generic file dialog.
Definition: field-fwd.hpp:23
std::string label
What to show in the filter&#39;s drop-down list.
Definition: manager.cpp:217
A tree view is a control that holds several items of the same or different types. ...
Definition: tree_view.hpp:60
virtual std::unique_ptr< widget > build() const =0
Base class for all visible items.
A generic container base class.
std::shared_ptr< builder_grid > builder_grid_ptr
Functions to load and save images from/to disk.
Simple push button.
Definition: button.hpp:36
point resolution()
Definition: general.cpp:399
std::unique_ptr< window > build(const builder_window::window_resolution &definition)
Builds a window.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.