The Battle for Wesnoth  1.19.7+dev
unit_preview_pane.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
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
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  explicit builder_unit_preview_pane(const config& cfg);
139 
141 
142  virtual std::unique_ptr<widget> build() const override;
143 
144  std::string image_mods;
145 };
146 
147 } // namespace implementation
148 
149 // }------------ END --------------
150 
151 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
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 print_attack_details(T attacks, tree_view_node &parent_node)
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.
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:200
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