3
0

NodePaletteModel.cpp 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Interface/Interface.h>
  9. #include <AzCore/RTTI/BehaviorContextUtilities.h>
  10. #include <AzCore/Serialization/EditContext.h>
  11. #include <AzCore/Serialization/SerializeContext.h>
  12. #include <AzToolsFramework/ToolsComponents/EditorComponentBase.h>
  13. #include <AzToolsFramework/AssetBrowser/Entries/ProductAssetBrowserEntry.h>
  14. #include <Editor/View/Widgets/NodePalette/NodePaletteModel.h>
  15. #include <Editor/Include/ScriptCanvas/Bus/RequestBus.h>
  16. #include <Editor/GraphCanvas/GraphCanvasEditorNotificationBusId.h>
  17. #include <Editor/Nodes/NodeUtils.h>
  18. #include <Editor/Settings.h>
  19. #include <Editor/Translation/TranslationHelper.h>
  20. #include <ScriptCanvas/Data/DataRegistry.h>
  21. #include <ScriptCanvas/Libraries/Libraries.h>
  22. #include <ScriptCanvas/Libraries/Core/GetVariable.h>
  23. #include <ScriptCanvas/Libraries/Core/Method.h>
  24. #include <ScriptCanvas/Libraries/Core/SetVariable.h>
  25. #include <ScriptCanvas/Utils/NodeUtils.h>
  26. #include <ScriptCanvas/Data/Traits.h>
  27. #include <StaticLib/GraphCanvas/Styling/definitions.h>
  28. AZ_DEFINE_BUDGET(NodePaletteModel);
  29. namespace
  30. {
  31. static constexpr char DefaultGlobalConstantCategory[] = "Global Constants";
  32. static constexpr char DefaultGlobalMethodCategory[] = "Global Methods";
  33. static constexpr char DefaultClassMethodCategory[] = "Class Methods";
  34. static constexpr char DefaultEbusHandlerCategory[] = "Event Handlers";
  35. static constexpr char DefaultEbusEventCategory[] = "Events";
  36. // Various Helper Methods
  37. bool IsDeprecated(const AZ::AttributeArray& attributes)
  38. {
  39. bool isDeprecated{};
  40. if (auto isDeprecatedAttributePtr = AZ::FindAttribute(AZ::Script::Attributes::Deprecated, attributes))
  41. {
  42. AZ::AttributeReader(nullptr, isDeprecatedAttributePtr).Read<bool>(isDeprecated);
  43. }
  44. return isDeprecated;
  45. }
  46. bool ShouldExcludeFromNodeList(const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>* excludeAttributeData, const AZ::Uuid& typeId)
  47. {
  48. if (excludeAttributeData)
  49. {
  50. AZ::u64 exclusionFlags = AZ::Script::Attributes::ExcludeFlags::List | AZ::Script::Attributes::ExcludeFlags::ListOnly;
  51. if (typeId == AzToolsFramework::Components::EditorComponentBase::TYPEINFO_Uuid())
  52. {
  53. return true;
  54. }
  55. return (static_cast<AZ::u64>(excludeAttributeData->Get(nullptr)) & exclusionFlags) != 0; // warning C4800: 'AZ::u64': forcing value to bool 'true' or 'false' (performance warning)
  56. }
  57. return false;
  58. }
  59. bool HasExcludeFromNodeListAttribute(const AZ::SerializeContext* serializeContext, const AZ::Uuid& typeId)
  60. {
  61. const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(typeId);
  62. if (classData && classData->m_editData)
  63. {
  64. if (auto editorElementData = classData->m_editData->FindElementData(AZ::Edit::ClassElements::EditorData))
  65. {
  66. if (auto excludeAttribute = editorElementData->FindAttribute(AZ::Script::Attributes::ExcludeFrom))
  67. {
  68. auto excludeAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(excludeAttribute);
  69. return excludeAttributeData && ShouldExcludeFromNodeList(excludeAttributeData, typeId);
  70. }
  71. }
  72. }
  73. return false;
  74. }
  75. // Checks for and returns the Category attribute from an AZ::AttributeArray
  76. AZStd::string GetCategoryPath(const AZ::AttributeArray& attributes, const AZ::BehaviorContext& behaviorContext)
  77. {
  78. AZStd::string retVal;
  79. AZ::Attribute* categoryAttribute = AZ::FindAttribute(AZ::Script::Attributes::Category, attributes);
  80. if (categoryAttribute)
  81. {
  82. AZ::AttributeReader(nullptr, categoryAttribute).Read<AZStd::string>(retVal, behaviorContext);
  83. }
  84. return retVal;
  85. }
  86. bool IsExplicitOverload(const AZ::BehaviorMethod& method)
  87. {
  88. return AZ::FindAttribute(AZ::ScriptCanvasAttributes::ExplicitOverloadCrc, method.m_attributes) != nullptr;
  89. }
  90. void RegisterMethod
  91. ( ScriptCanvasEditor::NodePaletteModel& nodePaletteModel
  92. , const AZ::BehaviorContext& behaviorContext
  93. , const AZStd::string& categoryPath
  94. , const AZ::BehaviorClass* behaviorClass
  95. , const AZStd::string& name
  96. , const AZ::BehaviorMethod& method
  97. , ScriptCanvas::PropertyStatus propertyStatus
  98. , bool isOverloaded)
  99. {
  100. AZ_PROFILE_SCOPE(NodePaletteModel, "RegisterMethod");
  101. if (IsDeprecated(method.m_attributes))
  102. {
  103. return;
  104. }
  105. if (behaviorClass && !isOverloaded)
  106. {
  107. auto excludeMethodAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, method.m_attributes));
  108. if (ShouldExcludeFromNodeList(excludeMethodAttributeData, behaviorClass->m_azRtti ? behaviorClass->m_azRtti->GetTypeId() : behaviorClass->m_typeId))
  109. {
  110. return;
  111. }
  112. }
  113. const auto isExposableOutcome = ScriptCanvas::IsExposable(method);
  114. if (!isExposableOutcome.IsSuccess())
  115. {
  116. AZ_Warning("ScriptCanvas", false, "Unable to expose method: %s to ScriptCanvas because: %s", method.m_name.data(), isExposableOutcome.GetError().data());
  117. return;
  118. }
  119. nodePaletteModel.RegisterClassNode(categoryPath, behaviorClass ? behaviorClass->m_name : "", name, &method, &behaviorContext, propertyStatus, isOverloaded);
  120. }
  121. void RegisterGlobalMethod(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel, const AZ::BehaviorContext& behaviorContext,
  122. const AZ::BehaviorMethod& behaviorMethod)
  123. {
  124. AZ_PROFILE_SCOPE(NodePaletteModel, "RegisterGlobalMethod");
  125. const auto isExposableOutcome = ScriptCanvas::IsExposable(behaviorMethod);
  126. if (!isExposableOutcome.IsSuccess())
  127. {
  128. AZ_Warning("ScriptCanvas", false, "Unable to expose method: %s to ScriptCanvas because: %s",
  129. behaviorMethod.m_name.c_str(), isExposableOutcome.GetError().data());
  130. return;
  131. }
  132. if (!AZ::Internal::IsInScope(behaviorMethod.m_attributes, AZ::Script::Attributes::ScopeFlags::Common))
  133. {
  134. return; // skip this method
  135. }
  136. nodePaletteModel.RegisterGlobalMethodNode(behaviorContext, behaviorMethod);
  137. }
  138. //! Retrieve the list of EBuses t hat should not be exposed in the ScriptCanvasEditor Node Palette
  139. AZStd::unordered_set<AZ::Crc32> GetEBusExcludeSet(const AZ::BehaviorContext& behaviorContext)
  140. {
  141. AZ_PROFILE_SCOPE(NodePaletteModel, "GetEBusExcludeSet");
  142. // We will skip buses that are ONLY registered on classes that derive from EditorComponentBase,
  143. // because they don't have a runtime implementation. Buses such as the TransformComponent which
  144. // is implemented by both an EditorComponentBase derived class and a Component derived class
  145. // will still appear
  146. AZStd::unordered_set<AZ::Crc32> skipBuses;
  147. AZStd::unordered_set<AZ::Crc32> potentialSkipBuses;
  148. AZStd::unordered_set<AZ::Crc32> nonSkipBuses;
  149. for (const auto& classIter : behaviorContext.m_classes)
  150. {
  151. const AZ::BehaviorClass* behaviorClass = classIter.second;
  152. if (IsDeprecated(behaviorClass->m_attributes))
  153. {
  154. continue;
  155. }
  156. // Only bind Behavior Classes marked with the Scope type of Launcher
  157. if (!AZ::Internal::IsInScope(behaviorClass->m_attributes, AZ::Script::Attributes::ScopeFlags::Launcher))
  158. {
  159. continue; // skip this class
  160. }
  161. // Check for "ExcludeFrom" attribute for ScriptCanvas
  162. auto excludeClassAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(
  163. AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, behaviorClass->m_attributes));
  164. // We don't want to show any components, since there isn't anything we can do with them
  165. // from ScriptCanvas since we use buses to communicate to everything.
  166. if (ShouldExcludeFromNodeList(excludeClassAttributeData, behaviorClass->m_azRtti ? behaviorClass->m_azRtti->GetTypeId() : behaviorClass->m_typeId))
  167. {
  168. for (const auto& requestBus : behaviorClass->m_requestBuses)
  169. {
  170. skipBuses.insert(AZ::Crc32(requestBus.c_str()));
  171. }
  172. continue;
  173. }
  174. auto baseClass = AZStd::find(behaviorClass->m_baseClasses.begin(),
  175. behaviorClass->m_baseClasses.end(),
  176. AzToolsFramework::Components::EditorComponentBase::TYPEINFO_Uuid());
  177. if (baseClass != behaviorClass->m_baseClasses.end())
  178. {
  179. for (const auto& requestBus : behaviorClass->m_requestBuses)
  180. {
  181. potentialSkipBuses.insert(AZ::Crc32(requestBus.c_str()));
  182. }
  183. }
  184. // If the Ebus does not inherit from EditorComponentBase then do not skip it
  185. else
  186. {
  187. for (const auto& requestBus : behaviorClass->m_requestBuses)
  188. {
  189. nonSkipBuses.insert(AZ::Crc32(requestBus.c_str()));
  190. }
  191. }
  192. }
  193. // Add buses which are not on the non-skip list to the skipBuses set
  194. for (auto potentialSkipBus : potentialSkipBuses)
  195. {
  196. if (nonSkipBuses.find(potentialSkipBus) == nonSkipBuses.end())
  197. {
  198. skipBuses.insert(potentialSkipBus);
  199. }
  200. }
  201. return skipBuses;
  202. }
  203. //! Register all nodes populated into the ScriptCanvas NodeRegistry
  204. void PopulateScriptCanvasDerivedNodes(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  205. const AZ::SerializeContext& serializeContext)
  206. {
  207. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateScriptCanvasDerivedNodes");
  208. nodePaletteModel.RegisterDefaultCateogryInformation();
  209. for (auto& descriptor : ScriptCanvasModel::Instance().GetDescriptors())
  210. {
  211. const auto& classId = descriptor->GetUuid();
  212. if (const AZ::SerializeContext::ClassData* nodeClassData = serializeContext.FindClassData(classId))
  213. {
  214. if (HasExcludeFromNodeListAttribute(&serializeContext, classId))
  215. {
  216. continue;
  217. }
  218. // Skip over some of our more dynamic nodes that we want to populate using different means
  219. else if (nodeClassData->m_azRtti && nodeClassData->m_azRtti->IsTypeOf<ScriptCanvas::Nodes::Core::GetVariableNode>())
  220. {
  221. continue;
  222. }
  223. else if (nodeClassData->m_azRtti && nodeClassData->m_azRtti->IsTypeOf<ScriptCanvas::Nodes::Core::SetVariableNode>())
  224. {
  225. continue;
  226. }
  227. else
  228. {
  229. nodePaletteModel.RegisterCustomNode(nodeClassData);
  230. }
  231. }
  232. }
  233. ScriptCanvas::NodeRegistry* registry = ScriptCanvas::NodeRegistry::GetInstance();
  234. for (auto nodeId : registry->m_nodes)
  235. {
  236. if (HasExcludeFromNodeListAttribute(&serializeContext, nodeId))
  237. {
  238. continue;
  239. }
  240. // Pass in the associated class data so we can do more intensive lookups?
  241. const AZ::SerializeContext::ClassData* nodeClassData = serializeContext.FindClassData(nodeId);
  242. if (nodeClassData == nullptr)
  243. {
  244. continue;
  245. }
  246. // Skip over some of our more dynamic nodes that we want to populate using different means
  247. else if (nodeClassData->m_azRtti && nodeClassData->m_azRtti->IsTypeOf<ScriptCanvas::Nodes::Core::GetVariableNode>())
  248. {
  249. continue;
  250. }
  251. else if (nodeClassData->m_azRtti && nodeClassData->m_azRtti->IsTypeOf<ScriptCanvas::Nodes::Core::SetVariableNode>())
  252. {
  253. continue;
  254. }
  255. else
  256. {
  257. nodePaletteModel.RegisterCustomNode(nodeClassData);
  258. }
  259. }
  260. }
  261. void PopulateScriptCanvasDerivedNodesDeprecated(
  262. ScriptCanvasEditor::NodePaletteModel& nodePaletteModel, const AZ::SerializeContext& serializeContext)
  263. {
  264. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateScriptCanvasDerivedNodes");
  265. // Get all the types.
  266. auto EnumerateLibraryDefintionNodes = [&nodePaletteModel,
  267. &serializeContext](const AZ::SerializeContext::ClassData* classData, const AZ::Uuid&) -> bool
  268. {
  269. ScriptCanvasEditor::CategoryInformation categoryInfo;
  270. AZStd::string categoryPath = classData->m_editData ? classData->m_editData->m_name : classData->m_name;
  271. if (classData->m_editData)
  272. {
  273. auto editorElementData = classData->m_editData->FindElementData(AZ::Edit::ClassElements::EditorData);
  274. if (editorElementData)
  275. {
  276. if (auto categoryAttribute = editorElementData->FindAttribute(AZ::Edit::Attributes::Category))
  277. {
  278. if (auto categoryAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<const char*>*>(categoryAttribute))
  279. {
  280. categoryPath = categoryAttributeData->Get(nullptr);
  281. }
  282. }
  283. if (auto categoryStyleAttribute = editorElementData->FindAttribute(AZ::Edit::Attributes::CategoryStyle))
  284. {
  285. if (auto categoryAttributeData =
  286. azdynamic_cast<const AZ::Edit::AttributeData<const char*>*>(categoryStyleAttribute))
  287. {
  288. categoryInfo.m_styleOverride = categoryAttributeData->Get(nullptr);
  289. }
  290. }
  291. if (auto titlePaletteAttribute = editorElementData->FindAttribute(ScriptCanvas::Attributes::Node::TitlePaletteOverride))
  292. {
  293. if (auto categoryAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<const char*>*>(titlePaletteAttribute))
  294. {
  295. categoryInfo.m_paletteOverride = categoryAttributeData->Get(nullptr);
  296. }
  297. }
  298. }
  299. }
  300. nodePaletteModel.RegisterCategoryInformation(categoryPath, categoryInfo);
  301. // Children
  302. for (auto& node : ScriptCanvas::Library::LibraryDefinition::GetNodes(classData->m_typeId))
  303. {
  304. if (HasExcludeFromNodeListAttribute(&serializeContext, node.first))
  305. {
  306. continue;
  307. }
  308. // Pass in the associated class data so we can do more intensive lookups?
  309. const AZ::SerializeContext::ClassData* nodeClassData = serializeContext.FindClassData(node.first);
  310. if (nodeClassData == nullptr)
  311. {
  312. continue;
  313. }
  314. // Skip over some of our more dynamic nodes that we want to populate using different means
  315. else if (nodeClassData->m_azRtti && nodeClassData->m_azRtti->IsTypeOf<ScriptCanvas::Nodes::Core::GetVariableNode>())
  316. {
  317. continue;
  318. }
  319. else if (nodeClassData->m_azRtti && nodeClassData->m_azRtti->IsTypeOf<ScriptCanvas::Nodes::Core::SetVariableNode>())
  320. {
  321. continue;
  322. }
  323. else
  324. {
  325. nodePaletteModel.RegisterCustomNode(nodeClassData, categoryPath);
  326. }
  327. }
  328. return true;
  329. };
  330. const AZ::TypeId& libraryDefTypeId = azrtti_typeid<ScriptCanvas::Library::LibraryDefinition>();
  331. serializeContext.EnumerateDerived(EnumerateLibraryDefintionNodes, libraryDefTypeId, libraryDefTypeId);
  332. }
  333. void PopulateVariablePalette()
  334. {
  335. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateVariablePalette");
  336. auto dataRegistry = ScriptCanvas::GetDataRegistry();
  337. for (auto& type : dataRegistry->m_creatableTypes)
  338. {
  339. if (!type.second.m_isTransient)
  340. {
  341. ScriptCanvasEditor::VariablePaletteRequestBus::Broadcast(&ScriptCanvasEditor::VariablePaletteRequests::RegisterVariableType, type.first);
  342. }
  343. }
  344. }
  345. void PopulateBehaviorContextGlobalMethods(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  346. const AZ::BehaviorContext& behaviorContext)
  347. {
  348. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateBehaviorContextGlobalMethods");
  349. // BehaviorMethods are not associated with a class
  350. // therefore the Uuid is set to Null
  351. const AZ::Uuid behaviorMethodUuid = AZ::Uuid::CreateNull();
  352. for (const auto& [methodName, behaviorMethod] : behaviorContext.m_methods)
  353. {
  354. // Skip behavior methods that are deprecated
  355. if (behaviorMethod == nullptr || IsDeprecated(behaviorMethod->m_attributes))
  356. {
  357. continue;
  358. }
  359. // Check for "ExcludeFrom" attribute for ScriptCanvas
  360. auto excludeMethodAttributeData = azrtti_cast<const AZ::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(
  361. AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, behaviorMethod->m_attributes));
  362. if (ShouldExcludeFromNodeList(excludeMethodAttributeData, behaviorMethodUuid))
  363. {
  364. continue;
  365. }
  366. RegisterGlobalMethod(nodePaletteModel, behaviorContext, *behaviorMethod);
  367. }
  368. }
  369. //! Iterates over all Properties directly reflected to the BehaviorContext instance
  370. //! and registers there Getter/Setter methods to the NodePaletteModel
  371. void PopulateBehaviorContextGlobalProperties(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  372. const AZ::BehaviorContext& behaviorContext)
  373. {
  374. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateBehaviorContextGlobalProperties");
  375. const AZ::Uuid behaviorMethodUuid = AZ::Uuid::CreateNull();
  376. for (const auto& [propertyName, behaviorProperty] : behaviorContext.m_properties)
  377. {
  378. // Skip behavior properties that are deprecated
  379. if (behaviorProperty == nullptr || IsDeprecated(behaviorProperty->m_attributes))
  380. {
  381. continue;
  382. }
  383. // Check for "ExcludeFrom" attribute for ScriptCanvas
  384. auto excludePropertyAttributeData = azrtti_cast<const AZ::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(
  385. AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, behaviorProperty->m_attributes));
  386. if (ShouldExcludeFromNodeList(excludePropertyAttributeData, behaviorMethodUuid))
  387. {
  388. continue;
  389. }
  390. if (behaviorProperty->m_getter && !behaviorProperty->m_setter)
  391. {
  392. nodePaletteModel.RegisterGlobalConstant(behaviorContext, behaviorProperty , *behaviorProperty->m_getter);
  393. }
  394. else
  395. {
  396. if (behaviorProperty->m_getter)
  397. {
  398. RegisterGlobalMethod(nodePaletteModel, behaviorContext, *behaviorProperty->m_getter);
  399. }
  400. if (behaviorProperty->m_setter)
  401. {
  402. RegisterGlobalMethod(nodePaletteModel, behaviorContext, *behaviorProperty->m_setter);
  403. }
  404. }
  405. }
  406. }
  407. void PopulateBehaviorContextClassMethods(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  408. const AZ::BehaviorContext& behaviorContext)
  409. {
  410. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateBehaviorContextClassMethods");
  411. AZ::SerializeContext* serializeContext{};
  412. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  413. for (const auto& classIter : behaviorContext.m_classes)
  414. {
  415. const AZ::BehaviorClass* behaviorClass = classIter.second;
  416. if (IsDeprecated(behaviorClass->m_attributes))
  417. {
  418. continue;
  419. }
  420. if (AZ::FindAttribute(AZ::ScriptCanvasAttributes::Internal::ImplementedAsNodeGeneric, behaviorClass->m_attributes))
  421. {
  422. continue;
  423. }
  424. if (auto excludeFromPointer = AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, behaviorClass->m_attributes))
  425. {
  426. AZ::Script::Attributes::ExcludeFlags excludeFlags{};
  427. AZ::AttributeReader(nullptr, excludeFromPointer).Read<AZ::Script::Attributes::ExcludeFlags>(excludeFlags);
  428. if ((excludeFlags & (AZ::Script::Attributes::ExcludeFlags::List | AZ::Script::Attributes::ExcludeFlags::ListOnly)) != 0)
  429. {
  430. continue;
  431. }
  432. }
  433. if (!AZ::Internal::IsInScope(behaviorClass->m_attributes, AZ::Script::Attributes::ScopeFlags::Launcher))
  434. {
  435. continue;
  436. }
  437. // Objects and Object methods
  438. {
  439. AZStd::string categoryPath;
  440. GraphCanvas::TranslationKey key;
  441. key << ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorClassContext << behaviorClass->m_name.c_str() << "details";
  442. GraphCanvas::TranslationRequests::Details details;
  443. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  444. categoryPath = details.m_category;
  445. if (categoryPath.empty())
  446. {
  447. categoryPath = GetCategoryPath(behaviorClass->m_attributes, behaviorContext);
  448. }
  449. auto dataRegistry = ScriptCanvas::GetDataRegistry();
  450. ScriptCanvas::Data::Type type = dataRegistry->m_typeIdTraitMap[ScriptCanvas::Data::eType::BehaviorContextObject].m_dataTraits.GetSCType(behaviorClass->m_typeId);
  451. if (type.IsValid())
  452. {
  453. if (dataRegistry->m_creatableTypes.contains(type))
  454. {
  455. ScriptCanvasEditor::VariablePaletteRequestBus::Broadcast(&ScriptCanvasEditor::VariablePaletteRequests::RegisterVariableType, type);
  456. }
  457. }
  458. AZStd::string classNamePretty(classIter.first);
  459. AZ::Attribute* prettyNameAttribute = AZ::FindAttribute(AZ::ScriptCanvasAttributes::PrettyName, behaviorClass->m_attributes);
  460. if (prettyNameAttribute)
  461. {
  462. AZ::AttributeReader(nullptr, prettyNameAttribute).Read<AZStd::string>(classNamePretty, behaviorContext);
  463. }
  464. if (categoryPath.empty())
  465. {
  466. if (!classNamePretty.empty())
  467. {
  468. categoryPath = classNamePretty;
  469. }
  470. else
  471. {
  472. categoryPath = DefaultClassMethodCategory;
  473. }
  474. }
  475. categoryPath.append("/");
  476. if (details.m_name.empty())
  477. {
  478. categoryPath.append(classNamePretty.c_str());
  479. }
  480. else
  481. {
  482. categoryPath.append(details.m_name.c_str());
  483. }
  484. for (auto property : behaviorClass->m_properties)
  485. {
  486. if (property.second->m_getter)
  487. {
  488. RegisterMethod(nodePaletteModel, behaviorContext, categoryPath, behaviorClass, property.first, *property.second->m_getter, ScriptCanvas::PropertyStatus::Getter, behaviorClass->IsMethodOverloaded(property.first));
  489. }
  490. if (property.second->m_setter)
  491. {
  492. RegisterMethod(nodePaletteModel, behaviorContext, categoryPath, behaviorClass, property.first, *property.second->m_setter, ScriptCanvas::PropertyStatus::Setter, behaviorClass->IsMethodOverloaded(property.first));
  493. }
  494. }
  495. for (auto methodIter : behaviorClass->m_methods)
  496. {
  497. if (!IsExplicitOverload(*methodIter.second))
  498. {
  499. // Respect the exclusion flags
  500. auto attributeData = azdynamic_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, methodIter.second->m_attributes));
  501. if (ShouldExcludeFromNodeList(attributeData , {}))
  502. {
  503. continue;
  504. }
  505. RegisterMethod(nodePaletteModel, behaviorContext, categoryPath, behaviorClass, methodIter.first, *methodIter.second, ScriptCanvas::PropertyStatus::None, behaviorClass->IsMethodOverloaded(methodIter.first));
  506. }
  507. }
  508. }
  509. }
  510. }
  511. void PopulateBehaviorContextOverloadedMethods(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  512. const AZ::BehaviorContext& behaviorContext)
  513. {
  514. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateBehaviorContextOverloadedMethods");
  515. for (const AZ::ExplicitOverloadInfo& explicitOverload : behaviorContext.m_explicitOverloads)
  516. {
  517. RegisterMethod(nodePaletteModel, behaviorContext, explicitOverload.m_categoryPath, nullptr, explicitOverload.m_name, *explicitOverload.m_overloads.begin()->first, ScriptCanvas::PropertyStatus::None, true);
  518. }
  519. }
  520. void PopulateBehaviorContextEBusHandler(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  521. const AZ::BehaviorContext& behaviorContext, const AZ::BehaviorEBus& behaviorEbus)
  522. {
  523. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateBehaviorContextEBusHandler");
  524. if (AZ::ScopedBehaviorEBusHandler handler{ behaviorEbus }; handler)
  525. {
  526. auto excludeEbusAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(
  527. AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, behaviorEbus.m_attributes));
  528. if (ShouldExcludeFromNodeList(excludeEbusAttributeData, handler->RTTI_GetType()))
  529. {
  530. return;
  531. }
  532. const AZ::BehaviorEBusHandler::EventArray& events(handler->GetEvents());
  533. if (!events.empty())
  534. {
  535. GraphCanvas::TranslationKey key;
  536. key << ScriptCanvasEditor::TranslationHelper::AssetContext::EBusHandlerContext << behaviorEbus.m_name.c_str() << "details";
  537. GraphCanvas::TranslationRequests::Details details;
  538. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  539. AZStd::string categoryPath = details.m_category.empty() ? GetCategoryPath(behaviorEbus.m_attributes, behaviorContext) : details.m_category;
  540. // Treat the EBusHandler name as a Category key in order to allow multiple buses to be merged into a single Category.
  541. {
  542. if (!categoryPath.empty())
  543. {
  544. categoryPath.append("/");
  545. }
  546. else
  547. {
  548. categoryPath = AZStd::string::format("%s/", DefaultEbusHandlerCategory);
  549. }
  550. if (!details.m_name.empty())
  551. {
  552. categoryPath.append(details.m_name.c_str());
  553. }
  554. else if (categoryPath.contains(DefaultEbusHandlerCategory))
  555. {
  556. // Use the BehaviorEBus name to categorize within the default ebus handler category
  557. categoryPath.append(behaviorEbus.m_name.c_str());
  558. }
  559. }
  560. for (const auto& event : events)
  561. {
  562. nodePaletteModel.RegisterEBusHandlerNodeModelInformation(categoryPath.c_str(), behaviorEbus.m_name, event.m_name, ScriptCanvas::EBusBusId(behaviorEbus.m_name), event);
  563. }
  564. }
  565. }
  566. }
  567. void PopulateBehaviorContextEBusEventMethods(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  568. const AZ::BehaviorContext& behaviorContext, const AZ::BehaviorEBus& behaviorEbus)
  569. {
  570. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateBehaviorContextEBusEventMethods");
  571. if (!behaviorEbus.m_events.empty())
  572. {
  573. GraphCanvas::TranslationKey key;
  574. key << ScriptCanvasEditor::TranslationHelper::AssetContext::EBusSenderContext << behaviorEbus.m_name.c_str() << "details";
  575. GraphCanvas::TranslationRequests::Details details;
  576. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  577. AZStd::string categoryPath = details.m_category.empty() ? GetCategoryPath(behaviorEbus.m_attributes, behaviorContext) : details.m_category;
  578. // Parent
  579. AZStd::string displayName = details.m_name;
  580. // Treat the EBus name as a Category key in order to allow multiple buses to be merged into a single Category.
  581. if (!categoryPath.empty())
  582. {
  583. categoryPath.append("/");
  584. }
  585. else
  586. {
  587. categoryPath = AZStd::string::format("%s/", DefaultEbusEventCategory);
  588. }
  589. if (!details.m_name.empty())
  590. {
  591. categoryPath.append(details.m_name.c_str());
  592. }
  593. else if (categoryPath.contains(DefaultEbusEventCategory))
  594. {
  595. // Use the behavior EBus name to categorize within the ebus event category
  596. categoryPath.append(behaviorEbus.m_name.c_str());
  597. }
  598. ScriptCanvasEditor::CategoryInformation ebusCategoryInformation;
  599. ebusCategoryInformation.m_tooltip = details.m_tooltip;
  600. nodePaletteModel.RegisterCategoryInformation(categoryPath, ebusCategoryInformation);
  601. for (auto event : behaviorEbus.m_events)
  602. {
  603. if (IsDeprecated(event.second.m_attributes))
  604. {
  605. continue;
  606. }
  607. auto excludeEventAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, event.second.m_attributes));
  608. if (ShouldExcludeFromNodeList(excludeEventAttributeData, AZ::Uuid::CreateNull()))
  609. {
  610. continue; // skip this event
  611. }
  612. const bool isOverload{ false }; // overloaded events are not trivially supported
  613. nodePaletteModel.RegisterEBusSenderNodeModelInformation(categoryPath, behaviorEbus.m_name, event.first, ScriptCanvas::EBusBusId(behaviorEbus.m_name.c_str()), ScriptCanvas::EBusEventId(event.first.c_str()), ScriptCanvas::PropertyStatus::None, isOverload);
  614. }
  615. }
  616. }
  617. void PopulateBehaviorContextEBuses(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel,
  618. const AZ::BehaviorContext& behaviorContext)
  619. {
  620. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateBehaviorContextEBuses");
  621. AZStd::unordered_set<AZ::Crc32> skipBuses = GetEBusExcludeSet(behaviorContext);
  622. for (const auto& [ebusName, behaviorEbus] : behaviorContext.m_ebuses)
  623. {
  624. if (behaviorEbus == nullptr)
  625. {
  626. continue;
  627. }
  628. auto skipBusIterator = skipBuses.find(AZ::Crc32(ebusName));
  629. if (skipBusIterator != skipBuses.end())
  630. {
  631. continue;
  632. }
  633. // Skip buses mapped by their deprecated name (usually duplicates)
  634. if (ebusName == behaviorEbus->m_deprecatedName)
  635. {
  636. continue;
  637. }
  638. // Only bind Behavior Buses marked with the Scope type of Launcher
  639. if (!AZ::Internal::IsInScope(behaviorEbus->m_attributes, AZ::Script::Attributes::ScopeFlags::Launcher))
  640. {
  641. continue; // skip this bus
  642. }
  643. if (IsDeprecated(behaviorEbus->m_attributes))
  644. {
  645. continue;
  646. }
  647. auto excludeEbusAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<AZ::Script::Attributes::ExcludeFlags>*>(
  648. AZ::FindAttribute(AZ::Script::Attributes::ExcludeFrom, behaviorEbus->m_attributes));
  649. if (ShouldExcludeFromNodeList(excludeEbusAttributeData, AZ::Uuid::CreateNull()))
  650. {
  651. continue;
  652. }
  653. if (auto runtimeEbusAttributePtr = AZ::FindAttribute(AZ::RuntimeEBusAttribute, behaviorEbus->m_attributes))
  654. {
  655. bool isRuntimeEbus = false;
  656. AZ::AttributeReader(nullptr, runtimeEbusAttributePtr).Read<bool>(isRuntimeEbus);
  657. if (isRuntimeEbus)
  658. {
  659. continue;
  660. }
  661. }
  662. // EBus Handler
  663. PopulateBehaviorContextEBusHandler(nodePaletteModel, behaviorContext, *behaviorEbus);
  664. // EBus Sender
  665. PopulateBehaviorContextEBusEventMethods(nodePaletteModel, behaviorContext, *behaviorEbus);
  666. }
  667. }
  668. // Helper function for populating the node palette model.
  669. // Pulled out just to make the tabbing a bit nicer, since it's a huge method.
  670. void PopulateNodePaletteModel(ScriptCanvasEditor::NodePaletteModel& nodePaletteModel)
  671. {
  672. AZ_PROFILE_SCOPE(NodePaletteModel, "PopulateNodePaletteModel");
  673. AZ::SerializeContext* serializeContext = nullptr;
  674. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  675. AZ::BehaviorContext* behaviorContext = nullptr;
  676. AZ::ComponentApplicationBus::BroadcastResult(behaviorContext, &AZ::ComponentApplicationRequests::GetBehaviorContext);
  677. AZ_Assert(serializeContext, "Could not find SerializeContext. Aborting Palette Creation.");
  678. AZ_Assert(behaviorContext, "Could not find BehaviorContext. Aborting Palette Creation.");
  679. if (serializeContext == nullptr || behaviorContext == nullptr)
  680. {
  681. return;
  682. }
  683. // Populates the NodePalette in ScriptCanvas NodeRegistry
  684. PopulateScriptCanvasDerivedNodes(nodePaletteModel, *serializeContext);
  685. // Deprecated, populates the NodePalette in deprecated ScriptCanvas NodeRegistry
  686. PopulateScriptCanvasDerivedNodesDeprecated(nodePaletteModel, *serializeContext);
  687. // Populates the VariablePalette with type registered with the ScriptCanvas DataRegistry
  688. PopulateVariablePalette();
  689. // Populates the NodePalette with Behavior Class method nodes
  690. PopulateBehaviorContextClassMethods(nodePaletteModel, *behaviorContext);
  691. // Populates the NodePalette with BehaviorContext methods overloaded on the same name
  692. PopulateBehaviorContextOverloadedMethods(nodePaletteModel, *behaviorContext);
  693. // Populates the NodePalette with EBus Event method nodes and EBus Event handler nodes
  694. PopulateBehaviorContextEBuses(nodePaletteModel, *behaviorContext);
  695. // Populates the NodePalette with Methods reflected directly on the BehaviorContext
  696. PopulateBehaviorContextGlobalMethods(nodePaletteModel, *behaviorContext);
  697. // Populates the NodePalette with Properties reflected directly on the BehaviorContext
  698. PopulateBehaviorContextGlobalProperties(nodePaletteModel, *behaviorContext);
  699. }
  700. }
  701. namespace ScriptCanvasEditor
  702. {
  703. ////////////////////////////////
  704. // NodePaletteModelInformation
  705. ////////////////////////////////
  706. void NodePaletteModelInformation::PopulateTreeItem(GraphCanvas::NodePaletteTreeItem& treeItem) const
  707. {
  708. if (!m_toolTip.empty())
  709. {
  710. treeItem.SetToolTip(m_toolTip.c_str());
  711. }
  712. if (!m_styleOverride.empty())
  713. {
  714. treeItem.SetStyleOverride(m_styleOverride.c_str());
  715. }
  716. if (!m_titlePaletteOverride.empty())
  717. {
  718. const bool forceSet = true;
  719. treeItem.SetTitlePalette(m_titlePaletteOverride.c_str(), forceSet);
  720. }
  721. }
  722. /////////////////////
  723. // NodePaletteModel
  724. /////////////////////
  725. NodePaletteModel::NodePaletteModel()
  726. : m_paletteId(AZ::Entity::MakeId())
  727. {
  728. UpgradeNotificationsBus::Handler::BusConnect();
  729. }
  730. NodePaletteModel::~NodePaletteModel()
  731. {
  732. UpgradeNotificationsBus::Handler::BusDisconnect();
  733. DisconnectLambdas();
  734. ClearRegistry();
  735. }
  736. NodePaletteId NodePaletteModel::GetNotificationId() const
  737. {
  738. return m_paletteId;
  739. }
  740. void NodePaletteModel::AssignAssetModel(AzToolsFramework::AssetBrowser::AssetBrowserFilterModel* assetModel)
  741. {
  742. m_assetModel = assetModel;
  743. if (m_assetModel)
  744. {
  745. TraverseTree();
  746. ConnectLambdas();
  747. }
  748. }
  749. void NodePaletteModel::ConnectLambdas()
  750. {
  751. {
  752. auto connection = QObject::connect(m_assetModel, &QAbstractItemModel::rowsInserted, [this](const QModelIndex& parentIndex, int first, int last) { this->OnRowsInserted(parentIndex, first, last); });
  753. m_lambdaConnections.emplace_back(connection);
  754. }
  755. {
  756. auto connection = QObject::connect(m_assetModel, &QAbstractItemModel::rowsAboutToBeRemoved, [this](const QModelIndex& parentIndex, int first, int last) { this->OnRowsAboutToBeRemoved(parentIndex, first, last); });
  757. m_lambdaConnections.emplace_back(connection);
  758. }
  759. }
  760. void NodePaletteModel::DisconnectLambdas()
  761. {
  762. for (auto connection : m_lambdaConnections)
  763. {
  764. QObject::disconnect(connection);
  765. }
  766. }
  767. void NodePaletteModel::RepopulateModel()
  768. {
  769. AZ_PROFILE_FUNCTION(ScriptCanvas);
  770. ClearRegistry();
  771. PopulateNodePaletteModel((*this));
  772. if (m_assetModel)
  773. {
  774. TraverseTree();
  775. }
  776. NodePaletteModelNotificationBus::Event(m_paletteId, &NodePaletteModelNotifications::OnAssetModelRepopulated);
  777. }
  778. void NodePaletteModel::RegisterCustomNode(const AZ::SerializeContext::ClassData* classData, const AZStd::string& categoryPath)
  779. {
  780. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterCustomNode");
  781. ScriptCanvas::NodeTypeIdentifier nodeIdentifier = ScriptCanvas::NodeUtils::ConstructCustomNodeIdentifier(classData->m_typeId);
  782. auto mapIter = m_registeredNodes.find(nodeIdentifier);
  783. if (mapIter == m_registeredNodes.end())
  784. {
  785. CustomNodeModelInformation* customNodeInformation = aznew CustomNodeModelInformation();
  786. customNodeInformation->m_nodeIdentifier = nodeIdentifier;
  787. customNodeInformation->m_typeId = classData->m_typeId;
  788. customNodeInformation->m_displayName = classData->m_name;
  789. customNodeInformation->m_categoryPath = categoryPath;
  790. bool isDeprecated(false);
  791. if (classData && classData->m_editData && classData->m_editData->m_name)
  792. {
  793. GraphCanvas::TranslationKey key;
  794. key << ScriptCanvasEditor::TranslationHelper::AssetContext::CustomNodeContext << classData->m_typeId.ToString<AZStd::string>().c_str() << "details";
  795. GraphCanvas::TranslationRequests::Details details;
  796. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  797. if (details.m_name.empty())
  798. {
  799. details.m_name = classData->m_editData->m_name;
  800. details.m_tooltip = classData->m_editData->m_description;
  801. }
  802. customNodeInformation->m_displayName = details.m_name;
  803. customNodeInformation->m_toolTip = details.m_tooltip;
  804. if (customNodeInformation->m_displayName.empty())
  805. {
  806. customNodeInformation->m_displayName = classData->m_editData->m_name;
  807. }
  808. auto editorDataElement = classData->m_editData->FindElementData(AZ::Edit::ClassElements::EditorData);
  809. if (editorDataElement)
  810. {
  811. if (auto categoryStyleAttribute = editorDataElement->FindAttribute(AZ::Edit::Attributes::CategoryStyle))
  812. {
  813. if (auto categoryAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<const char*>*>(categoryStyleAttribute))
  814. {
  815. if (categoryAttributeData->Get(nullptr))
  816. {
  817. customNodeInformation->m_styleOverride = categoryAttributeData->Get(nullptr);
  818. }
  819. }
  820. }
  821. if (auto categoryNameAttribute = editorDataElement->FindAttribute(AZ::Edit::Attributes::Category))
  822. {
  823. if(auto categoryNameAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<const char*>*>(categoryNameAttribute))
  824. {
  825. if (categoryNameAttributeData->Get(nullptr))
  826. {
  827. customNodeInformation->m_categoryPath = categoryNameAttributeData->Get(nullptr);
  828. }
  829. }
  830. }
  831. if (auto titlePaletteAttribute = editorDataElement->FindAttribute(ScriptCanvas::Attributes::Node::TitlePaletteOverride))
  832. {
  833. if (auto titlePaletteAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<const char*>*>(titlePaletteAttribute))
  834. {
  835. if (titlePaletteAttributeData->Get(nullptr))
  836. {
  837. customNodeInformation->m_titlePaletteOverride = titlePaletteAttributeData->Get(nullptr);
  838. }
  839. }
  840. }
  841. if (auto deprecatedAttribute = editorDataElement->FindAttribute(AZ::Script::Attributes::Deprecated))
  842. {
  843. if (auto deprecatedAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<bool>*>(deprecatedAttribute))
  844. {
  845. isDeprecated = deprecatedAttributeData->Get(nullptr);
  846. }
  847. }
  848. if (customNodeInformation->m_toolTip.empty() && classData->m_editData->m_description)
  849. {
  850. customNodeInformation->m_toolTip = classData->m_editData->m_description;
  851. }
  852. }
  853. if (!details.m_category.empty())
  854. {
  855. customNodeInformation->m_categoryPath = details.m_category;
  856. }
  857. }
  858. if (!isDeprecated)
  859. {
  860. m_registeredNodes.emplace(AZStd::make_pair(nodeIdentifier, customNodeInformation));
  861. }
  862. else
  863. {
  864. delete customNodeInformation;
  865. }
  866. }
  867. }
  868. void NodePaletteModel::RegisterClassNode
  869. ( const AZStd::string& categoryPath
  870. , const AZStd::string& methodClass
  871. , const AZStd::string& methodName
  872. , const AZ::BehaviorMethod*
  873. , const AZ::BehaviorContext*
  874. , ScriptCanvas::PropertyStatus propertyStatus
  875. , bool isOverload)
  876. {
  877. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterClassNode");
  878. ScriptCanvas::NodeTypeIdentifier nodeIdentifier = isOverload ? ScriptCanvas::NodeUtils::ConstructMethodOverloadedNodeIdentifier(methodName) : ScriptCanvas::NodeUtils::ConstructMethodNodeIdentifier(methodClass, methodName, propertyStatus);
  879. auto registerIter = m_registeredNodes.find(nodeIdentifier);
  880. if (registerIter == m_registeredNodes.end())
  881. {
  882. MethodNodeModelInformation* methodModelInformation = aznew MethodNodeModelInformation();
  883. methodModelInformation->m_isOverload = isOverload;
  884. methodModelInformation->m_nodeIdentifier = nodeIdentifier;
  885. methodModelInformation->m_classMethod = methodClass;
  886. methodModelInformation->m_methodName = methodName;
  887. methodModelInformation->m_propertyStatus = propertyStatus;
  888. methodModelInformation->m_titlePaletteOverride = "MethodNodeTitlePalette";
  889. GraphCanvas::TranslationKey catkey;
  890. catkey << ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorClassContext << methodClass.c_str() << "details";
  891. GraphCanvas::TranslationRequests::Details catdetails;
  892. GraphCanvas::TranslationRequestBus::BroadcastResult(catdetails, &GraphCanvas::TranslationRequests::GetDetails, catkey, catdetails);
  893. GraphCanvas::TranslationKey key;
  894. AZStd::string context;
  895. AZStd::string updatedMethodName;
  896. if (propertyStatus != ScriptCanvas::PropertyStatus::None)
  897. {
  898. updatedMethodName = (propertyStatus == ScriptCanvas::PropertyStatus::Getter) ? "Get" : "Set";
  899. context = (propertyStatus == ScriptCanvas::PropertyStatus::Getter) ? "Getter" : "Setter";
  900. }
  901. updatedMethodName += methodName;
  902. key << ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorClassContext << methodClass << "methods" << updatedMethodName << context << "details";
  903. GraphCanvas::TranslationRequests::Details details;
  904. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  905. methodModelInformation->m_displayName = details.m_name.empty() ? updatedMethodName : details.m_name;
  906. methodModelInformation->m_toolTip = details.m_tooltip;
  907. methodModelInformation->m_categoryPath = categoryPath;
  908. if (methodModelInformation->m_categoryPath.empty())
  909. {
  910. methodModelInformation->m_categoryPath = DefaultClassMethodCategory;
  911. }
  912. m_registeredNodes.emplace(AZStd::make_pair(nodeIdentifier, methodModelInformation));
  913. }
  914. }
  915. void NodePaletteModel::RegisterGlobalConstant(const AZ::BehaviorContext&, const AZ::BehaviorProperty* behaviorProperty, const AZ::BehaviorMethod& behaviorMethod)
  916. {
  917. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterGlobalConstant");
  918. // Construct Node Identifier using the BehaviorMethod name and the ScriptCanvas Method typeid
  919. ScriptCanvas::NodeTypeIdentifier nodeIdentifier =
  920. ScriptCanvas::NodeUtils::ConstructGlobalMethodNodeIdentifier(behaviorMethod.m_name);
  921. // Register the methodModelInformation if not already registered
  922. if (auto registerIter = m_registeredNodes.find(nodeIdentifier); registerIter == m_registeredNodes.end())
  923. {
  924. auto methodModelInformation = AZStd::make_unique<GlobalMethodNodeModelInformation>();
  925. methodModelInformation->m_nodeIdentifier = nodeIdentifier;
  926. methodModelInformation->m_methodName = behaviorMethod.m_name;
  927. methodModelInformation->m_isProperty = true;
  928. methodModelInformation->m_titlePaletteOverride = "MethodNodeTitlePalette";
  929. AZStd::string name = behaviorProperty->m_name;
  930. AZ::StringFunc::Replace(name, "::Getter", "");
  931. AZ::StringFunc::Replace(name, "::Setter", "");
  932. GraphCanvas::TranslationKey key;
  933. key << ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorGlobalPropertyContext << name << "details";
  934. GraphCanvas::TranslationRequests::Details details;
  935. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  936. methodModelInformation->m_displayName = details.m_name;
  937. methodModelInformation->m_toolTip = details.m_tooltip;
  938. methodModelInformation->m_categoryPath = details.m_category;
  939. if (methodModelInformation->m_categoryPath.empty())
  940. {
  941. methodModelInformation->m_categoryPath = DefaultGlobalConstantCategory;
  942. }
  943. m_registeredNodes.emplace(nodeIdentifier, methodModelInformation.release());
  944. }
  945. }
  946. void NodePaletteModel::RegisterGlobalMethodNode(const AZ::BehaviorContext& behaviorContext, const AZ::BehaviorMethod& behaviorMethod)
  947. {
  948. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterGlobalMethodNode");
  949. // Construct Node Identifier using the BehaviorMethod name and the ScriptCanvas Method typeid
  950. ScriptCanvas::NodeTypeIdentifier nodeIdentifier =
  951. ScriptCanvas::NodeUtils::ConstructGlobalMethodNodeIdentifier(behaviorMethod.m_name);
  952. // Register the methodModelInformation if not already registered
  953. if (auto registerIter = m_registeredNodes.find(nodeIdentifier); registerIter == m_registeredNodes.end())
  954. {
  955. auto methodModelInformation = AZStd::make_unique<GlobalMethodNodeModelInformation>();
  956. methodModelInformation->m_methodName = behaviorMethod.m_name;
  957. methodModelInformation->m_nodeIdentifier = nodeIdentifier;
  958. methodModelInformation->m_isProperty = false;
  959. methodModelInformation->m_titlePaletteOverride = "MethodNodeTitlePalette";
  960. GraphCanvas::TranslationKey key;
  961. key << ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorGlobalMethodContext << behaviorMethod.m_name.c_str() << "details";
  962. GraphCanvas::TranslationRequests::Details details;
  963. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  964. methodModelInformation->m_displayName = details.m_name.empty() ? behaviorMethod.m_name : details.m_name;
  965. methodModelInformation->m_toolTip = details.m_tooltip.empty() ? "" : details.m_tooltip;
  966. if (details.m_category.empty())
  967. {
  968. auto categoryPath = GetCategoryPath(behaviorMethod.m_attributes, behaviorContext);
  969. methodModelInformation->m_categoryPath = categoryPath.empty() ? DefaultGlobalMethodCategory : categoryPath;
  970. }
  971. else
  972. {
  973. methodModelInformation->m_categoryPath = details.m_category;
  974. }
  975. m_registeredNodes.emplace(nodeIdentifier, methodModelInformation.release());
  976. }
  977. }
  978. void NodePaletteModel::RegisterEBusHandlerNodeModelInformation(AZStd::string_view categoryPath, AZStd::string_view busName, AZStd::string_view eventName, const ScriptCanvas::EBusBusId& busId, const AZ::BehaviorEBusHandler::BusForwarderEvent& forwardEvent)
  979. {
  980. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterEBusHandlerNodeModelInformation");
  981. ScriptCanvas::NodeTypeIdentifier nodeIdentifier = ScriptCanvas::NodeUtils::ConstructEBusEventReceiverIdentifier(busId, forwardEvent.m_eventId);
  982. auto nodeIter = m_registeredNodes.find(nodeIdentifier);
  983. if (nodeIter == m_registeredNodes.end())
  984. {
  985. EBusHandlerNodeModelInformation* handlerInformation = aznew EBusHandlerNodeModelInformation();
  986. handlerInformation->m_titlePaletteOverride = "HandlerNodeTitlePalette";
  987. handlerInformation->m_categoryPath = categoryPath;
  988. handlerInformation->m_nodeIdentifier = nodeIdentifier;
  989. handlerInformation->m_busName = busName;
  990. handlerInformation->m_eventName = eventName;
  991. handlerInformation->m_busId = busId;
  992. handlerInformation->m_eventId = forwardEvent.m_eventId;
  993. GraphCanvas::TranslationKey key;
  994. key << ScriptCanvasEditor::TranslationHelper::AssetContext::EBusHandlerContext << busName << "methods" << eventName << "details";
  995. GraphCanvas::TranslationRequests::Details details;
  996. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  997. handlerInformation->m_displayName = details.m_name.empty() ? eventName : details.m_name.c_str();
  998. handlerInformation->m_toolTip = details.m_tooltip.empty() ? "" : details.m_tooltip;
  999. m_registeredNodes.emplace(AZStd::make_pair(nodeIdentifier, handlerInformation));
  1000. }
  1001. }
  1002. void NodePaletteModel::RegisterEBusSenderNodeModelInformation
  1003. ( AZStd::string_view categoryPath
  1004. , AZStd::string_view busName
  1005. , AZStd::string_view eventName
  1006. , const ScriptCanvas::EBusBusId& busId
  1007. , const ScriptCanvas::EBusEventId& eventId
  1008. , ScriptCanvas::PropertyStatus propertyStatus
  1009. , bool isOverload)
  1010. {
  1011. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterEBusSenderNodeModelInformation");
  1012. ScriptCanvas::NodeTypeIdentifier nodeIdentifier = isOverload ? ScriptCanvas::NodeUtils::ConstructEBusEventSenderOverloadedIdentifier(busId, eventId) : ScriptCanvas::NodeUtils::ConstructEBusEventSenderIdentifier(busId, eventId);
  1013. auto nodeIter = m_registeredNodes.find(nodeIdentifier);
  1014. if (nodeIter == m_registeredNodes.end())
  1015. {
  1016. EBusSenderNodeModelInformation* senderInformation = aznew EBusSenderNodeModelInformation();
  1017. senderInformation->m_isOverload = isOverload;
  1018. senderInformation->m_titlePaletteOverride = "MethodNodeTitlePalette";
  1019. senderInformation->m_categoryPath = categoryPath;
  1020. senderInformation->m_nodeIdentifier = nodeIdentifier;
  1021. senderInformation->m_propertyStatus = propertyStatus;
  1022. senderInformation->m_busName = busName;
  1023. senderInformation->m_eventName = eventName;
  1024. senderInformation->m_busId = busId;
  1025. senderInformation->m_eventId = eventId;
  1026. GraphCanvas::TranslationKey key;
  1027. key << ScriptCanvasEditor::TranslationHelper::AssetContext::EBusSenderContext << busName << "methods" << eventName << "details";
  1028. GraphCanvas::TranslationRequests::Details details;
  1029. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  1030. senderInformation->m_displayName = details.m_name.empty() ? eventName : details.m_name.c_str();
  1031. senderInformation->m_toolTip = details.m_tooltip.empty() ? "" : details.m_tooltip;
  1032. m_registeredNodes.emplace(AZStd::make_pair(nodeIdentifier, senderInformation));
  1033. }
  1034. }
  1035. AZStd::vector<ScriptCanvas::NodeTypeIdentifier> NodePaletteModel::RegisterScriptEvent(ScriptEvents::ScriptEventsAsset* scriptEventAsset)
  1036. {
  1037. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterScriptEvent");
  1038. const ScriptEvents::ScriptEvent& scriptEvent = scriptEventAsset->m_definition;
  1039. ScriptCanvas::EBusBusId busId = scriptEventAsset->GetBusId();
  1040. AZStd::string category = scriptEvent.GetCategory();
  1041. auto methods = scriptEvent.GetMethods();
  1042. AZStd::vector<ScriptCanvas::NodeTypeIdentifier> identifiers;
  1043. // Each event has a handler and a receiver
  1044. identifiers.reserve(methods.size() * 2);
  1045. for (const auto& method : methods)
  1046. {
  1047. ScriptCanvas::EBusEventId eventId = method.GetEventId();
  1048. ScriptCanvas::NodeTypeIdentifier senderIdentifier = ScriptCanvas::NodeUtils::ConstructSendScriptEventIdentifier(busId, eventId);
  1049. ScriptCanvas::NodeTypeIdentifier receiverIdentifier = ScriptCanvas::NodeUtils::ConstructScriptEventReceiverIdentifier(busId, eventId);
  1050. ScriptEventHandlerNodeModelInformation* handlerInformation = aznew ScriptEventHandlerNodeModelInformation();
  1051. handlerInformation->m_titlePaletteOverride = "HandlerNodeTitlePalette";
  1052. handlerInformation->m_busName = scriptEvent.GetName();
  1053. handlerInformation->m_eventName = method.GetName();
  1054. handlerInformation->m_displayName = method.GetName();
  1055. handlerInformation->m_categoryPath = scriptEvent.GetCategory();
  1056. handlerInformation->m_busId = busId;
  1057. handlerInformation->m_eventId = eventId;
  1058. handlerInformation->m_nodeIdentifier = receiverIdentifier;
  1059. m_registeredNodes.emplace(AZStd::make_pair(receiverIdentifier, handlerInformation));
  1060. ScriptEventSenderNodeModelInformation* senderInformation = aznew ScriptEventSenderNodeModelInformation();
  1061. senderInformation->m_titlePaletteOverride = "MethodNodeTitlePalette";
  1062. senderInformation->m_busName = scriptEvent.GetName();
  1063. senderInformation->m_eventName = method.GetName();
  1064. senderInformation->m_displayName = method.GetName();
  1065. senderInformation->m_categoryPath = scriptEvent.GetCategory();
  1066. senderInformation->m_busId = busId;
  1067. senderInformation->m_eventId = eventId;
  1068. senderInformation->m_nodeIdentifier = senderIdentifier;
  1069. m_registeredNodes.emplace(AZStd::make_pair(senderIdentifier, senderInformation));
  1070. m_assetMapping.insert(AZStd::make_pair(scriptEventAsset->GetId(), senderIdentifier));
  1071. m_assetMapping.insert(AZStd::make_pair(scriptEventAsset->GetId(), receiverIdentifier));
  1072. identifiers.emplace_back(senderIdentifier);
  1073. identifiers.emplace_back(receiverIdentifier);
  1074. }
  1075. return identifiers;
  1076. }
  1077. void NodePaletteModel::RegisterDefaultCateogryInformation()
  1078. {
  1079. {
  1080. CategoryInformation categoryInformation;
  1081. categoryInformation.m_paletteOverride = "ComparisonNodeTitlePalette";
  1082. m_categoryInformation["Math/Comparisions"] = categoryInformation;
  1083. }
  1084. {
  1085. CategoryInformation categoryInformation;
  1086. categoryInformation.m_paletteOverride = "CoreNodeTitlePalette";
  1087. m_categoryInformation["Core"] = categoryInformation;
  1088. }
  1089. {
  1090. CategoryInformation categoryInformation;
  1091. categoryInformation.m_paletteOverride = "LogicNodeTitlePalette";
  1092. m_categoryInformation["Logic"] = categoryInformation;
  1093. }
  1094. {
  1095. CategoryInformation categoryInformation;
  1096. categoryInformation.m_paletteOverride = "MathNodeTitlePalette";
  1097. m_categoryInformation["Math"] = categoryInformation;
  1098. }
  1099. {
  1100. CategoryInformation categoryInformation;
  1101. categoryInformation.m_paletteOverride = "OperatorsNodeTitlePalette";
  1102. m_categoryInformation["Operators"] = categoryInformation;
  1103. }
  1104. {
  1105. CategoryInformation categoryInformation;
  1106. categoryInformation.m_paletteOverride = "StringNodeTitlePalette";
  1107. m_categoryInformation["String"] = categoryInformation;
  1108. }
  1109. {
  1110. CategoryInformation categoryInformation;
  1111. categoryInformation.m_paletteOverride = "TimeNodeTitlePalette";
  1112. m_categoryInformation["Timing"] = categoryInformation;
  1113. }
  1114. {
  1115. CategoryInformation categoryInformation;
  1116. categoryInformation.m_paletteOverride = "TestingNodeTitlePalette";
  1117. m_categoryInformation["Utilities/Unit Testing"] = categoryInformation;
  1118. }
  1119. }
  1120. void NodePaletteModel::RegisterCategoryInformation(const AZStd::string& category, const CategoryInformation& categoryInformation)
  1121. {
  1122. auto categoryIter = m_categoryInformation.find(category);
  1123. if (categoryIter == m_categoryInformation.end())
  1124. {
  1125. m_categoryInformation[category] = categoryInformation;
  1126. }
  1127. }
  1128. const CategoryInformation* NodePaletteModel::FindCategoryInformation(const AZStd::string& categoryStyle) const
  1129. {
  1130. auto categoryIter = m_categoryInformation.find(categoryStyle);
  1131. if (categoryIter != m_categoryInformation.end())
  1132. {
  1133. return &(categoryIter->second);
  1134. }
  1135. return nullptr;
  1136. }
  1137. const CategoryInformation* NodePaletteModel::FindBestCategoryInformation(AZStd::string_view categoryView) const
  1138. {
  1139. const CategoryInformation* bestCategoryFit = nullptr;
  1140. auto categoryIter = m_categoryInformation.find(categoryView);
  1141. size_t offset = AZStd::string_view::npos;
  1142. AZStd::string_view categoryTrail = categoryView;
  1143. while (categoryIter == m_categoryInformation.end() && !categoryTrail.empty())
  1144. {
  1145. size_t seperator = categoryTrail.find_last_of('/', offset);
  1146. if (seperator == AZStd::string_view::npos)
  1147. {
  1148. categoryTrail = {};
  1149. }
  1150. else
  1151. {
  1152. categoryTrail = categoryTrail.substr(0, seperator - 1);
  1153. categoryIter = m_categoryInformation.find(categoryTrail);
  1154. }
  1155. }
  1156. if (categoryIter != m_categoryInformation.end())
  1157. {
  1158. bestCategoryFit = &(categoryIter->second);
  1159. }
  1160. return bestCategoryFit;
  1161. }
  1162. const NodePaletteModelInformation* NodePaletteModel::FindNodePaletteInformation(const ScriptCanvas::NodeTypeIdentifier& nodeType) const
  1163. {
  1164. auto registryIter = m_registeredNodes.find(nodeType);
  1165. if (registryIter != m_registeredNodes.end())
  1166. {
  1167. return registryIter->second;
  1168. }
  1169. return nullptr;
  1170. }
  1171. const NodePaletteModel::NodePaletteRegistry& NodePaletteModel::GetNodeRegistry() const
  1172. {
  1173. return m_registeredNodes;
  1174. }
  1175. GraphCanvas::GraphCanvasTreeItem* NodePaletteModel::CreateCategoryNode(AZStd::string_view categoryPath, AZStd::string_view categoryName, GraphCanvas::GraphCanvasTreeItem* parentItem) const
  1176. {
  1177. GraphCanvas::NodePaletteTreeItem* treeItem = parentItem->CreateChildNode<GraphCanvas::NodePaletteTreeItem>(categoryName, ScriptCanvasEditor::AssetEditorId);
  1178. const CategoryInformation* categoryInformation = FindCategoryInformation(categoryPath);
  1179. if (categoryInformation)
  1180. {
  1181. if (!categoryInformation->m_tooltip.empty())
  1182. {
  1183. treeItem->SetToolTip(categoryInformation->m_tooltip.c_str());
  1184. }
  1185. if (!categoryInformation->m_paletteOverride.empty())
  1186. {
  1187. treeItem->SetTitlePalette(categoryInformation->m_paletteOverride.c_str());
  1188. }
  1189. if (!categoryInformation->m_styleOverride.empty())
  1190. {
  1191. treeItem->SetStyleOverride(categoryInformation->m_styleOverride.c_str());
  1192. }
  1193. }
  1194. return treeItem;
  1195. }
  1196. void NodePaletteModel::OnRowsInserted(const QModelIndex& parentIndex, int first, int last)
  1197. {
  1198. for (int i = first; i <= last; ++i)
  1199. {
  1200. QModelIndex modelIndex = m_assetModel->index(i, 0, parentIndex);
  1201. QModelIndex sourceIndex = m_assetModel->mapToSource(modelIndex);
  1202. AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry = reinterpret_cast<AzToolsFramework::AssetBrowser::AssetBrowserEntry*>(sourceIndex.internalPointer());
  1203. auto nodeTypeIdentifiers = ProcessAsset(entry);
  1204. for (auto nodeTypeIdentifier : nodeTypeIdentifiers)
  1205. {
  1206. auto nodeIter = m_registeredNodes.find(nodeTypeIdentifier);
  1207. if (nodeIter != m_registeredNodes.end())
  1208. {
  1209. NodePaletteModelNotificationBus::Event(m_paletteId, &NodePaletteModelNotifications::OnAssetNodeAdded, nodeIter->second);
  1210. }
  1211. }
  1212. }
  1213. }
  1214. void NodePaletteModel::OnRowsAboutToBeRemoved(const QModelIndex& parentIndex, int first, int last)
  1215. {
  1216. for (int i = first; i <= last; ++i)
  1217. {
  1218. QModelIndex modelIndex = m_assetModel->index(first, 0, parentIndex);
  1219. QModelIndex sourceIndex = m_assetModel->mapToSource(modelIndex);
  1220. const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry = reinterpret_cast<AzToolsFramework::AssetBrowser::AssetBrowserEntry*>(sourceIndex.internalPointer());
  1221. if (entry->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Product)
  1222. {
  1223. const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry* productEntry = azrtti_cast<const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry*>(entry);
  1224. if (productEntry)
  1225. {
  1226. RemoveAsset(productEntry->GetAssetId());
  1227. }
  1228. }
  1229. }
  1230. }
  1231. void NodePaletteModel::TraverseTree(QModelIndex index)
  1232. {
  1233. QModelIndex sourceIndex = m_assetModel->mapToSource(index);
  1234. AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry = reinterpret_cast<AzToolsFramework::AssetBrowser::AssetBrowserEntry*>(sourceIndex.internalPointer());
  1235. ProcessAsset(entry);
  1236. int rowCount = m_assetModel->rowCount(index);
  1237. for (int i = 0; i < rowCount; ++i)
  1238. {
  1239. QModelIndex nextIndex = m_assetModel->index(i, 0, index);
  1240. TraverseTree(nextIndex);
  1241. }
  1242. }
  1243. AZStd::vector<ScriptCanvas::NodeTypeIdentifier> NodePaletteModel::ProcessAsset(AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry)
  1244. {
  1245. AZ_PROFILE_SCOPE(NodePaletteModel, "NodePaletteModel::RegisterScriptEvent");
  1246. AZStd::lock_guard<AZStd::recursive_mutex> myLocker(m_mutex);
  1247. if (entry)
  1248. {
  1249. if (entry->GetEntryType() == AzToolsFramework::AssetBrowser::AssetBrowserEntry::AssetEntryType::Product)
  1250. {
  1251. const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry* productEntry = static_cast<const AzToolsFramework::AssetBrowser::ProductAssetBrowserEntry*>(entry);
  1252. if (productEntry->GetAssetType() == azrtti_typeid<ScriptEvents::ScriptEventsAsset>())
  1253. {
  1254. const AZ::Data::AssetId& assetId = productEntry->GetAssetId();
  1255. auto busAsset = AZ::Data::AssetManager::Instance().GetAsset(assetId, azrtti_typeid<ScriptEvents::ScriptEventsAsset>(), AZ::Data::AssetLoadBehavior::PreLoad);
  1256. busAsset.BlockUntilLoadComplete();
  1257. if (busAsset.IsReady())
  1258. {
  1259. ScriptEvents::ScriptEventsAsset* data = busAsset.GetAs<ScriptEvents::ScriptEventsAsset>();
  1260. return RegisterScriptEvent(data);
  1261. }
  1262. else
  1263. {
  1264. AZ_TracePrintf("NodePaletteModel", "Could not refresh node palette properly, the asset failed to load correctly.");
  1265. }
  1266. }
  1267. }
  1268. }
  1269. return AZStd::vector<ScriptCanvas::NodeTypeIdentifier>();
  1270. }
  1271. void NodePaletteModel::RemoveAsset(const AZ::Data::AssetId& assetId)
  1272. {
  1273. auto mapRange = m_assetMapping.equal_range(assetId);
  1274. for (auto rangeIter = mapRange.first; rangeIter != mapRange.second; ++rangeIter)
  1275. {
  1276. auto nodeIter = m_registeredNodes.find(rangeIter->second);
  1277. if (nodeIter != m_registeredNodes.end())
  1278. {
  1279. NodePaletteModelNotificationBus::Event(m_paletteId, &NodePaletteModelNotifications::OnAssetNodeRemoved, nodeIter->second);
  1280. delete nodeIter->second;
  1281. m_registeredNodes.erase(nodeIter);
  1282. }
  1283. }
  1284. }
  1285. void NodePaletteModel::ClearRegistry()
  1286. {
  1287. for (auto& mapPair : m_registeredNodes)
  1288. {
  1289. delete mapPair.second;
  1290. }
  1291. m_registeredNodes.clear();
  1292. m_categoryInformation.clear();
  1293. }
  1294. }