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 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();

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

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

View File

@ -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)
{

View File

@ -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);

View File

@ -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();
}

View File

@ -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

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}