The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
animation_component.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 // This class encapsulates the animation functionality of unit.
16 
17 #ifndef UNIT_ANIM_COMP_HPP
18 #define UNIT_ANIM_COMP_HPP
19 
20 #include "halo.hpp"
21 #include "units/animation.hpp" //Note: only needed for enum
22 
23 #include <boost/scoped_ptr.hpp>
24 
25 class config;
26 class unit;
27 class unit_drawer;
28 class unit_type;
29 
31 {
32 public:
33  /** States for animation. */
34  enum STATE {
35  STATE_STANDING, /** anim must fit in a hex */
36  STATE_FORGET, /** animation will be automatically replaced by a standing anim when finished */
37  STATE_ANIM}; /** normal anims */
38 
39  /** Default construct a unit animation component corresponding to a unit. */
41  u_(my_unit),
42  anim_(nullptr),
43  animations_(),
45  next_idling_(0),
47  draw_bars_(false),
48  refreshing_(false),
49  unit_halo_() {}
50 
51  /** Copy construct a unit animation component, for use when copy constructing a unit. */
53  u_(my_unit),
54  anim_(nullptr),
56  state_(o.state_),
57  next_idling_(0),
61  unit_halo_() {}
62 
63  /** Chooses an appropriate animation from the list of known animations. */
64  const unit_animation* choose_animation(const display& disp,
65  const map_location& loc, const std::string& event,
66  const map_location& second_loc = map_location::null_location(),
67  const int damage=0,
69  const attack_type* attack=nullptr,const attack_type* second_attack = nullptr,
70  int swing_num =0);
71 
72  /** Sets the animation state to standing. */
73  void set_standing(bool with_bars = true);
74 
75  /** Sets the animation state to ghosted. (For use with whiteboard / planning mode.) */
76  void set_ghosted(bool with_bars = true);
77 
78  /** Whiteboard related somehow. TODO: Figure out exactly what this does. */
79  void set_disabled_ghosted(bool with_bars = true);
80 
81  /** Sets the animation state to idling. */
82  void set_idling();
83 
84  /** Sets the animation state to that when the unit is selected */
85  void set_selecting();
86 
87  /** Begin an animation. */
88  void start_animation (int start_time, const unit_animation *animation,
89  bool with_bars, const std::string &text = "",
90  Uint32 text_color = 0, STATE state = STATE_ANIM);
91 
92  /** Invalidates an animation with respect to a display object, preparing it for redraw. */
93  bool invalidate(const display & disp);
94 
95  /** Intermittently activates the idling animations in place of the standing animations. Used by display object. */
96  void refresh();
97 
98  /** Clear the haloes associated to the unit */
99  void clear_haloes();
100 
101  /** Resets the animations list after the unit is advanced. */
102  void reset_after_advance(const unit_type * newtype = nullptr);
103 
104  /** Adds an animation described by a config. Uses an internal cache to avoid redoing work. */
105  void apply_new_animation_effect(const config & effect);
106 
107  /** Get a pointer to the current animation. */
108  unit_animation* get_animation() const { return anim_.get(); }
109 
110  friend class unit;
111  friend class unit_drawer;
112 private:
113  const unit & u_; /**< A reference to the unit that owns this object. It does so with a scoped pointer, so this reference should not dangle. */
114 
115  boost::scoped_ptr<unit_animation> anim_; /**< The current animation. */
116  std::vector<unit_animation> animations_; /**< List of registered animations for this unit. */
117 
118  STATE state_; //!< animation state
119 
120  int next_idling_; //!< time for next idle animation
121  int frame_begin_time_; //!< time for the frame to begin
122 
123  bool draw_bars_; //!< bool indicating whether to draw bars with the unit
124  bool refreshing_; //!< avoid infinite recursion. flag used for drawing / animation
125 
126  halo::handle unit_halo_; //!< handle to the halo of this unit
127 };
128 
129 #endif
bool refreshing_
avoid infinite recursion. flag used for drawing / animation
const unit & u_
A reference to the unit that owns this object.
Definition: unit.hpp:95
void set_disabled_ghosted(bool with_bars=true)
Whiteboard related somehow.
void set_selecting()
Sets the animation state to that when the unit is selected.
animation will be automatically replaced by a standing anim when finished
bool draw_bars_
bool indicating whether to draw bars with the unit
void refresh()
Intermittently activates the idling animations in place of the standing animations.
int frame_begin_time_
time for the frame to begin
unit_animation_component(unit &my_unit, const unit_animation_component &o)
Copy construct a unit animation component, for use when copy constructing a unit. ...
void clear_haloes()
Clear the haloes associated to the unit.
unit_animation * get_animation() const
Get a pointer to the current animation.
STATE state_
animation state
bool invalidate(const display &disp)
Invalidates an animation with respect to a display object, preparing it for redraw.
static const map_location & null_location()
Definition: location.hpp:195
boost::scoped_ptr< unit_animation > anim_
The current animation.
STATE
States for animation.
Encapsulates the map of the game.
Definition: location.hpp:38
void set_idling()
Sets the animation state to idling.
void start_animation(int start_time, const unit_animation *animation, bool with_bars, const std::string &text="", Uint32 text_color=0, STATE state=STATE_ANIM)
Begin an animation.
void apply_new_animation_effect(const config &effect)
Adds an animation described by a config.
std::vector< unit_animation > animations_
List of registered animations for this unit.
const unit_animation * choose_animation(const display &disp, const map_location &loc, const std::string &event, const map_location &second_loc=map_location::null_location(), const int damage=0, const unit_animation::hit_type hit_type=unit_animation::INVALID, const attack_type *attack=nullptr, const attack_type *second_attack=nullptr, int swing_num=0)
Chooses an appropriate animation from the list of known animations.
cl_event event
Definition: glew.h:3070
unit_animation_component(unit &my_unit)
normal anims
halo::handle unit_halo_
handle to the halo of this unit
void set_standing(bool with_bars=true)
Sets the animation state to standing.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void set_ghosted(bool with_bars=true)
Sets the animation state to ghosted.
void reset_after_advance(const unit_type *newtype=nullptr)
Resets the animations list after the unit is advanced.
int next_idling_
time for next idle animation