The Battle for Wesnoth  1.17.0-dev
unit_preview_pane.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2021
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 image;
32 class label;
33 class tree_view;
34 class tree_view_node;
35 
36 namespace implementation
37 {
38  struct builder_unit_preview_pane;
39 }
40 
42 {
44 
45 public:
47 
48  /** Displays the stats of a specified unit type */
49  void set_displayed_type(const unit_type& type);
50 
51  /** Displays the stats of a specific unit */
52  void set_displayed_unit(const unit& u);
53 
54  /** Sets the facing of the unit image */
55  void set_image_mods(const std::string& mods);
56 
57  /** Callback for the profile button */
58  void profile_button_callback();
59 
60  /** See @ref styled_widget::set_active. */
61  virtual void set_active(const bool active) override;
62 
63  /** See @ref styled_widget::get_active. */
64  virtual bool get_active() const override;
65 
66  /** See @ref styled_widget::get_state. */
67  virtual unsigned get_state() const override;
68 
69 protected:
70  /**
71  * Initializes the internal sub-widget pointers.
72  * Should be called when building the window, so the pointers
73  * are initialized when set_displayed_type() is called.
74  */
75  void finalize_setup();
76 
77 private:
79 
83 
87 
90 
92 
93  std::string image_mods_;
94 
95  template<typename T> // This is only a template to avoid including units/attack.hpp
96  void print_attack_details(T attacks, tree_view_node& parent_node);
97 
98  enum state_t {
99  ENABLED
100  };
101 
102 public:
103  /** Static type getter that does not rely on the widget being constructed. */
104  static const std::string& type();
105 
106 private:
107  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
108  virtual const std::string& get_control_type() const override;
109 
110  /** See @ref container_base::set_self_active. */
111  virtual void set_self_active(const bool active) override;
112 
113 };
114 
115 // }---------- DEFINITION ---------{
116 
118 {
119 
120  explicit unit_preview_pane_definition(const config& cfg);
121 
123  {
124  explicit resolution(const config& cfg);
125 
127  };
128 };
129 
130 // }---------- BUILDER -----------{
131 
132 namespace implementation
133 {
134 
136 {
137 public:
138  explicit builder_unit_preview_pane(const config& cfg);
139 
141 
142  virtual widget* build() const override;
143 
144 private:
145  const std::string image_mods_;
146 };
147 
148 } // namespace implementation
149 
150 // }------------ END --------------
151 
152 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
utils::optional_reference< const unit_type > current_type_
This class represents a single unit of a specific type.
Definition: unit.hpp:121
Base class for all widgets.
Definition: widget.hpp:49
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
Base class for all visible items.
A generic container base class.
Functions to load and save images from/to disk.
Simple push button.
Definition: button.hpp:36
point resolution()
Definition: general.cpp:393
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
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.