Ejemplo n.º 1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button == MouseButtons.Left)
            {
                // Because selection events may change the currently active tool,
                // start by agreeing on what tool we're dealing with in this mouse event.
                RigidBodyEditorTool proposedAction = this.activeTool;

                // If there is no tool active, don't do selection changes or begin an action
                if (proposedAction == this.toolNone)
                {
                    return;
                }

                if (this.actionTool == proposedAction)
                {
                    // Notify an already active action that the action key has
                    // been pressed again. This can be used for "action checkpoints",
                    // such as finishing the current vertex and adding another one.
                    this.actionTool.OnActionKeyPressed();
                }
                else
                {
                    // Begin a new action with the proposed action tool
                    this.BeginToolAction(proposedAction);
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                // A right-click signals the end of our current tool action
                this.EndToolAction();
            }
        }
        private bool BeginToolAction(RigidBodyEditorTool action, MouseButtons mouseButton)
        {
            if (this.actionTool == action)
            {
                return(true);
            }
            if (!action.CanBeginAction(mouseButton))
            {
                return(false);
            }

            if (this.actionTool != this.toolNone)
            {
                this.EndToolAction();
            }

            this.selectedBody.BeginUpdateBodyShape();

            this.lockedWorldPos = this.hoveredWorldPos;
            this.actionTool     = action;
            this.actionTool.BeginAction(mouseButton);

            this.UpdateRigidBodyToolButtons();
            this.Invalidate();

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

            return(true);
        }
Ejemplo n.º 3
0
        private void BeginToolAction(RigidBodyEditorTool action)
        {
            if (this.actionTool == action)
            {
                return;
            }
            if (this.actionTool != this.toolNone)
            {
                this.EndToolAction();
            }

            this.MouseActionAllowed = false;
            this.selectedBody.BeginUpdateBodyShape();
            DualityEditorApp.Deselect(this, ObjectSelection.Category.Other);

            this.lockedWorldPos = this.activeWorldPos;

            this.actionTool = action;
            this.actionTool.BeginAction();

            this.UpdateRigidBodyToolButtons();
            this.Invalidate();

            if (Sandbox.State == SandboxState.Playing)
            {
                Sandbox.Pause();
            }
        }
Ejemplo n.º 4
0
        private void UpdateActiveState()
        {
            // Update active world and local positions
            GameObject selGameObj   = this.selectedBody != null ? this.selectedBody.GameObj : null;
            Transform  selTransform = selGameObj != null ? selGameObj.Transform : null;
            Point      mousePos     = this.PointToClient(Cursor.Position);

            if (selTransform != null)
            {
                this.activeWorldPos = this.GetSpaceCoord(new Vector3(mousePos.X, mousePos.Y, selTransform.Pos.Z));
            }
            else
            {
                this.activeWorldPos = Vector3.Zero;
            }

            // Snap active position to user guides
            if ((this.SnapToUserGuides & UserGuideType.Position) != UserGuideType.None)
            {
                this.activeWorldPos = this.EditingUserGuide.SnapPosition(this.activeWorldPos);
            }

            // Snap active position to active axis locks
            this.activeWorldPos = this.ApplyAxisLock(this.activeWorldPos, this.lockedWorldPos);

            // Calculate object-local active position
            if (selTransform != null)
            {
                this.activeObjPos = selTransform.GetLocalPoint(this.activeWorldPos).Xy;
            }
            else
            {
                this.activeObjPos = Vector2.Zero;
            }

            // If an action is currently being performed, that action will always be the active tool
            if (this.actionTool != this.toolNone)
            {
                this.activeTool = this.actionTool;
            }
            // Otherwise, we'll go with the user-selected tool
            else
            {
                this.activeTool = this.selectedTool;
            }

            // Apply our own cursor. We'll need to do this continuously, since the object editor base
            // class will inject its regular move-scale-select cursors.
            if (this.activeTool != this.toolNone)
            {
                this.ApplyCursor();
            }
        }
