Beispiel #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);
            };
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the ControllerBase class.
        /// </summary>
        public ControllerBase()
        {
            this.savePath = null;
            this.model    = null;

            this.asyncOperation = AsyncOperationManager.CreateOperation(null);

            this.undoManager       = this.InitializeUndoManager();
            this.searchEngine      = this.InitializeSearchEngine();
            this.validationManager = this.InitializeValidationManager();
            this.pluginManager     = this.InitializePluginManager();
        }
Beispiel #3
0
        public MoveRoomsUndoInstance(EditorUndoManager parent, List <Room> rooms, VectorInt3 delta) : base(parent, null)
        {
            Delta = -delta;
            Rooms = rooms;
            Rooms.ForEach(room => Sizes.Add(room, room.SectorSize));

            Valid = () => Rooms != null && Rooms.All(room => room != null && room.ExistsInLevel && !room.Locked) &&
                    Rooms.All(room => !Parent.Editor.Level.GetConnectedRooms(room).Except(Rooms).Any()) &&
                    Rooms.All(room => Sizes.ContainsKey(room) && room.SectorSize == Sizes[room]);
            UndoAction   = () => EditorActions.MoveRooms(Delta, Rooms, true);
            RedoInstance = () => new MoveRoomsUndoInstance(Parent, Rooms, Delta);
        }
Beispiel #4
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);
            };
        }
Beispiel #5
0
        public AddAdjoiningRoomUndoInstance(EditorUndoManager parent, Room room) : base(parent, room)
        {
            ParentRoom = room.Portals.Count() == 1 ? room.Portals.First().AdjoiningRoom : null;

            Valid = () => Room != null && ParentRoom != null &&
                    Room.ExistsInLevel && ParentRoom.ExistsInLevel &&
                    Room.Portals.Count(p => p.AdjoiningRoom == ParentRoom) == 1 && Room.AnyObjects.Count(obj => (obj is PortalInstance)) == 1 &&
                    Room.AnyObjects.Count(obj => !(obj is PortalInstance)) == 0;

            UndoAction = () =>
            {
                Parent.Editor.SelectedRoom = ParentRoom;
                EditorActions.DeleteRooms(new[] { Room });
            };
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        public GeometryUndoInstance(EditorUndoManager parent, Room room) : base(parent, room)
        {
            Area.Start = VectorInt2.Zero;
            Area.End   = new VectorInt2(room.NumXSectors, room.NumZSectors);

            Blocks = new Block[Area.Size.X + 1, Area.Size.Y + 1];

            for (int x = Area.X0, i = 0; x < Area.X1; x++, i++)
            {
                for (int z = Area.Y0, j = 0; z < Area.Y1; z++, j++)
                {
                    Blocks[i, j] = Room.Blocks[x, z].Clone();
                }
            }

            Valid = () => (Room != null && Room.ExistsInLevel && Room.SectorSize == Area.Size);

            UndoAction = () =>
            {
                for (int x = Area.X0, i = 0; x < Area.X1; x++, i++)
                {
                    for (int z = Area.Y0, j = 0; z < Area.Y1; z++, j++)
                    {
                        Room.Blocks[x, z].ReplaceGeometry(Parent.Editor.Level, Blocks[i, j]);
                    }
                }

                Room.BuildGeometry();
                Parent.Editor.RoomGeometryChange(Room);
                Parent.Editor.RoomSectorPropertiesChange(Room);
                var relevantRooms = room.Portals.Select(p => p.AdjoiningRoom);
                Parallel.ForEach(relevantRooms, relevantRoom => relevantRoom.BuildGeometry());

                foreach (Room relevantRoom in relevantRooms)
                {
                    Parent.Editor.RoomGeometryChange(relevantRoom);
                }
            };
            RedoInstance = () => new GeometryUndoInstance(Parent, Room);
        }
Beispiel #8
0
 private void OnEnable()
 {
     this.eventManager = (base.target as EventManagerEx);
     this.undoManager  = new EditorUndoManager(this.eventManager, this.eventManager.name);
 }
Beispiel #9
0
 public AddRoomUndoInstance(EditorUndoManager parent, Room room) : base(parent, room)
 {
     Valid      = () => Room != null && Room.ExistsInLevel && Room.AnyObjects.Count() == 0;
     UndoAction = () => EditorActions.DeleteRooms(new[] { Room });
 }
Beispiel #10
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);
 }
