Пример #1
0
        private void butSwapSrcDest_Click(object sender, EventArgs e)
        {
            var temp = Source;

            Source = Dest;
            Dest   = temp;
        }
Пример #2
0
 private void InitializeNewSearch(bool resetSelectionType = true)
 {
     Source = Dest = null;
     if (resetSelectionType)
     {
         SelectionType = ObjectSelectionType.Source;
     }
     RepopulateUI(true);
 }
Пример #3
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);
            };
        }
Пример #4
0
        private void ToggleItem(PositionBasedObjectInstance item, ObjectSelectionType?selectionType = null)
        {
            var realSelectionType = selectionType.HasValue ? selectionType : SelectionType;
            var replItem          = item as IReplaceable;

            if (replItem != null)
            {
                // Foolproofness to prevent selection of objects of different types.
                // Probably more smart approach is to reset opposite selection type, but IMO it's too intrusive. -- Lwmte

                switch (realSelectionType)
                {
                case ObjectSelectionType.Destination:
                    if (Source != null && replItem != null && replItem.GetType() != Source.GetType())
                    {
                        InitializeNewSearch(false);
                        ToggleItem(item, realSelectionType);
                    }
                    else
                    {
                        Dest = item;
                    }
                    break;

                case ObjectSelectionType.Source:
                    if (Dest != null && replItem != null && replItem.GetType() != Dest.GetType())
                    {
                        InitializeNewSearch(false);
                        ToggleItem(item, realSelectionType);
                    }
                    else
                    {
                        var firstSearch = Source == null;
                        Source = item;
                        RepopulateUI();
                    }
                    break;
                }
            }
        }
Пример #5
0
 public void MoveObjectRelative(PositionBasedObjectInstance instance, Vector3 pos, Vector3 precision = new Vector3(), bool canGoOutsideRoom = false)
 {
     if (panel3D.Camera.RotationY < Math.PI * (1.0 / 4.0))
     {
         EditorActions.MoveObjectRelative(instance, pos, precision, canGoOutsideRoom);
     }
     else if (panel3D.Camera.RotationY < Math.PI * (3.0 / 4.0))
     {
         EditorActions.MoveObjectRelative(instance, new Vector3(pos.Z, pos.Y, -pos.X), new Vector3(precision.Z, precision.Y, -precision.X), canGoOutsideRoom);
     }
     else if (panel3D.Camera.RotationY < Math.PI * (5.0 / 4.0))
     {
         EditorActions.MoveObjectRelative(instance, new Vector3(-pos.X, pos.Y, -pos.Z), new Vector3(-precision.X, precision.Y, -precision.Z), canGoOutsideRoom);
     }
     else if (panel3D.Camera.RotationY < Math.PI * (7.0 / 4.0))
     {
         EditorActions.MoveObjectRelative(instance, new Vector3(-pos.Z, pos.Y, pos.X), new Vector3(-precision.Z, precision.Y, precision.X), canGoOutsideRoom);
     }
     else
     {
         EditorActions.MoveObjectRelative(instance, pos, precision, canGoOutsideRoom);
     }
 }
Пример #6
0
 public void PushObjectPropertyChanged(PositionBasedObjectInstance obj) => Push(new ChangeObjectPropertyUndoInstance(this, obj));
Пример #7
0
 public void PushObjectTransformed(PositionBasedObjectInstance obj) => Push(new TransformObjectUndoInstance(this, obj));
Пример #8
0
 public void PushObjectDeleted(PositionBasedObjectInstance obj) => Push(new AddRemoveObjectUndoInstance(this, obj, false));
Пример #9
0
 public void PushObjectCreated(PositionBasedObjectInstance obj) => Push(new AddRemoveObjectUndoInstance(this, obj, true));
Пример #10
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);
        }
    }
Пример #11
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);
        }