The Battle for Wesnoth  1.15.2+dev
unit_preview_pane.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 
17 
18 #include <boost/optional.hpp>
19 #include <string>
20 
21 class unit;
22 class unit_type;
23 
24 namespace gui2
25 {
26 
27 // ------------ WIDGET -----------{
28 
29 class button;
30 class image;
31 class label;
32 class tree_view;
33 class tree_view_node;
34 
35 namespace implementation
36 {
37  struct builder_unit_preview_pane;
38 }
39 
41 {
43 
44 public:
46 
47  /** Displays the stats of a specified unit type */
48  void set_displayed_type(const unit_type& type);
49 
50  /** Displays the stats of a specific unit */
51  void set_displayed_unit(const unit& u);
52 
53  /** Sets the facing of the unit image */
54  void set_image_mods(const std::string& mods);
55 
56  /** Callback for the profile button */
57  void profile_button_callback();
58 
59  /** See @ref styled_widget::set_active. */
60  virtual void set_active(const bool active) override;
61 
62  /** See @ref styled_widget::get_active. */
63  virtual bool get_active() const override;
64 
65  /** See @ref styled_widget::get_state. */
66  virtual unsigned get_state() const override;
67 
68 protected:
69  /**
70  * Initializes the internal sub-widget pointers.
71  * Should be called when building the window, so the pointers
72  * are initialized when set_displayed_type() is called.
73  */
74  void finalize_setup();
75 
76 private:
77  boost::optional<const unit_type&> current_type_;
78 
82 
86 
89 
91 
92  std::string image_mods_;
93 
94  template<typename T> // This is only a template to avoid including units/attack.hpp
95  void print_attack_details(T attacks, tree_view_node& parent_node);
96 
97  enum state_t {
98  ENABLED
99  };
100 
101 public:
102  /** Static type getter that does not rely on the widget being constructed. */
103  static const std::string& type();
104 
105 private:
106  /** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
107  virtual const std::string& get_control_type() const override;
108 
109  /** See @ref container_base::set_self_active. */
110  virtual void set_self_active(const bool active) override;
111 
112 };
113 
114 // }---------- DEFINITION ---------{
115 
117 {
118 
119  explicit unit_preview_pane_definition(const config& cfg);
120 
122  {
123  explicit resolution(const config& cfg);
124 
126  };
127 };
128 
129 // }---------- BUILDER -----------{
130 
131 namespace implementation
132 {
133 
135 {
136 public:
137  explicit builder_unit_preview_pane(const config& cfg);
138 
140 
141  widget* build() const;
142 
143 private:
144  const std::string image_mods_;
145 };
146 
147 } // namespace implementation
148 
149 // }------------ END --------------
150 
151 } // namespace gui2
Base class of a resolution, contains the common keys for a resolution.
virtual widget * build() const =0
This class represents a single unit of a specific type.
Definition: unit.hpp:99
Base class for all widgets.
Definition: widget.hpp:47
styled_widget * label_details_
Label showing a text.
Definition: label.hpp:32
A single unit type that the player may recruit.
Definition: types.hpp:42
Generic file dialog.
Definition: field-fwd.hpp:22
boost::optional< const unit_type & > current_type_
window * build(const builder_window::window_resolution *definition)
Builds a window.
Base class for all visible items.
A generic container base class.
this module manages the cache of images.
Simple push button.
Definition: button.hpp:35
point resolution()
Definition: general.cpp:373
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
std::shared_ptr< builder_grid > builder_grid_ptr
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.