The Battle for Wesnoth  1.19.7+dev
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
actions::undo_list Class Reference

Class to store the actions that a player can undo and redo. More...

#include <undo.hpp>

Public Member Functions

 undo_list (const undo_list &)=delete
 
undo_listoperator= (const undo_list &)=delete
 
 undo_list ()
 Constructor. More...
 
 ~undo_list ()
 Destructor. More...
 
void add_auto_shroud (bool turned_on)
 Adds an auto-shroud toggle to the undo stack. More...
 
void add_dismissal (const unit_const_ptr &u)
 Adds a dismissal to the undo stack. More...
 
void add_move (const unit_const_ptr &u, const std::vector< map_location >::const_iterator &begin, const std::vector< map_location >::const_iterator &end, int start_moves, const map_location::direction dir=map_location::direction::indeterminate)
 Adds a move to the undo stack. More...
 
void add_recall (const unit_const_ptr &u, const map_location &loc, const map_location &from)
 Adds a recall to the undo stack. More...
 
void add_recruit (const unit_const_ptr &u, const map_location &loc, const map_location &from)
 Adds a recruit to the undo stack. More...
 
template<class T , class... Args>
void add_custom (Args &&... args)
 
void clear ()
 Clears the stack of undoable (and redoable) actions. More...
 
bool commit_vision ()
 Updates fog/shroud based on the undo stack, then updates stack as needed. More...
 
void new_side_turn (int side)
 Performs some initializations and error checks when starting a new side-turn. More...
 
bool player_acted () const
 Returns true if the player has performed any actions this turn. More...
 
void read (const config &cfg, int current_side)
 Read the undo_list from the provided config. More...
 
void write (config &cfg) const
 Write the undo_list into the provided config. More...
 
bool can_undo () const
 True if there are actions that can be undone. More...
 
bool can_redo () const
 True if there are actions that can be redone. More...
 
void init_action ()
 called before a user action, starts collecting undo steps for the new action. More...
 
void finish_action (bool can_undo)
 called after a user action, pushes the collected undo steps on the undo stack. More...
 
void cleanup_action ()
 called after a user action, removes empty actions More...
 
void undo ()
 Undoes the top action on the undo stack. More...
 
void redo ()
 Redoes the top action on the redo stack. More...
 
undo_action_containerget_current ()
 

Private Types

typedef std::unique_ptr< undo_action_containeraction_ptr_t
 
typedef std::vector< action_ptr_taction_list
 
typedef std::vector< std::unique_ptr< config > > redos_list
 

Private Member Functions

void add (std::unique_ptr< undo_action > &&action)
 Adds an undo step to the current action. More...
 
bool apply_shroud_changes () const
 Applies the pending fog/shroud changes from the undo stack. More...
 

Private Attributes

action_ptr_t current_
 
action_list undos_
 
redos_list redos_
 
int side_
 Tracks the current side. More...
 
bool committed_actions_
 Tracks if actions have been cleared from the stack since the turn began. More...
 

Detailed Description

Class to store the actions that a player can undo and redo.

Definition at line 34 of file undo.hpp.

Member Typedef Documentation

◆ action_list

typedef std::vector<action_ptr_t> actions::undo_list::action_list
private

Definition at line 37 of file undo.hpp.

◆ action_ptr_t

typedef std::unique_ptr<undo_action_container> actions::undo_list::action_ptr_t
private

Definition at line 36 of file undo.hpp.

◆ redos_list

typedef std::vector<std::unique_ptr<config> > actions::undo_list::redos_list
private

Definition at line 38 of file undo.hpp.

Constructor & Destructor Documentation

◆ undo_list() [1/2]

actions::undo_list::undo_list ( const undo_list )
delete

◆ undo_list() [2/2]

actions::undo_list::undo_list ( )

Constructor.

The config is allowed to be invalid.

Definition at line 61 of file undo.cpp.

◆ ~undo_list()

actions::undo_list::~undo_list ( )

Destructor.

Definition at line 69 of file undo.cpp.

Member Function Documentation

◆ add()

void actions::undo_list::add ( std::unique_ptr< undo_action > &&  action)
inlineprivate

Adds an undo step to the current action.

Definition at line 117 of file undo.hpp.

References current_.

Referenced by add_auto_shroud(), add_custom(), add_dismissal(), add_move(), add_recall(), and add_recruit().

◆ add_auto_shroud()

void actions::undo_list::add_auto_shroud ( bool  turned_on)

Adds an auto-shroud toggle to the undo stack.

Definition at line 79 of file undo.cpp.

References add().

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

◆ add_custom()

template<class T , class... Args>
void actions::undo_list::add_custom ( Args &&...  args)
inline

Definition at line 67 of file undo.hpp.

References add().

Referenced by actions::get_village().

◆ add_dismissal()

void actions::undo_list::add_dismissal ( const unit_const_ptr u)

Adds a dismissal to the undo stack.

Definition at line 88 of file undo.cpp.

References add().

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

◆ add_move()

void actions::undo_list::add_move ( const unit_const_ptr u,
const std::vector< map_location >::const_iterator &  begin,
const std::vector< map_location >::const_iterator &  end,
int  start_moves,
const map_location::direction  dir = map_location::direction::indeterminate 
)

Adds a move to the undo stack.

Definition at line 96 of file undo.cpp.

References add().

◆ add_recall()

void actions::undo_list::add_recall ( const unit_const_ptr u,
const map_location loc,
const map_location from 
)

Adds a recall to the undo stack.

Definition at line 108 of file undo.cpp.

References add(), and loc.

Referenced by actions::recall_unit().

◆ add_recruit()

void actions::undo_list::add_recruit ( const unit_const_ptr u,
const map_location loc,
const map_location from 
)

Adds a recruit to the undo stack.

Definition at line 117 of file undo.cpp.

References add(), and loc.

Referenced by actions::recruit_unit().

◆ apply_shroud_changes()

bool actions::undo_list::apply_shroud_changes ( ) const
private

Applies the pending fog/shroud changes from the undo stack.

Does nothing if the the current side does not use fog or shroud.

Returns
true if shroud or fog was cleared.

Definition at line 359 of file undo.cpp.

References team::auto_shroud_updates(), actions::clear_shroud(), actions::shroud_clearer::clear_unit(), actions::shroud_clearer::fire_events(), team::fog_or_shroud(), resources::gameboard, game_display::get_singleton(), game_board::get_team(), i, actions::shroud_clearer::invalidate_after_clear(), game_display::invalidate_unit(), synced_context::is_synced(), LOG_NG, side_, and undos_.

Referenced by clear(), and commit_vision().

◆ can_redo()

bool actions::undo_list::can_redo ( ) const
inline

True if there are actions that can be redone.

Definition at line 97 of file undo.hpp.

References redos_.

Referenced by play_controller::can_redo().

◆ can_undo()

bool actions::undo_list::can_undo ( ) const
inline

True if there are actions that can be undone.

Definition at line 95 of file undo.hpp.

References undos_.

Referenced by play_controller::can_undo(), finish_action(), and playmp_controller::send_actions().

◆ cleanup_action()

void actions::undo_list::cleanup_action ( )

called after a user action, removes empty actions

Definition at line 269 of file undo.cpp.

References undo(), and undos_.

Referenced by synced_context::run_and_store().

◆ clear()

void actions::undo_list::clear ( )

Clears the stack of undoable (and redoable) actions.

(Also handles updating fog/shroud if needed.) Call this if an action alters the game state, but add that action to the stack before calling this (if the action is a kind that can be undone). This may fire events and change the game state.

Definition at line 131 of file undo.cpp.

References apply_shroud_changes(), committed_actions_, redos_, and undos_.

