protected override string UpdateActionText(ref Vector2 actionTextPos)
        {
            string             actionText          = null;
            ObjectEditorAction visibleObjectAction = this.VisibleObjAction;

            if (visibleObjectAction != ObjectEditorAction.None && ((this.mouseoverObject != null && this.mouseoverSelect) || this.actionObjSel.Count == 1))
            {
                ObjectEditorSelObj obj;
                if (this.mouseoverObject != null || this.mouseoverAction == visibleObjectAction)
                {
                    obj = (this.mouseoverObject != null && this.mouseoverSelect) ? this.mouseoverObject : this.actionObjSel[0];
                }
                else
                {
                    obj           = this.actionObjSel[0];
                    actionTextPos = this.GetScreenCoord(this.actionObjSel[0].Pos).Xy;
                }

                // If the SelObj is valid, let it determine the current action text
                if (obj.ActualObject != null)
                {
                    actionText = obj.UpdateActionText(visibleObjectAction, this.action != ObjectEditorAction.None);
                }
            }

            if (actionText != null)
            {
                return(actionText);
            }

            return(base.UpdateActionText(ref actionTextPos));
        }
		protected void BeginAction(ObjectEditorAction action)
		{
			if (action == ObjectEditorAction.None) return;
			Point mouseLoc = this.PointToClient(Cursor.Position);

			this.ValidateSelectionStats();

			this.StopCameraMovement();

			this.action = action;
			this.actionBeginLoc = mouseLoc;
			this.actionBeginLocSpace = this.GetSpaceCoord(new Vector3(
				mouseLoc.X, 
				mouseLoc.Y, 
				(this.action == ObjectEditorAction.RectSelect) ? 0.0f : this.selectionCenter.Z));

			if (this.action == ObjectEditorAction.Move)
				this.actionBeginLocSpace.Z = this.CameraObj.Transform.Pos.Z;

			this.actionLastLocSpace = this.actionBeginLocSpace;

			if (Sandbox.State == SandboxState.Playing)
				Sandbox.Freeze();

			this.OnBeginAction(this.action);
		}
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            bool alt = (Control.ModifierKeys & Keys.Alt) != Keys.None;

            this.drawSelGizmoState = ObjectEditorAction.None;

            if (this.action == ObjectEditorAction.None)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (this.mouseoverSelect)
                    {
                        // To interact with an object that isn't selected yet: Select it.
                        if (!this.allObjSel.Contains(this.mouseoverObject))
                        {
                            this.SelectObjects(new [] { this.mouseoverObject });
                        }
                    }
                    if (alt)
                    {
                        UndoRedoManager.BeginMacro();
                        this.actionIsClone = true;
                        this.SelectObjects(this.CloneObjects(this.actionObjSel));
                    }
                    this.BeginAction(this.mouseoverAction);
                }
            }
        }
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     if (action == ObjectEditorAction.Move) return true;
     if (action == ObjectEditorAction.Rotate) return true;
     if (action == ObjectEditorAction.Scale) return true;
     return false;
 }
Exemple #5
0
 public override string UpdateActionText(ObjectEditorAction action, bool performing)
 {
     if (action == ObjectEditorAction.Move)
     {
         return
             (string.Format("Center X:{0,9:0.00}/n", this.center.X) +
              string.Format("Center Y:{0,9:0.00}", this.center.Y));
     }
     else if (action == ObjectEditorAction.Scale)
     {
         if (MathF.Abs(this.scale.X - this.scale.Y) >= 0.01f)
         {
             return
                 (string.Format("Scale X:{0,8:0.00}/n", this.scale.X) +
                  string.Format("Scale Y:{0,8:0.00}", this.scale.Y));
         }
         else
         {
             return(string.Format("Scale:{0,8:0.00}", this.scale.X));
         }
     }
     else if (action == ObjectEditorAction.Rotate)
     {
         return(string.Format("Angle:{0,6:0.0}°", MathF.RadToDeg(this.angle)));
     }
     return(base.UpdateActionText(action, performing));
 }
        protected void EndAction()
        {
            if (this.action == ObjectEditorAction.None)
            {
                return;
            }
            Point mouseLoc = this.PointToClient(Cursor.Position);

            if (this.action == ObjectEditorAction.RectSelect)
            {
                this.activeRectSel = new ObjectSelection();
            }

            if (Sandbox.State == SandboxState.Playing)
            {
                Sandbox.UnFreeze();
            }

            this.OnEndAction(this.action);
            this.action = ObjectEditorAction.None;

            if (this.actionIsClone)
            {
                this.actionIsClone = false;
                UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromFirst);
            }
            UndoRedoManager.Finish();
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            this.mouseoverAction = ObjectEditorAction.None;
            this.mouseoverObject = null;
            this.mouseoverSelect = false;
        }
