示例#1
0
        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);
            };
        }
示例#2
0
        public AddRemoveObjectUndoInstance(EditorUndoManager parent, PositionBasedObjectInstance obj, bool created) : base(parent, obj.Room)
        {
            Created    = created;
            UndoObject = obj;

            Valid = () =>
            {
                var result = UndoObject != null && ((Created && UndoObject.Room != null) ||
                                                    (!Created && Room.ExistsInLevel && Room.LocalArea.Width > UndoObject.SectorPosition.X && Room.LocalArea.Height > UndoObject.SectorPosition.Y));

                if (!result)
                {
                    return(result);
                }

                // Special case for imported geometry: in case user deletes model from geometry list, we should prevent it from reappearing on the map.

                if (UndoObject is ImportedGeometryInstance)
                {
                    var geo = UndoObject as ImportedGeometryInstance;
                    if (!Room.Level.Settings.ImportedGeometries.Contains(geo.Model))
                    {
                        return(false);
                    }
                }
                return(result);
            };

            UndoAction = () =>
            {
                if (Created)
                {
                    EditorActions.DeleteObjectWithoutUpdate(UndoObject);
                }
                else
                {
                    var backupPos = obj.Position; // Preserve original position and reassign it after placement
                    EditorActions.PlaceObjectWithoutUpdate(Room, obj.SectorPosition, UndoObject);
                    EditorActions.MoveObject(UndoObject, backupPos);
                }
            };

            RedoInstance = () =>
            {
                var result = new AddRemoveObjectUndoInstance(Parent, UndoObject, !Created);
                result.Room = Room; // Relink parent room
                return(result);
            };
        }
示例#3
0
 public AddSectorBasedObjectUndoInstance(EditorUndoManager parent, SectorBasedObjectInstance obj) : base(parent, obj.Room)
 {
     SectorObject = obj;
     Valid        = () => SectorObject != null && SectorObject.Room != null && Room != null && SectorObject.Room == Room && Room.ExistsInLevel;
     UndoAction   = () => EditorActions.DeleteObjectWithoutUpdate(SectorObject);
 }