From 4c873591f0b5ba678df1bc7a0a2249a63ce69daa Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 13 Jun 2019 13:05:22 -1000 Subject: [PATCH] Make InstanceID label selectable and add parsing tooltip --- src/Core/Resource/Script/CScriptObject.h | 17 +++++++++++++++-- src/Editor/Undo/ObjReferences.h | 6 +++--- src/Editor/WorldEditor/WEditorProperties.cpp | 13 +++++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Core/Resource/Script/CScriptObject.h b/src/Core/Resource/Script/CScriptObject.h index 7d6bfe75..d9696f2a 100644 --- a/src/Core/Resource/Script/CScriptObject.h +++ b/src/Core/Resource/Script/CScriptObject.h @@ -16,6 +16,19 @@ enum class ELinkType Outgoing }; +class CInstanceID +{ + uint32 mId = 0; +public: + operator uint32() const { return mId; } + CInstanceID() = default; + CInstanceID(uint32 id) : mId(id) {} + CInstanceID& operator=(uint32 id) { mId = id; return *this; } + uint8 Layer() const { return uint8((mId >> 26u) & 0x3fu); } + uint16 Area() const { return uint16((mId >> 16u) & 0x3ffu); } + uint16 Id() const { return uint16(mId & 0xffffu); } +}; + class CScriptObject { friend class CScriptLoader; @@ -26,7 +39,7 @@ class CScriptObject CScriptLayer *mpLayer; uint32 mVersion; - uint32 mInstanceID; + CInstanceID mInstanceID; std::vector mOutLinks; std::vector mInLinks; std::vector mPropertyData; @@ -75,7 +88,7 @@ public: CScriptLayer* Layer() const { return mpLayer; } uint32 Version() const { return mVersion; } uint32 ObjectTypeID() const { return mpTemplate->ObjectID(); } - uint32 InstanceID() const { return mInstanceID; } + CInstanceID InstanceID() const { return mInstanceID; } uint32 NumLinks(ELinkType Type) const { return (Type == ELinkType::Incoming ? mInLinks.size() : mOutLinks.size()); } CLink* Link(ELinkType Type, uint32 Index) const { return (Type == ELinkType::Incoming ? mInLinks[Index] : mOutLinks[Index]); } void* PropertyData() const { return (void*) mPropertyData.data(); } diff --git a/src/Editor/Undo/ObjReferences.h b/src/Editor/Undo/ObjReferences.h index c4a49cbb..30a8dfdd 100644 --- a/src/Editor/Undo/ObjReferences.h +++ b/src/Editor/Undo/ObjReferences.h @@ -84,7 +84,7 @@ public: class CInstancePtr { - uint32 mInstanceID; + CInstanceID mInstanceID; CGameArea *mpArea; bool mValid; @@ -94,12 +94,12 @@ public: inline void SetInstance(CScriptObject *pInst) { - mInstanceID = pInst ? pInst->InstanceID() : 0; + mInstanceID = pInst ? pInst->InstanceID() : CInstanceID(); mpArea = pInst ? pInst->Area() : nullptr; mValid = pInst ? true : false; } - inline uint32 InstanceID() const { return mInstanceID; } + inline CInstanceID InstanceID() const { return mInstanceID; } inline CGameArea* Area() const { return mpArea; } inline CScriptObject* operator* () const { return mValid ? mpArea->InstanceByID(mInstanceID) : nullptr; } inline CScriptObject* operator->() const { return mValid ? mpArea->InstanceByID(mInstanceID) : nullptr; } diff --git a/src/Editor/WorldEditor/WEditorProperties.cpp b/src/Editor/WorldEditor/WEditorProperties.cpp index 96b9e64b..9053758f 100644 --- a/src/Editor/WorldEditor/WEditorProperties.cpp +++ b/src/Editor/WorldEditor/WEditorProperties.cpp @@ -10,6 +10,7 @@ WEditorProperties::WEditorProperties(QWidget *pParent /*= 0*/) { mpInstanceInfoLabel = new QLabel; mpInstanceInfoLabel->setText("[No selection]"); + mpInstanceInfoLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); mpInstanceInfoLayout = new QHBoxLayout; mpInstanceInfoLayout->addWidget(mpInstanceInfoLabel); @@ -124,14 +125,22 @@ void WEditorProperties::OnSelectionModified() mpInstanceInfoLabel->setText(QString("[%1 objects selected]").arg(pSelection->Size())); mpInstanceNameLineEdit->clear(); } + + mpInstanceInfoLabel->setToolTip({}); } else { CScriptNode *pScript = static_cast(mpDisplayNode); - TString InstanceID = TString::HexString(pScript->Instance()->InstanceID(), 8, false); + CInstanceID InstanceID = pScript->Instance()->InstanceID(); TString ObjectType = pScript->Template()->Name(); - mpInstanceInfoLabel->setText(QString("[%1] [%2]").arg( TO_QSTRING(ObjectType) ).arg( TO_QSTRING(InstanceID) )); + mpInstanceInfoLabel->setText(QString("[%1] [%2]"). + arg( TO_QSTRING(ObjectType) ). + arg( TO_QSTRING(TString::HexString(InstanceID, 8, false)) )); + mpInstanceInfoLabel->setToolTip(QString("[Layer: %1] [Area: %2] [ID: %3]"). + arg( InstanceID.Layer() ). + arg( InstanceID.Area() ). + arg( TO_QSTRING(TString::HexString(InstanceID.Id(), 4, false)) )); UpdatePropertyValues(); }