NodeDisplayUtils.cpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  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/RTTI/BehaviorContextUtilities.h>
  9. #include <Editor/Components/IconComponent.h>
  10. #include <Editor/GraphCanvas/PropertySlotIds.h>
  11. #include <Editor/Nodes/NodeDisplayUtils.h>
  12. #include <Editor/Translation/TranslationHelper.h>
  13. #include <GraphCanvas/Components/DynamicOrderingDynamicSlotComponent.h>
  14. #include <GraphCanvas/Components/MappingComponent.h>
  15. #include <GraphCanvas/Components/NodeDescriptors/AzEventHandlerNodeDescriptorComponent.h>
  16. #include <GraphCanvas/Components/NodeDescriptors/ClassMethodNodeDescriptorComponent.h>
  17. #include <GraphCanvas/Components/NodeDescriptors/EBusHandlerEventNodeDescriptorComponent.h>
  18. #include <GraphCanvas/Components/NodeDescriptors/EBusHandlerNodeDescriptorComponent.h>
  19. #include <GraphCanvas/Components/NodeDescriptors/EBusSenderNodeDescriptorComponent.h>
  20. #include <GraphCanvas/Components/NodeDescriptors/FunctionNodeDescriptorComponent.h>
  21. #include <GraphCanvas/Components/NodeDescriptors/GetVariableNodeDescriptorComponent.h>
  22. #include <GraphCanvas/Components/NodeDescriptors/NodelingDescriptorComponent.h>
  23. #include <GraphCanvas/Components/NodeDescriptors/SetVariableNodeDescriptorComponent.h>
  24. #include <GraphCanvas/Components/NodeDescriptors/ScriptEventReceiverEventNodeDescriptorComponent.h>
  25. #include <GraphCanvas/Components/NodeDescriptors/ScriptEventReceiverNodeDescriptorComponent.h>
  26. #include <GraphCanvas/Components/NodeDescriptors/ScriptEventSenderNodeDescriptorComponent.h>
  27. #include <GraphCanvas/Components/NodeDescriptors/UserDefinedNodeDescriptorComponent.h>
  28. #include <GraphCanvas/Components/NodeDescriptors/FunctionDefinitionNodeDescriptorComponent.h>
  29. #include <GraphCanvas/Components/Slots/SlotBus.h>
  30. #include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
  31. #include <GraphCanvas/GraphCanvasBus.h>
  32. #include <GraphCanvas/Components/Slots/Extender/ExtenderSlotBus.h>
  33. #include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
  34. #include <ScriptCanvas/Core/Node.h>
  35. #include <ScriptCanvas/Libraries/Core/AzEventHandler.h>
  36. #include <ScriptCanvas/Libraries/Core/EBusEventHandler.h>
  37. #include <ScriptCanvas/Libraries/Core/FunctionDefinitionNode.h>
  38. #include <ScriptCanvas/Libraries/Core/FunctionCallNode.h>
  39. #include <ScriptCanvas/Libraries/Core/GetVariable.h>
  40. #include <ScriptCanvas/Libraries/Core/ReceiveScriptEvent.h>
  41. #include <ScriptCanvas/Libraries/Core/Method.h>
  42. #include <ScriptCanvas/Libraries/Core/SendScriptEvent.h>
  43. #include <ScriptCanvas/Libraries/Core/SetVariable.h>
  44. #include <Source/Translation/TranslationBus.h>
  45. namespace ScriptCanvasEditor::Nodes::SlotDisplayHelper
  46. {
  47. AZ::EntityId DisplayPropertySlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::VisualExtensionSlotConfiguration& propertyConfiguration);
  48. AZ::EntityId DisplayExtendableSlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::VisualExtensionSlotConfiguration& extenderConfiguration);
  49. AZ::EntityId DisplayVisualExtensionSlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::VisualExtensionSlotConfiguration& extensionConfiguration);
  50. }
  51. namespace ScriptCanvasEditor::Nodes
  52. {
  53. // Handles the creation of a node through the node configurations for most nodes.
  54. AZ::EntityId DisplayGeneralScriptCanvasNode(AZ::EntityId, const ScriptCanvas::Node* node, const NodeReplacementConfiguration& nodeConfiguration)
  55. {
  56. AZ_PROFILE_FUNCTION(ScriptCanvas);
  57. AZ::Entity* graphCanvasEntity = nullptr;
  58. if (nodeConfiguration.m_nodeType == NodeType::GeneralNode)
  59. {
  60. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(
  61. graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateGeneralNode, nodeConfiguration.m_nodeSubStyle.c_str());
  62. }
  63. else if (nodeConfiguration.m_nodeType == NodeType::WrapperNode)
  64. {
  65. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(
  66. graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateWrapperNode, nodeConfiguration.m_nodeSubStyle.c_str());
  67. }
  68. AZ_Assert(graphCanvasEntity, "Unable to create GraphCanvas Bus Node");
  69. if (graphCanvasEntity == nullptr)
  70. {
  71. return AZ::EntityId();
  72. }
  73. for (const AZ::Uuid& componentId : nodeConfiguration.m_customComponents)
  74. {
  75. graphCanvasEntity->CreateComponent(componentId);
  76. }
  77. // Apply SceneMember remapping if ScriptCanvasId is valid.
  78. if (nodeConfiguration.m_scriptCanvasId.IsValid())
  79. {
  80. graphCanvasEntity->CreateComponent<SceneMemberMappingComponent>(nodeConfiguration.m_scriptCanvasId);
  81. graphCanvasEntity->CreateComponent<SlotMappingComponent>(nodeConfiguration.m_scriptCanvasId);
  82. }
  83. graphCanvasEntity->Init();
  84. graphCanvasEntity->Activate();
  85. // Set the user data on the GraphCanvas node to be the EntityId of the ScriptCanvas node
  86. AZStd::any* graphCanvasUserData = nullptr;
  87. GraphCanvas::NodeRequestBus::EventResult(graphCanvasUserData, graphCanvasEntity->GetId(), &GraphCanvas::NodeRequests::GetUserData);
  88. if (graphCanvasUserData)
  89. {
  90. *graphCanvasUserData = node->GetEntityId();
  91. }
  92. GraphCanvas::TranslationKey key;
  93. key << ScriptCanvasEditor::TranslationHelper::AssetContext::CustomNodeContext << azrtti_typeid(node).ToString<AZStd::string>()
  94. << "details";
  95. GraphCanvas::TranslationRequests::Details details;
  96. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  97. int paramIndex = 0;
  98. int outputIndex = 0;
  99. int exeInputIndex = 0;
  100. int exeOutputIndex = 0;
  101. int dataInputIndex = 0;
  102. int dataOutputIndex = 0;
  103. // Create the GraphCanvas slots
  104. for (const auto& slot : node->GetSlots())
  105. {
  106. GraphCanvas::TranslationKey slotKey;
  107. slotKey << ScriptCanvasEditor::TranslationHelper::AssetContext::CustomNodeContext
  108. << azrtti_typeid(node).ToString<AZStd::string>() << "slots";
  109. int& index = (slot.IsData() && slot.IsInput()) ? paramIndex : outputIndex;
  110. if (slot.IsVisible())
  111. {
  112. AZStd::string slotKeyStr;
  113. if (slot.IsData())
  114. {
  115. if (slot.GetConnectionType() == ScriptCanvas::ConnectionType::Input)
  116. {
  117. slotKeyStr.append(AZStd::string::format("DataInput_%s_%d", slot.GetName().c_str(), dataInputIndex++));
  118. }
  119. else
  120. {
  121. slotKeyStr.append(AZStd::string::format("DataOutput_%s_%d", slot.GetName().c_str(), dataOutputIndex++));
  122. }
  123. }
  124. else
  125. {
  126. if (slot.GetConnectionType() == ScriptCanvas::ConnectionType::Input)
  127. {
  128. slotKeyStr.append(AZStd::string::format("Input_%s_%d", slot.GetName().c_str(), exeInputIndex++));
  129. }
  130. else
  131. {
  132. slotKeyStr.append(AZStd::string::format("Output_%s_%d", slot.GetName().c_str(), exeOutputIndex++));
  133. }
  134. }
  135. slotKey << slotKeyStr << "details";
  136. GraphCanvas::TranslationRequests::Details slotDetails;
  137. GraphCanvas::TranslationRequestBus::BroadcastResult(
  138. slotDetails, &GraphCanvas::TranslationRequests::GetDetails, slotKey, slotDetails);
  139. if (slotDetails.m_name.empty())
  140. {
  141. slotDetails.m_name = slot.GetName();
  142. }
  143. if (slotDetails.m_tooltip.empty())
  144. {
  145. slotDetails.m_tooltip = slot.GetToolTip();
  146. }
  147. AZ::EntityId graphCanvasSlotId = DisplayScriptCanvasSlot(graphCanvasEntity->GetId(), slot, index);
  148. GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetName, slotDetails.m_name);
  149. GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTooltip, slotDetails.m_tooltip);
  150. }
  151. ++index;
  152. }
  153. const auto& visualExtensions = node->GetVisualExtensions();
  154. for (const auto& extensionConfiguration : visualExtensions)
  155. {
  156. SlotDisplayHelper::DisplayVisualExtensionSlot(graphCanvasEntity->GetId(), extensionConfiguration);
  157. }
  158. if (details.m_name.empty())
  159. {
  160. details.m_name = node->GetNodeName();
  161. }
  162. graphCanvasEntity->SetName(AZStd::string::format("GC-Node(%s)", details.m_name.c_str()));
  163. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasEntity->GetId(), &GraphCanvas::NodeTitleRequests::SetTitle, details.m_name);
  164. GraphCanvas::NodeTitleRequestBus::Event(
  165. graphCanvasEntity->GetId(), &GraphCanvas::NodeTitleRequests::SetSubTitle, details.m_category);
  166. if (node->GetNodeToolTip().empty()) // Old way of setting the node tooltip
  167. {
  168. // Add to the tooltip the C++ class for reference
  169. if (!details.m_tooltip.empty())
  170. {
  171. details.m_tooltip.append("\n");
  172. }
  173. details.m_tooltip.append(AZStd::string::format("[C++] %s", node->GetNodeTypeName().c_str()));
  174. GraphCanvas::NodeRequestBus::Event(graphCanvasEntity->GetId(), &GraphCanvas::NodeRequests::SetTooltip, details.m_tooltip);
  175. }
  176. else
  177. {
  178. AZStd::string toolTip = node->GetNodeToolTip();
  179. toolTip.append(AZStd::string::format("\n[C++] %s", node->GetNodeTypeName().c_str()));
  180. GraphCanvas::NodeRequestBus::Event(graphCanvasEntity->GetId(), &GraphCanvas::NodeRequests::SetTooltip, toolTip);
  181. }
  182. if (!nodeConfiguration.m_titlePalette.empty())
  183. {
  184. GraphCanvas::NodeTitleRequestBus::Event(
  185. graphCanvasEntity->GetId(), &GraphCanvas::NodeTitleRequests::SetPaletteOverride, nodeConfiguration.m_titlePalette);
  186. }
  187. EditorNodeNotificationBus::Event(
  188. node->GetEntityId(), &EditorNodeNotifications::OnGraphCanvasNodeDisplayed, graphCanvasEntity->GetId());
  189. return graphCanvasEntity->GetId();
  190. }
  191. AZ::EntityId DisplayNode(AZ::EntityId graphCanvasGraphId, const ScriptCanvas::Node* node, StyleConfiguration styleConfiguration = StyleConfiguration())
  192. {
  193. NodeReplacementConfiguration nodeConfiguration;
  194. nodeConfiguration.PopulateComponentDescriptors<IconComponent, UserDefinedNodeDescriptorComponent>();
  195. if (node->RequiresDynamicSlotOrdering())
  196. {
  197. nodeConfiguration.PopulateComponentDescriptors<DynamicOrderingDynamicSlotComponent>();
  198. }
  199. else
  200. {
  201. nodeConfiguration.PopulateComponentDescriptors<DynamicSlotComponent>();
  202. }
  203. nodeConfiguration.m_nodeSubStyle = styleConfiguration.m_nodeSubStyle;
  204. nodeConfiguration.m_titlePalette = styleConfiguration.m_titlePalette;
  205. nodeConfiguration.m_scriptCanvasId = node->GetEntityId();
  206. AZ::SerializeContext* serializeContext = nullptr;
  207. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  208. AZ_Assert(serializeContext, "Failed to acquire application serialize context.");
  209. const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(azrtti_typeid(node));
  210. if (classData)
  211. {
  212. if (classData->m_editData)
  213. {
  214. const AZ::Edit::ElementData* elementData = classData->m_editData->FindElementData(AZ::Edit::ClassElements::EditorData);
  215. if (elementData)
  216. {
  217. if (auto nodeTypeAttribute = elementData->FindAttribute(ScriptCanvas::Attributes::Node::NodeType))
  218. {
  219. if (auto nodeTypeAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<NodeType>*>(nodeTypeAttribute))
  220. {
  221. nodeConfiguration.m_nodeType = nodeTypeAttributeData->Get(nullptr);
  222. }
  223. }
  224. }
  225. }
  226. }
  227. return DisplayGeneralScriptCanvasNode(graphCanvasGraphId, node, nodeConfiguration);
  228. }
  229. static void ConfigureGeneralScriptCanvasEntity(const ScriptCanvas::Node* node, AZ::Entity* graphCanvasEntity, const GraphCanvas::SlotGroup& slotGroup = GraphCanvas::SlotGroups::Invalid)
  230. {
  231. if (node->RequiresDynamicSlotOrdering())
  232. {
  233. graphCanvasEntity->CreateComponent<DynamicOrderingDynamicSlotComponent>(slotGroup);
  234. }
  235. else
  236. {
  237. graphCanvasEntity->CreateComponent<DynamicSlotComponent>(slotGroup);
  238. }
  239. }
  240. AZ::EntityId DisplayMethodNode(AZ::EntityId, const ScriptCanvas::Nodes::Core::Method* methodNode, bool isAccessor)
  241. {
  242. AZ::EntityId graphCanvasNodeId;
  243. AZ::Entity* graphCanvasEntity = nullptr;
  244. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateGeneralNode, ".method");
  245. AZ_Error("GraphCanvas", graphCanvasEntity, "Unable to create GraphCanvas Node");
  246. if (graphCanvasEntity)
  247. {
  248. graphCanvasNodeId = graphCanvasEntity->GetId();
  249. }
  250. // Add the icon component
  251. ConfigureGeneralScriptCanvasEntity(methodNode, graphCanvasEntity);
  252. graphCanvasEntity->CreateComponent<IconComponent>(ScriptCanvas::Nodes::Core::Method::RTTI_Type());
  253. graphCanvasEntity->CreateComponent<SlotMappingComponent>(methodNode->GetEntityId());
  254. graphCanvasEntity->CreateComponent<SceneMemberMappingComponent>(methodNode->GetEntityId());
  255. switch (methodNode->GetMethodType())
  256. {
  257. case ScriptCanvas::MethodType::Event:
  258. graphCanvasEntity->CreateComponent<EBusSenderNodeDescriptorComponent>();
  259. break;
  260. case ScriptCanvas::MethodType::Getter:
  261. case ScriptCanvas::MethodType::Setter:
  262. case ScriptCanvas::MethodType::Free:
  263. case ScriptCanvas::MethodType::Member:
  264. graphCanvasEntity->CreateComponent<ClassMethodNodeDescriptorComponent>();
  265. break;
  266. break;
  267. default:
  268. AZ_Error("ScriptCanvas", false, "Invalid method node type, node creation failed. This node needs to be deleted.");
  269. break;
  270. }
  271. graphCanvasEntity->Init();
  272. graphCanvasEntity->Activate();
  273. // Set the user data on the GraphCanvas node to be the EntityId of the ScriptCanvas node
  274. AZStd::any* graphCanvasUserData = nullptr;
  275. GraphCanvas::NodeRequestBus::EventResult(graphCanvasUserData, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetUserData);
  276. if (graphCanvasUserData)
  277. {
  278. *graphCanvasUserData = methodNode->GetEntityId();
  279. }
  280. const bool isFreeMethod = (methodNode->GetMethodType() == ScriptCanvas::MethodType::Free);
  281. const bool isEBusSender = (methodNode->GetMethodType() == ScriptCanvas::MethodType::Event);
  282. const AZStd::string& className = methodNode->GetMethodClassName();
  283. AZStd::string methodName = methodNode->GetName();
  284. GraphCanvas::TranslationKey key;
  285. if (isAccessor)
  286. {
  287. AZ::StringFunc::Replace(methodName, "::Getter", "");
  288. AZ::StringFunc::Replace(methodName, "::Setter", "");
  289. }
  290. GraphCanvas::TranslationRequests::Details details;
  291. details.m_name = methodName;
  292. AZStd::string context;
  293. if (isFreeMethod)
  294. {
  295. context = isAccessor
  296. ? ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorGlobalPropertyContext
  297. : ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorGlobalMethodContext;
  298. }
  299. else
  300. {
  301. context = isEBusSender
  302. ? ScriptCanvasEditor::TranslationHelper::AssetContext::EBusSenderContext
  303. : ScriptCanvasEditor::TranslationHelper::AssetContext::BehaviorClassContext;
  304. }
  305. key << context << className;
  306. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key + ".details", details);
  307. // Set the class' name as the subtitle fallback
  308. details.m_subtitle = details.m_name;
  309. AZStd::string methodContext;
  310. // Get the method's text data
  311. GraphCanvas::TranslationRequests::Details methodDetails;
  312. methodDetails.m_name = methodName; // fallback
  313. key << "methods";
  314. AZStd::string updatedMethodName = "";
  315. if (methodNode->GetMethodType() == ScriptCanvas::MethodType::Getter || isAccessor)
  316. {
  317. updatedMethodName = "Get";
  318. methodContext = "Getter";
  319. }
  320. else if (methodNode->GetMethodType() == ScriptCanvas::MethodType::Setter)
  321. {
  322. updatedMethodName = "Set";
  323. methodContext = "Setter";
  324. }
  325. updatedMethodName.append(methodName);
  326. key << updatedMethodName << methodContext;
  327. GraphCanvas::TranslationRequestBus::BroadcastResult(methodDetails, &GraphCanvas::TranslationRequests::GetDetails, key + ".details", methodDetails);
  328. if (methodDetails.m_subtitle.empty())
  329. {
  330. methodDetails.m_subtitle = details.m_category.empty() ? details.m_name : details.m_category;
  331. }
  332. // Add to the tooltip the C++ class for reference
  333. if (!methodDetails.m_tooltip.empty())
  334. {
  335. methodDetails.m_tooltip.append("\n");
  336. }
  337. methodDetails.m_tooltip.append(AZStd::string::format("[C++] %s", className.c_str()));
  338. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetDetails, methodDetails.m_name, methodDetails.m_subtitle);
  339. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::SetTooltip, methodDetails.m_tooltip);
  340. int paramIndex = 0;
  341. int outputIndex = 0;
  342. int slotIndex = 0;
  343. auto busId = methodNode->GetBusSlotId();
  344. for (const auto& slot : methodNode->GetSlots())
  345. {
  346. GraphCanvas::TranslationKey slotKey = key;
  347. int& inputOutputIndex = slot.IsInput() ? paramIndex : outputIndex;
  348. const bool isBusIdSlot =
  349. methodNode->HasBusID() && busId == slot.GetId() && slot.GetDescriptor() == ScriptCanvas::SlotDescriptors::DataIn();
  350. if (slot.IsVisible())
  351. {
  352. AZ::EntityId graphCanvasSlotId = DisplayScriptCanvasSlot(graphCanvasNodeId, slot, slotIndex);
  353. details.m_name = slot.GetName();
  354. details.m_tooltip = slot.GetToolTip();
  355. if (isBusIdSlot)
  356. {
  357. key = ::ScriptCanvasEditor::TranslationHelper::GlobalKeys::EBusSenderIDKey;
  358. GraphCanvas::TranslationRequestBus::BroadcastResult(
  359. details, &GraphCanvas::TranslationRequests::GetDetails, key + ".details", details);
  360. }
  361. else if (slot.IsData())
  362. {
  363. key.clear();
  364. key << context << className << "methods" << updatedMethodName;
  365. if (methodNode->GetMethodType() == ScriptCanvas::MethodType::Getter || isAccessor)
  366. {
  367. key << "Getter";
  368. }
  369. else if (methodNode->GetMethodType() == ScriptCanvas::MethodType::Setter)
  370. {
  371. key << "Setter";
  372. }
  373. if (slot.IsInput())
  374. {
  375. key << "params";
  376. }
  377. else
  378. {
  379. key << "results";
  380. }
  381. key << inputOutputIndex;
  382. GraphCanvas::TranslationRequestBus::BroadcastResult(
  383. details, &GraphCanvas::TranslationRequests::GetDetails, key + ".details", details);
  384. }
  385. else
  386. {
  387. AZStd::string direction = (slot.IsInput()) ? "entry" : "exit";
  388. // Get the translated value for the execution slot
  389. key.clear();
  390. key << context << className << "methods" << updatedMethodName << direction << "name";
  391. bool success = false;
  392. AZStd::string result;
  393. GraphCanvas::TranslationRequestBus::BroadcastResult(success, &GraphCanvas::TranslationRequests::Get, key, result);
  394. if (success)
  395. {
  396. details.m_name = result;
  397. }
  398. key.clear();
  399. key << context << className << "methods" << updatedMethodName << direction << "tooltip";
  400. GraphCanvas::TranslationRequestBus::BroadcastResult(success, &GraphCanvas::TranslationRequests::Get, key, result);
  401. if (success)
  402. {
  403. details.m_tooltip = result;
  404. }
  405. }
  406. GraphCanvas::SlotRequestBus::Event(
  407. graphCanvasSlotId, &GraphCanvas::SlotRequests::SetDetails, details.m_name, details.m_tooltip);
  408. UpdateSlotDatumLabel(graphCanvasNodeId, slot.GetId(), details.m_name);
  409. }
  410. ++slotIndex;
  411. if (!isBusIdSlot && slot.IsData())
  412. {
  413. ++inputOutputIndex;
  414. }
  415. }
  416. // Set the name
  417. AZStd::string displayName = methodNode->GetName();
  418. graphCanvasEntity->SetName(AZStd::string::format("GC-Node(%s)", displayName.c_str()));
  419. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetPaletteOverride, "MethodNodeTitlePalette");
  420. // Override the title if it has the Setter or Getter suffixes
  421. AZStd::string title;
  422. GraphCanvas::NodeTitleRequestBus::EventResult(title, graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::GetTitle);
  423. if (!title.empty())
  424. {
  425. AZ::RemovePropertyNameArtifacts(title);
  426. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetTitle, title);
  427. }
  428. return graphCanvasNodeId;
  429. }
  430. AZ::EntityId DisplayEbusWrapperNode(AZ::EntityId, const ScriptCanvas::Nodes::Core::EBusEventHandler* busNode)
  431. {
  432. AZ::Entity* graphCanvasEntity = nullptr;
  433. AZStd::string busName = busNode->GetEBusName();
  434. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateWrapperNode, "");
  435. AZ_Assert(graphCanvasEntity, "Unable to create GraphCanvas Node");
  436. AZ::EntityId graphCanvasNodeId = graphCanvasEntity->GetId();
  437. // Add the icon component
  438. graphCanvasEntity->CreateComponent<IconComponent>(ScriptCanvas::Nodes::Core::EBusEventHandler::RTTI_Type());
  439. graphCanvasEntity->CreateComponent<EBusHandlerNodeDescriptorComponent>(busName);
  440. graphCanvasEntity->CreateComponent<SlotMappingComponent>(busNode->GetEntityId());
  441. graphCanvasEntity->CreateComponent<SceneMemberMappingComponent>(busNode->GetEntityId());
  442. graphCanvasEntity->Init();
  443. graphCanvasEntity->Activate();
  444. // Set the user data on the GraphCanvas node to be the EntityId of the ScriptCanvas node
  445. AZStd::any* graphCanvasUserData = nullptr;
  446. GraphCanvas::NodeRequestBus::EventResult(graphCanvasUserData, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetUserData);
  447. if (graphCanvasUserData)
  448. {
  449. *graphCanvasUserData = busNode->GetEntityId();
  450. }
  451. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, SlotGroups::EBusConnectionSlotGroup, GraphCanvas::SlotGroupConfiguration(0));
  452. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::DataGroup, GraphCanvas::SlotGroupConfiguration(1));
  453. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::ExecutionGroup, GraphCanvas::SlotGroupConfiguration(2));
  454. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::SetDividersEnabled, false);
  455. AZStd::vector< ScriptCanvas::SlotId > scriptCanvasSlots = busNode->GetNonEventSlotIds();
  456. for (const auto& slotId : scriptCanvasSlots)
  457. {
  458. ScriptCanvas::Slot* slot = busNode->GetSlot(slotId);
  459. GraphCanvas::SlotGroup group = GraphCanvas::SlotGroups::Invalid;
  460. if (slot->GetDescriptor().IsExecution())
  461. {
  462. group = SlotGroups::EBusConnectionSlotGroup;
  463. }
  464. if (slot->IsVisible())
  465. {
  466. AZ::EntityId gcSlotId = DisplayScriptCanvasSlot(graphCanvasNodeId, (*slot), group);
  467. if (busNode->IsIDRequired() && slot->GetDescriptor() == ScriptCanvas::SlotDescriptors::DataIn())
  468. {
  469. GraphCanvas::TranslationKey key;
  470. key << ::ScriptCanvasEditor::TranslationHelper::GlobalKeys::EBusHandlerIDKey << "details";
  471. GraphCanvas::TranslationRequests::Details details;
  472. details.m_name = slot->GetName();
  473. details.m_tooltip = slot->GetToolTip();
  474. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  475. GraphCanvas::SlotRequestBus::Event(gcSlotId, &GraphCanvas::SlotRequests::SetDetails, details.m_name, details.m_tooltip);
  476. }
  477. }
  478. }
  479. // Set the name
  480. graphCanvasEntity->SetName(AZStd::string::format("GC-BusNode: %s", busName.data()));
  481. GraphCanvas::TranslationKey key;
  482. key << ScriptCanvasEditor::TranslationHelper::AssetContext::EBusHandlerContext << busName << "details";
  483. GraphCanvas::TranslationRequests::Details details;
  484. details.m_name = busName;
  485. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  486. // Add to the tooltip the C++ class for reference
  487. if (!details.m_tooltip.empty())
  488. {
  489. details.m_tooltip.append("\n");
  490. }
  491. details.m_tooltip.append(AZStd::string::format("[C++] %s", busName.c_str()));
  492. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::SetTooltip, details.m_tooltip);
  493. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetTitle, details.m_name);
  494. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetDefaultPalette, "HandlerWrapperNodeTitlePalette");
  495. return graphCanvasNodeId;
  496. }
  497. AZ::EntityId DisplayEbusEventNode(AZ::EntityId, const AZStd::string& busName, const AZStd::string& eventName, const ScriptCanvas::EBusEventId& eventId)
  498. {
  499. AZ_PROFILE_FUNCTION(ScriptCanvas);
  500. AZ::EntityId graphCanvasNodeId;
  501. AZ::Entity* graphCanvasEntity = nullptr;
  502. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateGeneralNode, ".handler");
  503. AZ_Assert(graphCanvasEntity, "Unable to create GraphCanvas Node");
  504. graphCanvasNodeId = graphCanvasEntity->GetId();
  505. graphCanvasEntity->CreateComponent<EBusHandlerEventNodeDescriptorComponent>(busName, eventName, eventId);
  506. graphCanvasEntity->CreateComponent<SlotMappingComponent>();
  507. graphCanvasEntity->Init();
  508. graphCanvasEntity->Activate();
  509. AZStd::string decoratedName = AZStd::string::format("%s::%s", busName.c_str(), eventName.c_str());
  510. GraphCanvas::TranslationKey key;
  511. key << ScriptCanvasEditor::TranslationHelper::AssetContext::EBusHandlerContext << busName << "methods" << eventName << "details";
  512. GraphCanvas::TranslationRequests::Details details;
  513. details.m_name = eventName;
  514. details.m_subtitle = busName;
  515. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  516. // Set the name
  517. graphCanvasEntity->SetName(AZStd::string::format("GC-Node(%s)", decoratedName.c_str()));
  518. // Add to the tooltip the C++ class for reference
  519. if (!details.m_tooltip.empty())
  520. {
  521. details.m_tooltip.append("\n");
  522. }
  523. details.m_tooltip.append(AZStd::string::format("[C++] %s", busName.c_str()));
  524. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::SetTooltip, details.m_tooltip);
  525. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetTitle, details.m_name);
  526. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetPaletteOverride, "HandlerNodeTitlePalette");
  527. return graphCanvasNodeId;
  528. }
  529. AZ::EntityId DisplayAzEventHandlerNode(AZ::EntityId, const ScriptCanvas::Nodes::Core::AzEventHandler* azEventNode)
  530. {
  531. AZ::Entity* graphCanvasEntity{};
  532. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateGeneralNode, ".azeventhandler");
  533. AZ_Assert(graphCanvasEntity, "Unable to create GraphCanvas Node");
  534. AZ::EntityId graphCanvasNodeId = graphCanvasEntity->GetId();
  535. const ScriptCanvas::Nodes::Core::AzEventEntry& azEventEntry{ azEventNode->GetEventEntry() };
  536. // Add the icon component
  537. graphCanvasEntity->CreateComponent<IconComponent>(azrtti_typeid<ScriptCanvas::Nodes::Core::AzEventHandler>());
  538. graphCanvasEntity->CreateComponent<AzEventHandlerNodeDescriptorComponent>(azEventEntry.m_eventName);
  539. graphCanvasEntity->CreateComponent<SlotMappingComponent>(azEventNode->GetEntityId());
  540. graphCanvasEntity->CreateComponent<SceneMemberMappingComponent>(azEventNode->GetEntityId());
  541. graphCanvasEntity->Init();
  542. graphCanvasEntity->Activate();
  543. // Set the user data on the GraphCanvas node to be the EntityId of the ScriptCanvas node
  544. AZStd::any* graphCanvasUserData = {};
  545. GraphCanvas::NodeRequestBus::EventResult(graphCanvasUserData, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetUserData);
  546. if (graphCanvasUserData)
  547. {
  548. *graphCanvasUserData = azEventNode->GetEntityId();
  549. }
  550. for (const ScriptCanvas::Slot& slot: azEventNode->GetSlots())
  551. {
  552. GraphCanvas::SlotGroup group = GraphCanvas::SlotGroups::Invalid;
  553. if (slot.IsVisible())
  554. {
  555. AZ::EntityId gcSlotId = DisplayScriptCanvasSlot(graphCanvasNodeId, slot, group);
  556. GraphCanvas::TranslationKey key;
  557. key << ScriptCanvasEditor::TranslationHelper::AssetContext::AZEventContext << azEventNode->GetNodeName() << "slots" << slot.GetName() << "details";
  558. GraphCanvas::TranslationRequests::Details details;
  559. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  560. GraphCanvas::SlotRequestBus::Event(gcSlotId, &GraphCanvas::SlotRequests::SetName, details.m_name);
  561. GraphCanvas::SlotRequestBus::Event(gcSlotId, &GraphCanvas::SlotRequests::SetTooltip, details.m_tooltip);;
  562. }
  563. }
  564. GraphCanvas::TranslationKey key;
  565. key << ScriptCanvasEditor::TranslationHelper::AssetContext::AZEventContext << azEventEntry.m_eventName << "details";
  566. GraphCanvas::TranslationRequests::Details details;
  567. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  568. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetTitle, details.m_name);
  569. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::SetTooltip, details.m_tooltip);
  570. graphCanvasEntity->SetName(AZStd::string::format("GC-EventNode: %s", azEventEntry.m_eventName.c_str()));
  571. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetPaletteOverride, "HandlerNodeTitlePalette");
  572. return graphCanvasNodeId;
  573. }
  574. AZ::EntityId DisplayScriptEventWrapperNode(AZ::EntityId, const ScriptCanvas::Nodes::Core::ReceiveScriptEvent* busNode)
  575. {
  576. AZ::Entity* graphCanvasEntity = nullptr;
  577. const AZ::Data::AssetId assetId = busNode->GetAssetId();
  578. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateWrapperNode, "");
  579. AZ_Assert(graphCanvasEntity, "Unable to create GraphCanvas Node");
  580. AZ::EntityId graphCanvasNodeId = graphCanvasEntity->GetId();
  581. // Add the icon component
  582. ConfigureGeneralScriptCanvasEntity(busNode, graphCanvasEntity);
  583. graphCanvasEntity->CreateComponent<IconComponent>(ScriptCanvas::Nodes::Core::ReceiveScriptEvent::RTTI_Type());
  584. graphCanvasEntity->CreateComponent<ScriptEventReceiverNodeDescriptorComponent>(assetId);
  585. graphCanvasEntity->CreateComponent<SlotMappingComponent>(busNode->GetEntityId());
  586. graphCanvasEntity->CreateComponent<SceneMemberMappingComponent>(busNode->GetEntityId());
  587. graphCanvasEntity->Init();
  588. graphCanvasEntity->Activate();
  589. // Set the user data on the GraphCanvas node to be the EntityId of the ScriptCanvas node
  590. AZStd::any* graphCanvasUserData = nullptr;
  591. GraphCanvas::NodeRequestBus::EventResult(graphCanvasUserData, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetUserData);
  592. if (graphCanvasUserData)
  593. {
  594. *graphCanvasUserData = busNode->GetEntityId();
  595. }
  596. AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(assetId, AZ::Data::AssetLoadBehavior::PreLoad);
  597. asset.BlockUntilLoadComplete();
  598. if (asset.GetStatus() == AZ::Data::AssetData::AssetStatus::Error)
  599. {
  600. return graphCanvasNodeId;
  601. }
  602. const ScriptEvents::ScriptEvent& definition = asset.Get()->m_definition;
  603. AZStd::string busName = definition.GetName();
  604. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, SlotGroups::EBusConnectionSlotGroup, GraphCanvas::SlotGroupConfiguration(0));
  605. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::DataGroup, GraphCanvas::SlotGroupConfiguration(1));
  606. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::ExecutionGroup, GraphCanvas::SlotGroupConfiguration(2));
  607. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::SetDividersEnabled, false);
  608. AZStd::vector< ScriptCanvas::SlotId > scriptCanvasSlots = busNode->GetNonEventSlotIds();
  609. for (const auto& slotId : scriptCanvasSlots)
  610. {
  611. ScriptCanvas::Slot* slot = busNode->GetSlot(slotId);
  612. GraphCanvas::SlotGroup group = GraphCanvas::SlotGroups::Invalid;
  613. if (slot->GetDescriptor().IsExecution())
  614. {
  615. group = SlotGroups::EBusConnectionSlotGroup;
  616. }
  617. if (slot->IsVisible())
  618. {
  619. AZ::EntityId gcSlotId = DisplayScriptCanvasSlot(graphCanvasNodeId, (*slot), group);
  620. if (busNode->IsIDRequired() && slot->GetDescriptor() == ScriptCanvas::SlotDescriptors::DataIn())
  621. {
  622. GraphCanvas::TranslationKey key;
  623. key << ::ScriptCanvasEditor::TranslationHelper::GlobalKeys::EBusHandlerIDKey << "details";
  624. GraphCanvas::TranslationRequests::Details details;
  625. GraphCanvas::TranslationRequestBus::BroadcastResult(details, &GraphCanvas::TranslationRequests::GetDetails, key, details);
  626. GraphCanvas::SlotRequestBus::Event(gcSlotId, &GraphCanvas::SlotRequests::SetDetails, details.m_name, details.m_tooltip);
  627. }
  628. }
  629. }
  630. // Set the name
  631. graphCanvasEntity->SetName(AZStd::string::format("GC-BusNode: %s", busName.data()));
  632. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetDefaultPalette, "HandlerWrapperNodeTitlePalette");
  633. return graphCanvasNodeId;
  634. }
  635. AZ::EntityId DisplayScriptEventNode(AZ::EntityId, const AZ::Data::AssetId assetId, const ScriptEvents::Method& methodDefinition)
  636. {
  637. AZ_PROFILE_FUNCTION(ScriptCanvas);
  638. AZ::EntityId graphCanvasNodeId;
  639. AZ::Entity* graphCanvasEntity = nullptr;
  640. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateGeneralNode, ".handler");
  641. AZ_Assert(graphCanvasEntity, "Unable to create GraphCanvas Node");
  642. graphCanvasNodeId = graphCanvasEntity->GetId();
  643. graphCanvasEntity->CreateComponent<ScriptEventReceiverEventNodeDescriptorComponent>(assetId, methodDefinition);
  644. graphCanvasEntity->CreateComponent<SlotMappingComponent>();
  645. graphCanvasEntity->CreateComponent<DynamicSlotComponent>();
  646. graphCanvasEntity->Init();
  647. graphCanvasEntity->Activate();
  648. AZStd::string eventName = methodDefinition.GetName();
  649. AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(assetId, AZ::Data::AssetLoadBehavior::PreLoad);
  650. asset.BlockUntilLoadComplete();
  651. const AZStd::string& busName = asset.Get()->m_definition.GetName();
  652. AZStd::string decoratedName = AZStd::string::format("%s::%s", busName.data(), eventName.c_str());
  653. // Set the name
  654. graphCanvasEntity->SetName(AZStd::string::format("GC-Node(%s)", decoratedName.c_str()));
  655. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetPaletteOverride, "HandlerNodeTitlePalette");
  656. return graphCanvasNodeId;
  657. }
  658. AZ::EntityId DisplayScriptEventSenderNode(AZ::EntityId, const ScriptCanvas::Nodes::Core::SendScriptEvent* senderNode)
  659. {
  660. AZ::EntityId graphCanvasNodeId;
  661. AZ::Entity* graphCanvasEntity = nullptr;
  662. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateGeneralNode, ".method");
  663. AZ_Error("GraphCanvas", graphCanvasEntity, "Unable to create GraphCanvas Node");
  664. if (graphCanvasEntity)
  665. {
  666. graphCanvasNodeId = graphCanvasEntity->GetId();
  667. }
  668. // Add the icon component
  669. ConfigureGeneralScriptCanvasEntity(senderNode, graphCanvasEntity);
  670. graphCanvasEntity->CreateComponent<IconComponent>(ScriptCanvas::Nodes::Core::Method::RTTI_Type());
  671. graphCanvasEntity->CreateComponent<SlotMappingComponent>(senderNode->GetEntityId());
  672. graphCanvasEntity->CreateComponent<SceneMemberMappingComponent>(senderNode->GetEntityId());
  673. graphCanvasEntity->CreateComponent<ScriptEventSenderNodeDescriptorComponent>(senderNode->GetAssetId(), senderNode->GetEventId());
  674. graphCanvasEntity->Init();
  675. graphCanvasEntity->Activate();
  676. // Set the user data on the GraphCanvas node to be the EntityId of the ScriptCanvas node
  677. AZStd::any* graphCanvasUserData = nullptr;
  678. GraphCanvas::NodeRequestBus::EventResult(graphCanvasUserData, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetUserData);
  679. if (graphCanvasUserData)
  680. {
  681. *graphCanvasUserData = senderNode->GetEntityId();
  682. }
  683. AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(senderNode->GetAssetId(), AZ::Data::AssetLoadBehavior::PreLoad);
  684. asset.BlockUntilLoadComplete();
  685. if (asset.GetStatus() == AZ::Data::AssetData::AssetStatus::Error)
  686. {
  687. return graphCanvasNodeId;
  688. }
  689. int paramIndex = 0;
  690. int outputIndex = 0;
  691. for (const auto& slot : senderNode->GetSlots())
  692. {
  693. int& index = (slot.IsData() && slot.IsInput()) ? paramIndex : outputIndex;
  694. if (slot.IsVisible())
  695. {
  696. AZ::EntityId graphCanvasSlotId = DisplayScriptCanvasSlot(graphCanvasNodeId, slot, index);
  697. GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetName, slot.GetName());
  698. GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTooltip, slot.GetToolTip());
  699. UpdateSlotDatumLabel(graphCanvasNodeId, slot.GetId(), slot.GetName());
  700. }
  701. ++index;
  702. }
  703. // Set the name
  704. AZStd::string displayName = senderNode->GetEventName();
  705. graphCanvasEntity->SetName(AZStd::string::format("GC-Node(%s)", displayName.c_str()));
  706. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetPaletteOverride, "MethodNodeTitlePalette");
  707. return graphCanvasNodeId;
  708. }
  709. // Function Nodes
  710. AZ::EntityId DisplayFunctionNode(AZ::EntityId graphCanvasGraphId, const ScriptCanvas::Nodes::Core::FunctionCallNode* functionNode)
  711. {
  712. return DisplayFunctionNode(graphCanvasGraphId, const_cast<ScriptCanvas::Nodes::Core::FunctionCallNode*>(functionNode));
  713. }
  714. AZ::EntityId DisplayFunctionNode(AZ::EntityId, ScriptCanvas::Nodes::Core::FunctionCallNode* functionNode)
  715. {
  716. AZ::EntityId graphCanvasNodeId;
  717. AZ::Entity* graphCanvasEntity = nullptr;
  718. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(graphCanvasEntity, &GraphCanvas::GraphCanvasRequests::CreateGeneralNode, ".method");
  719. AZ_Error("GraphCanvas", graphCanvasEntity, "Unable to create GraphCanvas Node");
  720. if (graphCanvasEntity)
  721. {
  722. graphCanvasNodeId = graphCanvasEntity->GetId();
  723. }
  724. auto asset = functionNode->GetAsset();
  725. // Add the icon component
  726. ConfigureGeneralScriptCanvasEntity(functionNode, graphCanvasEntity);
  727. graphCanvasEntity->CreateComponent<IconComponent>(ScriptCanvas::Nodes::Core::Method::RTTI_Type());
  728. graphCanvasEntity->CreateComponent<SlotMappingComponent>(functionNode->GetEntityId());
  729. graphCanvasEntity->CreateComponent<SceneMemberMappingComponent>(functionNode->GetEntityId());
  730. graphCanvasEntity->CreateComponent<FunctionNodeDescriptorComponent>(functionNode->GetAssetId(), functionNode->GetName());
  731. graphCanvasEntity->Init();
  732. graphCanvasEntity->Activate();
  733. // Set the user data on the GraphCanvas node to be the EntityId of the ScriptCanvas node
  734. AZStd::any* graphCanvasUserData = nullptr;
  735. GraphCanvas::NodeRequestBus::EventResult(graphCanvasUserData, graphCanvasNodeId, &GraphCanvas::NodeRequests::GetUserData);
  736. if (graphCanvasUserData)
  737. {
  738. *graphCanvasUserData = functionNode->GetEntityId();
  739. }
  740. if (asset->GetStatus() == AZ::Data::AssetData::AssetStatus::Error)
  741. {
  742. AZ_Error("Script Canvas", false, "Script Canvas Function asset (%s) is not loaded, unable to display the node.", functionNode->GetAssetId().ToString<AZStd::string>().c_str());
  743. GraphCanvas::TranslationKey key;
  744. key = "Globals.MissingFunctionAsset.Title.details.m_name";
  745. bool success = false;
  746. AZStd::string result = "Error!";
  747. GraphCanvas::TranslationRequestBus::BroadcastResult(success, &GraphCanvas::TranslationRequests::Get, key = "Globals.MissingFunctionAsset.Title.details.m_name", result);
  748. if (success)
  749. {
  750. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetTitle, result);
  751. }
  752. result = "Missing Script Canvas Function Asset";
  753. GraphCanvas::TranslationRequestBus::BroadcastResult(success, &GraphCanvas::TranslationRequests::Get, key = "Globals.MissingFunctionAsset.Title.details.tooltip", result);
  754. if (success)
  755. {
  756. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetSubTitle, result);
  757. }
  758. return graphCanvasNodeId;
  759. }
  760. int paramIndex = 0;
  761. int outputIndex = 0;
  762. for (const auto& slot : functionNode->GetSlots())
  763. {
  764. int& index = (slot.IsData() && slot.IsInput()) ? paramIndex : outputIndex;
  765. AZ::EntityId graphCanvasSlotId = DisplayScriptCanvasSlot(graphCanvasNodeId, slot, index);
  766. GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetName, slot.GetName());
  767. GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTooltip, slot.GetToolTip());
  768. UpdateSlotDatumLabel(graphCanvasNodeId, slot.GetId(), slot.GetName());
  769. ++index;
  770. }
  771. if (asset)
  772. {
  773. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetTitle, asset->m_interfaceData.m_name);
  774. }
  775. GraphCanvas::NodeTitleRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetPaletteOverride, "MethodNodeTitlePalette");
  776. return graphCanvasNodeId;
  777. }
  778. AZ::EntityId DisplayFunctionDefinitionNode(AZ::EntityId graphCanvasGraphId, const ScriptCanvas::Nodes::Core::FunctionDefinitionNode* functionDefinitionNode)
  779. {
  780. NodeReplacementConfiguration nodeConfiguration;
  781. nodeConfiguration.PopulateComponentDescriptors<IconComponent, FunctionDefinitionNodeDescriptorComponent>();
  782. if (functionDefinitionNode->RequiresDynamicSlotOrdering())
  783. {
  784. nodeConfiguration.PopulateComponentDescriptors<DynamicOrderingDynamicSlotComponent>();
  785. }
  786. else
  787. {
  788. nodeConfiguration.PopulateComponentDescriptors<DynamicSlotComponent>();
  789. }
  790. nodeConfiguration.m_nodeSubStyle = ".nodeling";
  791. nodeConfiguration.m_titlePalette = "NodelingTitlePalette";
  792. nodeConfiguration.m_scriptCanvasId = functionDefinitionNode->GetEntityId();
  793. AZ::SerializeContext* serializeContext = nullptr;
  794. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  795. AZ_Assert(serializeContext, "Failed to acquire application serialize context.");
  796. if (const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(azrtti_typeid(functionDefinitionNode)))
  797. {
  798. ScriptCanvas::GraphScopedNodeId nodelingId;
  799. nodelingId.m_identifier = nodeConfiguration.m_scriptCanvasId;
  800. nodelingId.m_scriptCanvasId = functionDefinitionNode->GetOwningScriptCanvasId();
  801. if (classData->m_editData)
  802. {
  803. const AZ::Edit::ElementData* elementData = classData->m_editData->FindElementData(AZ::Edit::ClassElements::EditorData);
  804. if (elementData)
  805. {
  806. if (auto nodeTypeAttribute = elementData->FindAttribute(ScriptCanvas::Attributes::Node::NodeType))
  807. {
  808. if (auto nodeTypeAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<NodeType>*>(nodeTypeAttribute))
  809. {
  810. nodeConfiguration.m_nodeType = nodeTypeAttributeData->Get(nullptr);
  811. }
  812. }
  813. }
  814. }
  815. }
  816. // Because of how the extender slots are registered, there isn't an easy way to only create one or the other based on
  817. // the type of nodeling, so instead they both get created and we need to remove the inapplicable one
  818. GraphCanvas::ConnectionType typeToRemove = (functionDefinitionNode->IsExecutionEntry()) ? GraphCanvas::CT_Input : GraphCanvas::CT_Output;
  819. AZ::EntityId graphCanvasNodeId = DisplayGeneralScriptCanvasNode(graphCanvasGraphId, functionDefinitionNode, nodeConfiguration);
  820. AZStd::vector<GraphCanvas::SlotId> extenderSlotIds, executionSlotIds;
  821. GraphCanvas::NodeRequestBus::EventResult(extenderSlotIds, graphCanvasNodeId, &GraphCanvas::NodeRequests::FindVisibleSlotIdsByType, typeToRemove, GraphCanvas::SlotTypes::ExtenderSlot);
  822. if (!extenderSlotIds.empty())
  823. {
  824. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::RemoveSlot, *extenderSlotIds.begin());
  825. }
  826. GraphCanvas::NodeRequestBus::EventResult(executionSlotIds, graphCanvasNodeId, &GraphCanvas::NodeRequests::FindVisibleSlotIdsByType, typeToRemove, GraphCanvas::SlotTypes::ExecutionSlot);
  827. if (!executionSlotIds.empty())
  828. {
  829. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::RemoveSlot, *executionSlotIds.begin());
  830. }
  831. return graphCanvasNodeId;
  832. }
  833. AZ::EntityId DisplayNodeling(AZ::EntityId graphCanvasGraphId, const ScriptCanvas::Nodes::Core::Internal::Nodeling* nodeling)
  834. {
  835. NodeReplacementConfiguration nodeConfiguration;
  836. nodeConfiguration.PopulateComponentDescriptors<IconComponent, NodelingDescriptorComponent>();
  837. if (nodeling->RequiresDynamicSlotOrdering())
  838. {
  839. nodeConfiguration.PopulateComponentDescriptors<DynamicOrderingDynamicSlotComponent>();
  840. }
  841. else
  842. {
  843. nodeConfiguration.PopulateComponentDescriptors<DynamicSlotComponent>();
  844. }
  845. nodeConfiguration.m_nodeSubStyle = ".nodeling";
  846. nodeConfiguration.m_titlePalette = "NodelingTitlePalette";
  847. nodeConfiguration.m_scriptCanvasId = nodeling->GetEntityId();
  848. AZ::SerializeContext* serializeContext = nullptr;
  849. AZ::ComponentApplicationBus::BroadcastResult(serializeContext, &AZ::ComponentApplicationRequests::GetSerializeContext);
  850. AZ_Assert(serializeContext, "Failed to acquire application serialize context.");
  851. const AZ::SerializeContext::ClassData* classData = serializeContext->FindClassData(azrtti_typeid(nodeling));
  852. if (classData)
  853. {
  854. if (classData->m_editData)
  855. {
  856. const AZ::Edit::ElementData* elementData = classData->m_editData->FindElementData(AZ::Edit::ClassElements::EditorData);
  857. if (elementData)
  858. {
  859. if (auto nodeTypeAttribute = elementData->FindAttribute(ScriptCanvas::Attributes::Node::NodeType))
  860. {
  861. if (auto nodeTypeAttributeData = azdynamic_cast<const AZ::Edit::AttributeData<NodeType>*>(nodeTypeAttribute))
  862. {
  863. nodeConfiguration.m_nodeType = nodeTypeAttributeData->Get(nullptr);
  864. }
  865. }
  866. }
  867. }
  868. }
  869. return DisplayGeneralScriptCanvasNode(graphCanvasGraphId, nodeling, nodeConfiguration);
  870. }
  871. AZ::EntityId DisplayGetVariableNode(AZ::EntityId graphCanvasGraphId, const ScriptCanvas::Nodes::Core::GetVariableNode* variableNode)
  872. {
  873. AZ_PROFILE_FUNCTION(ScriptCanvas);
  874. NodeReplacementConfiguration nodeConfiguration;
  875. nodeConfiguration.PopulateComponentDescriptors<IconComponent, DynamicSlotComponent, GetVariableNodeDescriptorComponent>();
  876. nodeConfiguration.m_nodeSubStyle = ".getVariable";
  877. nodeConfiguration.m_titlePalette = "GetVariableNodeTitlePalette";
  878. nodeConfiguration.m_scriptCanvasId = variableNode->GetEntityId();
  879. AZ::EntityId graphCanvasNodeId = DisplayGeneralScriptCanvasNode(graphCanvasGraphId, variableNode, nodeConfiguration);
  880. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::ExecutionGroup, GraphCanvas::SlotGroupConfiguration(0));
  881. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::PropertyGroup, GraphCanvas::SlotGroupConfiguration(1));
  882. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasNodeId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::DataGroup, GraphCanvas::SlotGroupConfiguration(2));
  883. return graphCanvasNodeId;
  884. }
  885. AZ::EntityId DisplaySetVariableNode(AZ::EntityId graphCanvasGraphId, const ScriptCanvas::Nodes::Core::SetVariableNode* variableNode)
  886. {
  887. AZ_PROFILE_FUNCTION(ScriptCanvas);
  888. NodeReplacementConfiguration nodeConfiguration;
  889. nodeConfiguration.PopulateComponentDescriptors<IconComponent, DynamicSlotComponent, SetVariableNodeDescriptorComponent>();
  890. nodeConfiguration.m_nodeSubStyle = ".setVariable";
  891. nodeConfiguration.m_titlePalette = "SetVariableNodeTitlePalette";
  892. nodeConfiguration.m_scriptCanvasId = variableNode->GetEntityId();
  893. AZ::EntityId graphCanvasId = DisplayGeneralScriptCanvasNode(graphCanvasGraphId, variableNode, nodeConfiguration);
  894. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::ExecutionGroup, GraphCanvas::SlotGroupConfiguration(0));
  895. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::PropertyGroup, GraphCanvas::SlotGroupConfiguration(1));
  896. GraphCanvas::SlotLayoutRequestBus::Event(graphCanvasId, &GraphCanvas::SlotLayoutRequests::ConfigureSlotGroup, GraphCanvas::SlotGroups::DataGroup, GraphCanvas::SlotGroupConfiguration(2));
  897. return graphCanvasId;
  898. }
  899. ///////////////////
  900. // Header Methods
  901. ///////////////////
  902. AZ::EntityId DisplayScriptCanvasNode(AZ::EntityId graphCanvasGraphId, const ScriptCanvas::Node* node)
  903. {
  904. AZ_PROFILE_FUNCTION(ScriptCanvas);
  905. AZ::EntityId graphCanvasNodeId;
  906. if (azrtti_istypeof<ScriptCanvas::Nodes::Core::SetVariableNode>(node))
  907. {
  908. graphCanvasNodeId = DisplaySetVariableNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::SetVariableNode*>(node));
  909. }
  910. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::GetVariableNode>(node))
  911. {
  912. graphCanvasNodeId = DisplayGetVariableNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::GetVariableNode*>(node));
  913. }
  914. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::Method>(node))
  915. {
  916. graphCanvasNodeId = DisplayMethodNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::Method*>(node));
  917. }
  918. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::EBusEventHandler>(node))
  919. {
  920. graphCanvasNodeId = DisplayEbusWrapperNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::EBusEventHandler*>(node));
  921. }
  922. else if (auto azEventHandlerNode{ azrtti_cast<const ScriptCanvas::Nodes::Core::AzEventHandler*>(node) }; azEventHandlerNode != nullptr)
  923. {
  924. graphCanvasNodeId = DisplayAzEventHandlerNode(graphCanvasGraphId, azEventHandlerNode);
  925. }
  926. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::ReceiveScriptEvent>(node))
  927. {
  928. graphCanvasNodeId = DisplayScriptEventWrapperNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::ReceiveScriptEvent*>(node));
  929. }
  930. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::SendScriptEvent>(node))
  931. {
  932. graphCanvasNodeId = DisplayScriptEventSenderNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::SendScriptEvent*>(node));
  933. }
  934. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::FunctionCallNode>(node))
  935. {
  936. graphCanvasNodeId = DisplayFunctionNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::FunctionCallNode*>(node));
  937. }
  938. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::FunctionDefinitionNode>(node))
  939. {
  940. graphCanvasNodeId = DisplayFunctionDefinitionNode(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::FunctionDefinitionNode*>(node));
  941. }
  942. else if (azrtti_istypeof<ScriptCanvas::Nodes::Core::Internal::Nodeling>(node))
  943. {
  944. graphCanvasNodeId = DisplayNodeling(graphCanvasGraphId, static_cast<const ScriptCanvas::Nodes::Core::Internal::Nodeling*>(node));
  945. }
  946. else if (node)
  947. {
  948. if (!node->GetNodeStyle().empty())
  949. {
  950. StyleConfiguration nodeConfiguration;
  951. nodeConfiguration.m_nodeSubStyle = node->GetNodeStyle();
  952. graphCanvasNodeId = DisplayNode(graphCanvasGraphId, node, nodeConfiguration);
  953. }
  954. else
  955. {
  956. graphCanvasNodeId = DisplayNode(graphCanvasGraphId, node);
  957. }
  958. }
  959. return graphCanvasNodeId;
  960. }
  961. static void RegisterAndActivateGraphCanvasSlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::SlotId& slotId, AZ::Entity* slotEntity)
  962. {
  963. AZ_PROFILE_FUNCTION(ScriptCanvas);
  964. if (slotEntity)
  965. {
  966. slotEntity->Init();
  967. slotEntity->Activate();
  968. // Set the user data on the GraphCanvas slot to be the SlotId of the ScriptCanvas
  969. AZStd::any* slotUserData = nullptr;
  970. GraphCanvas::SlotRequestBus::EventResult(slotUserData, slotEntity->GetId(), &GraphCanvas::SlotRequests::GetUserData);
  971. if (slotUserData)
  972. {
  973. *slotUserData = slotId;
  974. }
  975. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::AddSlot, slotEntity->GetId());
  976. }
  977. }
  978. static GraphCanvas::ConnectionType ToGraphCanvasConnectionType(ScriptCanvas::ConnectionType connectionType)
  979. {
  980. GraphCanvas::ConnectionType graphCanvasConnectionType = GraphCanvas::CT_Invalid;
  981. switch (connectionType)
  982. {
  983. case ScriptCanvas::ConnectionType::Input:
  984. graphCanvasConnectionType = GraphCanvas::CT_Input;
  985. break;
  986. case ScriptCanvas::ConnectionType::Output:
  987. graphCanvasConnectionType = GraphCanvas::CT_Output;
  988. break;
  989. default:
  990. break;
  991. }
  992. return graphCanvasConnectionType;
  993. }
  994. AZ::EntityId DisplayScriptCanvasSlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::Slot& slot, int slotIndex, GraphCanvas::SlotGroup slotGroup)
  995. {
  996. if (!slot.IsVisible())
  997. {
  998. return AZ::EntityId();
  999. }
  1000. AZ_PROFILE_FUNCTION(ScriptCanvas);
  1001. AZ::Entity* slotEntity = nullptr;
  1002. AZ::Uuid typeId = ScriptCanvas::Data::ToAZType(slot.GetDataType());
  1003. if (slot.IsExecution())
  1004. {
  1005. GraphCanvas::ExecutionSlotConfiguration executionConfiguration;
  1006. executionConfiguration.m_name = slot.GetName();
  1007. executionConfiguration.m_tooltip = slot.GetToolTip();
  1008. executionConfiguration.m_slotGroup = slotGroup;
  1009. executionConfiguration.m_isNameHidden = slot.IsNameHidden();
  1010. if (slot.IsLatent())
  1011. {
  1012. executionConfiguration.m_textDecoration = u8"\U0001f552";
  1013. executionConfiguration.m_textDecorationToolTip = "This slot will not be executed immediately.";
  1014. }
  1015. if (slotGroup == GraphCanvas::SlotGroups::Invalid && slot.GetDisplayGroup() != AZ::Crc32())
  1016. {
  1017. executionConfiguration.m_slotGroup = slot.GetDisplayGroup();
  1018. }
  1019. executionConfiguration.m_connectionType = ToGraphCanvasConnectionType(slot.GetConnectionType());
  1020. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(slotEntity, &GraphCanvas::GraphCanvasRequests::CreateSlot, graphCanvasNodeId, executionConfiguration);
  1021. }
  1022. else if (slot.IsData())
  1023. {
  1024. GraphCanvas::DataSlotConfiguration dataSlotConfiguration;
  1025. dataSlotConfiguration.m_typeId = typeId;
  1026. dataSlotConfiguration.m_dataSlotType = GraphCanvas::DataSlotType::Value;
  1027. dataSlotConfiguration.m_name = slot.GetName();
  1028. dataSlotConfiguration.m_tooltip = slot.GetToolTip();
  1029. dataSlotConfiguration.m_slotGroup = slotGroup;
  1030. dataSlotConfiguration.m_isNameHidden = slot.IsNameHidden();
  1031. if (slot.IsLatent())
  1032. {
  1033. dataSlotConfiguration.m_textDecoration = u8"\U0001f552";
  1034. dataSlotConfiguration.m_textDecorationToolTip = "This slot will not be executed immediately.";
  1035. }
  1036. if (slotGroup == GraphCanvas::SlotGroups::Invalid && slot.GetDisplayGroup() != AZ::Crc32())
  1037. {
  1038. dataSlotConfiguration.m_slotGroup = slot.GetDisplayGroup();
  1039. }
  1040. dataSlotConfiguration.m_connectionType = ToGraphCanvasConnectionType(slot.GetConnectionType());
  1041. if (ScriptCanvas::Data::IsContainerType(typeId))
  1042. {
  1043. dataSlotConfiguration.m_dataValueType = GraphCanvas::DataValueType::Container;
  1044. dataSlotConfiguration.m_containerTypeIds = ScriptCanvas::Data::GetContainedTypes(typeId);
  1045. }
  1046. switch (slot.GetDynamicDataType())
  1047. {
  1048. case ScriptCanvas::DynamicDataType::Container:
  1049. dataSlotConfiguration.m_dataValueType = GraphCanvas::DataValueType::Container;
  1050. break;
  1051. default:
  1052. break;
  1053. }
  1054. if (slot.IsVariableReference())
  1055. {
  1056. dataSlotConfiguration.m_dataSlotType = GraphCanvas::DataSlotType::Reference;
  1057. }
  1058. dataSlotConfiguration.m_canConvertTypes = slot.CanConvertTypes();
  1059. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(slotEntity, &GraphCanvas::GraphCanvasRequests::CreateSlot, graphCanvasNodeId, dataSlotConfiguration);
  1060. }
  1061. if (slotEntity)
  1062. {
  1063. GraphCanvas::TranslationKey slotKey;
  1064. slotKey << ScriptCanvasEditor::TranslationHelper::AssetContext::CustomNodeContext << azrtti_typeid(slot.GetNode()).ToString<AZStd::string>() << "slots";
  1065. AZStd::string slotKeyStr;
  1066. if (slot.IsData())
  1067. {
  1068. slotKeyStr.append("Data");
  1069. }
  1070. if (slot.GetConnectionType() == ScriptCanvas::ConnectionType::Input)
  1071. {
  1072. slotKeyStr.append("Input_");
  1073. }
  1074. else
  1075. {
  1076. slotKeyStr.append("Output_");
  1077. }
  1078. slotKeyStr.append(slot.GetName());
  1079. slotKeyStr.append(AZStd::string::format("_%d", slotIndex));
  1080. slotKey << slotKeyStr << "details";
  1081. GraphCanvas::TranslationRequests::Details slotDetails;
  1082. GraphCanvas::TranslationRequestBus::BroadcastResult(slotDetails, &GraphCanvas::TranslationRequests::GetDetails, slotKey, slotDetails);
  1083. if (slotDetails.m_name.empty())
  1084. {
  1085. slotDetails.m_name = slot.GetName();
  1086. }
  1087. if (slotDetails.m_tooltip.empty())
  1088. {
  1089. slotDetails.m_tooltip = slot.GetToolTip();
  1090. }
  1091. GraphCanvas::SlotRequestBus::Event(slotEntity->GetId(), &GraphCanvas::SlotRequests::SetName, slotDetails.m_name);
  1092. GraphCanvas::SlotRequestBus::Event(slotEntity->GetId(), &GraphCanvas::SlotRequests::SetTooltip, slotDetails.m_tooltip);
  1093. RegisterAndActivateGraphCanvasSlot(graphCanvasNodeId, slot.GetId(), slotEntity);
  1094. UpdateSlotDatumLabel(graphCanvasNodeId, slot.GetId(), slot.GetName());
  1095. return slotEntity->GetId();
  1096. }
  1097. else
  1098. {
  1099. return AZ::EntityId();
  1100. }
  1101. }
  1102. }
  1103. namespace ScriptCanvasEditor::Nodes::SlotDisplayHelper
  1104. {
  1105. AZ::EntityId DisplayPropertySlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::VisualExtensionSlotConfiguration& propertyConfiguration)
  1106. {
  1107. AZ_PROFILE_FUNCTION(ScriptCanvas);
  1108. GraphCanvas::SlotConfiguration graphCanvasConfiguration;
  1109. graphCanvasConfiguration.m_name = propertyConfiguration.m_name;
  1110. graphCanvasConfiguration.m_tooltip = propertyConfiguration.m_tooltip;
  1111. graphCanvasConfiguration.m_slotGroup = GraphCanvas::SlotGroup(propertyConfiguration.m_displayGroup);
  1112. graphCanvasConfiguration.m_connectionType = ToGraphCanvasConnectionType(propertyConfiguration.m_connectionType);
  1113. AZ::Entity* slotEntity = nullptr;
  1114. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(slotEntity, &GraphCanvas::GraphCanvasRequests::CreatePropertySlot, graphCanvasNodeId, propertyConfiguration.m_identifier, graphCanvasConfiguration);
  1115. if (slotEntity)
  1116. {
  1117. slotEntity->Init();
  1118. slotEntity->Activate();
  1119. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::AddSlot, slotEntity->GetId());
  1120. }
  1121. return slotEntity ? slotEntity->GetId() : AZ::EntityId();
  1122. }
  1123. AZ::EntityId DisplayExtendableSlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::VisualExtensionSlotConfiguration& extenderConfiguration)
  1124. {
  1125. AZ_PROFILE_FUNCTION(ScriptCanvas);
  1126. GraphCanvas::ExtenderSlotConfiguration graphCanvasConfiguration;
  1127. graphCanvasConfiguration.m_name = extenderConfiguration.m_name;
  1128. graphCanvasConfiguration.m_tooltip = extenderConfiguration.m_tooltip;
  1129. graphCanvasConfiguration.m_slotGroup = GraphCanvas::SlotGroup(extenderConfiguration.m_displayGroup);
  1130. graphCanvasConfiguration.m_connectionType = ToGraphCanvasConnectionType(extenderConfiguration.m_connectionType);
  1131. graphCanvasConfiguration.m_extenderId = extenderConfiguration.m_identifier;
  1132. AZ::Entity* slotEntity = nullptr;
  1133. GraphCanvas::GraphCanvasRequestBus::BroadcastResult(slotEntity, &GraphCanvas::GraphCanvasRequests::CreateSlot, graphCanvasNodeId, graphCanvasConfiguration);
  1134. if (slotEntity)
  1135. {
  1136. slotEntity->Init();
  1137. slotEntity->Activate();
  1138. GraphCanvas::NodeRequestBus::Event(graphCanvasNodeId, &GraphCanvas::NodeRequests::AddSlot, slotEntity->GetId());
  1139. }
  1140. return slotEntity ? slotEntity->GetId() : AZ::EntityId();
  1141. }
  1142. AZ::EntityId DisplayVisualExtensionSlot(AZ::EntityId graphCanvasNodeId, const ScriptCanvas::VisualExtensionSlotConfiguration& extensionConfiguration)
  1143. {
  1144. AZ::EntityId slotId;
  1145. switch (extensionConfiguration.m_extensionType)
  1146. {
  1147. case ScriptCanvas::VisualExtensionSlotConfiguration::VisualExtensionType::ExtenderSlot:
  1148. slotId = SlotDisplayHelper::DisplayExtendableSlot(graphCanvasNodeId, extensionConfiguration);
  1149. break;
  1150. case ScriptCanvas::VisualExtensionSlotConfiguration::VisualExtensionType::PropertySlot:
  1151. slotId = SlotDisplayHelper::DisplayPropertySlot(graphCanvasNodeId, extensionConfiguration);
  1152. break;
  1153. default:
  1154. break;
  1155. }
  1156. return slotId;
  1157. }
  1158. }