public AddRemoveGhostBlockUndoInstance(EditorUndoManager parent, GhostBlockInstance obj, bool created) : base(parent, obj.Room) { Created = created; UndoObject = obj; Valid = () => UndoObject != null && ((Created && UndoObject.Room != null) || (!Created && Room.ExistsInLevel)) && !Room.CoordinateInvalid(UndoObject.SectorPosition); UndoAction = () => { if (Created) { EditorActions.DeleteObjectWithoutUpdate(UndoObject); } else { var backupPos = obj.SectorPosition; // Preserve original position and reassign it after placement EditorActions.PlaceGhostBlockWithoutUpdate(Room, obj.SectorPosition, UndoObject); } }; RedoInstance = () => { var result = new AddRemoveGhostBlockUndoInstance(Parent, UndoObject, !Created); result.Room = Room; // Relink parent room return(result); }; }
public TransformGhostBlockUndoInstance(EditorUndoManager parent, GhostBlockInstance obj) : base(parent, obj.Room) { UndoObject = obj; Floor = obj.Floor; Ceiling = obj.Ceiling; Valid = () => UndoObject != null && UndoObject.Room != null && Room.ExistsInLevel && !Room.CoordinateInvalid(UndoObject.SectorPosition); UndoAction = () => { UndoObject.Floor = Floor; UndoObject.Ceiling = Ceiling; Parent.Editor.ObjectChange(UndoObject, ObjectChangeType.Change); }; RedoInstance = () => new TransformGhostBlockUndoInstance(Parent, UndoObject); }
public void PushGhostBlockTransformed(GhostBlockInstance obj) => Push(new TransformGhostBlockUndoInstance(this, obj));
public void PushGhostBlockDeleted(GhostBlockInstance obj) => Push(new AddRemoveGhostBlockUndoInstance(this, obj, false));
public void PushGhostBlockCreated(GhostBlockInstance obj) => Push(new AddRemoveGhostBlockUndoInstance(this, obj, true));