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 "UICommon.h"
#include "Editor/Undo/UndoCommands.h"
#include <Core/Render/CDrawUtil.h>
#include <Core/Render/SViewInfo.h>
#include <Core/Resource/Script/CScriptLayer.h>
#include <Core/Scene/CSceneIterator.h>
@ -131,14 +132,16 @@ void CSceneViewport::SceneRayCast(const CRay& rkRay)
}
else
{
mHoverPoint = rkRay.PointOnRay(5.f);
ResetHover();
}
}
void CSceneViewport::ResetHover()
{
if (mpHoverNode) mpHoverNode->SetMouseHovering(false);
mpHoverNode = nullptr;
mHoverPoint = CVector3f::skZero;
}
bool CSceneViewport::IsHoveringGizmo()
@ -259,6 +262,14 @@ void CSceneViewport::Paint()
mCamera.LoadMatrices();
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->RenderBloom();

View File

@ -34,6 +34,10 @@ class CSceneViewport : public CBasicViewport
QAction *mpUnhideAllAction;
CSceneNode *mpMenuNode;
// Link Line
bool mLinkLineEnabled;
CVector3f mLinkLinePoints[2];
public:
CSceneViewport(QWidget *pParent = 0);
~CSceneViewport();
@ -53,6 +57,14 @@ public:
void keyPressEvent(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:
void CreateContextMenu();
QMouseEvent CreateMouseEvent();

View File

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

View File

@ -2,12 +2,9 @@
#define CLINKDIALOG_H
#include "CStateMessageModel.h"
#include "ui_CLinkDialog.h"
#include <QDialog>
namespace Ui {
class CLinkDialog;
}
class CWorldEditor;
class CLinkDialog : public QDialog
@ -49,6 +46,9 @@ public:
inline CScriptObject* Sender() const { return mpSender; }
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:
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 ************
void CWorldEditor::GizmoModeChanged(CGizmo::EGizmoMode mode)
{
@ -654,6 +712,9 @@ void CWorldEditor::RefreshViewport()
// Process input
ui->MainViewport->ProcessInput();
// Update new link line
UpdateNewLinkLine();
// Render
ui->MainViewport->Render();
}

View File

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

View File

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