From b1f118898ea6a00ba8c1e51d9eeb8b08a4e4c8f5 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 23 May 2023 12:35:07 -0500 Subject: [PATCH] add TypeHints for inspector viewing typehints operate as an additional label for a given class in the inspector, allowing one to specify what class-entry to use as a tag examples: Prefab displays prefab filename TSStatic displays the used shape asset name SFXEmitter displays the played sound asset GameBase derivatives display the datablock used --- Engine/source/T3D/gameBase/gameBase.h | 2 ++ Engine/source/T3D/prefab.cpp | 4 +++ Engine/source/T3D/prefab.h | 3 ++ Engine/source/T3D/sfx/sfxEmitter.h | 2 ++ Engine/source/T3D/tsStatic.h | 2 ++ Engine/source/console/simObject.h | 3 ++ .../source/gui/controls/guiTreeViewCtrl.cpp | 28 ++++++++++++++++++- Engine/source/gui/controls/guiTreeViewCtrl.h | 4 +++ .../gui/WorldEditorTreeWindow.ed.gui | 1 + 9 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Engine/source/T3D/gameBase/gameBase.h b/Engine/source/T3D/gameBase/gameBase.h index 56f5e2929..4f1aee2ef 100644 --- a/Engine/source/T3D/gameBase/gameBase.h +++ b/Engine/source/T3D/gameBase/gameBase.h @@ -275,6 +275,8 @@ public: /// Returns the datablock for this object. GameBaseData* getDataBlock() { return mDataBlock; } + /// returns the datablock name for this object + StringTableEntry getTypeHint() const override { return (mDataBlock) ? mDataBlock->getName() : StringTable->EmptyString(); }; /// Called when a new datablock is set. This allows subclasses to /// appropriately handle new datablocks. /// diff --git a/Engine/source/T3D/prefab.cpp b/Engine/source/T3D/prefab.cpp index d43abb54a..255b44d24 100644 --- a/Engine/source/T3D/prefab.cpp +++ b/Engine/source/T3D/prefab.cpp @@ -93,6 +93,10 @@ void Prefab::initPersistFields() Parent::initPersistFields(); } +StringTableEntry Prefab::getTypeHint() const +{ + return (mFilename != StringTable->EmptyString()) ? StringTable->insert(Torque::Path(mFilename).getFileName().c_str()) : StringTable->EmptyString(); +} extern bool gEditingMission; bool Prefab::onAdd() diff --git a/Engine/source/T3D/prefab.h b/Engine/source/T3D/prefab.h index d6cde3e69..95af5e7ed 100644 --- a/Engine/source/T3D/prefab.h +++ b/Engine/source/T3D/prefab.h @@ -60,6 +60,9 @@ public: static void initPersistFields(); + /// returns the filename for this object + StringTableEntry getTypeHint() const override; + // SimObject virtual bool onAdd(); virtual void onRemove(); diff --git a/Engine/source/T3D/sfx/sfxEmitter.h b/Engine/source/T3D/sfx/sfxEmitter.h index cdb93a8bf..2715fa63a 100644 --- a/Engine/source/T3D/sfx/sfxEmitter.h +++ b/Engine/source/T3D/sfx/sfxEmitter.h @@ -106,6 +106,8 @@ class SFXEmitter : public SceneObject DECLARE_SOUNDASSET(SFXEmitter, Sound); DECLARE_ASSET_NET_SETGET(SFXEmitter, Sound, DirtyUpdateMask); + /// returns the shape asset used for this object + StringTableEntry getTypeHint() const override { return (getSoundAsset()) ? getSoundAsset()->getAssetName() : StringTable->EmptyString(); } /// The sound source for the emitter. SFXSource *mSource; diff --git a/Engine/source/T3D/tsStatic.h b/Engine/source/T3D/tsStatic.h index 02a4b535b..6aa8b8141 100644 --- a/Engine/source/T3D/tsStatic.h +++ b/Engine/source/T3D/tsStatic.h @@ -237,6 +237,8 @@ public: DECLARE_CONOBJECT(TSStatic); static void initPersistFields(); + /// returns the shape asset used for this object + StringTableEntry getTypeHint() const override { return (getShapeAsset()) ? getShapeAsset()->getAssetName(): StringTable->EmptyString(); } static void consoleInit(); static bool _setFieldSkin(void* object, const char* index, const char* data); static const char* _getFieldSkin(void* object, const char* data); diff --git a/Engine/source/console/simObject.h b/Engine/source/console/simObject.h index 612366132..912f1b086 100644 --- a/Engine/source/console/simObject.h +++ b/Engine/source/console/simObject.h @@ -549,6 +549,9 @@ class SimObject: public ConsoleObject, public TamlCallbacks /// Get the internal name of this control StringTableEntry getInternalName() const { return mInternalName; } + /// type-specified slot for returning hints for the main difference between object instances + virtual StringTableEntry getTypeHint() const { return StringTable->EmptyString(); } + /// Set the original name of this control void setOriginalName(const char* originalName); diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.cpp b/Engine/source/gui/controls/guiTreeViewCtrl.cpp index e9e01a8bf..e1589aed5 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.cpp +++ b/Engine/source/gui/controls/guiTreeViewCtrl.cpp @@ -425,6 +425,7 @@ U32 GuiTreeViewCtrl::Item::getDisplayTextLength() StringTableEntry name = obj->getName(); StringTableEntry internalName = obj->getInternalName(); + StringTableEntry typeHint = obj->getTypeHint(); StringTableEntry className = obj->getClassName(); if( showInternalNameOnly() ) @@ -466,6 +467,11 @@ U32 GuiTreeViewCtrl::Item::getDisplayTextLength() if( internalName && internalName[ 0 ] ) len += dStrlen( internalName ) + 3; // ' []' } + if ( mState.test(ShowTypeHint) ) + { + if (typeHint && typeHint[0]) + len += dStrlen(typeHint) + 3; + } if( mState.test( Marked ) ) { len += 1; // '*' @@ -502,8 +508,10 @@ void GuiTreeViewCtrl::Item::getDisplayText(U32 bufLen, char *buf) { const char* pObjName = pObject->getName(); const char* pInternalName = pObject->getInternalName(); + const char* pTypeHint = pObject->getTypeHint(); bool hasInternalName = pInternalName && pInternalName[0]; + bool hasTypeHint = pTypeHint && pTypeHint[0]; bool hasObjectName = pObjName && pObjName[0]; const char* pClassName = pObject->getClassName(); @@ -566,6 +574,14 @@ void GuiTreeViewCtrl::Item::getDisplayText(U32 bufLen, char *buf) else dSprintf(ptr, len, " [%s]", pInternalName); } + if (hasTypeHint && mState.test(ShowTypeHint)) + { + if (mState.test(Item::Marked)) + dSprintf(ptr, len, " *<%s>", pTypeHint); + else + dSprintf(ptr, len, " <%s>", pTypeHint); + + } } } else @@ -835,6 +851,7 @@ GuiTreeViewCtrl::GuiTreeViewCtrl() mShowClassNames = true; mShowObjectNames = true; mShowInternalNames = true; + mShowTypeHints = false; mShowClassNameForUnnamedObjects = false; mFlags.set(RebuildVisible); @@ -894,7 +911,10 @@ void GuiTreeViewCtrl::initPersistFields() addField( "showObjectNames", TypeBool, Offset( mShowObjectNames, GuiTreeViewCtrl ), "If true, item text labels for objects will include object names." ); addField( "showInternalNames", TypeBool, Offset( mShowInternalNames, GuiTreeViewCtrl ), - "If true, item text labels for obje ts will include internal names." ); + "If true, item text labels for objets will include internal names." ); + addField("showTypeHints", TypeBool, Offset(mShowTypeHints, GuiTreeViewCtrl), + "If true, item text labels for objets will include TypeHints."); + addField( "showClassNameForUnnamedObjects", TypeBool, Offset( mShowClassNameForUnnamedObjects, GuiTreeViewCtrl ), "If true, class names will be used as object names for unnamed objects." ); addField( "compareToObjectID", TypeBool, Offset(mCompareToObjectID, GuiTreeViewCtrl)); @@ -1794,6 +1814,7 @@ bool GuiTreeViewCtrl::onAdd() mShowClassNames = false; mShowObjectNames = false; mShowInternalNames = true; + mShowTypeHints = false; } const char* objectNamesOnly = getDataField( sObjectNamesOnly, NULL ); @@ -1803,6 +1824,7 @@ bool GuiTreeViewCtrl::onAdd() mShowClassNames = false; mShowObjectNames = true; mShowInternalNames = false; + mShowTypeHints = false; } } @@ -4109,6 +4131,10 @@ GuiTreeViewCtrl::Item* GuiTreeViewCtrl::addInspectorDataItem(Item *parent, SimOb item->mState.clear( Item::ShowInternalName ); else item->mState.set( Item::ShowInternalName ); + if (!mShowTypeHints) + item->mState.clear(Item::ShowTypeHint); + else + item->mState.set(Item::ShowTypeHint); if( mShowClassNameForUnnamedObjects ) item->mState.set( Item::ShowClassNameForUnnamed ); diff --git a/Engine/source/gui/controls/guiTreeViewCtrl.h b/Engine/source/gui/controls/guiTreeViewCtrl.h index 256a2c30f..6a3f2b39b 100644 --- a/Engine/source/gui/controls/guiTreeViewCtrl.h +++ b/Engine/source/gui/controls/guiTreeViewCtrl.h @@ -79,6 +79,7 @@ class GuiTreeViewCtrl : public GuiArrayCtrl ForceItemName = BIT(15), ForceDragTarget = BIT(16), DenyDrag = BIT(17), + ShowTypeHint = BIT(18), }; GuiTreeViewCtrl* mParentControl; @@ -395,6 +396,9 @@ class GuiTreeViewCtrl : public GuiArrayCtrl /// If true, internal names will be included in inspector tree item labels. bool mShowInternalNames; + /// If true, TypeHints will be included in inspector tree item labels. + bool mShowTypeHints; + /// If true, class names will be used as object names for unnamed objects. bool mShowClassNameForUnnamedObjects; diff --git a/Templates/BaseGame/game/tools/worldEditor/gui/WorldEditorTreeWindow.ed.gui b/Templates/BaseGame/game/tools/worldEditor/gui/WorldEditorTreeWindow.ed.gui index bcf9fbf44..8ed43db5d 100644 --- a/Templates/BaseGame/game/tools/worldEditor/gui/WorldEditorTreeWindow.ed.gui +++ b/Templates/BaseGame/game/tools/worldEditor/gui/WorldEditorTreeWindow.ed.gui @@ -172,6 +172,7 @@ $guiContent = new GuiControl() { showClassNames = "0"; showObjectNames = "1"; showInternalNames = "1"; + showTypeHints = "1"; showClassNameForUnnamedObjects = "1"; }; };