The Battle for Wesnoth  1.19.7+dev
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 (const unit_ptr &u)
 Initiates the display of movement for the supplied unit. More...
 
void proceed_to (const unit_ptr &u, std::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 (const unit_ptr &u, map_location::direction dir=map_location::direction::indeterminate)
 Finishes the display of movement for the supplied unit. More...
 

Private Member Functions

void replace_temporary (const 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_
 
std::chrono::milliseconds wait_until_
 The animation potential to wait until. More...
 
unit_ptr shown_unit_
 The unit to be (re-)shown after an animation finishes. More...
 
const std::vector< map_location > & path_
 
std::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 45 of file udisplay.hpp.

Constructor & Destructor Documentation

◆ unit_mover() [1/2]

unit_display::unit_mover::unit_mover ( const unit_mover )
delete

◆ unit_mover() [2/2]

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 174 of file udisplay.cpp.

References disp_, and path_.

◆ ~unit_mover()

unit_display::unit_mover::~unit_mover ( )

Definition at line 197 of file udisplay.cpp.

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

Member Function Documentation

◆ finish()

void unit_display::unit_mover::finish ( const unit_ptr u,
map_location::direction  dir = map_location::direction::indeterminate 
)

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 433 of file udisplay.cpp.

References unit_animator::add_animation(), animate_, animator_, can_draw_, unit_animator::clear(), current_, disp_, events::mouse_handler::get_singleton(), fake_unit_ptr::get_unit_ptr(), map_location::indeterminate, display::invalidate(), 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().

◆ operator=()

unit_mover& unit_display::unit_mover::operator= ( const unit_mover )
delete

◆ proceed_to()

void unit_display::unit_mover::proceed_to ( const unit_ptr u,
std::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 314 of file udisplay.cpp.

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

Referenced by unit_display::move_unit().

◆ replace_temporary()

void unit_display::unit_mover::replace_temporary ( const 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 216 of file udisplay.cpp.

References disp_, resources::fake_units, resources::gameboard, game_board::get_team(), team::is_enemy(), is_enemy_, team::side(), temp_unit_ptr_, display::viewing_team(), and was_hidden_.

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

◆ start()

void unit_display::unit_mover::start ( const unit_ptr u)

◆ update_shown_unit()

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 242 of file udisplay.cpp.

References shown_unit_, temp_unit_ptr_, and was_hidden_.

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

◆ wait_for_anims()

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().

Definition at line 393 of file udisplay.cpp.

References animator_, unit_animator::clear(), current_, disp_, get_adjacent_tiles(), 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

◆ animate_

const bool unit_display::unit_mover::animate_
private

Definition at line 65 of file udisplay.hpp.

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

◆ animator_

unit_animator unit_display::unit_mover::animator_
private

Definition at line 67 of file udisplay.hpp.

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

◆ can_draw_

const bool unit_display::unit_mover::can_draw_
private

Definition at line 64 of file udisplay.hpp.

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

◆ current_

std::size_t unit_display::unit_mover::current_
private

Definition at line 73 of file udisplay.hpp.

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

◆ disp_

game_display* const unit_display::unit_mover::disp_
private

Definition at line 63 of file udisplay.hpp.

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

◆ force_scroll_

const bool unit_display::unit_mover::force_scroll_
private

Definition at line 66 of file udisplay.hpp.

Referenced by proceed_to().

◆ is_enemy_

bool unit_display::unit_mover::is_enemy_
private

Definition at line 76 of file udisplay.hpp.

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

◆ path_

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

Definition at line 72 of file udisplay.hpp.

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

◆ shown_unit_

unit_ptr unit_display::unit_mover::shown_unit_
private

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

Definition at line 71 of file udisplay.hpp.

Referenced by proceed_to(), and update_shown_unit().

◆ temp_unit_ptr_

fake_unit_ptr unit_display::unit_mover::temp_unit_ptr_
private

Definition at line 74 of file udisplay.hpp.

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

◆ wait_until_

std::chrono::milliseconds unit_display::unit_mover::wait_until_
private

The animation potential to wait until.

milliseconds::min for no wait; milliseconds::max to wait for end.

Definition at line 69 of file udisplay.hpp.

Referenced by proceed_to(), and wait_for_anims().

◆ was_hidden_

bool unit_display::unit_mover::was_hidden_
private

Definition at line 75 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: