fix [allow_undo] in menu event commands

This was disabled in a previous commit
This commit is contained in:
gfgtdf 2015-06-13 18:27:03 +02:00
parent 6b28e1ae89
commit f42ea8097c
4 changed files with 45 additions and 3 deletions

View File

@ -162,6 +162,14 @@ void undo_list::add_auto_shroud(bool turned_on)
add(new undo::auto_shroud_action(turned_on));
}
void undo_list::add_dummy()
{
/// @todo: Consecutive shroud actions can be collapsed into one.
// Do not call add(), as this should not clear the redo stack.
add(new undo_dummy_action());
}
/**
* Adds a dismissal to the undo stack.
*/

View File

@ -51,6 +51,8 @@ public:
/// Adds an auto-shroud toggle to the undo stack.
void add_auto_shroud(bool turned_on);
/// Adds an auto-shroud toggle to the undo stack.
void add_dummy();
/// Adds a dismissal to the undo stack.
void add_dismissal(const unit_const_ptr u);
/// Adds a move to the undo stack.

View File

@ -74,4 +74,30 @@ namespace actions {
int unit_id_diff;
};
/// entry for player actions that do not need any special code to be performed when undoing such as right-click menu items.
struct undo_dummy_action : undo_action
{
undo_dummy_action ()
: undo_action()
{
}
explicit undo_dummy_action (const config & cfg)
: undo_action(cfg)
{
}
virtual const char* get_type() const { return "dummy"; }
virtual ~undo_dummy_action () {};
/// Undoes this action.
virtual bool undo(int side)
{
return true;
}
/// Redoes this action.
virtual bool redo(int side)
{
return true;
}
};
}

View File

@ -318,7 +318,7 @@ SYNCED_COMMAND_HANDLER_FUNCTION(move, child, use_undo, show, error_handler)
return true;
}
SYNCED_COMMAND_HANDLER_FUNCTION(fire_event, child, /*use_undo*/, /*show*/, /*error_handler*/)
SYNCED_COMMAND_HANDLER_FUNCTION(fire_event, child, use_undo, /*show*/, /*error_handler*/)
{
bool undoable = true;
@ -333,9 +333,15 @@ SYNCED_COMMAND_HANDLER_FUNCTION(fire_event, child, /*use_undo*/, /*show*/, /*er
} else {
undoable = undoable & !resources::game_events->pump().fire(event_name);
}
// Not clearing the undo stack here casues OOS because we added an entry to the replay but no entry to the undo stack.
// if ( !undoable)
resources::undo_stack->clear();
if(use_undo) {
if(!undoable) {
resources::undo_stack->clear();
} else {
resources::undo_stack->add_dummy();
}
}
return true;
}