Disable gizmo mode actions when the selected nodes don't allow them

This commit is contained in:
parax0 2015-12-06 22:44:56 -07:00
parent 0da183b161
commit b4855e37ed
12 changed files with 87 additions and 39 deletions

View File

@ -15,6 +15,7 @@ public:
void DrawSelection(); void DrawSelection();
void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
bool AllowsRotate() const { return false; }
CLight* Light(); CLight* Light();
CVector2f BillboardScale(); CVector2f BillboardScale();

View File

@ -58,6 +58,9 @@ public:
virtual void DrawSelection(); virtual void DrawSelection();
virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); virtual void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
virtual SRayIntersection RayNodeIntersectTest(const CRay& Ray, u32 AssetID, const SViewInfo& ViewInfo) = 0; 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 bool IsVisible() const;
virtual CColor TintColor(const SViewInfo& ViewInfo) const; virtual CColor TintColor(const SViewInfo& ViewInfo) const;
virtual CColor WireframeColor() const; virtual CColor WireframeColor() const;

View File

@ -363,6 +363,18 @@ SRayIntersection CScriptNode::RayNodeIntersectTest(const CRay& Ray, u32 AssetID,
return out; 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 bool CScriptNode::IsVisible() const
{ {
// Reimplementation of CSceneNode::IsVisible() to allow for layer and template visiblity to be taken into account // Reimplementation of CSceneNode::IsVisible() to allow for layer and template visiblity to be taken into account

View File

@ -33,6 +33,8 @@ public:
void DrawSelection(); void DrawSelection();
void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo); void RayAABoxIntersectTest(CRayCollisionTester& Tester, const SViewInfo& ViewInfo);
SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo); SRayIntersection RayNodeIntersectTest(const CRay &Ray, u32 AssetID, const SViewInfo& ViewInfo);
bool AllowsRotate() const;
bool AllowsScale() const;
bool IsVisible() const; bool IsVisible() const;
CColor TintColor(const SViewInfo &ViewInfo) const; CColor TintColor(const SViewInfo &ViewInfo) const;
CColor WireframeColor() const; CColor WireframeColor() const;

View File

@ -255,6 +255,7 @@ void CBasicViewport::ProcessInput()
} }
if (IsKeyboardInputActive()) if (IsKeyboardInputActive())
if ((mKeysPressed & eCtrlKey) == 0)
mCamera.ProcessKeyInput((EKeyInputs) mKeysPressed, DeltaTime); mCamera.ProcessKeyInput((EKeyInputs) mKeysPressed, DeltaTime);
// Update view info // Update view info

View File

@ -149,6 +149,26 @@ CGameArea* CWorldEditor::ActiveArea()
} }
// ************ UPDATE UI ************ // ************ 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() void CWorldEditor::UpdateGizmoUI()
{ {
// Update transform XYZ spin boxes // Update transform XYZ spin boxes
@ -224,26 +244,6 @@ void CWorldEditor::UpdateSelectionUI()
UpdateGizmoUI(); 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 ************ // ************ PROTECTED ************
void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode) void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode)
{ {

View File

@ -44,9 +44,11 @@ public:
CGameArea* ActiveArea(); CGameArea* ActiveArea();
// Update UI // Update UI
void UpdateStatusBar();
public slots:
void UpdateGizmoUI(); void UpdateGizmoUI();
void UpdateSelectionUI(); void UpdateSelectionUI();
void UpdateStatusBar();
protected: protected:
void GizmoModeChanged(CGizmo::EGizmoMode mode); void GizmoModeChanged(CGizmo::EGizmoMode mode);

View File

@ -49,6 +49,7 @@ INodeEditor::INodeEditor(QWidget *pParent)
connect(mGizmoActions[2], SIGNAL(triggered()), this, SLOT(OnRotateTriggered())); connect(mGizmoActions[2], SIGNAL(triggered()), this, SLOT(OnRotateTriggered()));
connect(mGizmoActions[3], SIGNAL(triggered()), this, SLOT(OnScaleTriggered())); connect(mGizmoActions[3], SIGNAL(triggered()), this, SLOT(OnScaleTriggered()));
connect(mpTransformCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnTransformSpaceChanged(int))); connect(mpTransformCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(OnTransformSpaceChanged(int)));
connect(this, SIGNAL(SelectionModified()), this, SLOT(OnSelectionModified()));
} }
INodeEditor::~INodeEditor() INodeEditor::~INodeEditor()
@ -134,24 +135,18 @@ void INodeEditor::SelectNode(CSceneNode *pNode)
{ {
if (!pNode->IsSelected()) if (!pNode->IsSelected())
mUndoStack.push(new CSelectNodeCommand(this, pNode, mSelection)); mUndoStack.push(new CSelectNodeCommand(this, pNode, mSelection));
emit SelectionModified();
} }
void INodeEditor::DeselectNode(CSceneNode *pNode) void INodeEditor::DeselectNode(CSceneNode *pNode)
{ {
if (pNode->IsSelected()) if (pNode->IsSelected())
mUndoStack.push(new CDeselectNodeCommand(this, pNode, mSelection)); mUndoStack.push(new CDeselectNodeCommand(this, pNode, mSelection));
emit SelectionModified();
} }
void INodeEditor::ClearSelection() void INodeEditor::ClearSelection()
{ {
if (!mSelection.empty()) if (!mSelection.empty())
mUndoStack.push(new CClearSelectionCommand(this, mSelection)); mUndoStack.push(new CClearSelectionCommand(this, mSelection));
emit SelectionModified();
} }
void INodeEditor::ClearAndSelectNode(CSceneNode *pNode) void INodeEditor::ClearAndSelectNode(CSceneNode *pNode)
@ -169,8 +164,6 @@ void INodeEditor::ClearAndSelectNode(CSceneNode *pNode)
mUndoStack.push(new CSelectNodeCommand(this, pNode, mSelection)); mUndoStack.push(new CSelectNodeCommand(this, pNode, mSelection));
mUndoStack.endMacro(); mUndoStack.endMacro();
} }
emit SelectionModified();
} }
// ************ PUBLIC SLOTS ************ // ************ PUBLIC SLOTS ************
@ -204,6 +197,31 @@ void INodeEditor::OnGizmoMoved()
UpdateGizmoUI(); 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 ************ // ************ PRIVATE SLOTS ************
void INodeEditor::OnSelectObjectsTriggered() void INodeEditor::OnSelectObjectsTriggered()
{ {
@ -278,3 +296,9 @@ void INodeEditor::OnTransformSpaceChanged(int spaceIndex)
mGizmo.SetTransformSpace(space); mGizmo.SetTransformSpace(space);
} }
void INodeEditor::OnSelectionModified()
{
UpdateTransformActionsEnabled();
UpdateSelectionUI();
}

