From 18184747e39d59b3b163f01389fbebfe22993f82 Mon Sep 17 00:00:00 2001 From: Areloch Date: Sun, 29 May 2016 11:54:50 -0500 Subject: [PATCH] Fixes an issue where script-based components listed in the scene tree would not have a name on their tree item. --- Engine/source/T3D/assets/ComponentAsset.h | 6 ++++ Engine/source/T3D/entity.cpp | 44 +++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Engine/source/T3D/assets/ComponentAsset.h b/Engine/source/T3D/assets/ComponentAsset.h index 0eaa5a86b..1db53b8c8 100644 --- a/Engine/source/T3D/assets/ComponentAsset.h +++ b/Engine/source/T3D/assets/ComponentAsset.h @@ -66,6 +66,12 @@ public: /// Declare Console Object. DECLARE_CONOBJECT(ComponentAsset); + StringTableEntry getComponentName() { return mComponentName; } + StringTableEntry getComponentClass() { return mComponentClass; } + StringTableEntry getFriendlyName() { return mFriendlyName; } + StringTableEntry getFriendlyType() { return mComponentType; } + StringTableEntry getDescription() { return mDescription; } + protected: virtual void initializeAsset(void) {} virtual void onAssetRefresh(void) {} diff --git a/Engine/source/T3D/entity.cpp b/Engine/source/T3D/entity.cpp index bff589570..ae6586360 100644 --- a/Engine/source/T3D/entity.cpp +++ b/Engine/source/T3D/entity.cpp @@ -39,6 +39,9 @@ #include "T3D/components/collision/collisionInterfaces.h" #include "gui/controls/guiTreeViewCtrl.h" +#include "assets/assetManager.h" +#include "assets/assetQuery.h" +#include "T3D/assets/ComponentAsset.h" #include "console/consoleInternal.h" #include "T3D/gameBase/std/stdMoveList.h" @@ -1353,7 +1356,8 @@ Component *Entity::getComponent(String componentType) void Entity::onInspect() { Vector updaters = getComponents(); - for (Vector::iterator it = updaters.begin(); it != updaters.end(); it++) { + for (Vector::iterator it = updaters.begin(); it != updaters.end(); it++) + { (*it)->onInspect(); } @@ -1374,9 +1378,45 @@ void Entity::onInspect() newItem->mState.set(GuiTreeViewCtrl::Item::ForceItemName); //newItem->mInspectorInfo.mObject = this; - for (U32 i = 0; i < mComponents.size(); i++) + AssetManager *assetDB = dynamic_cast(Sim::findObject("AssetDatabase")); + if (!assetDB) + return; + + //This is used in the event of script-created assets, which likely only have + //the name and other 'friendly' properties stored in a ComponentAsset. + //So we'll do a query for those assets and find the asset based on the component's + //class name + AssetQuery* qry = new AssetQuery(); + qry->registerObject(); + + assetDB->findAssetType(qry, "ComponentAsset"); + + for (U32 i = 0; i < mComponents.size(); ++i) { String compName = mComponents[i]->getFriendlyName(); + + if (compName == String("")) + { + String componentClass = mComponents[i]->getClassNamespace(); + + //Means that it's a script-derived component and we should consult the asset to try + //to get the info for it + S32 compAssetCount = qry->mAssetList.size(); + for (U32 c = 0; c < compAssetCount; ++c) + { + StringTableEntry assetID = qry->mAssetList[c]; + + ComponentAsset* compAsset = assetDB->acquireAsset(assetID); + + String compAssetClass = compAsset->getComponentName(); + if (componentClass == compAssetClass) + { + compName = compAsset->getFriendlyName(); + break; + } + } + } + S32 compID = editorTree->insertItem(componentID, compName); newItem = editorTree->getItem(compID); newItem->mInspectorInfo.mObject = mComponents[i];