Exemple #8
0
 public virtual bool IsActionAvailable(ObjectEditorAction action)
 {
     if (action == ObjectEditorAction.Move)
     {
         return(true);
     }
     return(false);
 }
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     if (action == ObjectEditorAction.Rotate)
     {
         return(false);
     }
     return(base.IsActionAvailable(action));
 }
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     if (action == ObjectEditorAction.Move ||
         action == ObjectEditorAction.Rotate ||
         action == ObjectEditorAction.Scale)
     {
         return(this.HasTransform);
     }
     return(false);
 }
		protected override void OnMouseUp(MouseEventArgs e)
		{
			base.OnMouseUp(e);
			this.drawSelGizmoState = ObjectEditorAction.None;

			if (this.action == ObjectEditorAction.RectSelect && this.actionBeginLoc == e.Location)
				this.UpdateRectSelection(e.Location);

			if (e.Button == MouseButtons.Left)
				this.EndAction();
		}
		protected override string UpdateStatusText()
		{
			ObjectEditorAction visibleObjectAction = this.VisibleObjAction;

			if (visibleObjectAction == ObjectEditorAction.Move)            return Properties.CamViewRes.CamView_Action_Move;
			else if (visibleObjectAction == ObjectEditorAction.Rotate)     return Properties.CamViewRes.CamView_Action_Rotate;
			else if (visibleObjectAction == ObjectEditorAction.Scale)      return Properties.CamViewRes.CamView_Action_Scale;
			else if (visibleObjectAction == ObjectEditorAction.RectSelect) return Properties.CamViewRes.CamView_Action_Select_Active;

			return base.UpdateStatusText();
		}
		public void RotateSelectionBy(float rotation)
		{
			if (rotation == 0.0f) return;
			
			UndoRedoManager.Do(new RotateCamViewObjAction(
				this.actionObjSel, 
				obj => this.PostPerformAction(obj, ObjectEditorAction.Rotate), 
				rotation));

			this.drawSelGizmoState = ObjectEditorAction.Rotate;
			this.InvalidateSelectionStats();
			this.Invalidate();
		}
		public void ScaleSelectionBy(float scale)
		{
			if (scale == 1.0f) return;

			UndoRedoManager.Do(new ScaleCamViewObjAction(
				this.actionObjSel, 
				obj => this.PostPerformAction(obj, ObjectEditorAction.Scale), 
				scale));

			this.drawSelGizmoState = ObjectEditorAction.Scale;
			this.InvalidateSelectionStats();
			this.Invalidate();
		}
		public void MoveSelectionBy(Vector3 move)
		{
			if (move == Vector3.Zero) return;

			UndoRedoManager.Do(new MoveCamViewObjAction(
				this.actionObjSel, 
				obj => this.PostPerformAction(obj, ObjectEditorAction.Move), 
				move));

			this.drawSelGizmoState = ObjectEditorAction.Move;
			this.InvalidateSelectionStats();
			this.Invalidate();
		}
 public override string UpdateActionText(ObjectEditorAction action, bool performing)
 {
     if (action == ObjectEditorAction.Move)
     {
         return
             string.Format("Center X:{0,9:0.00}/n", this.circle.Position.X) +
             string.Format("Center Y:{0,9:0.00}", this.circle.Position.Y);
     }
     else if (action == ObjectEditorAction.Scale)
     {
         return string.Format("Radius:{0,8:0.00}", this.circle.Radius);
     }
     return base.UpdateActionText(action, performing);
 }
 public override string UpdateActionText(ObjectEditorAction action, bool performing)
 {
     if (action == ObjectEditorAction.Move)
     {
         return
             (string.Format("Center X:{0,9:0.00}/n", this.circle.Position.X) +
              string.Format("Center Y:{0,9:0.00}", this.circle.Position.Y));
     }
     else if (action == ObjectEditorAction.Scale)
     {
         return(string.Format("Radius:{0,8:0.00}", this.circle.Radius));
     }
     return(base.UpdateActionText(action, performing));
 }
        protected override void OnBeginAction(ObjectEditorAction action)
        {
            base.OnBeginAction(action);

            bool shapeAction =
                action != ObjectEditorAction.RectSelect &&
                action != ObjectEditorAction.None;

            if (this.selectedBody != null && shapeAction)
            {
                this.selectedBody.BeginUpdateBodyShape();
                this.EditingUserGuide.SnapPosOrigin   = this.selectedBody.GameObj.Transform.Pos;
                this.EditingUserGuide.SnapScaleOrigin = Vector3.One * this.selectedBody.GameObj.Transform.Scale;
            }
        }
        protected override void OnEndAction(ObjectEditorAction action)
        {
            base.OnEndAction(action);

            bool shapeAction =
                action != ObjectEditorAction.RectSelect &&
                action != ObjectEditorAction.None;

            if (this.selectedBody != null && shapeAction)
            {
                this.selectedBody.EndUpdateBodyShape();
            }

            this.EditingUserGuide.SnapPosOrigin   = Vector3.Zero;
            this.EditingUserGuide.SnapScaleOrigin = Vector3.One;
        }
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     if (action == ObjectEditorAction.Move)
     {
         return(true);
     }
     if (action == ObjectEditorAction.Rotate)
     {
         return(true);
     }
     if (action == ObjectEditorAction.Scale)
     {
         return(true);
     }
     return(false);
 }
        protected void BeginAction(ObjectEditorAction action)
        {
            if (action == ObjectEditorAction.None)
            {
                return;
            }
            Point mouseLoc = this.PointToClient(Cursor.Position);

            this.ValidateSelectionStats();

            this.StopCameraMovement();

            this.action              = action;
            this.actionBeginLoc      = mouseLoc;
            this.actionBeginLocSpace = this.GetSpaceCoord(new Vector3(
                                                              mouseLoc.X,
                                                              mouseLoc.Y,
                                                              (this.action == ObjectEditorAction.RectSelect) ? 0.0f : this.selectionCenter.Z));

            if (this.action == ObjectEditorAction.Move)
            {
                this.actionBeginLocSpace.Z = this.CameraObj.Transform.Pos.Z;
            }

            this.actionLastLocSpace = this.actionBeginLocSpace;

            // Update snap-to-grid settings for this action
            if (this.actionObjSel.Count > 1)
            {
                // When moving multiple objects, snap only relative to the original selection center, so individual grid alignment is retained
                this.EditingUserGuide.SnapPosOrigin   = this.selectionCenter;
                this.EditingUserGuide.SnapScaleOrigin = Vector3.One;
            }
            else
            {
                this.EditingUserGuide.SnapPosOrigin   = Vector3.Zero;
                this.EditingUserGuide.SnapScaleOrigin = Vector3.One;
            }

            if (Sandbox.State == SandboxState.Playing)
            {
                Sandbox.Freeze();
            }

            this.OnBeginAction(this.action);
        }
		protected override void OnKeyDown(KeyEventArgs e)
		{
			base.OnKeyDown(e);
			this.drawSelGizmoState = ObjectEditorAction.None;

			if (this.actionAllowed)
			{
				if (e.KeyCode == Keys.Menu)
				{
					// Capture the left Alt key, so focus doesn't jump to the menu.
					// We'll need Alt keys right here for those drag-clone actions.
					e.Handled = true;
				}
				else if (e.KeyCode == Keys.Delete)
				{
					List<ObjectEditorSelObj> deleteList = this.actionObjSel.ToList();
					this.ClearSelection();
					this.DeleteObjects(deleteList);
				}
				else if (e.KeyCode == Keys.C && e.Control)
				{
					List<ObjectEditorSelObj> cloneList = this.CloneObjects(this.actionObjSel);
					this.SelectObjects(cloneList);
				}
				else if (e.KeyCode == Keys.G)
				{
					if (e.Alt)
					{
						this.SelectObjects(this.CloneObjects(this.actionObjSel));
						e.SuppressKeyPress = true; // Prevent menustrip from getting focused
					}
					this.MoveSelectionToCursor();
				}
				else if (!e.Control && e.KeyCode == Keys.Left)		this.MoveSelectionBy(-Vector3.UnitX);
				else if (!e.Control && e.KeyCode == Keys.Right)		this.MoveSelectionBy(Vector3.UnitX);
				else if (!e.Control && e.KeyCode == Keys.Up)		this.MoveSelectionBy(-Vector3.UnitY);
				else if (!e.Control && e.KeyCode == Keys.Down)		this.MoveSelectionBy(Vector3.UnitY);
				else if (!e.Control && e.KeyCode == Keys.Add)		this.MoveSelectionBy(Vector3.UnitZ);
				else if (!e.Control && e.KeyCode == Keys.Subtract)	this.MoveSelectionBy(-Vector3.UnitZ);
				else if (e.KeyCode == Keys.ShiftKey)				this.UpdateAction();
				else if (e.KeyCode == Keys.ControlKey)				this.UpdateAction();
			}
		}
        public override string UpdateActionText(ObjectEditorAction action, bool performing)
        {
            if (action == ObjectEditorAction.Move)
            {
                return
                    (string.Format("X:{0,7:0}/n", this.gameObj.Transform.RelativePos.X) +
                     string.Format("Y:{0,7:0}/n", this.gameObj.Transform.RelativePos.Y) +
                     string.Format("Z:{0,7:0}", this.gameObj.Transform.RelativePos.Z));
            }
            else if (action == ObjectEditorAction.Scale)
            {
                return(string.Format("Scale:{0,5:0.00}", this.gameObj.Transform.RelativeScale));
            }
            else if (action == ObjectEditorAction.Rotate)
            {
                return(string.Format("Angle:{0,5:0}°", MathF.RadToDeg(this.gameObj.Transform.RelativeAngle)));
            }

            return(base.UpdateActionText(action, performing));
        }
        protected void UpdateMouseover(Point mouseLoc)
        {
            bool lastMouseoverSelect = this.mouseoverSelect;
            ObjectEditorSelObj lastMouseoverObject = this.mouseoverObject;
            ObjectEditorAction lastMouseoverAction = this.mouseoverAction;

            if (this.actionAllowed && !this.CamActionRequiresCursor && this.CamAction == CameraAction.None)
            {
                this.ValidateSelectionStats();

                // Determine object at mouse position
                this.mouseoverObject = this.PickSelObjAt(mouseLoc.X, mouseLoc.Y);

                // Determine action variables
                Vector3     mouseSpaceCoord     = this.GetSpaceCoord(new Vector3(mouseLoc.X, mouseLoc.Y, this.selectionCenter.Z));
                float       scale               = this.GetScaleAtZ(this.selectionCenter.Z);
                const float boundaryThickness   = 10.0f;
                bool        tooSmall            = this.selectionRadius * scale <= boundaryThickness * 2.0f;
                bool        mouseOverBoundary   = MathF.Abs((mouseSpaceCoord - this.selectionCenter).Length - this.selectionRadius) * scale < boundaryThickness;
                bool        mouseInsideBoundary = !mouseOverBoundary && (mouseSpaceCoord - this.selectionCenter).Length < this.selectionRadius;
                bool        mouseAtCenterAxis   =
                    MathF.Abs(mouseSpaceCoord.X - this.selectionCenter.X) * scale < boundaryThickness ||
                    MathF.Abs(mouseSpaceCoord.Y - this.selectionCenter.Y) * scale < boundaryThickness;
                bool shift = (Control.ModifierKeys & Keys.Shift) != Keys.None;
                bool ctrl  = (Control.ModifierKeys & Keys.Control) != Keys.None;

                bool anySelection = this.actionObjSel.Count > 0;
                bool canMove      = this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Move));
                bool canRotate    = (canMove && this.actionObjSel.Count > 1) || this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Rotate));
                bool canScale     = (canMove && this.actionObjSel.Count > 1) || this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Scale));

                // Select which action to propose
                this.mouseoverSelect = false;
                if (ctrl)
                {
                    this.mouseoverAction = ObjectEditorAction.RectSelect;
                }
                else if (anySelection && !tooSmall && mouseOverBoundary && mouseAtCenterAxis && this.selectionRadius > 0.0f && canScale)
                {
                    this.mouseoverAction = ObjectEditorAction.Scale;
                }
                else if (anySelection && !tooSmall && mouseOverBoundary && canRotate)
                {
                    this.mouseoverAction = ObjectEditorAction.Rotate;
                }
                else if (anySelection && mouseInsideBoundary && canMove)
                {
                    this.mouseoverAction = ObjectEditorAction.Move;
                }
                else if (shift)                 // Lower prio than Ctrl, because Shift also modifies mouse actions
                {
                    this.mouseoverAction = ObjectEditorAction.RectSelect;
                }
                else if (this.mouseoverObject != null && this.mouseoverObject.IsActionAvailable(ObjectEditorAction.Move))
                {
                    this.mouseoverAction = ObjectEditorAction.Move;
                    this.mouseoverSelect = true;
                }
                else
                {
                    this.mouseoverAction = ObjectEditorAction.RectSelect;
                }
            }
            else
            {
                this.mouseoverObject = null;
                this.mouseoverSelect = false;
                this.mouseoverAction = ObjectEditorAction.None;
            }

            // If mouseover changed..
            if (this.mouseoverObject != lastMouseoverObject ||
                this.mouseoverSelect != lastMouseoverSelect ||
                this.mouseoverAction != lastMouseoverAction)
            {
                // Adjust mouse cursor based on proposed action
                if (this.mouseoverAction == ObjectEditorAction.Move)
                {
                    this.Cursor = CursorHelper.ArrowActionMove;
                }
                else if (this.mouseoverAction == ObjectEditorAction.Rotate)
                {
                    this.Cursor = CursorHelper.ArrowActionRotate;
                }
                else if (this.mouseoverAction == ObjectEditorAction.Scale)
                {
                    this.Cursor = CursorHelper.ArrowActionScale;
                }
                else
                {
                    this.Cursor = CursorHelper.Arrow;
                }
            }

            // Redraw if action gizmos might be visible
            if (this.actionAllowed)
            {
                this.Invalidate();
            }
        }
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            bool alt = (Control.ModifierKeys & Keys.Alt) != Keys.None;

            this.drawSelGizmoState = ObjectEditorAction.None;

            if (this.action == ObjectEditorAction.None)
            {
                if (e.Button == MouseButtons.Left)
                {
                    if (this.mouseoverSelect)
                    {
                        // To interact with an object that isn't selected yet: Select it.
                        if (!this.allObjSel.Contains(this.mouseoverObject))
                            this.SelectObjects(new [] { this.mouseoverObject });
                    }
                    if (alt)
                    {
                        UndoRedoManager.BeginMacro();
                        this.actionIsClone = true;
                        this.SelectObjects(this.CloneObjects(this.actionObjSel));
                    }
                    this.BeginAction(this.mouseoverAction);
                }
            }
        }
        public void ScaleSelectionBy(float scale)
        {
            if (scale == 1.0f) return;

            UndoRedoManager.Do(new ScaleCamViewObjAction(
                this.actionObjSel,
                obj => this.PostPerformAction(obj, ObjectEditorAction.Scale),
                scale));

            this.drawSelGizmoState = ObjectEditorAction.Scale;
            this.InvalidateSelectionStats();
            this.Invalidate();
        }
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     return false;
 }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            this.drawSelGizmoState = ObjectEditorAction.None;

            if (this.action == ObjectEditorAction.RectSelect && this.actionBeginLoc == e.Location)
                this.UpdateRectSelection(e.Location);

            if (e.Button == MouseButtons.Left)
                this.EndAction();
        }
 protected virtual void PostPerformAction(IEnumerable<ObjectEditorSelObj> selObjEnum, ObjectEditorAction action)
 {
 }
        protected override void OnEndAction(ObjectEditorAction action)
        {
            base.OnEndAction(action);

            bool shapeAction =
                action != ObjectEditorAction.RectSelect &&
                action != ObjectEditorAction.None;
            if (this.selectedBody != null && shapeAction)
                this.selectedBody.EndUpdateBodyShape();

            this.EditingUserGuide.SnapPosOrigin = Vector3.Zero;
            this.EditingUserGuide.SnapScaleOrigin = Vector3.One;
        }
        protected void EndAction()
        {
            if (this.action == ObjectEditorAction.None) return;
            Point mouseLoc = this.PointToClient(Cursor.Position);

            if (this.action == ObjectEditorAction.RectSelect)
            {
                this.activeRectSel = new ObjectSelection();
            }

            if (Sandbox.State == SandboxState.Playing)
                Sandbox.UnFreeze();

            this.OnEndAction(this.action);
            this.action = ObjectEditorAction.None;

            if (this.actionIsClone)
            {
                this.actionIsClone = false;
                UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromFirst);
            }
            UndoRedoManager.Finish();
        }
        public void RotateSelectionBy(float rotation)
        {
            if (rotation == 0.0f) return;

            UndoRedoManager.Do(new RotateCamViewObjAction(
                this.actionObjSel,
                obj => this.PostPerformAction(obj, ObjectEditorAction.Rotate),
                rotation));

            this.drawSelGizmoState = ObjectEditorAction.Rotate;
            this.InvalidateSelectionStats();
            this.Invalidate();
        }
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     if (action == ObjectEditorAction.Rotate) return false;
     return base.IsActionAvailable(action);
 }
 protected virtual void OnBeginAction(ObjectEditorAction action)
 {
 }
 protected virtual void OnEndAction(ObjectEditorAction action)
 {
 }
        protected override void PostPerformAction(IEnumerable <ObjectEditorSelObj> selObjEnum, ObjectEditorAction action)
        {
            base.PostPerformAction(selObjEnum, action);
            RigidBodyEditorSelShape[] selShapeArray = selObjEnum.OfType <RigidBodyEditorSelShape>().ToArray();

            // Update the body directly after modifying it
            if (this.selectedBody != null)
            {
                this.selectedBody.SynchronizeBodyShape();
            }

            // Notify property changes
            DualityEditorApp.NotifyObjPropChanged(this,
                                                  new ObjectSelection(this.selectedBody),
                                                  ReflectionInfo.Property_RigidBody_Shapes);
            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(selShapeArray.Select(s => s.ActualObject)));
        }
        protected void UpdateMouseover(Point mouseLoc)
        {
            bool lastMouseoverSelect = this.mouseoverSelect;
            ObjectEditorSelObj lastMouseoverObject = this.mouseoverObject;
            ObjectEditorAction lastMouseoverAction = this.mouseoverAction;

            if (this.actionAllowed && !this.CamActionRequiresCursor && this.CamAction == CameraAction.None)
            {
                this.ValidateSelectionStats();

                // Determine object at mouse position
                this.mouseoverObject = this.PickSelObjAt(mouseLoc.X, mouseLoc.Y);

                // Determine action variables
                Vector3 mouseSpaceCoord = this.GetSpaceCoord(new Vector3(mouseLoc.X, mouseLoc.Y, this.selectionCenter.Z));
                float scale = this.GetScaleAtZ(this.selectionCenter.Z);
                const float boundaryThickness = 10.0f;
                bool tooSmall = this.selectionRadius * scale <= boundaryThickness * 2.0f;
                bool mouseOverBoundary = MathF.Abs((mouseSpaceCoord - this.selectionCenter).Length - this.selectionRadius) * scale < boundaryThickness;
                bool mouseInsideBoundary = !mouseOverBoundary && (mouseSpaceCoord - this.selectionCenter).Length < this.selectionRadius;
                bool mouseAtCenterAxis =
                    MathF.Abs(mouseSpaceCoord.X - this.selectionCenter.X) * scale < boundaryThickness ||
                    MathF.Abs(mouseSpaceCoord.Y - this.selectionCenter.Y) * scale < boundaryThickness;
                bool shift = (Control.ModifierKeys & Keys.Shift) != Keys.None;
                bool ctrl = (Control.ModifierKeys & Keys.Control) != Keys.None;

                bool anySelection = this.actionObjSel.Count > 0;
                bool canMove = this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Move));
                bool canRotate = (canMove && this.actionObjSel.Count > 1) || this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Rotate));
                bool canScale = (canMove && this.actionObjSel.Count > 1) || this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Scale));

                // Select which action to propose
                this.mouseoverSelect = false;
                if (ctrl)
                    this.mouseoverAction = ObjectEditorAction.RectSelect;
                else if (anySelection && !tooSmall && mouseOverBoundary && mouseAtCenterAxis && this.selectionRadius > 0.0f && canScale)
                    this.mouseoverAction = ObjectEditorAction.Scale;
                else if (anySelection && !tooSmall && mouseOverBoundary && canRotate)
                    this.mouseoverAction = ObjectEditorAction.Rotate;
                else if (anySelection && mouseInsideBoundary && canMove)
                    this.mouseoverAction = ObjectEditorAction.Move;
                else if (shift) // Lower prio than Ctrl, because Shift also modifies mouse actions
                    this.mouseoverAction = ObjectEditorAction.RectSelect;
                else if (this.mouseoverObject != null && this.mouseoverObject.IsActionAvailable(ObjectEditorAction.Move))
                {
                    this.mouseoverAction = ObjectEditorAction.Move;
                    this.mouseoverSelect = true;
                }
                else
                    this.mouseoverAction = ObjectEditorAction.RectSelect;
            }
            else
            {
                this.mouseoverObject = null;
                this.mouseoverSelect = false;
                this.mouseoverAction = ObjectEditorAction.None;
            }

            // If mouseover changed..
            if (this.mouseoverObject != lastMouseoverObject ||
                this.mouseoverSelect != lastMouseoverSelect ||
                this.mouseoverAction != lastMouseoverAction)
            {
                // Adjust mouse cursor based on proposed action
                if (this.mouseoverAction == ObjectEditorAction.Move)
                    this.Cursor = CursorHelper.ArrowActionMove;
                else if (this.mouseoverAction == ObjectEditorAction.Rotate)
                    this.Cursor = CursorHelper.ArrowActionRotate;
                else if (this.mouseoverAction == ObjectEditorAction.Scale)
                    this.Cursor = CursorHelper.ArrowActionScale;
                else
                    this.Cursor = CursorHelper.Arrow;
            }

            // Redraw if action gizmos might be visible
            if (this.actionAllowed)
                this.Invalidate();
        }
 protected virtual void OnBeginAction(ObjectEditorAction action)
 {
 }
 protected override void OnMouseWheel(MouseEventArgs e)
 {
     base.OnMouseWheel(e);
     this.drawSelGizmoState = ObjectEditorAction.None;
 }
 protected virtual void OnEndAction(ObjectEditorAction action)
 {
 }
 protected override void OnMouseWheel(MouseEventArgs e)
 {
     base.OnMouseWheel(e);
     this.drawSelGizmoState = ObjectEditorAction.None;
 }
        public void MoveSelectionBy(Vector3 move)
        {
            if (move == Vector3.Zero) return;

            UndoRedoManager.Do(new MoveCamViewObjAction(
                this.actionObjSel,
                obj => this.PostPerformAction(obj, ObjectEditorAction.Move),
                move));

            this.drawSelGizmoState = ObjectEditorAction.Move;
            this.InvalidateSelectionStats();
            this.Invalidate();
        }
        protected void BeginAction(ObjectEditorAction action)
        {
            if (action == ObjectEditorAction.None) return;
            Point mouseLoc = this.PointToClient(Cursor.Position);

            this.ValidateSelectionStats();

            this.StopCameraMovement();

            this.action = action;
            this.actionBeginLoc = mouseLoc;
            this.actionBeginLocSpace = this.GetSpaceCoord(new Vector3(
                mouseLoc.X,
                mouseLoc.Y,
                (this.action == ObjectEditorAction.RectSelect) ? 0.0f : this.selectionCenter.Z));

            if (this.action == ObjectEditorAction.Move)
                this.actionBeginLocSpace.Z = this.CameraObj.Transform.Pos.Z;

            this.actionLastLocSpace = this.actionBeginLocSpace;

            if (Sandbox.State == SandboxState.Playing)
                Sandbox.Freeze();

            this.OnBeginAction(this.action);
        }
        protected override void PostPerformAction(IEnumerable<ObjectEditorSelObj> selObjEnum, ObjectEditorAction action)
        {
            base.PostPerformAction(selObjEnum, action);
            RigidBodyEditorSelShape[] selShapeArray = selObjEnum.OfType<RigidBodyEditorSelShape>().ToArray();

            // Update the body directly after modifying it
            if (this.selectedBody != null) this.selectedBody.SynchronizeBodyShape();

            // Notify property changes
            DualityEditorApp.NotifyObjPropChanged(this,
                new ObjectSelection(this.selectedBody),
                ReflectionInfo.Property_RigidBody_Shapes);
            DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(selShapeArray.Select(s => s.ActualObject)));
        }
