The Battle for Wesnoth  1.19.10+dev
unit_preview_pane.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2025
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_display_data(const unit_type& type);
51 
52  /** Displays the stats of a specific unit */
53  void set_display_data(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 */
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_display_data() 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
98  T attacks,
99  const int attacks_left,
100  const int max_attacks,
101  tree_view_node& parent_node);
102 
103  enum state_t {
104  ENABLED
105  };
106 
107 public:
108  /** Static type getter that does not rely on the widget being constructed. */
109  static const std::string& type();
110 
111 private:
112  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
113  virtual const std::string& get_control_type() const override;
114 
115  /** See @ref container_base::set_self_active. */
116  virtual void set_self_active(const bool active) override;
117 
118 };
119 
120 // }---------- DEFINITION ---------{
121 
123 {
124 
125  explicit unit_preview_pane_definition(const config& cfg);
126 
128  {
129  explicit resolution(const config& cfg);
130 
132  };
133 };
134 
135 // }---------- BUILDER -----------{
136 
137 namespace implementation
138 {
139 
141 {
142  explicit builder_unit_preview_pane(const config& cfg);
143 
145 
146  virtual std::unique_ptr<widget> build() const override;
147 
148  std::string image_mods;
149 };
150 
151 } // namespace implementation
152 
153 // }------------ END --------------
154 
155 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
Simple push button.
Definition: button.hpp:36
A generic container base class.
void profile_button_callback()
Callback for the profile button.
static const std::string & type()
Static type getter that does not rely on the widget being constructed.
virtual void set_active(const bool active) override
See styled_widget::set_active.
styled_widget * label_details_
void set_display_data(const unit_type &type)
Displays the stats of a specified unit type.
unit_preview_pane(const implementation::builder_unit_preview_pane &builder)
virtual bool get_active() const override
See styled_widget::get_active.
void set_image_mods(const std::string &mods)
Sets the facing of the unit image.
virtual void set_self_active(const bool active) override
See container_base::set_self_active.
virtual const std::string & get_control_type() const override
Inherited from styled_widget, implemented by REGISTER_WIDGET.
void print_attack_details(T attacks, const int attacks_left, const int max_attacks, tree_view_node &parent_node)
virtual unsigned get_state() const override
See styled_widget::get_state.
utils::optional_reference< const unit_type > current_type_
void finalize_setup()
Initializes the internal sub-widget pointers.
A single unit type that the player may recruit.
Definition: types.hpp:43
This class represents a single unit of a specific type.
Definition: unit.hpp:133
std::string label
What to show in the filter's drop-down list.
Definition: manager.cpp:201
Generic file dialog.
std::shared_ptr< builder_grid > builder_grid_ptr
Functions to load and save images from/to disk.
Contains the implementation details for lexical_cast and shouldn't be used directly.
virtual std::unique_ptr< widget > build() const=0
virtual std::unique_ptr< widget > build() const override