View File

@ -57,25 +57,28 @@ public:
void ClearSelection(); void ClearSelection();
void ClearAndSelectNode(CSceneNode *pNode); void ClearAndSelectNode(CSceneNode *pNode);
virtual void UpdateGizmoUI() = 0;
virtual void UpdateSelectionUI() = 0;
signals: signals:
void SelectionModified(); void SelectionModified();
void SelectionTransformed(); void SelectionTransformed();
public slots: public slots:
void OnGizmoMoved(); void OnGizmoMoved();
virtual void UpdateGizmoUI() = 0;
virtual void UpdateSelectionUI() = 0;
protected: protected:
virtual void GizmoModeChanged(CGizmo::EGizmoMode /*mode*/) {} virtual void GizmoModeChanged(CGizmo::EGizmoMode /*mode*/) {}
private:
void UpdateTransformActionsEnabled();
private slots: private slots:
void OnSelectObjectsTriggered(); void OnSelectObjectsTriggered();
void OnTranslateTriggered(); void OnTranslateTriggered();
void OnRotateTriggered(); void OnRotateTriggered();
void OnScaleTriggered(); void OnScaleTriggered();
void OnTransformSpaceChanged(int spaceIndex); void OnTransformSpaceChanged(int spaceIndex);
void OnSelectionModified();
}; };
#endif // INODEEDITOR_H #endif // INODEEDITOR_H

View File

@ -27,7 +27,7 @@ void CClearSelectionCommand::undo()
} }
mpEditor->RecalculateSelectionBounds(); mpEditor->RecalculateSelectionBounds();
mpEditor->UpdateSelectionUI(); mpEditor->SelectionModified();
} }
void CClearSelectionCommand::redo() void CClearSelectionCommand::redo()
@ -38,5 +38,5 @@ void CClearSelectionCommand::redo()
mpSelection->clear(); mpSelection->clear();
mpEditor->RecalculateSelectionBounds(); mpEditor->RecalculateSelectionBounds();
mpEditor->UpdateSelectionUI(); mpEditor->SelectionModified();
} }

View File

@ -18,7 +18,7 @@ void CDeselectNodeCommand::undo()
} }
mpEditor->ExpandSelectionBounds(mpNode); mpEditor->ExpandSelectionBounds(mpNode);
mpEditor->UpdateSelectionUI(); mpEditor->SelectionModified();
} }
void CDeselectNodeCommand::redo() void CDeselectNodeCommand::redo()
@ -38,5 +38,5 @@ void CDeselectNodeCommand::redo()
} }
mpEditor->RecalculateSelectionBounds(); mpEditor->RecalculateSelectionBounds();
mpEditor->UpdateSelectionUI(); mpEditor->SelectionModified();
} }

View File

@ -26,7 +26,7 @@ void CSelectNodeCommand::undo()
} }
mpEditor->RecalculateSelectionBounds(); mpEditor->RecalculateSelectionBounds();
mpEditor->UpdateSelectionUI(); mpEditor->SelectionModified();
} }
void CSelectNodeCommand::redo() void CSelectNodeCommand::redo()
@ -38,5 +38,5 @@ void CSelectNodeCommand::redo()
} }
mpEditor->ExpandSelectionBounds(mpNode); mpEditor->ExpandSelectionBounds(mpNode);
mpEditor->UpdateSelectionUI(); mpEditor->SelectionModified();
} }