Beispiel #1
0
 protected override void GizmoMove(Vector3 newPos)
 {
     if (_editor.SelectedObject is PositionBasedObjectInstance)
     {
         EditorActions.MoveObject(_editor.SelectedObject as PositionBasedObjectInstance,
                                  newPos - _editor.SelectedObject.Room.WorldPos, Control.ModifierKeys);
     }
 }
Beispiel #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);
            };
        }