The Battle for Wesnoth  1.19.5+dev
Public Types | Public Member Functions | Private Attributes | Friends | List of all members
unit_animation_component Class Reference

#include <animation_component.hpp>

Public Types

enum  STATE { STATE_STANDING , STATE_FORGET , STATE_ANIM }
 States for animation. More...
 

Public Member Functions

 unit_animation_component (unit &my_unit)
 normal anims More...
 
 unit_animation_component (unit &my_unit, const unit_animation_component &o)
 Copy construct a unit animation component, for use when copy constructing a unit. More...
 
const unit_animationchoose_animation (const map_location &loc, const std::string &event, const map_location &second_loc=map_location::null_location(), const int damage=0, const strike_result::type hit_type=strike_result::type::invalid, const_attack_ptr attack=nullptr, const_attack_ptr second_attack=nullptr, int swing_num=0)
 Chooses an appropriate animation from the list of known animations. More...
 
void set_standing (bool with_bars=true)
 Sets the animation state to standing. More...
 
void set_ghosted (bool with_bars=true)
 Sets the animation state to ghosted. More...
 
void set_disabled_ghosted (bool with_bars=true)
 Whiteboard related somehow. More...
 
void set_idling ()
 Sets the animation state to idling. More...
 
void set_selecting ()
 Sets the animation state to that when the unit is selected. More...
 
void start_animation (int start_time, const unit_animation *animation, bool with_bars, const std::string &text="", color_t text_color={}, STATE state=STATE_ANIM)
 Begin an animation. More...
 
bool invalidate (const display &disp)
 Invalidates an animation with respect to a display object, preparing it for redraw. More...
 
void refresh ()
 Intermittently activates the idling animations in place of the standing animations. More...
 
void clear_haloes ()
 Clear the haloes associated to the unit. More...
 
void reset_after_advance (const unit_type *newtype=nullptr)
 Resets the animations list after the unit is advanced. More...
 
void apply_new_animation_effect (const config &effect)
 Adds an animation described by a config. More...
 
unit_animationget_animation () const
 Get a pointer to the current animation. More...
 
std::vector< std::string > get_flags ()
 Get the flags of all registered animations. More...
 

Private Attributes

const unitu_
 A reference to the unit that owns this object. More...
 
std::unique_ptr< unit_animationanim_
 The current animation. More...
 
std::vector< unit_animationanimations_
 List of registered animations for this unit. More...
 
STATE state_
 animation state More...
 
int next_idling_
 time for next idle animation More...
 
int frame_begin_time_
 time for the frame to begin More...
 
bool draw_bars_
 bool indicating whether to draw bars with the unit More...
 
bool refreshing_
 avoid infinite recursion. More...
 
halo::handle unit_halo_
 handle to the halo of this unit More...
 
std::vector< halo::handleabil_halos_
 handle to the abilities halos of this unit More...
 
std::vector< std::string > abil_halos_ref_
 vector used to check that halo_abilities vector isn't modified between each read More...
 

Friends

class unit
 
class unit_drawer
 

Detailed Description

Definition at line 27 of file animation_component.hpp.

Member Enumeration Documentation

◆ STATE

States for animation.

Enumerator
STATE_STANDING 
STATE_FORGET 

anim must fit in a hex

STATE_ANIM 

animation will be automatically replaced by a standing anim when finished

Definition at line 31 of file animation_component.hpp.

Constructor & Destructor Documentation

◆ unit_animation_component() [1/2]

unit_animation_component::unit_animation_component ( unit my_unit)
inline

normal anims

Default construct a unit animation component corresponding to a unit.

Definition at line 37 of file animation_component.hpp.

◆ unit_animation_component() [2/2]

unit_animation_component::unit_animation_component ( unit my_unit,
const unit_animation_component o 
)
inline

Copy construct a unit animation component, for use when copy constructing a unit.

Definition at line 51 of file animation_component.hpp.

Member Function Documentation

◆ apply_new_animation_effect()

void unit_animation_component::apply_new_animation_effect ( const config effect)

Adds an animation described by a config.

Uses an internal cache to avoid redoing work.

Definition at line 197 of file animation_component.cpp.

References unit_animation::add_anims(), and animations_.

◆ choose_animation()

const unit_animation * unit_animation_component::choose_animation ( const map_location loc,
const std::string &  event,
const map_location second_loc = map_location::null_location(),
const int  damage = 0,
const strike_result::type  hit_type = strike_result::type::invalid,
const_attack_ptr  attack = nullptr,
const_attack_ptr  second_attack = nullptr,
int  swing_num = 0 
)

Chooses an appropriate animation from the list of known animations.

Definition at line 42 of file animation_component.cpp.

References animations_, randomness::rng::default_instance(), randomness::rng::get_random_int(), unit_animation::MATCH_FAIL, and u_.

Referenced by set_disabled_ghosted(), set_ghosted(), set_idling(), set_selecting(), and set_standing().

◆ clear_haloes()

void unit_animation_component::clear_haloes ( )

Clear the haloes associated to the unit.

Definition at line 151 of file animation_component.cpp.

References abil_halos_, abil_halos_ref_, anim_, and unit_halo_.

Referenced by unit_drawer::redraw_unit().

◆ get_animation()

unit_animation* unit_animation_component::get_animation ( ) const
inline

Get a pointer to the current animation.