Ejemplo n.º 5
0
        private void EndToolAction()
        {
            if (this.actionTool == this.toolNone)
            {
                return;
            }

            this.actionTool.EndAction();
            this.actionTool = this.toolNone;

            this.MouseActionAllowed = true;
            this.selectedBody.EndUpdateBodyShape();
            this.UpdateRigidBodyToolButtons();
            this.Invalidate();
            UndoRedoManager.Finish();

            // Since our tool actions are designed to block out other actions,
            // by default deselect each tool after using it.
            this.SelectedTool = null;
        }
        private void EndToolAction()
        {
            if (this.actionTool == this.toolNone)
            {
                return;
            }

            // Since EndAction might change tools or selections, remember what
            // we were originally using.
            RigidBodyEditorTool editingTool = this.actionTool;
            RigidBody           editedBody  = this.selectedBody;

            // Make sure we know we're done with the action when EndAction invokes
            // other code.
            this.actionTool = this.toolNone;

            editingTool.EndAction();
            editedBody.EndUpdateBodyShape();

            this.UpdateRigidBodyToolButtons();
            this.Invalidate();
            UndoRedoManager.Finish();
        }
        protected internal override void OnEnterState()
        {
            base.OnEnterState();

            // Init the available toolset, if not done before
            if (this.tools.Count == 0)
            {
                RigidBodyEditorTool[] availableTools = DualityEditorApp.GetAvailDualityEditorTypes(typeof(RigidBodyEditorTool))
                                                       .Where(t => !t.IsAbstract)
                                                       .Select(t => t.CreateInstanceOf() as RigidBodyEditorTool)
                                                       .NotNull()
                                                       .OrderBy(t => t.SortOrder)
                                                       .ToArray();

                this.toolNone = availableTools.OfType <NoRigidBodyEditorTool>().FirstOrDefault();

                this.tools.AddRange(availableTools);
                foreach (RigidBodyEditorTool tool in this.tools)
                {
                    tool.Environment = this;
                }

                this.selectedTool = this.toolNone;
                this.activeTool   = this.toolNone;
                this.actionTool   = this.toolNone;
            }

            // Init the custom tile editing toolbar
            {
                this.View.SuspendLayout();
                this.toolstrip = new ToolStrip();
                this.toolstrip.SuspendLayout();

                this.toolstrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
                this.toolstrip.Name      = "toolstrip";
                this.toolstrip.Text      = "RigidBody Editor Tools";
                this.toolstrip.Renderer  = new Duality.Editor.Controls.ToolStrip.DualitorToolStripProfessionalRenderer();
                this.toolstrip.BackColor = Color.FromArgb(212, 212, 212);

                int lastSortOrder = int.MinValue;
                foreach (RigidBodyEditorTool tool in this.tools)
                {
                    tool.InitToolButton();

                    if (tool.ToolButton == null)
                    {
                        continue;
                    }

                    // Insert a separator when the sorting order between two items is very large
                    if (lastSortOrder != int.MinValue && Math.Abs(tool.SortOrder - lastSortOrder) >= 100)
                    {
                        this.toolstrip.Items.Add(new ToolStripSeparator());
                    }

                    tool.ToolButton.Tag          = tool.HelpInfo;
                    tool.ToolButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
                    tool.ToolButton.AutoToolTip  = true;
                    this.toolstrip.Items.Add(tool.ToolButton);

                    lastSortOrder = tool.SortOrder;
                }

                this.View.Controls.Add(this.toolstrip);
                this.View.Controls.SetChildIndex(this.toolstrip, this.View.Controls.IndexOf(this.View.ToolbarCamera));
                this.toolstrip.ResumeLayout(true);
                this.View.ResumeLayout(true);
            }

            // Register events
            DualityEditorApp.SelectionChanged      += this.EditorForm_SelectionChanged;
            DualityEditorApp.ObjectPropertyChanged += this.EditorForm_ObjectPropertyChanged;

            // Initial update
            this.selectedBody = this.QuerySelectedCollider();
            this.InvalidateSelectionStats();
            this.UpdateRigidBodyToolButtons();

            this.View.ActivateLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
            this.View.LockLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
        }
