Draw a line in the viewport to visualize the link the user is editing

This commit is contained in:
parax0 2016-03-07 17:34:48 -07:00
parent 0eae2162b9
commit 95d4deeab6
7 changed files with 96 additions and 6 deletions

View File

@ -1,6 +1,7 @@
#include "CSceneViewport.h" #include "CSceneViewport.h"
#include "UICommon.h" #include "UICommon.h"
#include "Editor/Undo/UndoCommands.h" #include "Editor/Undo/UndoCommands.h"
#include <Core/Render/CDrawUtil.h>
#include <Core/Render/SViewInfo.h> #include <Core/Render/SViewInfo.h>
#include <Core/Resource/Script/CScriptLayer.h> #include <Core/Resource/Script/CScriptLayer.h>
#include <Core/Scene/CSceneIterator.h> #include <Core/Scene/CSceneIterator.h>
@ -131,14 +132,16 @@ void CSceneViewport::SceneRayCast(const CRay& rkRay)
} }
else else
{
mHoverPoint = rkRay.PointOnRay(5.f);
ResetHover(); ResetHover();
}
} }
void CSceneViewport::ResetHover() void CSceneViewport::ResetHover()
{ {
if (mpHoverNode) mpHoverNode->SetMouseHovering(false); if (mpHoverNode) mpHoverNode->SetMouseHovering(false);
mpHoverNode = nullptr; mpHoverNode = nullptr;
mHoverPoint = CVector3f::skZero;
} }
bool CSceneViewport::IsHoveringGizmo() bool CSceneViewport::IsHoveringGizmo()
@ -259,6 +262,14 @@ void CSceneViewport::Paint()
mCamera.LoadMatrices(); mCamera.LoadMatrices();
mpScene->AddSceneToRenderer(mpRenderer, mViewInfo); mpScene->AddSceneToRenderer(mpRenderer, mViewInfo);
// Draw the line for the link the user is editing. This is a little hacky but I don't really have a better way to do this atm.
if (mLinkLineEnabled)
{
glDepthRange(0.f, 1.f);
CDrawUtil::DrawLine(mLinkLinePoints[0], mLinkLinePoints[1], CColor::skYellow);
}
mpRenderer->RenderBuckets(mViewInfo); mpRenderer->RenderBuckets(mViewInfo);
mpRenderer->RenderBloom(); mpRenderer->RenderBloom();

View File

@ -34,6 +34,10 @@ class CSceneViewport : public CBasicViewport
QAction *mpUnhideAllAction; QAction *mpUnhideAllAction;
CSceneNode *mpMenuNode; CSceneNode *mpMenuNode;
// Link Line
bool mLinkLineEnabled;
CVector3f mLinkLinePoints[2];
public: public:
CSceneViewport(QWidget *pParent = 0); CSceneViewport(QWidget *pParent = 0);
~CSceneViewport(); ~CSceneViewport();
@ -53,6 +57,14 @@ public:
void keyPressEvent(QKeyEvent* pEvent); void keyPressEvent(QKeyEvent* pEvent);
void keyReleaseEvent(QKeyEvent* pEvent); void keyReleaseEvent(QKeyEvent* pEvent);
inline void SetLinkLineEnabled(bool Enable) { mLinkLineEnabled = Enable; }
inline void SetLinkLine(const CVector3f& rkPointA, const CVector3f& rkPointB)
{
mLinkLinePoints[0] = rkPointA;
mLinkLinePoints[1] = rkPointB;
}
protected: protected:
void CreateContextMenu(); void CreateContextMenu();
QMouseEvent CreateMouseEvent(); QMouseEvent CreateMouseEvent();

View File

@ -1,5 +1,4 @@
#include "CLinkDialog.h" #include "CLinkDialog.h"
#include "ui_CLinkDialog.h"
#include "CSelectInstanceDialog.h" #include "CSelectInstanceDialog.h"
#include "CStateMessageModel.h" #include "CStateMessageModel.h"
#include "CWorldEditor.h" #include "CWorldEditor.h"

View File

@ -2,12 +2,9 @@
#define CLINKDIALOG_H #define CLINKDIALOG_H
#include "CStateMessageModel.h" #include "CStateMessageModel.h"
#include "ui_CLinkDialog.h"
#include <QDialog> #include <QDialog>
namespace Ui {
class CLinkDialog;
}
class CWorldEditor; class CWorldEditor;
class CLinkDialog : public QDialog class CLinkDialog : public QDialog
@ -49,6 +46,9 @@ public:
inline CScriptObject* Sender() const { return mpSender; } inline CScriptObject* Sender() const { return mpSender; }
inline CScriptObject* Receiver() const { return mpReceiver; } inline CScriptObject* Receiver() const { return mpReceiver; }
inline bool IsPicking() const { return mIsPicking; }
inline bool IsPickingSender() const { return mIsPicking && ui->SenderPickFromViewport->isChecked(); }
inline bool IsPickingReceiver() const { return mIsPicking && ui->ReceiverPickFromViewport->isChecked(); }
public slots: public slots:
void accept(); void accept();

