From b4855e37edb5b1430b48d967abc7c48393e81999 Mon Sep 17 00:00:00 2001 From: parax0 Date: Sun, 6 Dec 2015 22:44:56 -0700 Subject: [PATCH] Disable gizmo mode actions when the selected nodes don't allow them --- Scene/CLightNode.h | 1 + Scene/CSceneNode.h | 3 +++ Scene/CScriptNode.cpp | 12 +++++++++ Scene/CScriptNode.h | 2 ++ UI/CBasicViewport.cpp | 3 ++- UI/CWorldEditor.cpp | 40 +++++++++++++++--------------- UI/CWorldEditor.h | 4 ++- UI/INodeEditor.cpp | 40 ++++++++++++++++++++++++------ UI/INodeEditor.h | 9 ++++--- UI/undo/CClearSelectionCommand.cpp | 4 +-- UI/undo/CDeselectNodeCommand.cpp | 4 +-- UI/undo/CSelectNodeCommand.cpp | 4 +-- 12 files changed, 87 insertions(+), 39 deletions(-) diff --git a/Scene/CLightNode.h b/Scene/CLightNode.h index 73226967..52ba1b47 100644 --- a/Scene/CLightNode.h +++ b/Scene/CLightNode.h @@ -15,6 +15,7 @@ public: void DrawSelection(); void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); + bool AllowsRotate() const { return false; } CLight* Light(); CVector2f BillboardScale(); diff --git a/Scene/CSceneNode.h b/Scene/CSceneNode.h index 19bf91c7..60f0f8ad 100644 --- a/Scene/CSceneNode.h +++ b/Scene/CSceneNode.h @@ -58,6 +58,9 @@ public: virtual void DrawSelection(); virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); virtual SRayIntersection RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo) = 0; + virtual bool AllowsTranslate() const { return true; } + virtual bool AllowsRotate() const { return true; } + virtual bool AllowsScale() const { return true; } virtual bool IsVisible() const; virtual CColor TintColor(const SViewInfo& ViewInfo) const; virtual CColor WireframeColor() const; diff --git a/Scene/CScriptNode.cpp b/Scene/CScriptNode.cpp index addfe985..7e902660 100644 --- a/Scene/CScriptNode.cpp +++ b/Scene/CScriptNode.cpp @@ -363,6 +363,18 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID, return out; } +bool CScriptNode::AllowsRotate() const +{ + CScriptTemplate *pTemp = mpInstance->Template(); + return (pTemp->RotationType() == CScriptTemplate::eRotationEnabled); +} + +bool CScriptNode::AllowsScale() const +{ + CScriptTemplate *pTemp = mpInstance->Template(); + return (pTemp->ScaleType() != CScriptTemplate::eScaleDisabled); +} + bool CScriptNode::IsVisible() const { // Reimplementation of CSceneNode::IsVisible() to allow for layer and template visiblity to be taken into account diff --git a/Scene/CScriptNode.h b/Scene/CScriptNode.h index a2769e97..a0ef1ac9 100644 --- a/Scene/CScriptNode.h +++ b/Scene/CScriptNode.h @@ -33,6 +33,8 @@ public: void DrawSelection(); void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); + bool AllowsRotate() const; + bool AllowsScale() const; bool IsVisible() const; CColor TintColor(const SViewInfo &ViewInfo) const; CColor WireframeColor() const; diff --git a/UI/CBasicViewport.cpp b/UI/CBasicViewport.cpp index 4fccea29..36e2d01d 100644 --- a/UI/CBasicViewport.cpp +++ b/UI/CBasicViewport.cpp @@ -255,7 +255,8 @@ void CBasicViewport::ProcessInput() } if (IsKeyboardInputActive()) - mCamera.ProcessKeyInput((EKeyInputs) mKeysPressed, DeltaTime); + if ((mKeysPressed & eCtrlKey) == 0) + mCamera.ProcessKeyInput((EKeyInputs) mKeysPressed, DeltaTime); // Update view info const CMatrix4f& View = mCamera.ViewMatrix(); diff --git a/UI/CWorldEditor.cpp b/UI/CWorldEditor.cpp index 5deb1510..49f95022 100644 --- a/UI/CWorldEditor.cpp +++ b/UI/CWorldEditor.cpp @@ -149,6 +149,26 @@ CGameArea* CWorldEditor::ActiveArea() } // ************ UPDATE UI ************ +void CWorldEditor::UpdateStatusBar() +{ + // Would be cool to do more frequent status bar updates with more info. Unfortunately, this causes lag. + QString StatusText = ""; + + if (!mGizmoHovering) + { + if (ui->MainViewport->underMouse()) + { + CSceneNode *pHoverNode = ui->MainViewport->HoverNode(); + + if (pHoverNode && (pHoverNode->NodeType() != eStaticNode)) + StatusText = TO_QSTRING(pHoverNode->Name()); + } + } + + if (ui->statusbar->currentMessage() != StatusText) + ui->statusbar->showMessage(StatusText); +} + void CWorldEditor::UpdateGizmoUI() { // Update transform XYZ spin boxes @@ -224,26 +244,6 @@ void CWorldEditor::UpdateSelectionUI() UpdateGizmoUI(); } -void CWorldEditor::UpdateStatusBar() -{ - // Would be cool to do more frequent status bar updates with more info. Unfortunately, this causes lag. - QString StatusText = ""; - - if (!mGizmoHovering) - { - if (ui->MainViewport->underMouse()) - { - CSceneNode *pHoverNode = ui->MainViewport->HoverNode(); - - if (pHoverNode && (pHoverNode->NodeType() != eStaticNode)) - StatusText = TO_QSTRING(pHoverNode->Name()); - } - } - - if (ui->statusbar->currentMessage() != StatusText) - ui->statusbar->showMessage(StatusText); -} - // ************ PROTECTED ************ void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode) { diff --git a/UI/CWorldEditor.h b/UI/CWorldEditor.h index a4bc884a..ae8908b4 100644 --- a/UI/CWorldEditor.h +++ b/UI/CWorldEditor.h @@ -44,9 +44,11 @@ public: CGameArea* ActiveArea(); // Update UI + void UpdateStatusBar(); + +public slots: void UpdateGizmoUI(); void UpdateSelectionUI(); - void UpdateStatusBar(); protected: void GizmoModeChanged(CGizmo::EGizmoMode mode); diff --git a/UI/INodeEditor.cpp b/UI/INodeEditor.cpp index 23af609f..9733910d 100644 --- a/UI/INodeEditor.cpp +++ b/UI/INodeEditor.cpp @@ -49,6 +49,7 @@ INodeEditor::INodeEditor(QWidget *pParent) connect(mGizmoActions[2], SIGNAL(triggered()), this, SLOT(OnRotateTriggered())); connect(mGizmoActions[3], SIGNAL(triggered()), this, SLOT(OnScaleTriggered())); connect(mpTransformCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnTransformSpaceChanged(int))); + connect(this, SIGNAL(SelectionModified()), this, SLOT(OnSelectionModified())); } INodeEditor::~INodeEditor() @@ -134,24 +135,18 @@ void INodeEditor::SelectNode(CSceneNode *pNode) { if (!pNode->IsSelected()) mUndoStack.push(new CSelectNodeCommand(this, pNode, mSelection)); - - emit SelectionModified(); } void INodeEditor::DeselectNode(CSceneNode *pNode) { if (pNode->IsSelected()) mUndoStack.push(new CDeselectNodeCommand(this, pNode, mSelection)); - - emit SelectionModified(); } void INodeEditor::ClearSelection() { if (!mSelection.empty()) mUndoStack.push(new CClearSelectionCommand(this, mSelection)); - - emit SelectionModified(); } void INodeEditor::ClearAndSelectNode(CSceneNode *pNode) @@ -169,8 +164,6 @@ void INodeEditor::ClearAndSelectNode(CSceneNode *pNode) mUndoStack.push(new CSelectNodeCommand(this, pNode, mSelection)); mUndoStack.endMacro(); } - - emit SelectionModified(); } // ************ PUBLIC SLOTS ************ @@ -204,6 +197,31 @@ void INodeEditor::OnGizmoMoved() UpdateGizmoUI(); } +// ************ PRIVATE ************ +void INodeEditor::UpdateTransformActionsEnabled() +{ + bool AllowTranslate = true, AllowRotate = true, AllowScale = true; + bool SelectedModeWasEnabled = mpGizmoGroup->checkedAction()->isEnabled(); + + for (auto it = mSelection.begin(); it != mSelection.end(); it++) + { + if (!(*it)->AllowsTranslate()) AllowTranslate = false; + if (!(*it)->AllowsRotate()) AllowRotate = false; + if (!(*it)->AllowsScale()) AllowScale = false; + } + + mGizmoActions[1]->setEnabled(AllowTranslate); + mGizmoActions[2]->setEnabled(AllowRotate); + mGizmoActions[3]->setEnabled(AllowScale); + + bool SelectedModeIsEnabled = mpGizmoGroup->checkedAction()->isEnabled(); + + if (SelectedModeWasEnabled && !SelectedModeIsEnabled) + OnSelectObjectsTriggered(); + else if (SelectedModeIsEnabled && !SelectedModeWasEnabled) + mpGizmoGroup->checkedAction()->trigger(); +} + // ************ PRIVATE SLOTS ************ void INodeEditor::OnSelectObjectsTriggered() { @@ -278,3 +296,9 @@ void INodeEditor::OnTransformSpaceChanged(int spaceIndex) mGizmo.SetTransformSpace(space); } + +void INodeEditor::OnSelectionModified() +{ + UpdateTransformActionsEnabled(); + UpdateSelectionUI(); +} diff --git a/UI/INodeEditor.h b/UI/INodeEditor.h index 095b3d2f..8b086fa5 100644 --- a/UI/INodeEditor.h +++ b/UI/INodeEditor.h @@ -57,25 +57,28 @@ public: void ClearSelection(); void ClearAndSelectNode(CSceneNode *pNode); - virtual void UpdateGizmoUI() = 0; - virtual void UpdateSelectionUI() = 0; - signals: void SelectionModified(); void SelectionTransformed(); public slots: void OnGizmoMoved(); + virtual void UpdateGizmoUI() = 0; + virtual void UpdateSelectionUI() = 0; protected: virtual void GizmoModeChanged(CGizmo::EGizmoMode /*mode*/) {} +private: + void UpdateTransformActionsEnabled(); + private slots: void OnSelectObjectsTriggered(); void OnTranslateTriggered(); void OnRotateTriggered(); void OnScaleTriggered(); void OnTransformSpaceChanged(int spaceIndex); + void OnSelectionModified(); }; #endif // INODEEDITOR_H diff --git a/UI/undo/CClearSelectionCommand.cpp b/UI/undo/CClearSelectionCommand.cpp index 89c81b5c..a4e208c7 100644 --- a/UI/undo/CClearSelectionCommand.cpp +++ b/UI/undo/CClearSelectionCommand.cpp @@ -27,7 +27,7 @@ void CClearSelectionCommand::undo() } mpEditor->RecalculateSelectionBounds(); - mpEditor->UpdateSelectionUI(); + mpEditor->SelectionModified(); } void CClearSelectionCommand::redo() @@ -38,5 +38,5 @@ void CClearSelectionCommand::redo() mpSelection->clear(); mpEditor->RecalculateSelectionBounds(); - mpEditor->UpdateSelectionUI(); + mpEditor->SelectionModified(); } diff --git a/UI/undo/CDeselectNodeCommand.cpp b/UI/undo/CDeselectNodeCommand.cpp index 76433df7..0aad6d86 100644 --- a/UI/undo/CDeselectNodeCommand.cpp +++ b/UI/undo/CDeselectNodeCommand.cpp @@ -18,7 +18,7 @@ void CDeselectNodeCommand::undo() } mpEditor->ExpandSelectionBounds(mpNode); - mpEditor->UpdateSelectionUI(); + mpEditor->SelectionModified(); } void CDeselectNodeCommand::redo() @@ -38,5 +38,5 @@ void CDeselectNodeCommand::redo() } mpEditor->RecalculateSelectionBounds(); - mpEditor->UpdateSelectionUI(); + mpEditor->SelectionModified(); } diff --git a/UI/undo/CSelectNodeCommand.cpp b/UI/undo/CSelectNodeCommand.cpp index 540e76bd..d20856f7 100644 --- a/UI/undo/CSelectNodeCommand.cpp +++ b/UI/undo/CSelectNodeCommand.cpp @@ -26,7 +26,7 @@ void CSelectNodeCommand::undo() } mpEditor->RecalculateSelectionBounds(); - mpEditor->UpdateSelectionUI(); + mpEditor->SelectionModified(); } void CSelectNodeCommand::redo() @@ -38,5 +38,5 @@ void CSelectNodeCommand::redo() } mpEditor->ExpandSelectionBounds(mpNode); - mpEditor->UpdateSelectionUI(); + mpEditor->SelectionModified(); }