Referenced by synced_context::block_undo(), ai::recall_result::do_execute(), ai::recruit_result::do_execute(), wb::side_actions::execute(), finish_action(), playsingle_controller::play_ai_turn(), playmp_controller::play_human_turn(), wb::manager::set_active(), and playmp_controller::surrender().

◆ commit_vision()

bool actions::undo_list::commit_vision ( )

Updates fog/shroud based on the undo stack, then updates stack as needed.

Returns true if somethign was cleared.

Call this when "updating shroud now". This may fire events and change the game state.

Definition at line 153 of file undo.cpp.

References apply_shroud_changes(), committed_actions_, and undos_.

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

◆ finish_action()

void actions::undo_list::finish_action ( bool  can_undo)

called after a user action, pushes the collected undo steps on the undo stack.

Definition at line 258 of file undo.cpp.

References can_undo(), clear(), current_, synced_context::get_unit_id_diff(), and undos_.

Referenced by synced_context::run().

◆ get_current()

undo_action_container* actions::undo_list::get_current ( )
inline

Definition at line 110 of file undo.hpp.

References current_.

◆ init_action()

void actions::undo_list::init_action ( )

called before a user action, starts collecting undo steps for the new action.

Definition at line 251 of file undo.cpp.

References current_, and redos_.

Referenced by synced_context::run().

◆ new_side_turn()

void actions::undo_list::new_side_turn ( int  side)

Performs some initializations and error checks when starting a new side-turn.

Parameters
[in]sideThe side whose turn is about to start.

Definition at line 173 of file undo.cpp.

References committed_actions_, ERR_NG, redos_, side_, and undos_.

Referenced by play_controller::do_init_side().

◆ operator=()

undo_list& actions::undo_list::operator= ( const undo_list )
delete

◆ player_acted()

bool actions::undo_list::player_acted ( ) const
inline

Returns true if the player has performed any actions this turn.

Definition at line 86 of file undo.hpp.

References committed_actions_, and undos_.

◆ read()

void actions::undo_list::read ( const config cfg,
int  current_side 
)

Read the undo_list from the provided config.

Currently, this is only used when the undo_list is empty, but in theory it could be used to append the config to the current data.

Definition at line 199 of file undo.cpp.

References config::child_range(), committed_actions_, config::debug(), e, ERR_NG, config::has_attribute(), redos_, side_, and undos_.

◆ redo()

void actions::undo_list::redo ( )

Redoes the top action on the redo stack.

Definition at line 313 of file undo.cpp.

References _(), data, ERR_NG, game_display::get_singleton(), wfl::msg(), resources::recorder, replay::redo(), redos_, synced_context::run(), and gui2::show_transient_message().

Referenced by play_controller::redo().

◆ undo()

void actions::undo_list::undo ( )

◆ write()

void actions::undo_list::write ( config cfg) const

Write the undo_list into the provided config.

Definition at line 239 of file undo.cpp.

References config::add_child(), committed_actions_, redos_, and undos_.

Member Data Documentation

◆ committed_actions_

bool actions::undo_list::committed_actions_
private

Tracks if actions have been cleared from the stack since the turn began.

Definition at line 134 of file undo.hpp.

Referenced by clear(), commit_vision(), new_side_turn(), player_acted(), read(), and write().

◆ current_

action_ptr_t actions::undo_list::current_
private

Definition at line 127 of file undo.hpp.

Referenced by add(), finish_action(), get_current(), and init_action().

◆ redos_

redos_list actions::undo_list::redos_
private

Definition at line 129 of file undo.hpp.

Referenced by can_redo(), clear(), init_action(), new_side_turn(), read(), redo(), undo(), and write().

◆ side_

int actions::undo_list::side_
private

Tracks the current side.

Definition at line 132 of file undo.hpp.

Referenced by apply_shroud_changes(), new_side_turn(), read(), and undo().

◆ undos_

action_list actions::undo_list::undos_
private

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