Beispiel #11
0
        public ChangeObjectPropertyUndoInstance(EditorUndoManager parent, PositionBasedObjectInstance obj) : base(parent, obj.Room)
        {
            UndoObject = obj;

            if (UndoObject is MoveableInstance)
            {
                var uo = (MoveableInstance)UndoObject;
                Base       = uo.WadObjectId;
                Properties = new List <object> {
                    uo.Ocb, uo.Invisible, uo.ClearBody, uo.CodeBits, uo.Color
                };
            }
            else if (UndoObject is StaticInstance)
            {
                var uo = (StaticInstance)UndoObject;
                Base       = uo.WadObjectId;
                Properties = new List <object> {
                    uo.Ocb, uo.Color
                };
            }
            else if (UndoObject is ImportedGeometryInstance)
            {
                var uo = (ImportedGeometryInstance)UndoObject;
                Base       = uo.Model;
                Properties = new List <object> {
                    uo.Scale
                };
            }
            else if (UndoObject is LightInstance)
            {
                Properties = new List <object> {
                    ((LightInstance)UndoObject).Color
                }
            }
            ;
            else if (UndoObject is SinkInstance)
            {
                Properties = new List <object> {
                    ((SinkInstance)UndoObject).Strength
                }
            }
            ;
            else if (UndoObject is SoundSourceInstance)
            {
                Properties = new List <object> {
                    ((SoundSourceInstance)UndoObject).SoundId
                }
            }
            ;

            Valid = () => UndoObject != null && UndoObject.Room != null && Room.ExistsInLevel;

            UndoAction = () =>
            {
                if (UndoObject is MoveableInstance)
                {
                    var uo = ((MoveableInstance)UndoObject);
                    uo.WadObjectId = (WadMoveableId)Base;
                    uo.Ocb         = (short)Properties[0];
                    uo.Invisible   = (bool)Properties[1];
                    uo.ClearBody   = (bool)Properties[2];
                    uo.CodeBits    = (byte)Properties[3];
                    uo.Color       = (Vector3)Properties[4];
                }
                else if (UndoObject is StaticInstance)
                {
                    var uo = ((StaticInstance)UndoObject);
                    uo.WadObjectId = (WadStaticId)Base;
                    uo.Ocb         = (short)Properties[0];
                    uo.Color       = (Vector3)Properties[1];
                }
                else if (UndoObject is ImportedGeometryInstance)
                {
                    var uo = ((ImportedGeometryInstance)UndoObject);
                    uo.Model = (ImportedGeometry)Base;
                    uo.Scale = (float)Properties[0];
                }
                else if (UndoObject is LightInstance)
                {
                    ((LightInstance)UndoObject).Color = (Vector3)Properties[0];
                    UndoObject.Room.RebuildLighting(parent.Editor.Configuration.Rendering3D_HighQualityLightPreview);
                }
                else if (UndoObject is SinkInstance)
                {
                    ((SinkInstance)UndoObject).Strength = (short)Properties[0];
                }
                else if (UndoObject is SoundSourceInstance)
                {
                    ((SoundSourceInstance)UndoObject).SoundId = (short)Properties[0];
                }

                parent.Editor.ObjectChange(UndoObject, ObjectChangeType.Change);
            };

            RedoInstance = () => new ChangeObjectPropertyUndoInstance(Parent, UndoObject);
        }
    }
Beispiel #12
0
 protected EditorUndoRedoInstance(EditorUndoManager parent, Room room)
 {
     Parent = parent; Room = room;
 }
Beispiel #13
0
        public TransformObjectUndoInstance(EditorUndoManager parent, PositionBasedObjectInstance obj) : base(parent, obj.Room)
        {
            UndoObject = obj;
            Position   = obj.Position;

            if (obj is ISizeable)
            {
                Size = ((ISizeable)obj).Size;
            }
            if (obj is IScaleable)
            {
                Scale = ((IScaleable)obj).Scale;
            }
            if (obj is IRotateableY)
            {
                RotationY = ((IRotateableY)obj).RotationY;
            }
            if (obj is IRotateableYX)
            {
                RotationX = ((IRotateableYX)obj).RotationX;
            }
            if (obj is IRotateableYXRoll)
            {
                Roll = ((IRotateableYXRoll)obj).Roll;
            }

            Valid = () => UndoObject != null && UndoObject.Room != null && Room.ExistsInLevel;

            UndoAction = () =>
            {
                bool roomChanged = false;

                if (UndoObject.Room != Room)
                {
                    var oldRoom = UndoObject.Room;
                    oldRoom.RemoveObject(Parent.Editor.Level, UndoObject);
                    Parent.Editor.ObjectChange(UndoObject, ObjectChangeType.Remove, oldRoom);

                    Room.AddObject(Parent.Editor.Level, UndoObject);
                    Parent.Editor.ObjectChange(UndoObject, ObjectChangeType.Add);

                    roomChanged = true;
                }

                UndoObject.Position = Position;
                if (UndoObject is ISizeable && Size.HasValue)
                {
                    ((ISizeable)obj).Size = Size.Value;
                }
                if (UndoObject is IScaleable && Scale.HasValue)
                {
                    ((IScaleable)obj).Scale = Scale.Value;
                }
                if (UndoObject is IRotateableY && RotationY.HasValue)
                {
                    ((IRotateableY)obj).RotationY = RotationY.Value;
                }
                if (UndoObject is IRotateableYX && RotationX.HasValue)
                {
                    ((IRotateableYX)obj).RotationX = RotationX.Value;
                }
                if (UndoObject is IRotateableYXRoll && Roll.HasValue)
                {
                    ((IRotateableYXRoll)obj).Roll = Roll.Value;
                }

                if (UndoObject is LightInstance)
                {
                    Room.BuildGeometry(); // Rebuild lighting!
                }
                if (!roomChanged)
                {
                    Parent.Editor.ObjectChange(UndoObject, ObjectChangeType.Change);
                }
            };
            RedoInstance = () => new TransformObjectUndoInstance(Parent, UndoObject);
        }
Beispiel #14
0
 private void OnEnable()
 {
     this.fabricManager = (base.target as FabricManager);
     this.undoManager   = new EditorUndoManager(this.fabricManager, this.fabricManager.name);
 }