Exemple #45
0
 protected override void PostPerformAction(IEnumerable <ObjectEditorSelObj> selObjEnum, ObjectEditorAction action)
 {
     base.PostPerformAction(selObjEnum, action);
     if (action == ObjectEditorAction.Move)
     {
         DualityEditorApp.NotifyObjPropChanged(
             this,
             new ObjectSelection(selObjEnum.Select(s => (s.ActualObject as GameObject).Transform)),
             ReflectionInfo.Property_Transform_RelativePos);
     }
     else if (action == ObjectEditorAction.Rotate)
     {
         DualityEditorApp.NotifyObjPropChanged(
             this,
             new ObjectSelection(selObjEnum.Select(s => (s.ActualObject as GameObject).Transform)),
             ReflectionInfo.Property_Transform_RelativePos,
             ReflectionInfo.Property_Transform_RelativeAngle);
     }
     else if (action == ObjectEditorAction.Scale)
     {
         DualityEditorApp.NotifyObjPropChanged(
             this,
             new ObjectSelection(selObjEnum.Select(s => (s.ActualObject as GameObject).Transform)),
             ReflectionInfo.Property_Transform_RelativePos,
             ReflectionInfo.Property_Transform_RelativeScale);
     }
 }
 protected override void PostPerformAction(IEnumerable<ObjectEditorSelObj> selObjEnum, ObjectEditorAction action)
 {
     base.PostPerformAction(selObjEnum, action);
     if (action == ObjectEditorAction.Move)
     {
         DualityEditorApp.NotifyObjPropChanged(
             this,
             new ObjectSelection(selObjEnum.Select(s => (s.ActualObject as GameObject).Transform)),
             ReflectionInfo.Property_Transform_RelativePos);
     }
     else if (action == ObjectEditorAction.Rotate)
     {
         DualityEditorApp.NotifyObjPropChanged(
             this,
             new ObjectSelection(selObjEnum.Select(s => (s.ActualObject as GameObject).Transform)),
             ReflectionInfo.Property_Transform_RelativePos,
             ReflectionInfo.Property_Transform_RelativeAngle);
     }
     else if (action == ObjectEditorAction.Scale)
     {
         DualityEditorApp.NotifyObjPropChanged(
             this,
             new ObjectSelection(selObjEnum.Select(s => (s.ActualObject as GameObject).Transform)),
             ReflectionInfo.Property_Transform_RelativePos,
             ReflectionInfo.Property_Transform_RelativeScale);
     }
 }
