3
0

NodePaletteModel.cpp 67 KB

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