Ejemplo n.º 8
0
        private void UpdateActiveState()
        {
            // Update active world and local positions
            GameObject selGameObj   = this.selectedBody != null ? this.selectedBody.GameObj : null;
            Transform  selTransform = selGameObj != null ? selGameObj.Transform : null;
            Point      mousePos     = this.PointToClient(Cursor.Position);

            if (selTransform != null)
            {
                this.hoveredWorldPos = this.GetSpaceCoord(new Vector3(mousePos.X, mousePos.Y, selTransform.Pos.Z));
                this.activeWorldPos  = this.hoveredWorldPos;
            }
            else
            {
                this.hoveredWorldPos = Vector3.Zero;
                this.activeWorldPos  = Vector3.Zero;
            }

            // Snap active position to user guides
            if ((this.SnapToUserGuides & UserGuideType.Position) != UserGuideType.None)
            {
                this.activeWorldPos = this.EditingUserGuide.SnapPosition(this.activeWorldPos);
            }

            // Snap active position to active axis locks
            this.activeWorldPos = this.ApplyAxisLock(this.activeWorldPos, this.lockedWorldPos);

            // Calculate object-local active position
            if (selTransform != null)
            {
                this.hoveredObjPos = selTransform.GetLocalPoint(this.hoveredWorldPos).Xy;
                this.activeObjPos  = selTransform.GetLocalPoint(this.activeWorldPos).Xy;
            }
            else
            {
                this.hoveredObjPos = Vector2.Zero;
                this.activeObjPos  = Vector2.Zero;
            }

            // If an action is currently being performed, that action will always be the active tool
            if (this.actionTool != this.toolNone || this.ObjAction != ObjectEditorAction.None)
            {
                this.activeTool = this.actionTool;
            }
            // Otherwise, ask the user-selected tool if its action is available right now
            else if (this.selectedTool.IsHoveringAction)
            {
                this.activeTool = this.selectedTool;
            }
            // Fallback to shape editing
            else
            {
                this.activeTool = this.toolNone;
            }

            // Apply our own cursor. We'll need to do this continuously, since the object editor base
            // class will inject its regular move-scale-select cursors.
            if (this.activeTool != this.toolNone)
            {
                this.ApplyCursor();
            }

            // Block inherited shape transform actions while a tool is active.
            this.MouseActionAllowed = (
                this.activeTool == this.toolNone &&
                this.actionTool == this.toolNone);
        }
        private void UpdateActiveState()
        {
            // Update active world and local positions
            GameObject selGameObj = this.selectedBody != null ? this.selectedBody.GameObj : null;
            Transform selTransform = selGameObj != null ? selGameObj.Transform : null;
            Point mousePos = this.PointToClient(Cursor.Position);
            if (selTransform != null)
                this.activeWorldPos = this.GetSpaceCoord(new Vector3(mousePos.X, mousePos.Y, selTransform.Pos.Z));
            else
                this.activeWorldPos = Vector3.Zero;

            // Snap active position to user guides
            if ((this.SnapToUserGuides & UserGuideType.Position) != UserGuideType.None)
                this.activeWorldPos = this.EditingUserGuide.SnapPosition(this.activeWorldPos);

            // Snap active position to active axis locks
            this.activeWorldPos = this.ApplyAxisLock(this.activeWorldPos, this.lockedWorldPos);

            // Calculate object-local active position
            if (selTransform != null)
                this.activeObjPos = selTransform.GetLocalPoint(this.activeWorldPos).Xy;
            else
                this.activeObjPos = Vector2.Zero;

            // If an action is currently being performed, that action will always be the active tool
            if (this.actionTool != this.toolNone)
                this.activeTool = this.actionTool;
            // Otherwise, we'll go with the user-selected tool
            else
                this.activeTool = this.selectedTool;

            // Apply our own cursor. We'll need to do this continuously, since the object editor base
            // class will inject its regular move-scale-select cursors.
            if (this.activeTool != this.toolNone)
                this.ApplyCursor();
        }
        private void EndToolAction()
        {
            if (this.actionTool == this.toolNone) return;

            this.actionTool.EndAction();
            this.actionTool = this.toolNone;

            this.MouseActionAllowed = true;
            this.selectedBody.EndUpdateBodyShape();
            this.UpdateRigidBodyToolButtons();
            this.Invalidate();
            UndoRedoManager.Finish();

            // Since our tool actions are designed to block out other actions,
            // by default deselect each tool after using it.
            this.SelectedTool = null;
        }
        private void BeginToolAction(RigidBodyEditorTool action)
        {
            if (this.actionTool == action) return;
            if (this.actionTool != this.toolNone)
                this.EndToolAction();

            this.MouseActionAllowed = false;
            this.selectedBody.BeginUpdateBodyShape();
            DualityEditorApp.Deselect(this, ObjectSelection.Category.Other);

            this.lockedWorldPos = this.activeWorldPos;

            this.actionTool = action;
            this.actionTool.BeginAction();

            this.UpdateRigidBodyToolButtons();
            this.Invalidate();

            if (Sandbox.State == SandboxState.Playing)
                Sandbox.Pause();
        }
        protected internal override void OnEnterState()
        {
            base.OnEnterState();

            // Init the available toolset, if not done before
            if (this.tools.Count == 0)
            {
                RigidBodyEditorTool[] availableTools = DualityEditorApp.GetAvailDualityEditorTypes(typeof(RigidBodyEditorTool))
                    .Where(t => !t.IsAbstract)
                    .Select(t => t.CreateInstanceOf() as RigidBodyEditorTool)
                    .NotNull()
                    .OrderBy(t => t.SortOrder)
                    .ToArray();

                this.toolNone = availableTools.OfType<NoRigidBodyEditorTool>().FirstOrDefault();

                this.tools.AddRange(availableTools);
                foreach (RigidBodyEditorTool tool in this.tools)
                {
                    tool.Environment = this;
                }
                this.tools.Remove(this.toolNone);

                this.selectedTool = this.toolNone;
                this.activeTool   = this.toolNone;
                this.actionTool   = this.toolNone;
            }

            // Init the custom tile editing toolbar
            {
                this.View.SuspendLayout();
                this.toolstrip = new ToolStrip();
                this.toolstrip.SuspendLayout();

                this.toolstrip.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
                this.toolstrip.Name = "toolstrip";
                this.toolstrip.Text = "RigidBody Editor Tools";
                this.toolstrip.Renderer = new Duality.Editor.Controls.ToolStrip.DualitorToolStripProfessionalRenderer();
                this.toolstrip.BackColor = Color.FromArgb(212, 212, 212);

                foreach (RigidBodyEditorTool tool in this.tools)
                {
                    tool.InitToolButton();

                    if (tool.ToolButton == null)
                        continue;

                    tool.ToolButton.Tag = tool.HelpInfo;
                    tool.ToolButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
                    tool.ToolButton.AutoToolTip = true;
                    this.toolstrip.Items.Add(tool.ToolButton);
                }

                this.View.Controls.Add(this.toolstrip);
                this.View.Controls.SetChildIndex(this.toolstrip, this.View.Controls.IndexOf(this.View.ToolbarCamera));
                this.toolstrip.ResumeLayout(true);
                this.View.ResumeLayout(true);
            }

            // Register events
            DualityEditorApp.SelectionChanged		+= this.EditorForm_SelectionChanged;
            DualityEditorApp.ObjectPropertyChanged	+= this.EditorForm_ObjectPropertyChanged;

            // Initial update
            this.selectedBody = this.QuerySelectedCollider();
            this.InvalidateSelectionStats();
            this.UpdateRigidBodyToolButtons();

            this.View.ActivateLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
            this.View.LockLayer(typeof(CamViewLayers.RigidBodyShapeCamViewLayer));
        }