#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_animation * | 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. 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 (const std::chrono::milliseconds &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_animation * | get_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 unit & | u_ |
A reference to the unit that owns this object. More... | |
std::unique_ptr< unit_animation > | anim_ |
The current animation. More... | |
std::vector< unit_animation > | animations_ |
List of registered animations for this unit. More... | |
STATE | state_ |
animation state More... | |
std::chrono::steady_clock::time_point | next_idling_ |
time for next idle animation More... | |
std::chrono::milliseconds | 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::handle > | abil_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 |
Definition at line 27 of file animation_component.hpp.
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.
|
inline |
normal anims
Default construct a unit animation component corresponding to a unit.
Definition at line 37 of file animation_component.hpp.
|
inline |
Copy construct a unit animation component, for use when copy constructing a unit.
Definition at line 53 of file animation_component.hpp.
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 199 of file animation_component.cpp.
References unit_animation::add_anims().
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 44 of file animation_component.cpp.
References randomness::rng::default_instance(), randomness::rng::get_random_int(), and unit_animation::MATCH_FAIL.
void unit_animation_component::clear_haloes | ( | ) |
Clear the haloes associated to the unit.
Definition at line 153 of file animation_component.cpp.
Referenced by unit_drawer::redraw_unit().
|
inline |
Get a pointer to the current animation.
Definition at line 113 of file animation_component.hpp.
References anim_.
std::vector< std::string > unit_animation_component::get_flags | ( | ) |
Get the flags of all registered animations.
Definition at line 212 of file animation_component.cpp.
References game_config::images::flag.
Referenced by UNIT_GETTER().
bool unit_animation_component::invalidate | ( | const display & | disp | ) |
Invalidates an animation with respect to a display object, preparing it for redraw.
Definition at line 161 of file animation_component.cpp.
References display::context(), gamemap_base::get_terrain(), gamemap::get_terrain_info(), display::get_zoom_factor(), frame_parameters::halo_mod, frame_parameters::halo_y, frame_parameters::image, frame_parameters::image_mod, display_context::map(), terrain_type::unit_height_adjust(), and frame_parameters::y.
void unit_animation_component::refresh | ( | ) |
Intermittently activates the idling animations in place of the standing animations.
Used by display object.
Definition at line 131 of file animation_component.cpp.
References get_current_animation_tick(), display::get_singleton(), and display::tile_nearly_on_screen().
void unit_animation_component::reset_after_advance | ( | const unit_type * | newtype = nullptr | ) |
Resets the animations list after the unit is advanced.
Definition at line 189 of file animation_component.cpp.
References unit_type::animations().
void unit_animation_component::set_disabled_ghosted | ( | bool | with_bars = true | ) |
Whiteboard related somehow.
TODO: Figure out exactly what this does.
Definition at line 86 of file animation_component.cpp.
Referenced by wb::ghost_owner_unit().
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 79 of file animation_component.cpp.
void unit_animation_component::set_idling | ( | ) |
Sets the animation state to idling.
Definition at line 92 of file animation_component.cpp.
void unit_animation_component::set_selecting | ( | ) |
Sets the animation state to that when the unit is selected.
Definition at line 98 of file animation_component.cpp.
References prefs::get().
Referenced by events::mouse_handler::select_hex().
void unit_animation_component::set_standing | ( | bool | with_bars = true | ) |
Sets the animation state to standing.
Definition at line 68 of file animation_component.cpp.
References prefs::get().
Referenced by editor::editor_action_unit_replace::perform_without_undo(), unit_drawer::redraw_unit(), and wb::unghost_owner_unit().
void unit_animation_component::start_animation | ( | const std::chrono::milliseconds & | start_time, |
const unit_animation * | animation, | ||
bool | with_bars, | ||
const std::string & | text = "" , |
||
color_t | text_color = {} , |
||
STATE | state = STATE_ANIM |
||
) |
Begin an animation.
Definition at line 109 of file animation_component.cpp.
|
friend |
Definition at line 118 of file animation_component.hpp.
|
friend |
Definition at line 119 of file animation_component.hpp.
|
private |
handle to the abilities halos of this unit
Definition at line 145 of file animation_component.hpp.
|
private |
vector used to check that halo_abilities vector isn't modified between each read
Definition at line 147 of file animation_component.hpp.
|
private |
The current animation.
Definition at line 125 of file animation_component.hpp.
Referenced by get_animation(), and unit_drawer::redraw_unit().
|
private |
List of registered animations for this unit.
Definition at line 127 of file animation_component.hpp.
|
private |
bool indicating whether to draw bars with the unit
Definition at line 138 of file animation_component.hpp.
Referenced by unit_drawer::redraw_unit().
|
private |
time for the frame to begin
Definition at line 135 of file animation_component.hpp.
|
private |
time for next idle animation
Definition at line 133 of file animation_component.hpp.
|
private |
avoid infinite recursion.
flag used for drawing / animation
Definition at line 140 of file animation_component.hpp.
Referenced by unit_drawer::redraw_unit().
|
private |
animation state
Definition at line 130 of file animation_component.hpp.
|
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 122 of file animation_component.hpp.
|
private |
handle to the halo of this unit
Definition at line 143 of file animation_component.hpp.