View File

@ -485,6 +485,64 @@ void CWorldEditor::UpdateCursor()
} }
} }
void CWorldEditor::UpdateNewLinkLine()
{
// Check if there is a sender+receiver
if (mpLinkDialog->isVisible() && mpLinkDialog->Sender() && mpLinkDialog->Receiver() && !mpLinkDialog->IsPicking())
{
CVector3f Start = mScene.NodeForObject(mpLinkDialog->Sender())->CenterPoint();
CVector3f End = mScene.NodeForObject(mpLinkDialog->Receiver())->CenterPoint();
ui->MainViewport->SetLinkLineEnabled(true);
ui->MainViewport->SetLinkLine(Start, End);
}
// Otherwise check whether there's just a sender or just a receiver
else
{
CScriptObject *pSender = nullptr;
CScriptObject *pReceiver = nullptr;
if (mpLinkDialog->isVisible())
{
if (mpLinkDialog->Sender() && !mpLinkDialog->IsPickingSender())
pSender = mpLinkDialog->Sender();
if (mpLinkDialog->Receiver() && !mpLinkDialog->IsPickingReceiver())
pReceiver = mpLinkDialog->Receiver();
}
else if (mIsMakingLink && mpNewLinkSender)
pSender = mpNewLinkSender;
// No sender and no receiver = no line
if (!pSender && !pReceiver)
ui->MainViewport->SetLinkLineEnabled(false);
// Yes sender and yes receiver = yes line
else if (pSender && pReceiver)
{
ui->MainViewport->SetLinkLineEnabled(true);
ui->MainViewport->SetLinkLine( mScene.NodeForObject(pSender)->CenterPoint(), mScene.NodeForObject(pReceiver)->CenterPoint() );
}
// Compensate for missing sender or missing receiver
else
{
if (ui->MainViewport->underMouse() && !ui->MainViewport->IsMouseInputActive() && (mIsMakingLink || mpLinkDialog->IsPicking()))
{
CSceneNode *pHoverNode = ui->MainViewport->HoverNode();
CScriptObject *pInst = (pSender ? pSender : pReceiver);
CVector3f Start = mScene.NodeForObject(pInst)->CenterPoint();
CVector3f End = (pHoverNode && pHoverNode->NodeType() == eScriptNode ? pHoverNode->CenterPoint() : ui->MainViewport->HoverPoint());
ui->MainViewport->SetLinkLineEnabled(true);
ui->MainViewport->SetLinkLine(Start, End);
}
else
ui->MainViewport->SetLinkLineEnabled(false);
}
}
}
// ************ PROTECTED ************ // ************ PROTECTED ************
void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode) void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode)
{ {
@ -654,6 +712,9 @@ void CWorldEditor::RefreshViewport()
// Process input // Process input
ui->MainViewport->ProcessInput(); ui->MainViewport->ProcessInput();
// Update new link line
UpdateNewLinkLine();
// Render // Render
ui->MainViewport->Render(); ui->MainViewport->Render();
} }

View File

@ -67,6 +67,7 @@ public slots:
void UpdateGizmoUI(); void UpdateGizmoUI();
void UpdateSelectionUI(); void UpdateSelectionUI();
void UpdateCursor(); void UpdateCursor();
void UpdateNewLinkLine();
protected: protected:
void GizmoModeChanged(CGizmo::EGizmoMode mode); void GizmoModeChanged(CGizmo::EGizmoMode mode);

View File

@ -185,6 +185,9 @@
</item> </item>
<item> <item>
<widget class="QToolButton" name="EditOutgoingConnectionButton"> <widget class="QToolButton" name="EditOutgoingConnectionButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::StrongFocus</enum> <enum>Qt::StrongFocus</enum>
</property> </property>
@ -299,6 +302,9 @@
</item> </item>
<item> <item>
<widget class="QToolButton" name="EditIncomingConnectionButton"> <widget class="QToolButton" name="EditIncomingConnectionButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::StrongFocus</enum> <enum>Qt::StrongFocus</enum>
</property> </property>