Mock.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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/std/containers/set.h>
  9. #include <Editor/Nodes/NodeUtils.h>
  10. #include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
  11. #include <GraphCanvas/Components/Slots/SlotBus.h>
  12. #include <GraphCanvas/Components/SceneBus.h>
  13. #include <GraphCanvas/Components/StyleBus.h>
  14. #include <ScriptCanvas/Data/DataRegistry.h>
  15. #include <ScriptCanvas/Bus/ScriptCanvasBus.h>
  16. #include <ScriptCanvasDeveloperEditor/Mock.h>
  17. namespace ScriptCanvas::Developer
  18. {
  19. namespace Nodes
  20. {
  21. struct DataTypeNameSortFunctor
  22. {
  23. bool operator()(const AZStd::pair<Data::Type, AZStd::string_view>& lhs, const AZStd::pair<Data::Type, AZStd::string>& rhs) const
  24. {
  25. return lhs.second < rhs.second;
  26. }
  27. };
  28. void SlotConfig::Reflect(AZ::ReflectContext* context)
  29. {
  30. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  31. {
  32. serializeContext->Class<SlotConfig>()
  33. ->Version(0)
  34. ->Field("m_name", &SlotConfig::m_name)
  35. ->Field("m_toolTip", &SlotConfig::m_toolTip)
  36. ->Field("m_type", &SlotConfig::m_type)
  37. ->Field("m_slotId", &SlotConfig::m_slotId)
  38. ->Field("m_state", &SlotConfig::m_state)
  39. ;
  40. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  41. {
  42. editContext->Class<SlotConfig>("SlotConfig", "Configuration for slot")
  43. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  44. ->DataElement(AZ::Edit::UIHandlers::Default, &SlotConfig::m_name, "Slot Name", "Slot Name")
  45. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SlotConfig::OnSlotNameChanged)
  46. ->DataElement(AZ::Edit::UIHandlers::Default, &SlotConfig::m_toolTip, "Slot Tooltip", "Slot Tooltip")
  47. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &SlotConfig::OnSlotToolTipChanged)
  48. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &SlotConfig::m_type, "Slot Type", "The Data Type represented by this slot")
  49. ->Attribute(AZ::Edit::Attributes::GenericValueList, &SlotConfig::GetCreatableTypes)
  50. ->Attribute(AZ::Edit::Attributes::PostChangeNotify, &SlotConfig::OnSlotDataTypeChanged)
  51. ;
  52. }
  53. }
  54. }
  55. SlotConfig::SlotConfig()
  56. : m_name("New Slot")
  57. {
  58. }
  59. SlotConfig::~SlotConfig()
  60. {
  61. if (m_owner)
  62. {
  63. m_owner->m_pendingConfigRemovals.push_back(m_slotId);
  64. }
  65. }
  66. AZStd::vector<AZStd::pair<Data::Type, AZStd::string>> SlotConfig::GetCreatableTypes()
  67. {
  68. if (!m_owner)
  69. {
  70. return AZStd::vector<AZStd::pair<Data::Type, AZStd::string>>{};
  71. }
  72. Slot* slot = m_owner->GetSlot(m_slotId);
  73. SlotDescriptor slotDescriptor = slot ? slot->GetDescriptor() : SlotDescriptor();
  74. if (slotDescriptor.IsExecution())
  75. {
  76. return AZStd::vector<AZStd::pair<Data::Type, AZStd::string>>{};
  77. }
  78. AZStd::set<AZStd::pair<Data::Type, AZStd::string_view>, DataTypeNameSortFunctor> sortedTypes;
  79. sortedTypes.emplace(Data::Type::Invalid(), "");
  80. AZStd::unordered_set<Data::Type> creatableTypes;
  81. ScriptCanvasEditor::SystemRequestBus::Broadcast(&ScriptCanvasEditor::SystemRequests::GetEditorCreatableTypes, creatableTypes);
  82. for (const Data::Type& creatableType : creatableTypes)
  83. {
  84. if (const AZ::BehaviorClass* behaviorClass = AZ::BehaviorContextHelper::GetClass(creatableType.GetAZType()))
  85. {
  86. if (AZ::FindAttribute(AZ::ScriptCanvasAttributes::VariableCreationForbidden, behaviorClass->m_attributes))
  87. {
  88. continue;
  89. }
  90. bool isDeprecated{};
  91. if (auto isDeprecatedAttributePtr = AZ::FindAttribute(AZ::Script::Attributes::Deprecated, behaviorClass->m_attributes))
  92. {
  93. AZ::AttributeReader(nullptr, isDeprecatedAttributePtr).Read<bool>(isDeprecated);
  94. }
  95. if (isDeprecated)
  96. {
  97. continue;
  98. }
  99. }
  100. sortedTypes.emplace(creatableType, Data::GetName(creatableType));
  101. }
  102. return AZStd::vector<AZStd::pair<Data::Type, AZStd::string>>(sortedTypes.begin(), sortedTypes.end());
  103. }
  104. AZ::Crc32 SlotConfig::OnSlotNameChanged()
  105. {
  106. if (m_owner)
  107. {
  108. auto gcSlotIt = AZStd::find_if(m_owner->m_graphCanvasSlotIds.begin(), m_owner->m_graphCanvasSlotIds.end(), [this](AZ::EntityId testSlotId)
  109. {
  110. AZStd::any* slotUserData{};
  111. GraphCanvas::SlotRequestBus::EventResult(slotUserData, testSlotId, &GraphCanvas::SlotRequests::GetUserData);
  112. auto scSlotId = AZStd::any_cast<SlotId>(slotUserData);
  113. return scSlotId && *scSlotId == m_slotId;
  114. });
  115. if (gcSlotIt != m_owner->m_graphCanvasSlotIds.end())
  116. {
  117. AZ::EntityId gcSlotId = *gcSlotIt;
  118. GraphCanvas::SlotRequestBus::Event(gcSlotId, &GraphCanvas::SlotRequests::SetName, m_name);
  119. }
  120. }
  121. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  122. }
  123. AZ::Crc32 SlotConfig::OnSlotToolTipChanged()
  124. {
  125. if (m_owner)
  126. {
  127. auto gcSlotIt = AZStd::find_if(m_owner->m_graphCanvasSlotIds.begin(), m_owner->m_graphCanvasSlotIds.end(), [this](AZ::EntityId testSlotId)
  128. {
  129. AZStd::any* slotUserData{};
  130. GraphCanvas::SlotRequestBus::EventResult(slotUserData, testSlotId, &GraphCanvas::SlotRequests::GetUserData);
  131. auto scSlotId = AZStd::any_cast<SlotId>(slotUserData);
  132. return scSlotId && *scSlotId == m_slotId;
  133. });
  134. if (gcSlotIt != m_owner->m_graphCanvasSlotIds.end())
  135. {
  136. AZ::EntityId gcSlotId = *gcSlotIt;
  137. GraphCanvas::SlotRequestBus::Event(gcSlotId, &GraphCanvas::SlotRequests::SetTooltip, m_toolTip);
  138. }
  139. }
  140. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  141. }
  142. void SlotConfig::OnSlotDataTypeChanged([[maybe_unused]] const Data::Type& oldDataType)
  143. {
  144. if (!m_owner)
  145. {
  146. return;
  147. }
  148. Slot* slot = m_owner->GetSlot(m_slotId);
  149. SlotDescriptor slotDescriptor = slot ? slot->GetDescriptor() : SlotDescriptor();
  150. if (slotDescriptor.IsExecution())
  151. {
  152. return;
  153. }
  154. m_owner->RemoveSlot(m_slotId);
  155. m_slotId = {};
  156. if (slotDescriptor.IsInput())
  157. {
  158. if (m_type.IsValid())
  159. {
  160. DataSlotConfiguration slotConfiguration;
  161. slotConfiguration.m_name = m_name;
  162. slotConfiguration.m_toolTip = m_toolTip;
  163. slotConfiguration.SetType(m_type);
  164. slotConfiguration.SetConnectionType(ConnectionType::Input);
  165. m_slotId = m_owner->AddSlot(slotConfiguration);
  166. }
  167. else
  168. {
  169. DynamicDataSlotConfiguration slotConfiguration;
  170. slotConfiguration.m_name = m_name;
  171. slotConfiguration.m_toolTip = m_toolTip;
  172. slotConfiguration.m_dynamicDataType = DynamicDataType::Any;
  173. slotConfiguration.SetConnectionType(ConnectionType::Input);
  174. m_slotId = m_owner->AddSlot(slotConfiguration);
  175. }
  176. }
  177. else if (slotDescriptor.IsOutput())
  178. {
  179. DataSlotConfiguration slotConfiguration;
  180. slotConfiguration.m_name = m_name;
  181. slotConfiguration.m_toolTip = m_toolTip;
  182. slotConfiguration.SetType(m_type);
  183. slotConfiguration.SetConnectionType(ConnectionType::Output);
  184. m_slotId = m_owner->AddSlot(slotConfiguration);
  185. }
  186. }
  187. void Mock::OnGraphCanvasNodeDisplayed(AZ::EntityId graphCanvasId)
  188. {
  189. if (!MockDescriptorRequestBus::Handler::BusIsConnected())
  190. {
  191. MockDescriptorRequestBus::Handler::BusConnect(GetEntityId());
  192. m_graphCanvasNodeId = graphCanvasId;
  193. SetUiEntityId(graphCanvasId);
  194. OnNodeDisplayed(graphCanvasId);
  195. }
  196. }
  197. void Mock::Reflect(AZ::ReflectContext* context)
  198. {
  199. SlotConfig::Reflect(context);
  200. if (auto serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  201. {
  202. serializeContext->Class<Mock, ScriptCanvas::Node>()
  203. ->Version(0)
  204. ->Field("m_uiEntityId", &Mock::m_graphCanvasNodeId)
  205. ->Field("m_uiSlotIds", &Mock::m_graphCanvasSlotIds)
  206. ->Field("m_nodeTitle", &Mock::m_nodeTitle)
  207. ->Field("m_nodeSubTitle", &Mock::m_nodeSubTitle)
  208. ->Field("m_dataInConfigArray", &Mock::m_dataInConfigArray)
  209. ->Field("m_dataOutConfigArray", &Mock::m_dataOutConfigArray)
  210. ->Field("m_executionInConfigArray", &Mock::m_executionInConfigArray)
  211. ->Field("m_executionOutConfigArray", &Mock::m_executionOutConfigArray)
  212. ->Field("m_nodeColorPaletteOverride", &Mock::m_nodeColorPaletteOverride);
  213. ;
  214. if (AZ::EditContext* editContext = serializeContext->GetEditContext())
  215. {
  216. editContext->Class<Mock>("Mock", "Node for mocking node visuals")
  217. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  218. ->DataElement(AZ::Edit::UIHandlers::Default, &Mock::m_nodeTitle, "Node Title", "Node Title for this mock node")
  219. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &Mock::OnNodeTitleChanged)
  220. ->DataElement(AZ::Edit::UIHandlers::Default, &Mock::m_nodeSubTitle, "Node Sub Title", "Node Sub Title for this mock node")
  221. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &Mock::OnNodeSubTitleChanged)
  222. ->DataElement(AZ::Edit::UIHandlers::Default, &Mock::m_dataInConfigArray, "Data Input Slot Configuration", "Configuration array of adding/removing Mock data input slots")
  223. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &Mock::OnDataInSlotArrayChanged)
  224. ->DataElement(AZ::Edit::UIHandlers::Default, &Mock::m_dataOutConfigArray, "Data Output Slot Configuration", "Configuration array of adding/removing Mock data output slots")
  225. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &Mock::OnDataOutSlotArrayChanged)
  226. ->DataElement(AZ::Edit::UIHandlers::Default, &Mock::m_executionInConfigArray, "Execution Input Slot Configuration", "Configuration array of adding/removing Mock execution input slots")
  227. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &Mock::OnExecutionInSlotArrayChanged)
  228. ->DataElement(AZ::Edit::UIHandlers::Default, &Mock::m_executionOutConfigArray, "Execution Output Slot Configuration", "Configuration array of adding/removing Mock execution output slots")
  229. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &Mock::OnExecutionOutSlotArrayChanged)
  230. ->DataElement(AZ::Edit::UIHandlers::ComboBox, &Mock::m_nodeColorPaletteOverride, "Node Color Palette Override", "Updates the node color from one of the possible palettes")
  231. ->Attribute(AZ::Edit::Attributes::StringList, &Mock::GetColorPaletteList)
  232. ->Attribute(AZ::Edit::Attributes::ChangeNotify, &Mock::OnNodeColorPaletteChanged)
  233. ;
  234. }
  235. }
  236. }
  237. Mock::Mock()
  238. : m_nodeTitle("Mock")
  239. , m_nodeSubTitle("Node")
  240. {
  241. }
  242. Mock::~Mock()
  243. {
  244. ScriptCanvasEditor::EditorNodeNotificationBus::Handler::BusDisconnect();
  245. GraphCanvas::NodeNotificationBus::Handler::BusDisconnect();
  246. }
  247. void Mock::OnInit()
  248. {
  249. ScriptCanvasEditor::EditorNodeNotificationBus::Handler::BusConnect(GetEntityId());
  250. if (m_graphCanvasNodeId.IsValid())
  251. {
  252. GraphCanvas::NodeNotificationBus::Handler::BusConnect(m_graphCanvasNodeId);
  253. GraphCanvas::SceneMemberNotificationBus::Handler::BusConnect(m_graphCanvasNodeId);
  254. }
  255. OnNodeTitleChanged();
  256. OnNodeSubTitleChanged();
  257. OnNodeColorPaletteChanged();
  258. for (auto& slotConfig : m_executionInConfigArray)
  259. {
  260. slotConfig.m_owner = this;
  261. slotConfig.OnSlotNameChanged();
  262. slotConfig.OnSlotToolTipChanged();
  263. }
  264. for (auto& slotConfig : m_executionOutConfigArray)
  265. {
  266. slotConfig.m_owner = this;
  267. slotConfig.OnSlotNameChanged();
  268. slotConfig.OnSlotToolTipChanged();
  269. }
  270. for (auto& slotConfig : m_dataInConfigArray)
  271. {
  272. slotConfig.m_owner = this;
  273. slotConfig.OnSlotNameChanged();
  274. slotConfig.OnSlotToolTipChanged();
  275. }
  276. for (auto& slotConfig : m_dataOutConfigArray)
  277. {
  278. slotConfig.m_owner = this;
  279. slotConfig.OnSlotNameChanged();
  280. slotConfig.OnSlotToolTipChanged();
  281. }
  282. }
  283. void Mock::SetUiEntityId(AZ::EntityId uiEntityId)
  284. {
  285. GraphCanvas::NodeNotificationBus::Handler::BusDisconnect();
  286. m_graphCanvasNodeId = uiEntityId;
  287. if (m_graphCanvasNodeId.IsValid())
  288. {
  289. GraphCanvas::NodeNotificationBus::Handler::BusConnect(m_graphCanvasNodeId);
  290. }
  291. }
  292. void Mock::Clear()
  293. {
  294. m_graphCanvasNodeId.SetInvalid();
  295. m_graphCanvasSlotIds.clear();
  296. m_nodeTitle = "Mock";
  297. OnNodeTitleChanged();
  298. m_nodeSubTitle.clear();
  299. OnNodeSubTitleChanged();
  300. m_dataInConfigArray.clear();
  301. OnDataInSlotArrayChanged();
  302. m_dataOutConfigArray.clear();
  303. OnDataOutSlotArrayChanged();
  304. m_executionInConfigArray.clear();
  305. OnExecutionInSlotArrayChanged();
  306. m_executionInConfigArray.clear();
  307. OnExecutionOutSlotArrayChanged();
  308. OnClear();
  309. }
  310. void Mock::OnClear()
  311. {
  312. }
  313. void Mock::OnNodeDisplayed([[maybe_unused]] const GraphCanvas::NodeId& nodeId)
  314. {
  315. }
  316. AZ::Crc32 Mock::OnNodeTitleChanged()
  317. {
  318. GraphCanvas::NodeTitleRequestBus::Event(m_graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetTitle, m_nodeTitle);
  319. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  320. }
  321. AZ::Crc32 Mock::OnNodeSubTitleChanged()
  322. {
  323. GraphCanvas::NodeTitleRequestBus::Event(m_graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetSubTitle, m_nodeSubTitle);
  324. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  325. }
  326. AZ::Crc32 Mock::OnNodeColorPaletteChanged()
  327. {
  328. if (!m_nodeColorPaletteOverride.empty())
  329. {
  330. GraphCanvas::NodeTitleRequestBus::Event(m_graphCanvasNodeId, &GraphCanvas::NodeTitleRequests::SetDefaultPalette, m_nodeColorPaletteOverride);
  331. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  332. }
  333. return AZ::Edit::PropertyRefreshLevels::None;
  334. }
  335. AZStd::vector<AZStd::string> Mock::GetColorPaletteList() const
  336. {
  337. AZStd::vector<AZStd::string> colorPaletteOptions;
  338. AZ::EntityId uiSceneId;
  339. GraphCanvas::SceneMemberRequestBus::EventResult(uiSceneId, m_graphCanvasNodeId, &GraphCanvas::SceneMemberRequests::GetScene);
  340. GraphCanvas::EditorId editorId;
  341. GraphCanvas::SceneRequestBus::EventResult(editorId, uiSceneId, &GraphCanvas::SceneRequests::GetEditorId);
  342. GraphCanvas::StyleManagerRequestBus::EventResult(colorPaletteOptions, editorId, &GraphCanvas::StyleManagerRequests::GetColorPaletteStyles);
  343. return colorPaletteOptions;
  344. }
  345. AZ::Crc32 Mock::OnDataInSlotArrayChanged()
  346. {
  347. const auto pendingConfigRemovals = AZStd::move(m_pendingConfigRemovals);
  348. for (const auto& oldSlotId : pendingConfigRemovals)
  349. {
  350. RemoveSlot(oldSlotId);
  351. }
  352. for (auto& dataInConfig : m_dataInConfigArray)
  353. {
  354. dataInConfig.m_owner = this;
  355. if (dataInConfig.m_state == SlotConfigState::New)
  356. {
  357. if (dataInConfig.m_type.IsValid())
  358. {
  359. DataSlotConfiguration slotConfiguration;
  360. slotConfiguration.m_name = dataInConfig.m_name;
  361. slotConfiguration.m_toolTip = dataInConfig.m_toolTip;
  362. slotConfiguration.SetType(dataInConfig.m_type);
  363. slotConfiguration.SetConnectionType(ConnectionType::Input);
  364. dataInConfig.m_slotId = AddSlot(slotConfiguration);
  365. }
  366. else
  367. {
  368. DynamicDataSlotConfiguration slotConfiguration;
  369. slotConfiguration.m_name = dataInConfig.m_name;
  370. slotConfiguration.m_toolTip = dataInConfig.m_toolTip;
  371. slotConfiguration.m_dynamicDataType = DynamicDataType::Any;
  372. slotConfiguration.SetConnectionType(ConnectionType::Input);
  373. dataInConfig.m_slotId = AddSlot(slotConfiguration);
  374. }
  375. dataInConfig.m_state = SlotConfigState::Unmodified;
  376. }
  377. }
  378. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  379. }
  380. AZ::Crc32 Mock::OnDataOutSlotArrayChanged()
  381. {
  382. const auto pendingConfigRemovals = AZStd::move(m_pendingConfigRemovals);
  383. for (const auto& oldSlotId : pendingConfigRemovals)
  384. {
  385. RemoveSlot(oldSlotId);
  386. }
  387. for (auto& dataOutConfig : m_dataOutConfigArray)
  388. {
  389. dataOutConfig.m_owner = this;
  390. if (dataOutConfig.m_state == SlotConfigState::New)
  391. {
  392. DynamicDataSlotConfiguration slotConfiguration;
  393. slotConfiguration.m_name = dataOutConfig.m_name;
  394. slotConfiguration.m_toolTip = dataOutConfig.m_toolTip;
  395. slotConfiguration.SetConnectionType(ConnectionType::Output);
  396. dataOutConfig.m_slotId = AddSlot(slotConfiguration);
  397. dataOutConfig.m_state = SlotConfigState::Unmodified;
  398. }
  399. }
  400. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  401. }
  402. AZ::Crc32 Mock::OnExecutionInSlotArrayChanged()
  403. {
  404. const auto pendingConfigRemovals = AZStd::move(m_pendingConfigRemovals);
  405. for (const auto& oldSlotId : pendingConfigRemovals)
  406. {
  407. RemoveSlot(oldSlotId);
  408. }
  409. for (auto& executionInConfig : m_executionInConfigArray)
  410. {
  411. executionInConfig.m_owner = this;
  412. if (executionInConfig.m_state == SlotConfigState::New)
  413. {
  414. ExecutionSlotConfiguration slotConfiguration;
  415. slotConfiguration.m_name = executionInConfig.m_name;
  416. slotConfiguration.m_toolTip = executionInConfig.m_toolTip;
  417. slotConfiguration.SetConnectionType(ConnectionType::Input);
  418. executionInConfig.m_slotId = AddSlot(slotConfiguration);
  419. executionInConfig.m_state = SlotConfigState::Unmodified;
  420. }
  421. }
  422. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  423. }
  424. AZ::Crc32 Mock::OnExecutionOutSlotArrayChanged()
  425. {
  426. const auto pendingConfigRemovals = AZStd::move(m_pendingConfigRemovals);
  427. for (const auto& oldSlotId : pendingConfigRemovals)
  428. {
  429. RemoveSlot(oldSlotId);
  430. }
  431. for (auto& executionOutConfig : m_executionOutConfigArray)
  432. {
  433. executionOutConfig.m_owner = this;
  434. if (executionOutConfig.m_state == SlotConfigState::New)
  435. {
  436. ExecutionSlotConfiguration slotConfiguration;
  437. slotConfiguration.m_name = executionOutConfig.m_name;
  438. slotConfiguration.m_toolTip = executionOutConfig.m_toolTip;
  439. slotConfiguration.SetConnectionType(ConnectionType::Output);
  440. executionOutConfig.m_slotId = AddSlot(slotConfiguration);
  441. executionOutConfig.m_state = SlotConfigState::Unmodified;
  442. }
  443. }
  444. return AZ::Edit::PropertyRefreshLevels::AttributesAndValues;
  445. }
  446. void Mock::OnSlotAddedToNode(const AZ::EntityId& slotId)
  447. {
  448. if (AZStd::find(m_graphCanvasSlotIds.begin(), m_graphCanvasSlotIds.end(), slotId) == m_graphCanvasSlotIds.end())
  449. {
  450. m_graphCanvasSlotIds.push_back(slotId);
  451. }
  452. }
  453. void Mock::OnSlotRemovedFromNode(const AZ::EntityId& slotId)
  454. {
  455. auto slotIt = AZStd::find(m_graphCanvasSlotIds.begin(), m_graphCanvasSlotIds.end(), slotId);
  456. if (slotIt == m_graphCanvasSlotIds.end())
  457. {
  458. m_graphCanvasSlotIds.erase(slotIt);
  459. }
  460. }
  461. void Mock::OnAddedToScene([[maybe_unused]] const AZ::EntityId& sceneId)
  462. {
  463. OnNodeTitleChanged();
  464. OnNodeSubTitleChanged();
  465. OnNodeColorPaletteChanged();
  466. for (auto& slotConfig : m_executionInConfigArray)
  467. {
  468. slotConfig.OnSlotNameChanged();
  469. slotConfig.OnSlotToolTipChanged();
  470. }
  471. for (auto& slotConfig : m_executionOutConfigArray)
  472. {
  473. slotConfig.OnSlotNameChanged();
  474. slotConfig.OnSlotToolTipChanged();
  475. }
  476. for (auto& slotConfig : m_dataInConfigArray)
  477. {
  478. slotConfig.OnSlotNameChanged();
  479. slotConfig.OnSlotToolTipChanged();
  480. }
  481. for (auto& slotConfig : m_dataOutConfigArray)
  482. {
  483. slotConfig.m_owner = this;
  484. slotConfig.OnSlotNameChanged();
  485. slotConfig.OnSlotToolTipChanged();
  486. }
  487. MockDescriptorNotificationBus::Event(GetEntityId(), &MockDescriptorNotifications::OnGraphCanvasNodeSetup, m_graphCanvasNodeId);
  488. }
  489. void Mock::OnSceneMemberDeserialized([[maybe_unused]] const GraphCanvas::GraphId& graphId, [[maybe_unused]] const GraphCanvas::GraphSerialization& serialization)
  490. {
  491. OnGraphCanvasNodeDisplayed(m_graphCanvasNodeId);
  492. }
  493. }
  494. }