Definition at line 109 of file animation_component.hpp.

References anim_.

Referenced by invalidate().

◆ get_flags()

std::vector< std::string > unit_animation_component::get_flags ( )

Get the flags of all registered animations.

Definition at line 210 of file animation_component.cpp.

References animations_, and game_config::images::flag.

Referenced by UNIT_GETTER().

◆ invalidate()

bool unit_animation_component::invalidate ( const display disp)

◆ refresh()

void unit_animation_component::refresh ( )

Intermittently activates the idling animations in place of the standing animations.

Used by display object.

Definition at line 129 of file animation_component.cpp.

References anim_, get_current_animation_tick(), display::get_singleton(), unit::incapacitated(), unit::loc_, next_idling_, set_idling(), set_standing(), state_, STATE_FORGET, STATE_STANDING, display::tile_nearly_on_screen(), and u_.

◆ reset_after_advance()

void unit_animation_component::reset_after_advance ( const unit_type newtype = nullptr)

Resets the animations list after the unit is advanced.

Definition at line 187 of file animation_component.cpp.

References anim_, unit_type::animations(), animations_, and refreshing_.

◆ set_disabled_ghosted()

void unit_animation_component::set_disabled_ghosted ( bool  with_bars = true)

Whiteboard related somehow.

TODO: Figure out exactly what this does.

Definition at line 84 of file animation_component.cpp.

References choose_animation(), unit::loc_, start_animation(), and u_.

Referenced by wb::ghost_owner_unit().

◆ set_ghosted()

void unit_animation_component::set_ghosted ( bool  with_bars = true)

Sets the animation state to ghosted.

(For use with whiteboard / planning mode.)

Definition at line 77 of file animation_component.cpp.

References anim_, choose_animation(), unit::loc_, start_animation(), and u_.

◆ set_idling()

void unit_animation_component::set_idling ( )

Sets the animation state to idling.

Definition at line 90 of file animation_component.cpp.

References choose_animation(), unit::loc_, start_animation(), STATE_FORGET, and u_.

Referenced by refresh().

◆ set_selecting()

void unit_animation_component::set_selecting ( )

Sets the animation state to that when the unit is selected.

Definition at line 96 of file animation_component.cpp.

References choose_animation(), prefs::get(), unit::incapacitated(), unit::loc_, start_animation(), STATE_FORGET, and u_.

Referenced by events::mouse_handler::select_hex().

◆ set_standing()

void unit_animation_component::set_standing ( bool  with_bars = true)

◆ start_animation()

void unit_animation_component::start_animation ( int  start_time,
const unit_animation animation,
bool  with_bars,
const std::string &  text = "",
color_t  text_color = {},
STATE  state = STATE_ANIM 
)

Friends And Related Function Documentation

◆ unit

friend class unit
friend

Definition at line 114 of file animation_component.hpp.

◆ unit_drawer

friend class unit_drawer
friend

Definition at line 115 of file animation_component.hpp.

Member Data Documentation

◆ abil_halos_

std::vector<halo::handle> unit_animation_component::abil_halos_
private

handle to the abilities halos of this unit

Definition at line 141 of file animation_component.hpp.

Referenced by clear_haloes().

◆ abil_halos_ref_

std::vector<std::string> unit_animation_component::abil_halos_ref_
private

vector used to check that halo_abilities vector isn't modified between each read

Definition at line 143 of file animation_component.hpp.

Referenced by clear_haloes().

◆ anim_

std::unique_ptr<unit_animation> unit_animation_component::anim_
private

◆ animations_

std::vector<unit_animation> unit_animation_component::animations_
private

List of registered animations for this unit.

Definition at line 123 of file animation_component.hpp.

Referenced by apply_new_animation_effect(), choose_animation(), get_flags(), and reset_after_advance().

◆ draw_bars_

bool unit_animation_component::draw_bars_
private

bool indicating whether to draw bars with the unit

Definition at line 134 of file animation_component.hpp.

Referenced by unit_drawer::redraw_unit(), and start_animation().

◆ frame_begin_time_

int unit_animation_component::frame_begin_time_
private

time for the frame to begin

Definition at line 131 of file animation_component.hpp.

Referenced by start_animation().

◆ next_idling_

int unit_animation_component::next_idling_
private

time for next idle animation

Definition at line 129 of file animation_component.hpp.

Referenced by refresh(), and start_animation().

◆ refreshing_

bool unit_animation_component::refreshing_
private

avoid infinite recursion.

flag used for drawing / animation

Definition at line 136 of file animation_component.hpp.

Referenced by unit_drawer::redraw_unit(), and reset_after_advance().

◆ state_

STATE unit_animation_component::state_
private

animation state

Definition at line 126 of file animation_component.hpp.

Referenced by refresh(), and start_animation().

◆ u_

const unit& unit_animation_component::u_
private

A reference to the unit that owns this object.

It does so with a scoped pointer, so this reference should not dangle.

Definition at line 118 of file animation_component.hpp.

Referenced by choose_animation(), invalidate(), refresh(), set_disabled_ghosted(), set_ghosted(), set_idling(), set_selecting(), set_standing(), and start_animation().

◆ unit_halo_

halo::handle unit_animation_component::unit_halo_
private

handle to the halo of this unit

Definition at line 139 of file animation_component.hpp.

Referenced by clear_haloes().


The documentation for this class was generated from the following files: