The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
unit_display::unit_mover Class Reference

A class to encapsulate the steps of drawing a unit's move. More...

#include <udisplay.hpp>

Public Member Functions

 unit_mover (const unit_mover &)=delete
 
unit_moveroperator= (const unit_mover &)=delete
 
 unit_mover (const std::vector< map_location > &path, bool animate=true, bool force_scroll=false)
 The path must remain unchanged for the life of this object. More...
 
 ~unit_mover ()
 
void start (unit_ptr u)
 Initiates the display of movement for the supplied unit. More...
 
void proceed_to (unit_ptr u, size_t path_index, bool update=false, bool wait=true)
 Visually moves a unit from the last hex we drew to the one specified by path_index. More...
 
void wait_for_anims ()
 Waits for the final animation of the most recent proceed_to() to finish. More...
 
void finish (unit_ptr u, map_location::DIRECTION dir=map_location::NDIRECTIONS)
 Finishes the display of movement for the supplied unit. More...
 

Private Member Functions

void replace_temporary (unit_ptr u)
 Makes the temporary unit used by this match the supplied unit. More...
 
void update_shown_unit ()
 Switches the display back to *shown_unit_ after animating. More...
 

Private Attributes

game_display *const disp_
 
const bool can_draw_
 
const bool animate_
 
const bool force_scroll_
 
unit_animator animator_
 
int wait_until_
 
unit_ptr shown_unit_
 The animation potential to wait until. INT_MIN for no wait; INT_MAX to wait for end. More...
 
const std::vector< map_location > & path_
 The unit to be (re-)shown after an animation finishes. More...
 
size_t current_
 
fake_unit_ptr temp_unit_ptr_
 
bool was_hidden_
 
bool is_enemy_
 

Detailed Description

A class to encapsulate the steps of drawing a unit's move.

If control over how far the unit moves is not needed, move_unit() may be a more convenient interface.

Definition at line 46 of file udisplay.hpp.

Constructor & Destructor Documentation

unit_display::unit_mover::unit_mover ( const unit_mover )
delete
unit_display::unit_mover::unit_mover ( const std::vector< map_location > &  path,
bool  animate = true,
bool  force_scroll = false 
)
explicit

The path must remain unchanged for the life of this object.

Definition at line 156 of file udisplay.cpp.

References disp_, and path_.

unit_display::unit_mover::~unit_mover ( )

Definition at line 180 of file udisplay.cpp.

References animator_, unit_animator::clear(), and update_shown_unit().

Member Function Documentation

void unit_display::unit_mover::finish ( unit_ptr  u,
map_location::DIRECTION  dir = map_location::NDIRECTIONS 
)

Finishes the display of movement for the supplied unit.

If called before showing the unit reach the end of the path, it will be assumed that the movement ended early. If dir is not supplied, the final direction will be determined by (the last two traversed hexes of) the path.

Definition at line 423 of file udisplay.cpp.

References unit_animator::add_animation(), animate_, animator_, can_draw_, unit_animator::clear(), current_, disp_, fake_unit_ptr::get(), events::mouse_handler::get_singleton(), display::invalidate(), events::mouse_handler::invalidate_reachmap(), map_location::NDIRECTIONS, path_, replace_temporary(), unit_animator::start_animations(), temp_unit_ptr_, wait_for_anims(), unit_animator::wait_for_end(), and was_hidden_.

Referenced by unit_display::move_unit().

unit_mover& unit_display::unit_mover::operator= ( const unit_mover )
delete
void unit_display::unit_mover::proceed_to ( unit_ptr  u,
size_t  path_index,
bool  update = false,
bool  wait = true 
)

Visually moves a unit from the last hex we drew to the one specified by path_index.

If path_index points to an earlier hex, we do nothing. The moving unit will only be updated if update is set to true; otherwise, the provided unit is merely hidden during the movement and re-shown after. (Not updating the unit can produce smoother animations in some cases.) If wait is set to false, this returns without waiting for the final animation to finish. Call wait_for_anims() to explicitly get this final wait (another call to proceed_to() or finish() will implicitly wait). The unit must remain valid until the wait is finished.

Definition at line 311 of file udisplay.cpp.

References animate_, animator_, can_draw_, current_, disp_, force_scroll_, display::get_disp_context(), fake_unit_ptr::get_unit_ptr(), display::invalidate(), is_enemy_, move_unit_between(), display::ONSCREEN, path_, replace_temporary(), display::scroll_to_tiles(), shown_unit_, teleport_unit_between(), temp_unit_ptr_, display::tile_fully_on_screen(), tiles_adjacent(), wait_for_anims(), and wait_until_.

Referenced by unit_display::move_unit().

void unit_display::unit_mover::replace_temporary ( unit_ptr  u)
private

Makes the temporary unit used by this match the supplied unit.

This is called when setting the initial unit, as well as replacing it with something new. When this finishes, the supplied unit is hidden, while the temporary unit is not hidden.

Definition at line 199 of file udisplay.cpp.

References disp_, resources::fake_units, resources::gameboard, game_board::get_team(), is_enemy_, temp_unit_ptr_, display::viewing_side(), and was_hidden_.

Referenced by finish(), proceed_to(), and start().

void unit_display::unit_mover::start ( unit_ptr  u)
void unit_display::unit_mover::update_shown_unit ( )
private

Switches the display back to *shown_unit_ after animating.

This uses temp_unit_ptr_, so (in the destructor) call this before deleting temp_unit_ptr_.

Definition at line 225 of file udisplay.cpp.

References shown_unit_, temp_unit_ptr_, and was_hidden_.

Referenced by wait_for_anims(), and ~unit_mover().

void unit_display::unit_mover::wait_for_anims ( )

Waits for the final animation of the most recent proceed_to() to finish.

It is not necessary to call this unless you want to wait before the next call to proceed_to() or finish().

Todo:
For wesnoth 1.14+: check if efficient for redrawing? Check with large animated units too make sure artifacts are not left on screen after unit movement in particular.

Definition at line 383 of file udisplay.cpp.

References animator_, unit_animator::clear(), current_, disp_, get_adjacent_tiles(), i, display::invalidate(), path_, update_shown_unit(), unit_animator::wait_for_end(), unit_animator::wait_until(), and wait_until_.

Referenced by finish(), proceed_to(), and start().

Member Data Documentation

const bool unit_display::unit_mover::animate_
private

Definition at line 66 of file udisplay.hpp.

Referenced by finish(), proceed_to(), and start().

unit_animator unit_display::unit_mover::animator_
private

Definition at line 68 of file udisplay.hpp.

Referenced by finish(), proceed_to(), start(), wait_for_anims(), and ~unit_mover().

const bool unit_display::unit_mover::can_draw_
private

Definition at line 65 of file udisplay.hpp.

Referenced by finish(), proceed_to(), and start().

size_t unit_display::unit_mover::current_
private

Definition at line 72 of file udisplay.hpp.

Referenced by finish(), proceed_to(), and wait_for_anims().

game_display* const unit_display::unit_mover::disp_
private

Definition at line 64 of file udisplay.hpp.

Referenced by finish(), proceed_to(), replace_temporary(), start(), unit_mover(), and wait_for_anims().

const bool unit_display::unit_mover::force_scroll_
private

Definition at line 67 of file udisplay.hpp.

Referenced by proceed_to().

bool unit_display::unit_mover::is_enemy_
private

Definition at line 75 of file udisplay.hpp.

Referenced by proceed_to(), replace_temporary(), and start().

const std::vector<map_location>& unit_display::unit_mover::path_
private

The unit to be (re-)shown after an animation finishes.

Definition at line 71 of file udisplay.hpp.

Referenced by finish(), proceed_to(), start(), unit_mover(), and wait_for_anims().

unit_ptr unit_display::unit_mover::shown_unit_
private

The animation potential to wait until. INT_MIN for no wait; INT_MAX to wait for end.

Definition at line 70 of file udisplay.hpp.

Referenced by proceed_to(), and update_shown_unit().

fake_unit_ptr unit_display::unit_mover::temp_unit_ptr_
private

Definition at line 73 of file udisplay.hpp.

Referenced by finish(), proceed_to(), replace_temporary(), start(), and update_shown_unit().

int unit_display::unit_mover::wait_until_
private

Definition at line 69 of file udisplay.hpp.

Referenced by proceed_to(), and wait_for_anims().

bool unit_display::unit_mover::was_hidden_
private

Definition at line 74 of file udisplay.hpp.

Referenced by finish(), replace_temporary(), start(), and update_shown_unit().


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