Exemple #47
0
 public virtual string UpdateActionText(ObjectEditorAction action, bool performing)
 {
     return(null);
 }
        protected override void OnBeginAction(ObjectEditorAction action)
        {
            base.OnBeginAction(action);

            bool shapeAction =
                action != ObjectEditorAction.RectSelect &&
                action != ObjectEditorAction.None;
            if (this.selectedBody != null && shapeAction)
            {
                this.selectedBody.BeginUpdateBodyShape();
                this.EditingUserGuide.SnapPosOrigin = this.selectedBody.GameObj.Transform.Pos;
                this.EditingUserGuide.SnapScaleOrigin = Vector3.One * this.selectedBody.GameObj.Transform.Scale;
            }
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            this.mouseoverAction = ObjectEditorAction.None;
            this.mouseoverObject = null;
            this.mouseoverSelect = false;
        }
 public override string UpdateActionText(ObjectEditorAction action, bool performing)
 {
     if (action == ObjectEditorAction.Move)
     {
         return
             string.Format("Center X:{0,9:0.00}/n", this.center.X) +
             string.Format("Center Y:{0,9:0.00}", this.center.Y);
     }
     else if (action == ObjectEditorAction.Scale)
     {
         if (MathF.Abs(this.scale.X - this.scale.Y) >= 0.01f)
         {
             return
                 string.Format("Scale X:{0,8:0.00}/n", this.scale.X) +
                 string.Format("Scale Y:{0,8:0.00}", this.scale.Y);
         }
         else
         {
             return string.Format("Scale:{0,8:0.00}", this.scale.X);
         }
     }
     else if (action == ObjectEditorAction.Rotate)
     {
         return string.Format("Angle:{0,6:0.0}°", MathF.RadToDeg(this.angle));
     }
     return base.UpdateActionText(action, performing);
 }
 protected virtual void PostPerformAction(IEnumerable <ObjectEditorSelObj> selObjEnum, ObjectEditorAction action)
 {
 }
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     if (action == ObjectEditorAction.Move ||
         action == ObjectEditorAction.Rotate ||
         action == ObjectEditorAction.Scale)
         return this.HasTransform;
     return false;
 }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            this.drawSelGizmoState = ObjectEditorAction.None;

            if (this.actionAllowed)
            {
                if (e.KeyCode == Keys.Menu)
                {
                    // Capture the left Alt key, so focus doesn't jump to the menu.
                    // We'll need Alt keys right here for those drag-clone actions.
                    e.Handled = true;
                }
                else if (e.KeyCode == Keys.Delete)
                {
                    List<ObjectEditorSelObj> deleteList = this.actionObjSel.ToList();
                    this.ClearSelection();
                    this.DeleteObjects(deleteList);
                }
                else if (e.KeyCode == Keys.C && e.Control)
                {
                    List<ObjectEditorSelObj> cloneList = this.CloneObjects(this.actionObjSel);
                    this.SelectObjects(cloneList);
                }
                else if (e.KeyCode == Keys.G)
                {
                    if (e.Alt)
                    {
                        this.SelectObjects(this.CloneObjects(this.actionObjSel));
                        e.SuppressKeyPress = true; // Prevent menustrip from getting focused
                    }
                    this.MoveSelectionToCursor();
                }
                else if (!e.Control && e.KeyCode == Keys.Left)		this.MoveSelectionBy(-Vector3.UnitX);
                else if (!e.Control && e.KeyCode == Keys.Right)		this.MoveSelectionBy(Vector3.UnitX);
                else if (!e.Control && e.KeyCode == Keys.Up)		this.MoveSelectionBy(-Vector3.UnitY);
                else if (!e.Control && e.KeyCode == Keys.Down)		this.MoveSelectionBy(Vector3.UnitY);
                else if (!e.Control && e.KeyCode == Keys.Add)		this.MoveSelectionBy(Vector3.UnitZ);
                else if (!e.Control && e.KeyCode == Keys.Subtract)	this.MoveSelectionBy(-Vector3.UnitZ);
                else if (e.KeyCode == Keys.ShiftKey)				this.UpdateAction();
                else if (e.KeyCode == Keys.ControlKey)				this.UpdateAction();
            }
        }
Exemple #54
0
 public override bool IsActionAvailable(ObjectEditorAction action)
 {
     return(false);
 }
        public override string UpdateActionText(ObjectEditorAction action, bool performing)
        {
            if (action == ObjectEditorAction.Move)
            {
                return
                    string.Format("X:{0,7:0}/n", this.gameObj.Transform.RelativePos.X) +
                    string.Format("Y:{0,7:0}/n", this.gameObj.Transform.RelativePos.Y) +
                    string.Format("Z:{0,7:0}", this.gameObj.Transform.RelativePos.Z);
            }
            else if (action == ObjectEditorAction.Scale)
            {
                return string.Format("Scale:{0,5:0.00}", this.gameObj.Transform.RelativeScale);
            }
            else if (action == ObjectEditorAction.Rotate)
            {
                return string.Format("Angle:{0,5:0}°", MathF.RadToDeg(this.gameObj.Transform.RelativeAngle));
            }

            return base.UpdateActionText(action, performing);
        }