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_mover & | operator= (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_ |
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.
|
delete |
|
explicit |
The path must remain unchanged for the life of this object.
Definition at line 174 of file udisplay.cpp.
unit_display::unit_mover::~unit_mover | ( | ) |
Definition at line 197 of file udisplay.cpp.
References animator_, unit_animator::clear(), and update_shown_unit().
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().
|
delete |
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().
|
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().
void unit_display::unit_mover::start | ( | const unit_ptr & | u | ) |
Initiates the display of movement for the supplied unit.
This should be called before attempting to display moving to a new hex.
Definition at line 257 of file udisplay.cpp.
References unit_animator::add_animation(), animate_, animator_, can_draw_, unit_animator::clear(), disp_, fake_unit_ptr::get_unit_ptr(), display::invalidate(), is_enemy_, display::ONSCREEN, path_, replace_temporary(), display::scroll_to_tiles(), unit_animator::start_animations(), temp_unit_ptr_, wait_for_anims(), unit_animator::wait_for_end(), and was_hidden_.
Referenced by unit_display::move_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().
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().
|
private |
Definition at line 65 of file udisplay.hpp.
Referenced by finish(), proceed_to(), and start().
|
private |
Definition at line 67 of file udisplay.hpp.
Referenced by finish(), proceed_to(), start(), wait_for_anims(), and ~unit_mover().
|
private |
Definition at line 64 of file udisplay.hpp.
Referenced by finish(), proceed_to(), and start().
|
private |
Definition at line 73 of file udisplay.hpp.
Referenced by finish(), proceed_to(), and wait_for_anims().
|
private |
Definition at line 63 of file udisplay.hpp.
Referenced by finish(), proceed_to(), replace_temporary(), start(), unit_mover(), and wait_for_anims().
|
private |
Definition at line 66 of file udisplay.hpp.
Referenced by proceed_to().
|
private |
Definition at line 76 of file udisplay.hpp.
Referenced by proceed_to(), replace_temporary(), and start().
|
private |
Definition at line 72 of file udisplay.hpp.
Referenced by finish(), proceed_to(), start(), unit_mover(), and wait_for_anims().
|
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().
|
private |
Definition at line 74 of file udisplay.hpp.
Referenced by finish(), proceed_to(), replace_temporary(), start(), and update_shown_unit().
|
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().
|
private |
Definition at line 75 of file udisplay.hpp.
Referenced by finish(), replace_temporary(), start(), and update_shown_unit().