Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,40 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include "ClassMethodNodeDescriptorComponent.h"
namespace ScriptCanvasEditor
{
///////////////////////////////////////
// ClassMethodNodeDescriptorComponent
///////////////////////////////////////
void ClassMethodNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<ClassMethodNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(2)
;
}
}
ClassMethodNodeDescriptorComponent::ClassMethodNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::ClassMethod)
{
}
}
@@ -0,0 +1,28 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h"
namespace ScriptCanvasEditor
{
class ClassMethodNodeDescriptorComponent
: public NodeDescriptorComponent
{
public:
AZ_COMPONENT(ClassMethodNodeDescriptorComponent, "{853F137F-C2E8-4D7D-8A1C-D99D167BD569}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
ClassMethodNodeDescriptorComponent();
~ClassMethodNodeDescriptorComponent() = default;
};
}
@@ -0,0 +1,361 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <GraphCanvas/Components/SceneBus.h>
#include <GraphCanvas/Components/GeometryBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/EBusHandlerEventNodeDescriptorComponent.h>
#include <ScriptCanvas/Bus/RequestBus.h>
#include <ScriptCanvas/Core/NodeBus.h>
#include <ScriptCanvas/Core/EBusNodeBus.h>
#include <ScriptCanvas/Libraries/Core/EBusEventHandler.h>
#include <Editor/Nodes/NodeUtils.h>
#include <Editor/View/Widgets/NodePalette/EBusNodePaletteTreeItemTypes.h>
#include <Editor/Translation/TranslationHelper.h>
namespace ScriptCanvasEditor
{
////////////////////////////////////////////
// EBusHandlerEventNodeDescriptorComponent
////////////////////////////////////////////
static bool EBusHandlerEventNodeDescriptorComponentVersionConverter(AZ::SerializeContext& serializeContext, AZ::SerializeContext::DataElementNode& rootElement)
{
if (rootElement.GetVersion() <= 1)
{
auto element = rootElement.FindSubElement(AZ_CRC("EventName", 0x0287a22f));
AZStd::string eventName;
if (element->GetData(eventName))
{
AZ::Crc32 eventId = AZ::Crc32(eventName.c_str());
if (rootElement.AddElementWithData(serializeContext, "EventId", eventId) == -1)
{
return false;
}
}
}
return true;
}
void EBusHandlerEventNodeDescriptorComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<EBusHandlerEventNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(2, EBusHandlerEventNodeDescriptorComponentVersionConverter)
->Field("BusName", &EBusHandlerEventNodeDescriptorComponent::m_busName)
->Field("EventName", &EBusHandlerEventNodeDescriptorComponent::m_eventName)
->Field("EventId", &EBusHandlerEventNodeDescriptorComponent::m_eventId)
;
}
}
EBusHandlerEventNodeDescriptorComponent::EBusHandlerEventNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::EBusHandlerEvent)
{
}
EBusHandlerEventNodeDescriptorComponent::EBusHandlerEventNodeDescriptorComponent(const AZStd::string& busName, const AZStd::string& eventName, ScriptCanvas::EBusEventId eventId)
: NodeDescriptorComponent(NodeDescriptorType::EBusHandlerEvent)
, m_busName(busName)
, m_eventName(eventName)
, m_eventId(eventId)
{
}
void EBusHandlerEventNodeDescriptorComponent::Activate()
{
NodeDescriptorComponent::Activate();
EBusHandlerEventNodeDescriptorRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::ForcedWrappedNodeRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::SceneMemberNotificationBus::Handler::BusConnect(GetEntityId());
}
void EBusHandlerEventNodeDescriptorComponent::Deactivate()
{
NodeDescriptorComponent::Deactivate();
GraphCanvas::SceneMemberNotificationBus::Handler::BusDisconnect();
GraphCanvas::ForcedWrappedNodeRequestBus::Handler::BusDisconnect();
EBusHandlerEventNodeDescriptorRequestBus::Handler::BusDisconnect();
}
AZStd::string_view EBusHandlerEventNodeDescriptorComponent::GetBusName() const
{
return m_busName;
}
AZStd::string_view EBusHandlerEventNodeDescriptorComponent::GetEventName() const
{
return m_eventName;
}
ScriptCanvas::EBusEventId EBusHandlerEventNodeDescriptorComponent::GetEventId() const
{
return m_eventId;
}
void EBusHandlerEventNodeDescriptorComponent::SetHandlerAddress(const ScriptCanvas::Datum& idDatum)
{
if (m_ebusWrapper.m_scriptCanvasId.IsValid())
{
GraphCanvas::GraphId graphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
ScriptCanvas::ScriptCanvasId canvasId;
GeneralRequestBus::BroadcastResult(canvasId, &GeneralRequests::GetScriptCanvasId, graphId);
ScriptCanvas::GraphScopedNodeId scopedNodeId(canvasId, m_ebusWrapper.m_scriptCanvasId);
ScriptCanvas::EBusHandlerNodeRequestBus::Event(scopedNodeId, &ScriptCanvas::EBusHandlerNodeRequests::SetAddressId, AZStd::move(idDatum));
m_queuedId = AZStd::move(ScriptCanvas::Datum());
}
else
{
m_queuedId.DeepCopyDatum(idDatum);
}
}
void EBusHandlerEventNodeDescriptorComponent::OnNodeWrapped(const AZ::EntityId& wrappingNode)
{
bool isValid = false;
AZStd::any* userData = nullptr;
GraphCanvas::NodeRequestBus::EventResult(userData, wrappingNode, &GraphCanvas::NodeRequests::GetUserData);
if (userData && userData->is<AZ::EntityId>())
{
AZ_Warning("ScriptCanvas", !m_ebusWrapper.m_graphCanvasId.IsValid() && !m_ebusWrapper.m_scriptCanvasId.IsValid(), "Wrapping the same ebus event node twice without unwrapping it.");
AZ::EntityId scriptCanvasId = (*AZStd::any_cast<AZ::EntityId>(userData));
m_ebusWrapper.m_graphCanvasId = wrappingNode;
m_ebusWrapper.m_scriptCanvasId = scriptCanvasId;
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, scriptCanvasId);
AZStd::string ebusContextName = TranslationHelper::GetEbusHandlerContext(m_busName);
if (entity)
{
ScriptCanvas::Nodes::Core::EBusEventHandler* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::EBusEventHandler>(entity);
if (eventHandler)
{
AZStd::vector< AZ::EntityId > graphCanvasSlotIds;
GraphCanvas::NodeRequestBus::EventResult(graphCanvasSlotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
const ScriptCanvas::Nodes::Core::EBusEventHandler::EventMap& events = eventHandler->GetEvents();
ScriptCanvas::Nodes::Core::EBusEventEntry myEvent;
for (const auto& event : events)
{
if (event.second.m_eventName.compare(m_eventName) == 0)
{
myEvent = event.second;
break;
}
}
const int numEventSlots = 1;
const int numResultSlots = myEvent.m_resultSlotId.IsValid() ? 1 : 0;
const int totalSlots = (myEvent.m_numExpectedArguments + numEventSlots + numResultSlots);
// Potentially overly simplistic way of detecting if we need to refresh our Slot information.
if (totalSlots != graphCanvasSlotIds.size())
{
// Remove the previous slots
for (const auto& graphCanvasSlotId : graphCanvasSlotIds)
{
GraphCanvas::NodeRequestBus::Event(GetEntityId(), &GraphCanvas::NodeRequests::RemoveSlot, graphCanvasSlotId);
}
// Then from a clean slate, fully regenerate all of our slots.
ScriptCanvas::Slot* scriptCanvasSlot = eventHandler->GetSlot(myEvent.m_eventSlotId);
if (scriptCanvasSlot)
{
AZ::EntityId slotId = Nodes::DisplayScriptCanvasSlot(GetEntityId(), (*scriptCanvasSlot));
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusHandlerOnEventTriggeredNameKey());
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusHandlerOnEventTriggeredTooltipKey());
}
//
// inputCount and outputCount work because the order of the slots is maintained from the BehaviorContext, if this changes
// in the future then we should consider storing the actual offset or key name at that time.
//
int inputCount = 0;
int outputCount = 0;
for (const auto& slotId : myEvent.m_parameterSlotIds)
{
scriptCanvasSlot = eventHandler->GetSlot(slotId);
if (scriptCanvasSlot)
{
AZ::EntityId graphCanvasSlotId = Nodes::DisplayScriptCanvasSlot(GetEntityId(), (*scriptCanvasSlot));
TranslationItemType itemType = TranslationHelper::GetItemType(scriptCanvasSlot->GetDescriptor());
GraphCanvas::TranslationKeyedString slotNameKeyedString(scriptCanvasSlot->GetName());
slotNameKeyedString.m_context = ebusContextName;
GraphCanvas::TranslationKeyedString slotTooltipKeyedString(scriptCanvasSlot->GetToolTip());
slotTooltipKeyedString.m_context = ebusContextName;
slotNameKeyedString.SetFallback(scriptCanvasSlot->GetName());
slotTooltipKeyedString.SetFallback(scriptCanvasSlot->GetToolTip());
if (scriptCanvasSlot->GetDescriptor() == ScriptCanvas::SlotDescriptors::DataOut())
{
slotNameKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Name, outputCount);
slotTooltipKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Tooltip, outputCount);
++outputCount;
}
else
{
slotNameKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Name, inputCount);
slotTooltipKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Tooltip, inputCount);
++inputCount;
}
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, slotNameKeyedString);
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, slotTooltipKeyedString);
}
}
if (myEvent.m_resultSlotId.IsValid())
{
scriptCanvasSlot = eventHandler->GetSlot(myEvent.m_resultSlotId);
if (scriptCanvasSlot)
{
AZ::EntityId graphCanvasSlotId = Nodes::DisplayScriptCanvasSlot(GetEntityId(), (*scriptCanvasSlot));
TranslationItemType itemType = TranslationHelper::GetItemType(scriptCanvasSlot->GetDescriptor());
GraphCanvas::TranslationKeyedString slotNameKeyedString(scriptCanvasSlot->GetName(), ebusContextName);
slotNameKeyedString.m_key = slotNameKeyedString.m_key = TranslationHelper::GetKey(TranslationContextGroup::EbusHandler, m_busName, m_eventName, itemType, TranslationKeyId::Name);
GraphCanvas::TranslationKeyedString slotTooltipKeyedString(TranslationHelper::GetSafeTypeName(scriptCanvasSlot->GetDataType()), ebusContextName);
slotTooltipKeyedString.m_key = TranslationHelper::GetKey(TranslationContextGroup::EbusHandler, m_busName, m_eventName, itemType, TranslationKeyId::Tooltip);
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, slotNameKeyedString);
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, slotTooltipKeyedString);
}
}
GraphCanvas::NodeRequestBus::EventResult(graphCanvasSlotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
}
isValid = (totalSlots == graphCanvasSlotIds.size());
}
if (m_queuedId.GetType().IsValid())
{
SetHandlerAddress(m_queuedId);
}
}
}
if (!isValid)
{
AZ::EntityId sceneId;
GraphCanvas::SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
if (sceneId.IsValid())
{
AZ_Error("GraphCanvas", false, "Failed to find valid configuration for EBusEventNode(%s::%s). Deleting Node", m_busName.c_str(), m_eventName.c_str());
AZStd::unordered_set<AZ::EntityId> deleteNodes;
deleteNodes.insert(GetEntityId());
GraphCanvas::SceneRequestBus::Event(sceneId, &GraphCanvas::SceneRequests::Delete, deleteNodes);
}
}
}
void EBusHandlerEventNodeDescriptorComponent::OnSceneMemberAboutToSerialize(GraphCanvas::GraphSerialization& sceneSerialization)
{
AZ::Entity* wrapperEntity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(wrapperEntity, &AZ::ComponentApplicationRequests::FindEntity, m_ebusWrapper.m_graphCanvasId);
if (wrapperEntity)
{
sceneSerialization.GetGraphData().m_nodes.insert(wrapperEntity);
}
}
AZ::Crc32 EBusHandlerEventNodeDescriptorComponent::GetWrapperType() const
{
return AZ::Crc32(m_busName.c_str());
}
AZ::Crc32 EBusHandlerEventNodeDescriptorComponent::GetIdentifier() const
{
return AZ::Crc32(m_eventName.c_str());
}
AZ::EntityId EBusHandlerEventNodeDescriptorComponent::CreateWrapperNode(const AZ::EntityId& sceneId, const AZ::Vector2& nodePosition)
{
CreateEBusHandlerMimeEvent createEbusMimeEvent(m_busName);
AZ::EntityId wrapperNode;
AZ::Vector2 dummyPosition = nodePosition;
if (createEbusMimeEvent.ExecuteEvent(nodePosition, dummyPosition, sceneId))
{
const NodeIdPair& nodePair = createEbusMimeEvent.GetCreatedPair();
wrapperNode = nodePair.m_graphCanvasId;
}
return wrapperNode;
}
void EBusHandlerEventNodeDescriptorComponent::OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId&, const AZ::EntityId&)
{
AZStd::vector< AZ::EntityId > slotIds;
GraphCanvas::NodeRequestBus::EventResult(slotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
for (const auto& slotId : slotIds)
{
GraphCanvas::SlotType slotType;
GraphCanvas::SlotRequestBus::EventResult(slotType, slotId, &GraphCanvas::SlotRequests::GetSlotType);
if (slotType == GraphCanvas::SlotTypes::ExecutionSlot)
{
GraphCanvas::ConnectionType connectionType = GraphCanvas::ConnectionType::CT_None;
GraphCanvas::SlotRequestBus::EventResult(connectionType, slotId, &GraphCanvas::SlotRequests::GetConnectionType);
if (connectionType == GraphCanvas::ConnectionType::CT_Output)
{
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusHandlerOnEventTriggeredNameKey());
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusHandlerOnEventTriggeredTooltipKey());
break;
}
}
}
}
}
@@ -0,0 +1,77 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include "Editor/Include/ScriptCanvas/Bus/NodeIdPair.h"
#include "Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h"
namespace ScriptCanvasEditor
{
class EBusHandlerEventNodeDescriptorComponent
: public NodeDescriptorComponent
, public EBusHandlerEventNodeDescriptorRequestBus::Handler
, public GraphCanvas::ForcedWrappedNodeRequestBus::Handler
, public GraphCanvas::SceneMemberNotificationBus::Handler
{
public:
AZ_COMPONENT(EBusHandlerEventNodeDescriptorComponent, "{F08F673C-0815-4CCA-AB9D-21965E9A14F2}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
EBusHandlerEventNodeDescriptorComponent();
EBusHandlerEventNodeDescriptorComponent(const AZStd::string& busName, const AZStd::string& methodName, ScriptCanvas::EBusEventId eventId);
~EBusHandlerEventNodeDescriptorComponent() = default;
void Activate() override;
void Deactivate() override;
// EBusHandlerEventNodeDescriptorRequestBus
AZStd::string_view GetBusName() const override;
AZStd::string_view GetEventName() const override;
ScriptCanvas::EBusEventId GetEventId() const override;
void SetHandlerAddress(const ScriptCanvas::Datum& idDatum) override;
////
// NodeNotificationBus::Handler
void OnNodeWrapped(const AZ::EntityId& wrappingNode) override;
////
// SceneMemberNotifications
void OnSceneMemberAboutToSerialize(GraphCanvas::GraphSerialization& graphSerialization) override;
////
// ForcedWrappedNodeRequestBus
AZ::Crc32 GetWrapperType() const override;
AZ::Crc32 GetIdentifier() const override;
AZ::EntityId CreateWrapperNode(const AZ::EntityId& sceneId, const AZ::Vector2& nodePosition) override;
////
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& sceneId, const AZ::EntityId& scriptCanvasNodeId) override;
private:
NodeIdPair m_ebusWrapper;
AZStd::string m_busName;
AZStd::string m_eventName;
ScriptCanvas::EBusEventId m_eventId;
ScriptCanvas::Datum m_queuedId;
};
}
@@ -0,0 +1,605 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <qstring.h>
#include <GraphCanvas/Components/SceneBus.h>
#include <GraphCanvas/Components/Slots/Data/DataSlotBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/EBusHandlerNodeDescriptorComponent.h>
#include <ScriptCanvas/Libraries/Core/EBusEventHandler.h>
#include <ScriptCanvas/GraphCanvas/DynamicSlotBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/EBusHandlerEventNodeDescriptorComponent.h>
#include <Editor/GraphCanvas/PropertySlotIds.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/Nodes/NodeUtils.h>
#include <Editor/Include/ScriptCanvas/GraphCanvas/MappingBus.h>
#include <Editor/View/Widgets/PropertyGridBus.h>
#include <Editor/Include/ScriptCanvas/Bus/RequestBus.h>
namespace ScriptCanvasEditor
{
//////////////////////////////////////
// EBusHandlerNodeDescriptorSaveData
//////////////////////////////////////
bool EBusHandlerNodeDescriptorSaveDataVersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
if (classElement.GetVersion() < 2)
{
AZStd::vector< AZStd::string > eventNames;
auto subElement = classElement.FindSubElement(AZ_CRC("EventNames", 0xb0dd75f0));
if (subElement)
{
if (!subElement->GetData(eventNames))
{
return false;
}
}
AZStd::vector< ScriptCanvas::EBusEventId > handlerEventIds;
handlerEventIds.reserve(eventNames.size());
for (const AZStd::string& eventName : eventNames)
{
handlerEventIds.emplace_back(eventName.c_str());
}
classElement.RemoveElementByName(AZ_CRC("EventNames", 0xb0dd75f0));
classElement.AddElementWithData(context, "EventIds", handlerEventIds);
}
return true;
}
EBusHandlerNodeDescriptorComponent::EBusHandlerNodeDescriptorSaveData::EBusHandlerNodeDescriptorSaveData()
: m_displayConnections(false)
, m_callback(nullptr)
{
}
EBusHandlerNodeDescriptorComponent::EBusHandlerNodeDescriptorSaveData::EBusHandlerNodeDescriptorSaveData(EBusHandlerNodeDescriptorComponent* component)
: m_displayConnections(false)
, m_callback(component)
{
}
void EBusHandlerNodeDescriptorComponent::EBusHandlerNodeDescriptorSaveData::operator=(const EBusHandlerNodeDescriptorSaveData& other)
{
// Purposefully skipping over the callback
m_displayConnections = other.m_displayConnections;
m_enabledEvents = other.m_enabledEvents;
}
void EBusHandlerNodeDescriptorComponent::EBusHandlerNodeDescriptorSaveData::OnDisplayConnectionsChanged()
{
if (m_callback)
{
m_callback->OnDisplayConnectionsChanged();
SignalDirty();
}
}
///////////////////////////////////////
// EBusHandlerNodeDescriptorComponent
///////////////////////////////////////
bool EBusHandlerDescriptorVersionConverter(AZ::SerializeContext& context, AZ::SerializeContext::DataElementNode& classElement)
{
if (classElement.GetVersion() <= 1)
{
AZ::Crc32 displayConnectionId = AZ_CRC("DisplayConnections", 0x710635cc);
EBusHandlerNodeDescriptorComponent::EBusHandlerNodeDescriptorSaveData saveData;
AZ::SerializeContext::DataElementNode* dataNode = classElement.FindSubElement(displayConnectionId);
if (dataNode)
{
dataNode->GetData(saveData.m_displayConnections);
}
classElement.RemoveElementByName(displayConnectionId);
classElement.RemoveElementByName(AZ_CRC("BusName", 0x1bbf25c5));
classElement.AddElementWithData(context, "SaveData", saveData);
}
return true;
}
void EBusHandlerNodeDescriptorComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<EBusHandlerNodeDescriptorSaveData, GraphCanvas::ComponentSaveData>()
->Version(2, &EBusHandlerNodeDescriptorSaveDataVersionConverter)
->Field("DisplayConnections", &EBusHandlerNodeDescriptorSaveData::m_displayConnections)
->Field("EventIds", &EBusHandlerNodeDescriptorSaveData::m_enabledEvents)
;
serializeContext->Class<EBusHandlerNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(3, &EBusHandlerDescriptorVersionConverter)
->Field("SaveData", &EBusHandlerNodeDescriptorComponent::m_saveData)
->Field("BusName", &EBusHandlerNodeDescriptorComponent::m_busName)
;
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<EBusHandlerNodeDescriptorSaveData>("SaveData", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "Properties")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &EBusHandlerNodeDescriptorSaveData::m_displayConnections, "Display Connection Controls", "Controls whether or not manual connection controls are visible for this node.")
->Attribute(AZ::Edit::Attributes::ChangeNotify, &EBusHandlerNodeDescriptorSaveData::OnDisplayConnectionsChanged)
;
editContext->Class<EBusHandlerNodeDescriptorComponent>("Event Handler", "Configuration values for the EBus node.")
->ClassElement(AZ::Edit::ClassElements::EditorData, "Properties")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &EBusHandlerNodeDescriptorComponent::m_saveData, "SaveData", "The modifiable information about this comment.")
;
}
}
}
EBusHandlerNodeDescriptorComponent::EBusHandlerNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::EBusHandler)
, m_saveData(this)
, m_loadingEvents(false)
{
}
EBusHandlerNodeDescriptorComponent::EBusHandlerNodeDescriptorComponent(const AZStd::string& busName)
: NodeDescriptorComponent(NodeDescriptorType::EBusHandler)
, m_saveData(this)
, m_busName(busName)
, m_loadingEvents(false)
{
}
void EBusHandlerNodeDescriptorComponent::Activate()
{
NodeDescriptorComponent::Activate();
EBusHandlerNodeDescriptorRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::WrapperNodeNotificationBus::Handler::BusConnect(GetEntityId());
GraphCanvas::GraphCanvasPropertyBusHandler::OnActivate(GetEntityId());
GraphCanvas::WrapperNodeConfigurationRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::EntitySaveDataRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::SceneMemberNotificationBus::Handler::BusConnect(GetEntityId());
}
void EBusHandlerNodeDescriptorComponent::Deactivate()
{
NodeDescriptorComponent::Deactivate();
GraphCanvas::SceneMemberNotificationBus::Handler::BusDisconnect();
GraphCanvas::EntitySaveDataRequestBus::Handler::BusDisconnect();
GraphCanvas::WrapperNodeConfigurationRequestBus::Handler::BusDisconnect();
GraphCanvas::GraphCanvasPropertyBusHandler::OnDeactivate();
GraphCanvas::WrapperNodeNotificationBus::Handler::BusDisconnect();
EBusHandlerNodeDescriptorRequestBus::Handler::BusDisconnect();
}
void EBusHandlerNodeDescriptorComponent::OnNodeActivated()
{
GraphCanvas::WrapperNodeRequestBus::Event(GetEntityId(), &GraphCanvas::WrapperNodeRequests::SetWrapperType, AZ::Crc32(m_busName.c_str()));
}
void EBusHandlerNodeDescriptorComponent::OnMemberSetupComplete()
{
m_loadingEvents = true;
AZ::EntityId graphCanvasGraphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphCanvasGraphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
AZStd::vector< HandlerEventConfiguration > eventConfigurations = GetEventConfigurations();
for (const ScriptCanvas::EBusEventId& eventId : m_saveData.m_enabledEvents)
{
if (m_eventTypeToId.find(eventId) == m_eventTypeToId.end())
{
AZStd::string eventName;
for (const HandlerEventConfiguration& testEventConfiguration : eventConfigurations)
{
if (testEventConfiguration.m_eventId == eventId)
{
eventName = testEventConfiguration.m_eventName;
}
}
AZ::EntityId internalNode = Nodes::DisplayEbusEventNode(graphCanvasGraphId, m_busName, eventName, eventId);
if (internalNode.IsValid())
{
GraphCanvas::SceneRequestBus::Event(graphCanvasGraphId, &GraphCanvas::SceneRequests::Add, internalNode);
GraphCanvas::WrappedNodeConfiguration configuration = GetEventConfiguration(eventId);
GraphCanvas::WrapperNodeRequestBus::Event(GetEntityId(), &GraphCanvas::WrapperNodeRequests::WrapNode, internalNode, configuration);
}
}
}
m_loadingEvents = false;
m_saveData.RegisterIds(GetEntityId(), graphCanvasGraphId);
}
void EBusHandlerNodeDescriptorComponent::OnSceneMemberDeserialized(const AZ::EntityId&, const GraphCanvas::GraphSerialization&)
{
m_saveData.m_enabledEvents.clear();
}
void EBusHandlerNodeDescriptorComponent::WriteSaveData(GraphCanvas::EntitySaveDataContainer& saveDataContainer) const
{
EBusHandlerNodeDescriptorSaveData* saveData = saveDataContainer.FindCreateSaveData<EBusHandlerNodeDescriptorSaveData>();
if (saveData)
{
(*saveData) = m_saveData;
}
}
void EBusHandlerNodeDescriptorComponent::ReadSaveData(const GraphCanvas::EntitySaveDataContainer& saveDataContainer)
{
const EBusHandlerNodeDescriptorSaveData* saveData = saveDataContainer.FindSaveDataAs<EBusHandlerNodeDescriptorSaveData>();
if (saveData)
{
m_saveData = (*saveData);
}
}
AZStd::string_view EBusHandlerNodeDescriptorComponent::GetBusName() const
{
return m_busName;
}
GraphCanvas::WrappedNodeConfiguration EBusHandlerNodeDescriptorComponent::GetEventConfiguration(const ScriptCanvas::EBusEventId& eventId) const
{
AZ_Warning("ScriptCanvas", m_scriptCanvasId.IsValid(), "Trying to query event list before the node is added to the scene.");
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, m_scriptCanvasId);
GraphCanvas::WrappedNodeConfiguration wrappedConfiguration;
if (entity)
{
ScriptCanvas::Nodes::Core::EBusEventHandler* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::EBusEventHandler>(entity);
if (eventHandler)
{
const ScriptCanvas::Nodes::Core::EBusEventHandler::EventMap& events = eventHandler->GetEvents();
AZ::u32 i = 0;
for (const auto& event : events)
{
if (event.second.m_eventId == eventId)
{
wrappedConfiguration.m_layoutOrder = i;
break;
}
++i;
}
}
}
return wrappedConfiguration;
}
bool EBusHandlerNodeDescriptorComponent::ContainsEvent(const ScriptCanvas::EBusEventId& eventId) const
{
return m_eventTypeToId.find(eventId) != m_eventTypeToId.end();
}
AZStd::vector< HandlerEventConfiguration > EBusHandlerNodeDescriptorComponent::GetEventConfigurations() const
{
AZ_Warning("ScriptCanvas", m_scriptCanvasId.IsValid(), "Trying to query event list before the node is added to the scene.");
AZStd::vector< HandlerEventConfiguration > eventConfigurations;
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, m_scriptCanvasId);
if (entity)
{
ScriptCanvas::Nodes::Core::EBusEventHandler* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::EBusEventHandler>(entity);
if (eventHandler)
{
const ScriptCanvas::Nodes::Core::EBusEventHandler::EventMap& events = eventHandler->GetEvents();
eventConfigurations.reserve(events.size());
for (const auto& eventEntry : events)
{
HandlerEventConfiguration configuration;
configuration.m_eventName = eventEntry.second.m_eventName;
configuration.m_eventId = eventEntry.second.m_eventId;
eventConfigurations.emplace_back(configuration);
}
}
}
return eventConfigurations;
}
AZ::EntityId EBusHandlerNodeDescriptorComponent::FindEventNodeId(const ScriptCanvas::EBusEventId& eventId) const
{
AZ::EntityId retVal;
auto iter = m_eventTypeToId.find(eventId);
if (iter != m_eventTypeToId.end())
{
retVal = iter->second;
}
return retVal;
}
AZ::EntityId EBusHandlerNodeDescriptorComponent::FindGraphCanvasNodeIdForSlot(const ScriptCanvas::SlotId& slotId) const
{
ScriptCanvas::Nodes::Core::EBusEventHandler* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::EBusEventHandler>(m_scriptCanvasId);
if (eventHandler)
{
auto nonEventSlotIds = eventHandler->GetNonEventSlotIds();
bool isNonEventSlot = (AZStd::find(nonEventSlotIds.begin(), nonEventSlotIds.end(), slotId) != nonEventSlotIds.end());
if (isNonEventSlot)
{
return GetEntityId();
}
auto scriptEvents = eventHandler->GetEvents();
ScriptCanvas::EBusEventId foundEventId = ScriptCanvas::EBusEventId();
for (auto scriptEventPair : scriptEvents)
{
const auto& scriptEvent = scriptEventPair.second;
bool foundResult = scriptEvent.m_eventSlotId == slotId;
foundResult = foundResult || scriptEvent.m_resultSlotId == slotId;
foundResult = foundResult || (AZStd::find(scriptEvent.m_parameterSlotIds.begin(), scriptEvent.m_parameterSlotIds.end(), slotId) != nonEventSlotIds.end());
if (foundResult)
{
foundEventId = scriptEventPair.first;
break;
}
}
if (foundEventId != ScriptCanvas::EBusEventId())
{
return FindEventNodeId(foundEventId);
}
}
return AZ::EntityId();
}
GraphCanvas::Endpoint EBusHandlerNodeDescriptorComponent::MapSlotToGraphCanvasEndpoint(const ScriptCanvas::SlotId& scriptCanvasSlotId) const
{
GraphCanvas::Endpoint endpoint;
AZ::EntityId graphCanvasSlotId;
SlotMappingRequestBus::EventResult(graphCanvasSlotId, GetEntityId(), &SlotMappingRequests::MapToGraphCanvasId, scriptCanvasSlotId);
if (!graphCanvasSlotId.IsValid())
{
for (auto& mapPair : m_eventTypeToId)
{
SlotMappingRequestBus::EventResult(graphCanvasSlotId, mapPair.second, &SlotMappingRequests::MapToGraphCanvasId, scriptCanvasSlotId);
if (graphCanvasSlotId.IsValid())
{
endpoint = GraphCanvas::Endpoint(mapPair.second, graphCanvasSlotId);
break;
}
}
}
else
{
endpoint = GraphCanvas::Endpoint(GetEntityId(), graphCanvasSlotId);
}
return endpoint;
}
void EBusHandlerNodeDescriptorComponent::OnWrappedNode(const AZ::EntityId& wrappedNode)
{
ScriptCanvas::EBusEventId eventId;
EBusHandlerEventNodeDescriptorRequestBus::EventResult(eventId, wrappedNode, &EBusHandlerEventNodeDescriptorRequests::GetEventId);
if (eventId == ScriptCanvas::EBusEventId())
{
AZ_Warning("ScriptCanvas", false, "Trying to wrap an event node without an event name being specified.");
return;
}
auto emplaceResult = m_eventTypeToId.emplace(eventId, wrappedNode);
if (emplaceResult.second)
{
m_idToEventType.emplace(wrappedNode, eventId);
AZStd::any* userData = nullptr;
GraphCanvas::NodeRequestBus::EventResult(userData, wrappedNode, &GraphCanvas::NodeRequests::GetUserData);
if (userData)
{
(*userData) = m_scriptCanvasId;
DynamicSlotRequestBus::Event(wrappedNode, &DynamicSlotRequests::OnUserDataChanged);
GraphCanvas::NodeDataSlotRequestBus::Event(wrappedNode, &GraphCanvas::NodeDataSlotRequests::RecreatePropertyDisplay);
}
if (!m_loadingEvents)
{
m_saveData.m_enabledEvents.emplace_back(eventId);
m_saveData.SignalDirty();
}
}
// If we are wrapping the same node twice for just ignore it and log a message
else if (emplaceResult.first->second != wrappedNode)
{
AZ_Error("ScriptCanvas", false, "Trying to wrap two identically named methods under the same EBus Handler. Deleting the second node.");
AZ::EntityId sceneId;
GraphCanvas::SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
AZStd::unordered_set<AZ::EntityId> deleteNodes;
deleteNodes.insert(wrappedNode);
GraphCanvas::SceneRequestBus::Event(sceneId, &GraphCanvas::SceneRequests::Delete, deleteNodes);
}
else
{
AZ_Warning("ScriptCanvas", false, "Trying to wrap the same node twice.");
}
}
void EBusHandlerNodeDescriptorComponent::OnUnwrappedNode(const AZ::EntityId& unwrappedNode)
{
auto iter = m_idToEventType.find(unwrappedNode);
if (iter != m_idToEventType.end())
{
ScriptCanvas::EBusEventId eventId = iter->second;
m_eventTypeToId.erase(eventId);
m_idToEventType.erase(iter);
for (auto eventIter = m_saveData.m_enabledEvents.begin(); eventIter != m_saveData.m_enabledEvents.end(); ++eventIter)
{
if ((*eventIter) == eventId)
{
m_saveData.m_enabledEvents.erase(eventIter);
m_saveData.SignalDirty();
break;
}
}
}
}
GraphCanvas::WrappedNodeConfiguration EBusHandlerNodeDescriptorComponent::GetWrappedNodeConfiguration(const AZ::EntityId& wrappedNodeId) const
{
ScriptCanvas::EBusEventId eventId;
EBusHandlerEventNodeDescriptorRequestBus::EventResult(eventId, wrappedNodeId, &EBusHandlerEventNodeDescriptorRequests::GetEventId);
return GetEventConfiguration(eventId);
}
AZ::Component* EBusHandlerNodeDescriptorComponent::GetPropertyComponent()
{
return this;
}
void EBusHandlerNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId)
{
m_scriptCanvasId = scriptCanvasNodeId;
GraphCanvas::WrapperNodeRequestBus::Event(GetEntityId(), &GraphCanvas::WrapperNodeRequests::SetActionString, "Add/Remove Events");
GraphCanvas::SlotLayoutRequestBus::Event(GetEntityId(), &GraphCanvas::SlotLayoutRequests::SetSlotGroupVisible, SlotGroups::EBusConnectionSlotGroup, m_saveData.m_displayConnections);
if (m_scriptCanvasId.IsValid())
{
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, m_scriptCanvasId);
if (entity)
{
ScriptCanvas::Nodes::Core::EBusEventHandler* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::EBusEventHandler>(entity);
if (eventHandler && eventHandler->IsIDRequired())
{
AZStd::vector< AZ::EntityId > slotIds;
GraphCanvas::NodeRequestBus::EventResult(slotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
// Should be exactly one data slot on ourselves. And that is the BusId
for (const AZ::EntityId& testSlotId : slotIds)
{
GraphCanvas::SlotType slotType;
GraphCanvas::SlotRequestBus::EventResult(slotType, testSlotId, &GraphCanvas::SlotRequests::GetSlotType);
if (slotType == GraphCanvas::SlotTypes::DataSlot)
{
GraphCanvas::SlotRequestBus::Event(testSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusHandlerBusIdNameKey());
GraphCanvas::SlotRequestBus::Event(testSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusHandlerBusIdTooltipKey());
break;
}
}
}
}
}
}
void EBusHandlerNodeDescriptorComponent::OnDisplayConnectionsChanged()
{
// If we are hiding the connections, we need to confirm that
// everything will be ok(i.e. no active connections)
if (!m_saveData.m_displayConnections)
{
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, m_scriptCanvasId);
if (entity)
{
ScriptCanvas::Nodes::Core::EBusEventHandler* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::EBusEventHandler>(entity);
if (eventHandler)
{
AZStd::vector< ScriptCanvas::SlotId > scriptCanvasSlots = eventHandler->GetNonEventSlotIds();
bool allowChange = true;
for (const auto& slotId : scriptCanvasSlots)
{
ScriptCanvas::Slot* slot = eventHandler->GetSlot(slotId);
if (slot->IsExecution() && eventHandler->IsConnected((*slot)))
{
allowChange = false;
break;
}
}
if (!allowChange)
{
AZ_Warning("Script Canvas", false, "Cannot hide EBus Connection Controls because one ore more slots are currently connected. Please disconnect all slots to hide.");
m_saveData.m_displayConnections = true;
PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RefreshPropertyGrid);
}
// If we are displaying the connection options, do not auto connect the graph as it's expected
// that the user will manage it.
eventHandler->SetAutoConnectToGraphOwner(!m_saveData.m_displayConnections);
}
}
}
GraphCanvas::SlotLayoutRequestBus::Event(GetEntityId(), &GraphCanvas::SlotLayoutRequests::SetSlotGroupVisible, SlotGroups::EBusConnectionSlotGroup, m_saveData.m_displayConnections);
}
}
@@ -0,0 +1,128 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <GraphCanvas/Components/Nodes/Wrapper/WrapperNodeBus.h>
#include <GraphCanvas/Components/GraphCanvasPropertyBus.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
#include <GraphCanvas/Components/EntitySaveDataBus.h>
#include <GraphCanvas/Types/EntitySaveData.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h>
namespace ScriptCanvasEditor
{
class EBusHandlerNodeDescriptorComponent
: public NodeDescriptorComponent
, public EBusHandlerNodeDescriptorRequestBus::Handler
, public GraphCanvas::WrapperNodeNotificationBus::Handler
, public GraphCanvas::GraphCanvasPropertyBusHandler
, public GraphCanvas::WrapperNodeConfigurationRequestBus::Handler
, public GraphCanvas::EntitySaveDataRequestBus::Handler
, public GraphCanvas::SceneMemberNotificationBus::Handler
{
public:
class EBusHandlerNodeDescriptorSaveData
: public GraphCanvas::ComponentSaveData
{
public:
AZ_RTTI(EBusHandlerNodeDescriptorSaveData, "{9E81C95F-89C0-4476-8E82-63CCC4E52E04}", GraphCanvas::ComponentSaveData);
AZ_CLASS_ALLOCATOR(EBusHandlerNodeDescriptorSaveData, AZ::SystemAllocator, 0);
EBusHandlerNodeDescriptorSaveData();
EBusHandlerNodeDescriptorSaveData(EBusHandlerNodeDescriptorComponent* component);
~EBusHandlerNodeDescriptorSaveData() = default;
void operator=(const EBusHandlerNodeDescriptorSaveData& other);
void OnDisplayConnectionsChanged();
bool m_displayConnections;
AZStd::vector< ScriptCanvas::EBusEventId > m_enabledEvents;
private:
EBusHandlerNodeDescriptorComponent* m_callback;
};
friend class EBusHandlerNodeDescriptorSaveData;
AZ_COMPONENT(EBusHandlerNodeDescriptorComponent, "{A93B4B22-DBB8-4F18-B741-EB041BFEA4F6}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
EBusHandlerNodeDescriptorComponent();
EBusHandlerNodeDescriptorComponent(const AZStd::string& busName);
~EBusHandlerNodeDescriptorComponent() = default;
void Activate() override;
void Deactivate() override;
// NodeNotifications
void OnNodeActivated() override;
////
// SceneMemberNotifications
void OnMemberSetupComplete() override;
void OnSceneMemberDeserialized(const AZ::EntityId& graphId, const GraphCanvas::GraphSerialization&) override;
////
// GraphCanvas::EntitySaveDataRequestBus::Handler
void WriteSaveData(GraphCanvas::EntitySaveDataContainer& saveDataContainer) const override;
void ReadSaveData(const GraphCanvas::EntitySaveDataContainer& saveDataContainer) override;
////
// EBusNodeDescriptorRequestBus
AZStd::string_view GetBusName() const override;
bool ContainsEvent(const ScriptCanvas::EBusEventId& eventId) const override;
GraphCanvas::WrappedNodeConfiguration GetEventConfiguration(const ScriptCanvas::EBusEventId& eventName) const override;
AZStd::vector< HandlerEventConfiguration > GetEventConfigurations() const override;
AZ::EntityId FindEventNodeId(const ScriptCanvas::EBusEventId& eventId) const override;
AZ::EntityId FindGraphCanvasNodeIdForSlot(const ScriptCanvas::SlotId& eventName) const override;
GraphCanvas::Endpoint MapSlotToGraphCanvasEndpoint(const ScriptCanvas::SlotId& eventName) const override;
////
// WrapperNodeNotificationBus
void OnWrappedNode(const AZ::EntityId& wrappedNode) override;
void OnUnwrappedNode(const AZ::EntityId& unwrappedNode) override;
////
// WrapperNodeConfigurationRequests
GraphCanvas::WrappedNodeConfiguration GetWrappedNodeConfiguration(const AZ::EntityId& wrappedNodeId) const override;
////
// GraphCanvasPropertyBus
AZ::Component* GetPropertyComponent() override;
////
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId);
private:
void OnDisplayConnectionsChanged();
EBusHandlerNodeDescriptorSaveData m_saveData;
AZStd::string m_busName;
bool m_loadingEvents;
AZ::EntityId m_scriptCanvasId;
AZStd::unordered_map< ScriptCanvas::EBusEventId, AZ::EntityId > m_eventTypeToId;
AZStd::unordered_map< AZ::EntityId, ScriptCanvas::EBusEventId > m_idToEventType;
};
}
@@ -0,0 +1,87 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
#include "EBusSenderNodeDescriptorComponent.h"
#include "Editor/Translation/TranslationHelper.h"
#include "ScriptCanvas/Libraries/Core/Method.h"
namespace ScriptCanvasEditor
{
//////////////////////////////////////
// EBusSenderNodeDescriptorComponent
//////////////////////////////////////
void EBusSenderNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<EBusSenderNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(2)
;
}
}
EBusSenderNodeDescriptorComponent::EBusSenderNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::EBusSender)
{
}
void EBusSenderNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const GraphCanvas::GraphId& sceneId, const AZ::EntityId& scriptCanvasNodeId)
{
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, scriptCanvasNodeId);
if (entity)
{
ScriptCanvas::Nodes::Core::Method* method = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::Method>(entity);
if (method)
{
if (method->HasBusID())
{
ScriptCanvas::SlotId slotId = method->GetBusSlotId();
AZStd::vector< AZ::EntityId > graphCanvasSlots;
GraphCanvas::NodeRequestBus::EventResult(graphCanvasSlots, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
for (const AZ::EntityId& graphCanvasId : graphCanvasSlots)
{
AZStd::any* slotData = nullptr;
GraphCanvas::SlotRequestBus::EventResult(slotData, graphCanvasId, &GraphCanvas::SlotRequests::GetUserData);
if (slotData
&& slotData->is< ScriptCanvas::SlotId >())
{
ScriptCanvas::SlotId currentSlotId = (*AZStd::any_cast<ScriptCanvas::SlotId>(slotData));
if (currentSlotId == slotId)
{
GraphCanvas::SlotRequestBus::Event(graphCanvasId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusSenderBusIdNameKey());
GraphCanvas::SlotRequestBus::Event(graphCanvasId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusSenderBusIdTooltipKey());
break;
}
}
}
}
}
}
}
}
@@ -0,0 +1,33 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include "Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h"
namespace ScriptCanvasEditor
{
class EBusSenderNodeDescriptorComponent
: public NodeDescriptorComponent
{
public:
AZ_COMPONENT(EBusSenderNodeDescriptorComponent, "{6B646A3A-CB7F-49C4-8146-D848F418E0B1}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
EBusSenderNodeDescriptorComponent();
~EBusSenderNodeDescriptorComponent() = default;
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId) override;
};
}
@@ -0,0 +1,131 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include "EntityRefNodeDescriptorComponent.h"
#include "ScriptCanvas/Core/Datum.h"
#include "ScriptCanvas/Core/PureData.h"
#include "ScriptCanvas/Core/Slot.h"
namespace ScriptCanvasEditor
{
/////////////////////////////////////
// EntityRefNodeDescriptorComponent
/////////////////////////////////////
void EntityRefNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<EntityRefNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(1)
;
}
}
EntityRefNodeDescriptorComponent::EntityRefNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::EntityRef)
{
}
void EntityRefNodeDescriptorComponent::OnEntityNameChanged([[maybe_unused]] const AZStd::string& name)
{
UpdateNodeTitle();
}
void EntityRefNodeDescriptorComponent::OnInputChanged(const ScriptCanvas::SlotId& slotId)
{
if (slotId == m_endpoint.GetSlotId())
{
AZ::EntityBus::Handler::BusDisconnect();
AZ::EntityId referencedId = GetReferencedEntityId();
if (referencedId.IsValid())
{
AZ::EntityBus::Handler::BusConnect(referencedId);
}
UpdateNodeTitle();
}
}
void EntityRefNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const GraphCanvas::GraphId& sceneId, const AZ::EntityId& scriptCanvasNodeId)
{
ScriptCanvas::SlotId scriptCanvasSlotId;
ScriptCanvas::NodeRequestBus::EventResult(scriptCanvasSlotId, scriptCanvasNodeId, &ScriptCanvas::NodeRequests::GetSlotId, ScriptCanvas::PureData::k_setThis);
m_endpoint = ScriptCanvas::Endpoint(scriptCanvasNodeId, scriptCanvasSlotId);
if (m_endpoint.IsValid())
{
AZ::EntityId referencedId = GetReferencedEntityId();
if (referencedId.IsValid())
{
AZ::EntityBus::Handler::BusConnect(referencedId);
}
}
UpdateNodeTitle();
}
AZ::EntityId EntityRefNodeDescriptorComponent::GetReferencedEntityId() const
{
AZ::EntityId retVal;
const ScriptCanvas::Datum* object = nullptr;
ScriptCanvas::NodeRequestBus::EventResult(object, m_endpoint.GetNodeId(), &ScriptCanvas::NodeRequests::FindDatum, m_endpoint.GetSlotId());
if (object && object->IS_A<AZ::EntityId>())
{
retVal = (*object->GetAs<AZ::EntityId>());
}
return retVal;
}
void EntityRefNodeDescriptorComponent::UpdateNodeTitle()
{
bool needsTitle = true;
if (m_endpoint.IsValid())
{
AZ::EntityId referencedId = GetReferencedEntityId();
AZStd::string entityName;
AZ::ComponentApplicationBus::BroadcastResult(entityName, &AZ::ComponentApplicationRequests::GetEntityName, referencedId);
if (!entityName.empty())
{
needsTitle = false;
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, entityName.c_str());
}
else if (referencedId.IsValid())
{
needsTitle = false;
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, referencedId.ToString().c_str());
}
}
if (needsTitle)
{
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, "<None>");
}
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetSubTitle, "EntityRef");
}
}
@@ -0,0 +1,53 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <AzCore/Component/EntityBus.h>
#include "Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h"
#include "ScriptCanvas/Core/NodeBus.h"
#include "ScriptCanvas/Core/Endpoint.h"
namespace ScriptCanvasEditor
{
class EntityRefNodeDescriptorComponent
: public NodeDescriptorComponent
, public AZ::EntityBus::Handler
{
public:
AZ_COMPONENT(EntityRefNodeDescriptorComponent, "{887AE9AC-C793-4FE5-BAE2-AF6A7F70A374}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
EntityRefNodeDescriptorComponent();
~EntityRefNodeDescriptorComponent() = default;
// AZ::EntityBus
void OnEntityNameChanged(const AZStd::string& name) override;
////
// ScriptCanvas::NodeNotificationsBus
void OnInputChanged(const ScriptCanvas::SlotId& slotId) override;
////
private:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId) override;
AZ::EntityId GetReferencedEntityId() const;
void UpdateNodeTitle();
ScriptCanvas::Endpoint m_endpoint;
};
}
@@ -0,0 +1,132 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include "FunctionNodeDescriptorComponent.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzToolsFramework/API/EditorAssetSystemAPI.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include <Editor/Assets/ScriptCanvasAssetHelpers.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/Include/ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <ScriptCanvas/Bus/RequestBus.h>
#include <ScriptCanvas/Libraries/Core/ScriptEventBase.h>
#include <ScriptCanvas/Libraries/Core/FunctionNode.h>
namespace ScriptCanvasEditor
{
/////////////////////////////////////////////
// FunctionNodeDescriptorComponent
/////////////////////////////////////////////
void FunctionNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<FunctionNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(1)
->Field("AssetId", &FunctionNodeDescriptorComponent::m_assetId)
;
}
}
FunctionNodeDescriptorComponent::FunctionNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::FunctionNode)
{
}
FunctionNodeDescriptorComponent::FunctionNodeDescriptorComponent(const AZ::Data::AssetId& assetId, const AZStd::string& name)
: NodeDescriptorComponent(NodeDescriptorType::FunctionNode)
, m_assetId(assetId)
, m_name(name)
{
}
void FunctionNodeDescriptorComponent::Activate()
{
NodeDescriptorComponent::Activate();
GraphCanvas::VisualNotificationBus::Handler::BusConnect(GetEntityId());
AZ::Data::AssetBus::Handler::BusConnect(m_assetId);
}
void FunctionNodeDescriptorComponent::Deactivate()
{
GraphCanvas::VisualNotificationBus::Handler::BusDisconnect();
AZ::Data::AssetBus::Handler::BusDisconnect();
}
void FunctionNodeDescriptorComponent::OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset)
{
AZ::EntityId graphCanvasGraphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphCanvasGraphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
ScriptCanvas::ScriptCanvasId scriptCanvasId;
GeneralRequestBus::BroadcastResult(scriptCanvasId, &GeneralRequests::GetScriptCanvasId, graphCanvasGraphId);
EditorGraphRequestBus::Event(scriptCanvasId, &EditorGraphRequests::QueueVersionUpdate, GetEntityId());
}
void FunctionNodeDescriptorComponent::OnVersionConversionEnd()
{
AZ::Data::Asset<ScriptCanvas::RuntimeFunctionAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptCanvas::RuntimeFunctionAsset>(m_assetId, AZ::Data::AssetLoadBehavior::Default);
asset.BlockUntilLoadComplete();
if (asset.IsReady())
{
//UpdateTitles();
// For reference:
//if (!asset.Get()->m_definition.HasMethod(m_eventId))
//{
// AZStd::unordered_set< AZ::EntityId > deleteNodes = { GetEntityId() };
// GraphCanvas::SceneRequestBus::Event(graphCanvasGraphId, &GraphCanvas::SceneRequests::Delete, deleteNodes);
//}
}
}
bool FunctionNodeDescriptorComponent::OnMouseDoubleClick(const QGraphicsSceneMouseEvent*)
{
AZ::Data::AssetInfo assetInfo = AssetHelpers::GetSourceInfoByProductId(m_assetId, azrtti_typeid< ScriptCanvas::RuntimeFunctionAsset>());
if (!assetInfo.m_assetId.IsValid())
{
return false;
}
AZ::Outcome<int, AZStd::string> openOutcome = AZ::Failure(AZStd::string());
GeneralRequestBus::BroadcastResult(openOutcome, &GeneralRequests::OpenScriptCanvasAsset, assetInfo.m_assetId, -1);
return openOutcome.IsSuccess();
}
void FunctionNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId)
{
m_scriptCanvasId = scriptCanvasNodeId;
EditorNodeNotificationBus::Handler::BusConnect(m_scriptCanvasId);
}
void FunctionNodeDescriptorComponent::UpdateTitles()
{
GraphCanvas::NodeRequestBus::Event(GetEntityId(), &GraphCanvas::NodeRequests::SetTooltip, m_name);
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, m_name);
}
}
@@ -0,0 +1,70 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <GraphCanvas/Components/VisualBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h>
#include <ScriptCanvas/Asset/Functions/ScriptCanvasFunctionAsset.h>
#include <ScriptCanvas/Bus/RequestBus.h>
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
namespace ScriptCanvasEditor
{
class FunctionNodeDescriptorComponent
: public NodeDescriptorComponent
, public AZ::Data::AssetBus::Handler
, public EditorNodeNotificationBus::Handler
, public GraphCanvas::VisualNotificationBus::Handler
{
public:
AZ_COMPONENT(FunctionNodeDescriptorComponent, "{B9DA0350-AF62-475E-8DD7-30E8F4F313BB}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
FunctionNodeDescriptorComponent();
FunctionNodeDescriptorComponent(const AZ::Data::AssetId& assetId, const AZStd::string& name);
~FunctionNodeDescriptorComponent() = default;
// Component
void Activate() override;
void Deactivate() override;
////
// AZ::Data::AssetBus::Handler
void OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
////
// VersionControlledNodeRequestBus::Handler
void OnVersionConversionEnd() override;
////
// GraphCanvas::NodeNotificationBus
bool OnMouseDoubleClick(const QGraphicsSceneMouseEvent*) override;
//
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId) override;
private:
void UpdateTitles();
AZ::EntityId m_scriptCanvasId;
AZ::Data::AssetId m_assetId;
AZStd::string m_name;
};
}
@@ -0,0 +1,57 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Component/ComponentApplicationBus.h>
#include <GraphCanvas/Components/Connections/ConnectionBus.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/GetVariableNodeDescriptorComponent.h>
#include <Editor/Include/ScriptCanvas/Bus/RequestBus.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/View/Widgets/PropertyGridBus.h>
#include <ScriptCanvas/Libraries/Core/GetVariable.h>
namespace ScriptCanvasEditor
{
///////////////////////////////////////
// GetVariableNodeDescriptorComponent
///////////////////////////////////////
void GetVariableNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<GetVariableNodeDescriptorComponent, VariableNodeDescriptorComponent>()
->Version(1)
;
}
}
GetVariableNodeDescriptorComponent::GetVariableNodeDescriptorComponent()
: VariableNodeDescriptorComponent(NodeDescriptorType::GetVariable)
{
}
void GetVariableNodeDescriptorComponent::UpdateTitle(AZStd::string_view variableName)
{
AZStd::string titleName = AZStd::string::format("Get %s", variableName.data());
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, titleName);
}
}
@@ -0,0 +1,33 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/VariableNodeDescriptorComponent.h>
#include <ScriptCanvas/Variable/VariableBus.h>
namespace ScriptCanvasEditor
{
class GetVariableNodeDescriptorComponent
: public VariableNodeDescriptorComponent
{
public:
AZ_COMPONENT(GetVariableNodeDescriptorComponent, "{78D946A9-4CC6-4BA7-A46A-A4C87191678D}", VariableNodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
GetVariableNodeDescriptorComponent();
protected:
void UpdateTitle(AZStd::string_view variableName) override;
};
}
@@ -0,0 +1,100 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <GraphCanvas/Components/SceneBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h>
namespace ScriptCanvasEditor
{
////////////////////////////
// NodeDescriptorComponent
////////////////////////////
void NodeDescriptorComponent::Reflect(AZ::ReflectContext* reflect)
{
if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflect))
{
serializeContext->Class<NodeDescriptorComponent, AZ::Component>()
->Version(0)
;
}
}
NodeDescriptorComponent::NodeDescriptorComponent()
: m_nodeDescriptorType(NodeDescriptorType::Unknown)
{
}
NodeDescriptorComponent::NodeDescriptorComponent(NodeDescriptorType descriptorType)
: m_nodeDescriptorType(descriptorType)
{
}
void NodeDescriptorComponent::Init()
{
}
void NodeDescriptorComponent::Activate()
{
NodeDescriptorRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::NodeNotificationBus::Handler::BusConnect(GetEntityId());
}
void NodeDescriptorComponent::Deactivate()
{
GraphCanvas::NodeNotificationBus::Handler::BusDisconnect();
NodeDescriptorRequestBus::Handler::BusDisconnect();
}
void NodeDescriptorComponent::OnAddedToScene(const AZ::EntityId& sceneId)
{
AZ::EntityId scriptCanvasNodeId = FindScriptCanvasNodeId();
ScriptCanvas::NodeNotificationsBus::Handler::BusConnect(scriptCanvasNodeId);
OnAddedToGraphCanvasGraph(sceneId, scriptCanvasNodeId);
bool isEnabled = true;
ScriptCanvas::NodeRequestBus::EventResult(isEnabled, scriptCanvasNodeId, &ScriptCanvas::NodeRequests::IsNodeEnabled);
if (!isEnabled)
{
GraphCanvas::GraphId graphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
GraphCanvas::SceneRequestBus::Event(graphId, &GraphCanvas::SceneRequests::Disable, GetEntityId());
}
}
void NodeDescriptorComponent::OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId)
{
AZ_UNUSED(graphId);
AZ_UNUSED(scriptCanvasNodeId);
}
AZ::EntityId NodeDescriptorComponent::FindScriptCanvasNodeId() const
{
AZStd::any* userData = nullptr;
GraphCanvas::NodeRequestBus::EventResult(userData, GetEntityId(), &GraphCanvas::NodeRequests::GetUserData);
AZ::EntityId* scNodeId = AZStd::any_cast<AZ::EntityId>(userData);
if (scNodeId)
{
return (*scNodeId);
}
return AZ::EntityId();
}
}
@@ -0,0 +1,62 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Component/Component.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <ScriptCanvas/Core/NodeBus.h>
#include <Editor/Include/ScriptCanvas/GraphCanvas/NodeDescriptorBus.h>
namespace ScriptCanvasEditor
{
class NodeDescriptorComponent
: public AZ::Component
, public GraphCanvas::NodeNotificationBus::Handler
, public ScriptCanvas::NodeNotificationsBus::Handler
, public NodeDescriptorRequestBus::Handler
{
public:
AZ_COMPONENT(NodeDescriptorComponent, "{C775A98E-D64E-457F-8ABA-B34CBAD10905}");
static void Reflect(AZ::ReflectContext* reflect);
NodeDescriptorComponent();
NodeDescriptorComponent(NodeDescriptorType descriptorType);
~NodeDescriptorComponent() override = default;
// Component
void Init();
void Activate();
void Deactivate();
////
// NodeDescriptorBus::Handler
NodeDescriptorType GetType() const override { return m_nodeDescriptorType; }
////
// GraphCanvas::NodeNotificationBus
void OnAddedToScene(const AZ::EntityId& sceneId) override final;
////
protected:
virtual void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId);
virtual AZ::EntityId FindScriptCanvasNodeId() const;
private:
NodeDescriptorType m_nodeDescriptorType;
};
}
@@ -0,0 +1,62 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include "NodelingDescriptorComponent.h"
#include <ScriptCanvas/Bus/RequestBus.h>
namespace ScriptCanvasEditor
{
////////////////////////////////
// NodelingDescriptorComponent
////////////////////////////////
void NodelingDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<NodelingDescriptorComponent, NodeDescriptorComponent>()
->Version(1)
;
}
}
NodelingDescriptorComponent::NodelingDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::ExecutionNodeling)
{
}
void NodelingDescriptorComponent::OnNameChanged(const AZStd::string& displayName)
{
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, displayName);
}
void NodelingDescriptorComponent::OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId)
{
ScriptCanvas::ScriptCanvasId scriptCanvasId;
GeneralRequestBus::BroadcastResult(scriptCanvasId, &GeneralRequests::GetScriptCanvasId, graphId);
ScriptCanvas::GraphScopedNodeId scopedNodeId(scriptCanvasId, scriptCanvasNodeId);
ScriptCanvas::NodelingNotificationBus::Handler::BusConnect(scopedNodeId);
AZStd::string displayName;
ScriptCanvas::NodelingRequestBus::EventResult(displayName, scopedNodeId, &ScriptCanvas::NodelingRequests::GetDisplayName);
OnNameChanged(displayName);
}
}
@@ -0,0 +1,40 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h>
#include <ScriptCanvas/Core/NodelingBus.h>
namespace ScriptCanvasEditor
{
class NodelingDescriptorComponent
: public NodeDescriptorComponent
, public ScriptCanvas::NodelingNotificationBus::Handler
{
public:
AZ_COMPONENT(NodelingDescriptorComponent, "{9EFA1DA5-2CCB-4A6D-AA84-BD121C75773A}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
NodelingDescriptorComponent();
~NodelingDescriptorComponent() = default;
// NodelingNotificationBus
void OnNameChanged(const AZStd::string& newName) override;
////
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId) override;
};
}
@@ -0,0 +1,391 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Component/ComponentApplicationBus.h>
#include <AzCore/Asset/AssetManager.h>
#include <GraphCanvas/Components/SceneBus.h>
#include <GraphCanvas/Components/GeometryBus.h>
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include <Editor/Nodes/NodeUtils.h>
#include <Editor/View/Widgets/NodePalette/EBusNodePaletteTreeItemTypes.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/View/Widgets/NodePalette/ScriptEventsNodePaletteTreeItemTypes.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/ScriptEventReceiverEventNodeDescriptorComponent.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include <ScriptCanvas/Bus/RequestBus.h>
#include <ScriptCanvas/Core/NodeBus.h>
#include <ScriptCanvas/GraphCanvas/MappingBus.h>
#include <ScriptCanvas/Libraries/Core/EBusEventHandler.h>
#include <ScriptCanvas/Libraries/Core/SendScriptEvent.h>
#include <Libraries/Core/ReceiveScriptEvent.h>
namespace ScriptCanvasEditor
{
////////////////////////////////////////////////////
// ScriptEventReceiverEventNodeDescriptorComponent
////////////////////////////////////////////////////
void ScriptEventReceiverEventNodeDescriptorComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<ScriptEventReceiverEventNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(3)
->Field("AssetId", &ScriptEventReceiverEventNodeDescriptorComponent::m_assetId)
->Field("BusName", &ScriptEventReceiverEventNodeDescriptorComponent::m_busName)
->Field("MethodDefinition", &ScriptEventReceiverEventNodeDescriptorComponent::m_methodDefinition)
->Field("EventName", &ScriptEventReceiverEventNodeDescriptorComponent::m_eventName)
->Field("EventId", &ScriptEventReceiverEventNodeDescriptorComponent::m_eventId)
->Field("EventPropertyId", &ScriptEventReceiverEventNodeDescriptorComponent::m_eventPropertyId)
;
}
}
ScriptEventReceiverEventNodeDescriptorComponent::ScriptEventReceiverEventNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::EBusHandlerEvent)
{
}
ScriptEventReceiverEventNodeDescriptorComponent::ScriptEventReceiverEventNodeDescriptorComponent(const AZ::Data::AssetId assetId, const ScriptEvents::Method& methodDefinition)
: NodeDescriptorComponent(NodeDescriptorType::EBusHandlerEvent)
, m_assetId(assetId)
, m_methodDefinition(methodDefinition)
{
m_eventName = m_methodDefinition.GetName();
m_eventId = m_methodDefinition.GetEventId();
m_eventPropertyId = m_methodDefinition.GetNameProperty().GetId();
}
void ScriptEventReceiverEventNodeDescriptorComponent::Activate()
{
NodeDescriptorComponent::Activate();
ScriptEventReceiverEventNodeDescriptorBus::Handler::BusConnect(GetEntityId());
EBusHandlerEventNodeDescriptorRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::ForcedWrappedNodeRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::SceneMemberNotificationBus::Handler::BusConnect(GetEntityId());
m_busId = AZ::Crc32(m_assetId.ToString<AZStd::string>().c_str());
}
void ScriptEventReceiverEventNodeDescriptorComponent::Deactivate()
{
NodeDescriptorComponent::Deactivate();
GraphCanvas::SceneMemberNotificationBus::Handler::BusDisconnect();
GraphCanvas::ForcedWrappedNodeRequestBus::Handler::BusDisconnect();
EBusHandlerEventNodeDescriptorRequestBus::Handler::BusDisconnect();
ScriptEventReceiverEventNodeDescriptorBus::Handler::BusDisconnect();
}
AZStd::string_view ScriptEventReceiverEventNodeDescriptorComponent::GetBusName() const
{
return m_busName;
}
AZStd::string_view ScriptEventReceiverEventNodeDescriptorComponent::GetEventName() const
{
return m_eventName;
}
ScriptCanvas::EBusEventId ScriptEventReceiverEventNodeDescriptorComponent::GetEventId() const
{
return m_eventId;
}
void ScriptEventReceiverEventNodeDescriptorComponent::SetHandlerAddress(const ScriptCanvas::Datum& idDatum)
{
if (m_ebusWrapper.m_scriptCanvasId.IsValid())
{
GraphCanvas::GraphId graphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
ScriptCanvas::ScriptCanvasId canvasId;
GeneralRequestBus::BroadcastResult(canvasId, &GeneralRequests::GetScriptCanvasId, graphId);
ScriptCanvas::GraphScopedNodeId scopedNodeId(canvasId, m_ebusWrapper.m_scriptCanvasId);
ScriptCanvas::EBusHandlerNodeRequestBus::Event(scopedNodeId, &ScriptCanvas::EBusHandlerNodeRequests::SetAddressId, AZStd::move(idDatum));
m_queuedId = AZStd::move(ScriptCanvas::Datum());
}
else
{
m_queuedId.DeepCopyDatum(idDatum);
}
}
void ScriptEventReceiverEventNodeDescriptorComponent::OnNodeWrapped(const AZ::EntityId& wrappingNode)
{
bool isValid = false;
AZStd::any* userData = nullptr;
GraphCanvas::NodeRequestBus::EventResult(userData, wrappingNode, &GraphCanvas::NodeRequests::GetUserData);
if (userData && userData->is<AZ::EntityId>())
{
AZ_Warning("ScriptCanvas", !m_ebusWrapper.m_graphCanvasId.IsValid() && !m_ebusWrapper.m_scriptCanvasId.IsValid(), "Wrapping the same ebus event node twice without unwrapping it.");
AZ::EntityId scriptCanvasId = (*AZStd::any_cast<AZ::EntityId>(userData));
m_ebusWrapper.m_graphCanvasId = wrappingNode;
m_ebusWrapper.m_scriptCanvasId = scriptCanvasId;
AZStd::string ebusContextName = TranslationHelper::GetEbusHandlerContext(m_busName);
ScriptCanvas::Nodes::Core::ReceiveScriptEvent* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::ReceiveScriptEvent>(scriptCanvasId);
if (eventHandler)
{
AZStd::vector< AZ::EntityId > graphCanvasSlotIds;
GraphCanvas::NodeRequestBus::EventResult(graphCanvasSlotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
const ScriptCanvas::Nodes::Core::SendScriptEvent::EventMap& events = eventHandler->GetEvents();
ScriptCanvas::Nodes::Core::Internal::ScriptEventEntry myEvent;
auto mapIter = events.find(m_eventId);
if (mapIter != events.end())
{
myEvent = mapIter->second;
}
const int numEventSlots = 1;
const int numResultSlots = myEvent.m_resultSlotId.IsValid() ? 1 : 0;
const int totalSlots = (myEvent.m_numExpectedArguments + numEventSlots + numResultSlots);
// Potentially overly simplistic way of detecting if we need to refresh our Slot information.
if (totalSlots != graphCanvasSlotIds.size())
{
// Remove the previous slots
for (const auto& graphCanvasSlotId : graphCanvasSlotIds)
{
GraphCanvas::NodeRequestBus::Event(GetEntityId(), &GraphCanvas::NodeRequests::RemoveSlot, graphCanvasSlotId);
}
// Then from a clean slate, fully regenerate all of our slots.
ScriptCanvas::Slot* scriptCanvasSlot = eventHandler->GetSlot(myEvent.m_eventSlotId);
if (scriptCanvasSlot)
{
AZ::EntityId slotId = Nodes::DisplayScriptCanvasSlot(GetEntityId(), (*scriptCanvasSlot));
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusHandlerOnEventTriggeredNameKey());
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusHandlerOnEventTriggeredTooltipKey());
}
//
// inputCount and outputCount work because the order of the slots is maintained from the BehaviorContext, if this changes
// in the future then we should consider storing the actual offset or key name at that time.
//
int inputCount = 0;
int outputCount = 0;
for (const auto& slotId : myEvent.m_parameterSlotIds)
{
scriptCanvasSlot = eventHandler->GetSlot(slotId);
if (scriptCanvasSlot)
{
AZ::EntityId graphCanvasSlotId = Nodes::DisplayScriptCanvasSlot(GetEntityId(), (*scriptCanvasSlot));
TranslationItemType itemType = TranslationHelper::GetItemType(scriptCanvasSlot->GetDescriptor());
GraphCanvas::TranslationKeyedString slotNameKeyedString(scriptCanvasSlot->GetName());
slotNameKeyedString.m_context = ebusContextName;
GraphCanvas::TranslationKeyedString slotTooltipKeyedString(scriptCanvasSlot->GetToolTip());
slotTooltipKeyedString.m_context = ebusContextName;
if (scriptCanvasSlot->GetDescriptor() == ScriptCanvas::SlotDescriptors::DataOut())
{
slotNameKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Name, outputCount);
slotTooltipKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Tooltip, outputCount);
++outputCount;
}
else
{
slotNameKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Name, inputCount);
slotTooltipKeyedString.m_key = TranslationHelper::GetEBusHandlerSlotKey(m_busName, m_eventName, itemType, TranslationKeyId::Tooltip, inputCount);
++inputCount;
}
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, slotNameKeyedString);
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, slotTooltipKeyedString);
}
}
if (myEvent.m_resultSlotId.IsValid())
{
scriptCanvasSlot = eventHandler->GetSlot(myEvent.m_resultSlotId);
if (scriptCanvasSlot)
{
AZ::EntityId graphCanvasSlotId = Nodes::DisplayScriptCanvasSlot(GetEntityId(), (*scriptCanvasSlot));
TranslationItemType itemType = TranslationHelper::GetItemType(scriptCanvasSlot->GetDescriptor());
GraphCanvas::TranslationKeyedString slotNameKeyedString(scriptCanvasSlot->GetName(), ebusContextName);
slotNameKeyedString.m_key = slotNameKeyedString.m_key = TranslationHelper::GetKey(TranslationContextGroup::EbusHandler, m_busName, m_eventName, itemType, TranslationKeyId::Name);
GraphCanvas::TranslationKeyedString slotTooltipKeyedString(TranslationHelper::GetSafeTypeName(scriptCanvasSlot->GetDataType()), ebusContextName);
slotTooltipKeyedString.m_key = TranslationHelper::GetKey(TranslationContextGroup::EbusHandler, m_busName, m_eventName, itemType, TranslationKeyId::Tooltip);
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, slotNameKeyedString);
GraphCanvas::SlotRequestBus::Event(graphCanvasSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, slotTooltipKeyedString);
}
}
GraphCanvas::NodeRequestBus::EventResult(graphCanvasSlotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
}
isValid = (totalSlots == graphCanvasSlotIds.size());
}
if (m_queuedId.GetType().IsValid())
{
SetHandlerAddress(m_queuedId);
}
}
if (!isValid)
{
AZ::EntityId sceneId;
GraphCanvas::SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
if (sceneId.IsValid())
{
AZStd::unordered_set<AZ::EntityId> deleteNodes;
deleteNodes.insert(GetEntityId());
GraphCanvas::SceneRequestBus::Event(sceneId, &GraphCanvas::SceneRequests::Delete, deleteNodes);
}
}
else
{
ScriptEventReceiveNodeDescriptorNotificationBus::Handler::BusConnect(wrappingNode);
}
}
void ScriptEventReceiverEventNodeDescriptorComponent::OnSceneMemberAboutToSerialize(GraphCanvas::GraphSerialization& sceneSerialization)
{
AZ::Entity* wrapperEntity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(wrapperEntity, &AZ::ComponentApplicationRequests::FindEntity, m_ebusWrapper.m_graphCanvasId);
if (wrapperEntity)
{
sceneSerialization.GetGraphData().m_nodes.insert(wrapperEntity);
}
}
void ScriptEventReceiverEventNodeDescriptorComponent::OnSceneMemberDeserialized([[maybe_unused]] const AZ::EntityId& graphId, [[maybe_unused]] const GraphCanvas::GraphSerialization& serializationTarget)
{
// Add in the asset bus hook up here if we want to ensure we get asset notifications post copy/paste
}
AZ::Crc32 ScriptEventReceiverEventNodeDescriptorComponent::GetWrapperType() const
{
return m_busId;
}
AZ::Crc32 ScriptEventReceiverEventNodeDescriptorComponent::GetIdentifier() const
{
return AZ::Crc32(m_eventName.c_str());
}
AZ::EntityId ScriptEventReceiverEventNodeDescriptorComponent::CreateWrapperNode(const AZ::EntityId& sceneId, const AZ::Vector2& nodePosition)
{
CreateScriptEventsHandlerMimeEvent createEbusMimeEvent(m_assetId, m_methodDefinition);
AZ::EntityId wrapperNode;
AZ::Vector2 dummyPosition = nodePosition;
if (createEbusMimeEvent.ExecuteEvent(nodePosition, dummyPosition, sceneId))
{
const NodeIdPair& nodePair = createEbusMimeEvent.GetCreatedPair();
wrapperNode = nodePair.m_graphCanvasId;
}
return wrapperNode;
}
void ScriptEventReceiverEventNodeDescriptorComponent::OnScriptEventReloaded(const AZ::Data::Asset<ScriptEvents::ScriptEventsAsset>& asset)
{
bool isValid = false;
ScriptEvents::ScriptEvent definition = asset.Get()->m_definition;
for (auto methodDefinition : definition.GetMethods())
{
if (methodDefinition.GetEventId() == m_eventId)
{
m_methodDefinition = methodDefinition;
isValid = true;
break;
}
}
if (isValid)
{
UpdateTitles();
}
else
{
AZ::EntityId graphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
// From this point on this element is garbage, so do not reference anything internal
AZStd::unordered_set< AZ::EntityId > deleteSet = { GetEntityId() };
GraphCanvas::SceneRequestBus::Event(graphId, &GraphCanvas::SceneRequests::Delete, deleteSet);
}
}
void ScriptEventReceiverEventNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const GraphCanvas::GraphId& grapphId, [[maybe_unused]] const AZ::EntityId& scriptCanvasNodeId)
{
AZStd::vector< AZ::EntityId > slotIds;
GraphCanvas::NodeRequestBus::EventResult(slotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
for (const auto& slotId : slotIds)
{
GraphCanvas::SlotType slotType;
GraphCanvas::SlotRequestBus::EventResult(slotType, slotId, &GraphCanvas::SlotRequests::GetSlotType);
if (slotType == GraphCanvas::SlotTypes::ExecutionSlot)
{
GraphCanvas::ConnectionType connectionType = GraphCanvas::ConnectionType::CT_None;
GraphCanvas::SlotRequestBus::EventResult(connectionType, slotId, &GraphCanvas::SlotRequests::GetConnectionType);
if (connectionType == GraphCanvas::ConnectionType::CT_Output)
{
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusHandlerOnEventTriggeredNameKey());
GraphCanvas::SlotRequestBus::Event(slotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusHandlerOnEventTriggeredTooltipKey());
break;
}
}
}
UpdateTitles();
}
void ScriptEventReceiverEventNodeDescriptorComponent::UpdateTitles()
{
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, m_methodDefinition.GetName());
GraphCanvas::NodeRequestBus::Event(GetEntityId(), &GraphCanvas::NodeRequests::SetTooltip, m_methodDefinition.GetTooltip());
}
}
@@ -0,0 +1,106 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <GraphCanvas/Components/SceneBus.h>
#include "Editor/Include/ScriptCanvas/Bus/NodeIdPair.h"
#include "Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h"
#include <ScriptEvents/ScriptEventsAssetRef.h>
namespace ScriptCanvasEditor
{
class ScriptEventReceiverEventNodeDescriptorComponent
: public NodeDescriptorComponent
, protected GraphCanvas::SceneMemberNotificationBus::Handler
, protected ScriptEventReceiverEventNodeDescriptorBus::Handler
, public EBusHandlerEventNodeDescriptorRequestBus::Handler
, public GraphCanvas::ForcedWrappedNodeRequestBus::Handler
, public ScriptEventReceiveNodeDescriptorNotificationBus::Handler
{
public:
AZ_COMPONENT(ScriptEventReceiverEventNodeDescriptorComponent, "{EFC9CCCE-32FC-466F-AA29-2EEE1320FF4F}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
ScriptEventReceiverEventNodeDescriptorComponent();
ScriptEventReceiverEventNodeDescriptorComponent(const AZ::Data::AssetId assetId, const ScriptEvents::Method& methodDefinition);
~ScriptEventReceiverEventNodeDescriptorComponent() = default;
void Activate() override;
void Deactivate() override;
// EBusHandlerEventNodeDescriptorRequestBus
AZStd::string_view GetBusName() const override;
AZStd::string_view GetEventName() const override;
ScriptCanvas::EBusEventId GetEventId() const override;
void SetHandlerAddress(const ScriptCanvas::Datum& idDatum) override;
////
// NodeNotificationBus::Handler
void OnNodeWrapped(const AZ::EntityId& wrappingNode) override;
////
// SceneMemberNotifications
void OnSceneMemberAboutToSerialize(GraphCanvas::GraphSerialization& graphSerialization) override;
void OnSceneMemberDeserialized(const AZ::EntityId& graphId, const GraphCanvas::GraphSerialization& serializationTarget) override;
////
// ScriptEventSenderNodeDescriptorBus::Handler
const ScriptEvents::Method& GetMethodDefinition() override
{
return m_methodDefinition;
}
AZStd::string GetEventName() override
{
return m_eventName;
}
////
// ForcedWrappedNodeRequestBus
AZ::Crc32 GetWrapperType() const override;
AZ::Crc32 GetIdentifier() const override;
AZ::EntityId CreateWrapperNode(const AZ::EntityId& sceneId, const AZ::Vector2& nodePosition) override;
////
// ScriptEventReceiveNodeDescriptorNotifications
void OnScriptEventReloaded(const AZ::Data::Asset<ScriptEvents::ScriptEventsAsset>& asset);
////
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& grapphId, const AZ::EntityId& scriptCanvasNodeId) override;
private:
void UpdateTitles();
NodeIdPair m_ebusWrapper;
AZ::Data::AssetId m_assetId;
ScriptEvents::Method m_methodDefinition;
ScriptCanvas::EBusEventId m_eventId;
// These are required for reconstructing the node (i.e. copy/paste)
AZStd::string m_busName;
AZ::Crc32 m_busId;
AZStd::string m_eventName;
AZ::Uuid m_eventPropertyId;
ScriptCanvas::Datum m_queuedId;
};
}
@@ -0,0 +1,640 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Asset/AssetManager.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Serialization/EditContext.h>
#include <QString>
#include <GraphCanvas/Components/SceneBus.h>
#include <GraphCanvas/Components/Slots/Data/DataSlotBus.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/ScriptEventReceiverNodeDescriptorComponent.h>
#include <Editor/GraphCanvas/PropertySlotIds.h>
#include <Editor/Include/ScriptCanvas/Bus/RequestBus.h>
#include <Editor/Include/ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/Nodes/NodeUtils.h>
#include <Editor/View/Widgets/NodePalette/ScriptEventsNodePaletteTreeItemTypes.h>
#include <Editor/View/Widgets/PropertyGridBus.h>
#include <ScriptCanvas/Libraries/Core/SendScriptEvent.h>
#include <ScriptCanvas/Libraries/Core/ReceiveScriptEvent.h>
#include <ScriptCanvas/GraphCanvas/DynamicSlotBus.h>
#include <ScriptCanvas/GraphCanvas/MappingBus.h>
#include <AzCore/Math/Crc.h>
#include <ScriptCanvas/Libraries/Core/ScriptEventBase.h>
namespace ScriptCanvasEditor
{
/////////////////////////////////////////////////////
// ScriptEventReceiverHandlerNodeDescriptorSaveData
/////////////////////////////////////////////////////
ScriptEventReceiverNodeDescriptorComponent::ScriptEventReceiverHandlerNodeDescriptorSaveData::ScriptEventReceiverHandlerNodeDescriptorSaveData()
: m_displayConnections(false)
, m_callback(nullptr)
{
}
ScriptEventReceiverNodeDescriptorComponent::ScriptEventReceiverHandlerNodeDescriptorSaveData::ScriptEventReceiverHandlerNodeDescriptorSaveData(ScriptEventReceiverNodeDescriptorComponent* component)
: m_displayConnections(false)
, m_callback(component)
{
}
void ScriptEventReceiverNodeDescriptorComponent::ScriptEventReceiverHandlerNodeDescriptorSaveData::operator=(const ScriptEventReceiverHandlerNodeDescriptorSaveData& other)
{
// Purposefully skipping over the callback
m_displayConnections = other.m_displayConnections;
m_enabledEvents = other.m_enabledEvents;
}
void ScriptEventReceiverNodeDescriptorComponent::ScriptEventReceiverHandlerNodeDescriptorSaveData::OnDisplayConnectionsChanged()
{
if (m_callback)
{
m_callback->OnDisplayConnectionsChanged();
SignalDirty();
}
}
///////////////////////////////////////////////
// ScriptEventReceiverNodeDescriptorComponent
///////////////////////////////////////////////
void ScriptEventReceiverNodeDescriptorComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (serializeContext)
{
serializeContext->Class<ScriptEventReceiverHandlerNodeDescriptorSaveData, GraphCanvas::ComponentSaveData>()
->Version(2)
->Field("DisplayConnections", &ScriptEventReceiverHandlerNodeDescriptorSaveData::m_displayConnections)
->Field("EventNames", &ScriptEventReceiverHandlerNodeDescriptorSaveData::m_enabledEvents)
;
serializeContext->Class<ScriptEventReceiverNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(3)
->Field("AssetId", &ScriptEventReceiverNodeDescriptorComponent::m_scriptEventsAssetId)
->Field("SaveData", &ScriptEventReceiverNodeDescriptorComponent::m_saveData)
;
AZ::EditContext* editContext = serializeContext->GetEditContext();
if (editContext)
{
editContext->Class<ScriptEventReceiverHandlerNodeDescriptorSaveData>("SaveData", "")
->ClassElement(AZ::Edit::ClassElements::EditorData, "Properties")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &ScriptEventReceiverHandlerNodeDescriptorSaveData::m_displayConnections, "Display Connection Controls", "Controls whether or not manual connection controls are visible for this node.")
->Attribute(AZ::Edit::Attributes::ChangeNotify, &ScriptEventReceiverHandlerNodeDescriptorSaveData::OnDisplayConnectionsChanged)
;
editContext->Class<ScriptEventReceiverNodeDescriptorComponent>("Script Event Handler", "Configuration values for the Script Event Receiver node.")
->ClassElement(AZ::Edit::ClassElements::EditorData, "Properties")
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
->DataElement(AZ::Edit::UIHandlers::Default, &ScriptEventReceiverNodeDescriptorComponent::m_saveData, "SaveData", "The modifiable information about this comment.")
->DataElement(AZ::Edit::UIHandlers::Default, &ScriptEventReceiverNodeDescriptorComponent::m_scriptEventsAssetId, "Asset Id", "The Script Event Asset Id to use.")
;
}
}
}
ScriptEventReceiverNodeDescriptorComponent::ScriptEventReceiverNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::EBusHandler)
, m_saveData(this)
, m_loadingEvents(false)
{
}
ScriptEventReceiverNodeDescriptorComponent::ScriptEventReceiverNodeDescriptorComponent(AZ::Data::AssetId assetId)
: NodeDescriptorComponent(NodeDescriptorType::EBusHandler)
, m_saveData(this)
, m_scriptEventsAssetId(assetId)
, m_loadingEvents(false)
{
}
void ScriptEventReceiverNodeDescriptorComponent::Activate()
{
NodeDescriptorComponent::Activate();
EBusHandlerNodeDescriptorRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::WrapperNodeNotificationBus::Handler::BusConnect(GetEntityId());
GraphCanvas::GraphCanvasPropertyBusHandler::OnActivate(GetEntityId());
GraphCanvas::WrapperNodeConfigurationRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::EntitySaveDataRequestBus::Handler::BusConnect(GetEntityId());
GraphCanvas::SceneMemberNotificationBus::Handler::BusConnect(GetEntityId());
ScriptEventReceiverNodeDescriptorRequestBus::Handler::BusConnect(GetEntityId());
m_busId = AZ::Crc32(m_scriptEventsAssetId.ToString<AZStd::string>().c_str());
AZ::Data::AssetBus::Handler::BusConnect(m_scriptEventsAssetId);
}
void ScriptEventReceiverNodeDescriptorComponent::Deactivate()
{
NodeDescriptorComponent::Deactivate();
AZ::Data::AssetBus::Handler::BusDisconnect();
ScriptEventReceiverNodeDescriptorRequestBus::Handler::BusDisconnect();
GraphCanvas::SceneMemberNotificationBus::Handler::BusDisconnect();
GraphCanvas::EntitySaveDataRequestBus::Handler::BusDisconnect();
GraphCanvas::WrapperNodeConfigurationRequestBus::Handler::BusDisconnect();
GraphCanvas::GraphCanvasPropertyBusHandler::OnDeactivate();
GraphCanvas::WrapperNodeNotificationBus::Handler::BusDisconnect();
EBusHandlerNodeDescriptorRequestBus::Handler::BusDisconnect();
}
void ScriptEventReceiverNodeDescriptorComponent::OnNodeActivated()
{
GraphCanvas::WrapperNodeRequestBus::Event(GetEntityId(), &GraphCanvas::WrapperNodeRequests::SetWrapperType, m_busId);
}
void ScriptEventReceiverNodeDescriptorComponent::OnMemberSetupComplete()
{
m_loadingEvents = true;
AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(m_scriptEventsAssetId, AZ::Data::AssetLoadBehavior::Default);
AZ_Assert(asset.IsReady(), "ScriptEventsAsset is not ready");
AZ::EntityId graphCanvasGraphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphCanvasGraphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
ScriptEvents::ScriptEventsAsset* scriptEvent = asset.GetAs<ScriptEvents::ScriptEventsAsset>();
m_busName = scriptEvent->m_definition.GetName();
for (const auto& eventId : m_saveData.m_enabledEvents)
{
if (m_eventTypeToId.find(eventId.first) == m_eventTypeToId.end())
{
AZ::EntityId internalNode;
for (auto& method : scriptEvent->m_definition.GetMethods())
{
if (eventId.first == method.GetEventId())
{
internalNode = Nodes::DisplayScriptEventNode(graphCanvasGraphId, m_scriptEventsAssetId, method);
break;
}
}
if (internalNode.IsValid())
{
GraphCanvas::SceneRequestBus::Event(graphCanvasGraphId, &GraphCanvas::SceneRequests::Add, internalNode);
GraphCanvas::WrappedNodeConfiguration configuration = GetEventConfiguration(eventId.first);
GraphCanvas::WrapperNodeRequestBus::Event(GetEntityId(), &GraphCanvas::WrapperNodeRequests::WrapNode, internalNode, configuration);
}
}
}
m_loadingEvents = false;
m_saveData.RegisterIds(GetEntityId(), graphCanvasGraphId);
}
void ScriptEventReceiverNodeDescriptorComponent::OnSceneMemberDeserialized(const AZ::EntityId&, const GraphCanvas::GraphSerialization&)
{
m_saveData.m_enabledEvents.clear();
AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(m_scriptEventsAssetId, AZ::Data::AssetLoadBehavior::Default);
}
void ScriptEventReceiverNodeDescriptorComponent::WriteSaveData(GraphCanvas::EntitySaveDataContainer& saveDataContainer) const
{
ScriptEventReceiverHandlerNodeDescriptorSaveData* saveData = saveDataContainer.FindCreateSaveData<ScriptEventReceiverHandlerNodeDescriptorSaveData>();
if (saveData)
{
(*saveData) = m_saveData;
}
}
void ScriptEventReceiverNodeDescriptorComponent::ReadSaveData(const GraphCanvas::EntitySaveDataContainer& saveDataContainer)
{
const ScriptEventReceiverHandlerNodeDescriptorSaveData* saveData = saveDataContainer.FindSaveDataAs<ScriptEventReceiverHandlerNodeDescriptorSaveData>();
if (saveData)
{
m_saveData = (*saveData);
}
}
AZ::Data::AssetId ScriptEventReceiverNodeDescriptorComponent::GetAssetId() const
{
return m_scriptEventsAssetId;
}
AZStd::string_view ScriptEventReceiverNodeDescriptorComponent::GetBusName() const
{
return m_busName;
}
GraphCanvas::WrappedNodeConfiguration ScriptEventReceiverNodeDescriptorComponent::GetEventConfiguration(const ScriptCanvas::EBusEventId& eventId) const
{
AZ_Warning("ScriptCanvas", m_scriptCanvasId.IsValid(), "Trying to query event list before the node is added to the scene.");
GraphCanvas::WrappedNodeConfiguration wrappedConfiguration;
ScriptCanvas::Nodes::Core::ReceiveScriptEvent* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::ReceiveScriptEvent>(m_scriptCanvasId);
if (eventHandler)
{
const ScriptCanvas::Nodes::Core::Internal::ScriptEventBase::EventMap& events = eventHandler->GetEvents();
AZ::u32 i = 0;
for (const auto& event : events)
{
if (event.first == eventId)
{
wrappedConfiguration.m_layoutOrder = i;
break;
}
++i;
}
}
return wrappedConfiguration;
}
AZStd::vector< HandlerEventConfiguration > ScriptEventReceiverNodeDescriptorComponent::GetEventConfigurations() const
{
AZStd::vector< HandlerEventConfiguration > configurations;
AZ_Warning("ScriptCanvas", m_scriptCanvasId.IsValid(), "Trying to query event list before the node is added to the scene.");
ScriptCanvas::Nodes::Core::ReceiveScriptEvent* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::ReceiveScriptEvent>(m_scriptCanvasId);
if (eventHandler)
{
for (auto& event : eventHandler->GetEvents())
{
HandlerEventConfiguration configuration;
configuration.m_eventId = event.first;
configuration.m_eventName = event.second.m_eventName;
configurations.emplace_back(configuration);
}
}
return configurations;
}
bool ScriptEventReceiverNodeDescriptorComponent::ContainsEvent(const ScriptCanvas::EBusEventId& eventId) const
{
return m_eventTypeToId.count(eventId) != 0;
}
AZ::EntityId ScriptEventReceiverNodeDescriptorComponent::FindEventNodeId(const ScriptCanvas::EBusEventId& eventId) const
{
auto eventTypeEntry = m_eventTypeToId.find(eventId);
if (eventTypeEntry != m_eventTypeToId.end())
{
return eventTypeEntry->second;
}
return AZ::EntityId();
}
AZ::EntityId ScriptEventReceiverNodeDescriptorComponent::FindGraphCanvasNodeIdForSlot(const ScriptCanvas::SlotId& slotId) const
{
ScriptCanvas::Nodes::Core::ReceiveScriptEvent* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::ReceiveScriptEvent>(m_scriptCanvasId);
if (eventHandler)
{
auto nonEventSlotIds = eventHandler->GetNonEventSlotIds();
bool isNonEventSlot = (AZStd::find(nonEventSlotIds.begin(), nonEventSlotIds.end(), slotId) != nonEventSlotIds.end());
if (isNonEventSlot)
{
return GetEntityId();
}
auto scriptEvents = eventHandler->GetEvents();
ScriptCanvas::EBusEventId foundEventId = ScriptCanvas::EBusEventId();
for (auto scriptEventPair : scriptEvents)
{
const auto& scriptEvent = scriptEventPair.second;
bool foundResult = scriptEvent.m_eventSlotId == slotId;
foundResult = foundResult || scriptEvent.m_resultSlotId == slotId;
foundResult = foundResult || (AZStd::find(scriptEvent.m_parameterSlotIds.begin(), scriptEvent.m_parameterSlotIds.end(), slotId) != scriptEvent.m_parameterSlotIds.end());
if (foundResult)
{
foundEventId = scriptEventPair.first;
break;
}
}
if (foundEventId != ScriptCanvas::EBusEventId())
{
return FindEventNodeId(foundEventId);
}
}
return AZ::EntityId();
}
GraphCanvas::Endpoint ScriptEventReceiverNodeDescriptorComponent::MapSlotToGraphCanvasEndpoint(const ScriptCanvas::SlotId& scriptCanvasSlotId) const
{
GraphCanvas::Endpoint endpoint;
AZ::EntityId graphCanvasSlotId;
SlotMappingRequestBus::EventResult(graphCanvasSlotId, GetEntityId(), &SlotMappingRequests::MapToGraphCanvasId, scriptCanvasSlotId);
if (!graphCanvasSlotId.IsValid())
{
for (auto& mapPair : m_eventTypeToId)
{
AZ::EntityId graphCanvasSlotId2;
SlotMappingRequestBus::EventResult(graphCanvasSlotId2, mapPair.second, &SlotMappingRequests::MapToGraphCanvasId, scriptCanvasSlotId);
if (graphCanvasSlotId2.IsValid())
{
endpoint = GraphCanvas::Endpoint(mapPair.second, graphCanvasSlotId2);
break;
}
}
}
else
{
endpoint = GraphCanvas::Endpoint(GetEntityId(), graphCanvasSlotId);
}
return endpoint;
}
void ScriptEventReceiverNodeDescriptorComponent::OnWrappedNode(const AZ::EntityId& wrappedNode)
{
AZStd::string eventName;
ScriptEventReceiverEventNodeDescriptorBus::EventResult(eventName, wrappedNode, &ScriptEventReceiverEventNodeDescriptorRequests::GetEventName);
ScriptCanvas::EBusEventId eventId;
EBusHandlerEventNodeDescriptorRequestBus::EventResult(eventId, wrappedNode, &EBusHandlerEventNodeDescriptorRequests::GetEventId);
auto emplaceResult = m_eventTypeToId.emplace(eventId, wrappedNode);
if (emplaceResult.second)
{
m_idToEventType.emplace(wrappedNode, eventId);
AZStd::any* userData = nullptr;
GraphCanvas::NodeRequestBus::EventResult(userData, wrappedNode, &GraphCanvas::NodeRequests::GetUserData);
if (userData)
{
(*userData) = m_scriptCanvasId;
DynamicSlotRequestBus::Event(wrappedNode, &DynamicSlotRequests::OnUserDataChanged);
GraphCanvas::NodeDataSlotRequestBus::Event(wrappedNode, &GraphCanvas::NodeDataSlotRequests::RecreatePropertyDisplay);
}
if (!m_loadingEvents)
{
m_saveData.m_enabledEvents.push_back(AZStd::make_pair(eventId, eventName));
m_saveData.SignalDirty();
}
}
// If we are wrapping the same node twice for just ignore it and log a message
else if (emplaceResult.first->second != wrappedNode)
{
AZ_Error("ScriptCanvas", false, "Trying to wrap two identically named methods under the same EBus Handler. Deleting the second node.");
AZ::EntityId sceneId;
GraphCanvas::SceneMemberRequestBus::EventResult(sceneId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
AZStd::unordered_set<AZ::EntityId> deleteNodes;
deleteNodes.insert(wrappedNode);
GraphCanvas::SceneRequestBus::Event(sceneId, &GraphCanvas::SceneRequests::Delete, deleteNodes);
}
else
{
AZ_Warning("ScriptCanvas", false, "Trying to wrap the same node twice.");
}
}
void ScriptEventReceiverNodeDescriptorComponent::OnUnwrappedNode(const AZ::EntityId& unwrappedNode)
{
auto iter = m_idToEventType.find(unwrappedNode);
if (iter != m_idToEventType.end())
{
ScriptCanvas::EBusEventId eventId = iter->second;
m_eventTypeToId.erase(iter->second);
m_idToEventType.erase(iter);
for (auto eventIter = m_saveData.m_enabledEvents.begin(); eventIter != m_saveData.m_enabledEvents.end(); ++eventIter)
{
if (eventIter->first == eventId)
{
m_saveData.m_enabledEvents.erase(eventIter);
m_saveData.SignalDirty();
break;
}
}
}
}
GraphCanvas::WrappedNodeConfiguration ScriptEventReceiverNodeDescriptorComponent::GetWrappedNodeConfiguration(const AZ::EntityId& wrappedNodeId) const
{
ScriptEvents::Method methodDefinition;
ScriptEventReceiverEventNodeDescriptorBus::EventResult(methodDefinition, wrappedNodeId, &ScriptEventReceiverEventNodeDescriptorRequests::GetMethodDefinition);
if (methodDefinition.GetName().empty())
{
return GraphCanvas::WrappedNodeConfiguration();
}
else
{
return GetEventConfiguration(AZ::Crc32(methodDefinition.GetNameProperty().GetId().ToString<AZStd::string>().c_str()));
}
}
AZ::Component* ScriptEventReceiverNodeDescriptorComponent::GetPropertyComponent()
{
return this;
}
void ScriptEventReceiverNodeDescriptorComponent::OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset)
{
AZ::EntityId graphCanvasGraphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphCanvasGraphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
ScriptCanvas::ScriptCanvasId scriptCanvasId;
GeneralRequestBus::BroadcastResult(scriptCanvasId, &GeneralRequests::GetScriptCanvasId, graphCanvasGraphId);
EditorGraphRequestBus::Event(scriptCanvasId, &EditorGraphRequests::QueueVersionUpdate, GetEntityId());
}
void ScriptEventReceiverNodeDescriptorComponent::OnVersionConversionBegin()
{
DynamicSlotRequestBus::Event(GetEntityId(), &DynamicSlotRequests::StartQueueSlotUpdates);
}
void ScriptEventReceiverNodeDescriptorComponent::OnVersionConversionEnd()
{
AZ::EntityId graphCanvasGraphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphCanvasGraphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
ScriptCanvas::ScriptCanvasId scriptCanvasId;
GeneralRequestBus::BroadcastResult(scriptCanvasId, &GeneralRequests::GetScriptCanvasId, graphCanvasGraphId);
AZStd::vector< GraphCanvas::NodeId > wrappedNodes;
GraphCanvas::WrapperNodeRequestBus::EventResult(wrappedNodes, GetEntityId(), &GraphCanvas::WrapperNodeRequests::GetWrappedNodeIds);
AZStd::unordered_set< AZ::EntityId > deletedNodes;
deletedNodes.insert(wrappedNodes.begin(), wrappedNodes.end());
AZStd::vector<AZStd::pair<ScriptCanvas::EBusEventId, AZStd::string>> enabledEvents = m_saveData.m_enabledEvents;
GraphCanvas::SceneRequestBus::Event(graphCanvasGraphId, &GraphCanvas::SceneRequests::Delete, deletedNodes);
AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(m_scriptEventsAssetId, AZ::Data::AssetLoadBehavior::Default);
asset.BlockUntilLoadComplete();
AZ_Error("ScriptCanvas", asset.IsReady(), "Trying to work on asset that isn't ready after a blocking load.");
UpdateTitles(asset);
ScriptEventReceiveNodeDescriptorNotificationBus::Event(GetEntityId(), &ScriptEventReceiveNodeDescriptorNotifications::OnScriptEventReloaded, asset);
const ScriptEvents::ScriptEvent& definition = asset.Get()->m_definition;
for (auto eventToRecreate : enabledEvents)
{
ScriptEvents::Method outMethod;
if (definition.FindMethod(eventToRecreate.first, outMethod))
{
AZ::EntityId graphCanvasNodeId = Nodes::DisplayScriptEventNode(graphCanvasGraphId, m_scriptEventsAssetId, outMethod);
if (graphCanvasNodeId.IsValid())
{
GraphCanvas::SceneRequestBus::Event(graphCanvasGraphId, &GraphCanvas::SceneRequests::Add, graphCanvasNodeId);
GraphCanvas::WrappedNodeConfiguration configuration = GetWrappedNodeConfiguration(graphCanvasNodeId);
GraphCanvas::WrapperNodeRequestBus::Event(GetEntityId(), &GraphCanvas::WrapperNodeRequests::WrapNode, graphCanvasNodeId, configuration);
}
}
}
DynamicSlotRequestBus::Event(GetEntityId(), &DynamicSlotRequests::StopQueueSlotUpdates);
}
void ScriptEventReceiverNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId)
{
m_scriptCanvasId = scriptCanvasNodeId;
GraphCanvas::WrapperNodeRequestBus::Event(GetEntityId(), &GraphCanvas::WrapperNodeRequests::SetActionString, "Add/Remove Events");
GraphCanvas::SlotLayoutRequestBus::Event(GetEntityId(), &GraphCanvas::SlotLayoutRequests::SetSlotGroupVisible, SlotGroups::EBusConnectionSlotGroup, m_saveData.m_displayConnections);
if (m_scriptCanvasId.IsValid())
{
EditorNodeNotificationBus::Handler::BusConnect(m_scriptCanvasId);
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationRequests::FindEntity, m_scriptCanvasId);
if (entity)
{
ScriptCanvas::Nodes::Core::ReceiveScriptEvent* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::ReceiveScriptEvent>(entity);
if (eventHandler && eventHandler->IsIDRequired())
{
AZStd::vector< AZ::EntityId > slotIds;
GraphCanvas::NodeRequestBus::EventResult(slotIds, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
// Should be exactly one data slot on ourselves. And that is the BusId
for (const AZ::EntityId& testSlotId : slotIds)
{
GraphCanvas::SlotType slotType;
GraphCanvas::SlotRequestBus::EventResult(slotType, testSlotId, &GraphCanvas::SlotRequests::GetSlotType);
if (slotType == GraphCanvas::SlotTypes::DataSlot)
{
GraphCanvas::SlotRequestBus::Event(testSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusHandlerBusIdNameKey());
GraphCanvas::SlotRequestBus::Event(testSlotId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusHandlerBusIdTooltipKey());
break;
}
}
}
}
}
AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(m_scriptEventsAssetId, AZ::Data::AssetLoadBehavior::Default);
asset.BlockUntilLoadComplete();
if (asset.IsReady())
{
UpdateTitles(asset);
}
}
void ScriptEventReceiverNodeDescriptorComponent::OnDisplayConnectionsChanged()
{
AZ::Entity* entity = nullptr;
AZ::ComponentApplicationBus::BroadcastResult(entity, &AZ::ComponentApplicationBus::Events::FindEntity, m_scriptCanvasId);
if (entity)
{
ScriptCanvas::Nodes::Core::ReceiveScriptEvent* eventHandler = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::ReceiveScriptEvent>(entity);
if (eventHandler)
{
// If we are hiding the connections, we need to confirm that
// everything will be ok(i.e. no active connections)
if (!m_saveData.m_displayConnections)
{
AZStd::vector< ScriptCanvas::SlotId > scriptCanvasSlots = eventHandler->GetNonEventSlotIds();
bool allowChange = true;
for (const auto& slotId : scriptCanvasSlots)
{
ScriptCanvas::Slot* slot = eventHandler->GetSlot(slotId);
if (slot->IsExecution() && eventHandler->IsConnected((*slot)))
{
allowChange = false;
break;
}
}
if (!allowChange)
{
AZ_Warning("Script Canvas", false, "Cannot hide EBus Connection Controls because one ore more slots are currently connected. Please disconnect all slots to hide.");
m_saveData.m_displayConnections = true;
PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RefreshPropertyGrid);
}
}
eventHandler->SetAutoConnectToGraphOwner(!m_saveData.m_displayConnections);
}
}
GraphCanvas::SlotLayoutRequestBus::Event(GetEntityId(), &GraphCanvas::SlotLayoutRequests::SetSlotGroupVisible, SlotGroups::EBusConnectionSlotGroup, m_saveData.m_displayConnections);
}
void ScriptEventReceiverNodeDescriptorComponent::UpdateTitles(const AZ::Data::Asset<ScriptEvents::ScriptEventsAsset>& asset)
{
if (asset.IsReady())
{
const ScriptEvents::ScriptEvent& definition = asset.Get()->m_definition;
GraphCanvas::NodeRequestBus::Event(GetEntityId(), &GraphCanvas::NodeRequests::SetTooltip, definition.GetTooltip());
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, definition.GetName());
}
}
}
@@ -0,0 +1,154 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <GraphCanvas/Components/Nodes/Wrapper/WrapperNodeBus.h>
#include <GraphCanvas/Components/GraphCanvasPropertyBus.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
#include <GraphCanvas/Components/EntitySaveDataBus.h>
#include <GraphCanvas/Types/EntitySaveData.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h>
#include <ScriptEvents/ScriptEventsAsset.h>
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
namespace ScriptCanvasEditor
{
class ScriptEventReceiverNodeDescriptorComponent
: public NodeDescriptorComponent
, public EBusHandlerNodeDescriptorRequestBus::Handler
, public ScriptEventReceiverNodeDescriptorRequestBus::Handler
, public GraphCanvas::WrapperNodeNotificationBus::Handler
, public GraphCanvas::GraphCanvasPropertyBusHandler
, public GraphCanvas::WrapperNodeConfigurationRequestBus::Handler
, public GraphCanvas::EntitySaveDataRequestBus::Handler
, public GraphCanvas::SceneMemberNotificationBus::Handler
, public AZ::Data::AssetBus::Handler
, public EditorNodeNotificationBus::Handler
{
public:
class ScriptEventReceiverHandlerNodeDescriptorSaveData
: public GraphCanvas::ComponentSaveData
{
public:
AZ_RTTI(ScriptEventReceiverHandlerNodeDescriptorSaveData, "{D8BBE799-7E4D-495A-B69A-1E3940670891}", GraphCanvas::ComponentSaveData);
AZ_CLASS_ALLOCATOR(ScriptEventReceiverHandlerNodeDescriptorSaveData, AZ::SystemAllocator, 0);
ScriptEventReceiverHandlerNodeDescriptorSaveData();
ScriptEventReceiverHandlerNodeDescriptorSaveData(ScriptEventReceiverNodeDescriptorComponent* component);
~ScriptEventReceiverHandlerNodeDescriptorSaveData() = default;
void operator=(const ScriptEventReceiverHandlerNodeDescriptorSaveData& other);
void OnDisplayConnectionsChanged();
bool m_displayConnections;
AZStd::vector<AZStd::pair<ScriptCanvas::EBusEventId, AZStd::string>> m_enabledEvents;
private:
ScriptEventReceiverNodeDescriptorComponent * m_callback;
};
friend class ScriptEventReceiverHandlerNodeDescriptorSaveData;
AZ_COMPONENT(ScriptEventReceiverNodeDescriptorComponent, "{FF9D3121-64B5-41C8-99D4-211528F39615}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
ScriptEventReceiverNodeDescriptorComponent();
ScriptEventReceiverNodeDescriptorComponent(AZ::Data::AssetId assetId);
~ScriptEventReceiverNodeDescriptorComponent() = default;
void Activate() override;
void Deactivate() override;
// NodeNotifications
void OnNodeActivated() override;
////
// SceneMemberNotifications
void OnMemberSetupComplete() override;
void OnSceneMemberDeserialized(const AZ::EntityId& graphId, const GraphCanvas::GraphSerialization&) override;
////
// GraphCanvas::EntitySaveDataRequestBus::Handler
void WriteSaveData(GraphCanvas::EntitySaveDataContainer& saveDataContainer) const override;
void ReadSaveData(const GraphCanvas::EntitySaveDataContainer& saveDataContainer) override;
////
// ScriptEventReceiverNodeDescriptorRequests
AZ::Data::AssetId GetAssetId() const override;
////
// EBusHandlerNodeDescriptorRequestBus
AZStd::string_view GetBusName() const override;
bool ContainsEvent(const ScriptCanvas::EBusEventId& eventId) const override;
GraphCanvas::WrappedNodeConfiguration GetEventConfiguration(const ScriptCanvas::EBusEventId& eventId) const override;
AZStd::vector< HandlerEventConfiguration > GetEventConfigurations() const override;
AZ::EntityId FindEventNodeId(const ScriptCanvas::EBusEventId& eventId) const override;
AZ::EntityId FindGraphCanvasNodeIdForSlot(const ScriptCanvas::SlotId& slotId) const override;
GraphCanvas::Endpoint MapSlotToGraphCanvasEndpoint(const ScriptCanvas::SlotId& slotId) const override;
////
// WrapperNodeNotificationBus
void OnWrappedNode(const AZ::EntityId& wrappedNode) override;
void OnUnwrappedNode(const AZ::EntityId& unwrappedNode) override;
////
// WrapperNodeConfigurationRequests
GraphCanvas::WrappedNodeConfiguration GetWrappedNodeConfiguration(const AZ::EntityId& wrappedNodeId) const override;
////
// GraphCanvasPropertyBus
AZ::Component* GetPropertyComponent() override;
////
// AZ::Data::AssetBus::Handler
void OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
////
// EditorNodeNotificationBus::Handler
void OnVersionConversionBegin() override;
void OnVersionConversionEnd() override;
////
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId) override;
private:
void OnDisplayConnectionsChanged();
void UpdateTitles(const AZ::Data::Asset<ScriptEvents::ScriptEventsAsset>& asset);
ScriptEventReceiverHandlerNodeDescriptorSaveData m_saveData;
AZ::Crc32 m_busId;
AZStd::string m_busName;
bool m_loadingEvents;
AZ::Data::AssetId m_scriptEventsAssetId;
ScriptEvents::Method m_methodDefinition;
AZ::EntityId m_scriptCanvasId;
using EventKey = AZStd::pair<AZ::Uuid, AZStd::string>;
AZStd::unordered_map<ScriptCanvas::EBusEventId, AZ::EntityId> m_eventTypeToId;
AZStd::unordered_map<AZ::EntityId, ScriptCanvas::EBusEventId> m_idToEventType;
};
}
@@ -0,0 +1,173 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include "ScriptEventSenderNodeDescriptorComponent.h"
#include "Editor/Translation/TranslationHelper.h"
#include "ScriptCanvas/Libraries/Core/Method.h"
#include <Editor/Include/ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <ScriptCanvas/Bus/RequestBus.h>
#include <ScriptCanvas/GraphCanvas/DynamicSlotBus.h>
#include <ScriptCanvas/Libraries/Core/ScriptEventBase.h>
namespace ScriptCanvasEditor
{
/////////////////////////////////////////////
// ScriptEventSenderNodeDescriptorComponent
/////////////////////////////////////////////
void ScriptEventSenderNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<ScriptEventSenderNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(1)
;
}
}
ScriptEventSenderNodeDescriptorComponent::ScriptEventSenderNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::EBusSender)
{
}
ScriptEventSenderNodeDescriptorComponent::ScriptEventSenderNodeDescriptorComponent(const AZ::Data::AssetId& assetId, const ScriptCanvas::EBusEventId& eventId)
: NodeDescriptorComponent(NodeDescriptorType::EBusSender)
, m_assetId(assetId)
, m_eventId(eventId)
{
}
void ScriptEventSenderNodeDescriptorComponent::Activate()
{
NodeDescriptorComponent::Activate();
AZ::Data::AssetBus::Handler::BusConnect(m_assetId);
}
void ScriptEventSenderNodeDescriptorComponent::Deactivate()
{
NodeDescriptorComponent::Deactivate();
AZ::Data::AssetBus::Handler::BusDisconnect();
}
void ScriptEventSenderNodeDescriptorComponent::OnAssetUnloaded([[maybe_unused]] const AZ::Data::AssetId assetId, [[maybe_unused]] const AZ::Data::AssetType assetType)
{
SignalNeedsVersionConversion();
}
void ScriptEventSenderNodeDescriptorComponent::OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset)
{
SignalNeedsVersionConversion();
}
void ScriptEventSenderNodeDescriptorComponent::OnVersionConversionBegin()
{
DynamicSlotRequestBus::Event(GetEntityId(), &DynamicSlotRequests::StartQueueSlotUpdates);
}
void ScriptEventSenderNodeDescriptorComponent::OnVersionConversionEnd()
{
UpdateTitles();
DynamicSlotRequestBus::Event(GetEntityId(), &DynamicSlotRequests::StopQueueSlotUpdates);
}
void ScriptEventSenderNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId)
{
m_scriptCanvasId = scriptCanvasNodeId;
EditorNodeNotificationBus::Handler::BusConnect(scriptCanvasNodeId);
ScriptCanvas::Nodes::Core::Method* method = AZ::EntityUtils::FindFirstDerivedComponent<ScriptCanvas::Nodes::Core::Method>(m_scriptCanvasId);
if (method)
{
if (method->HasBusID())
{
ScriptCanvas::SlotId slotId = method->GetBusSlotId();
AZStd::vector< AZ::EntityId > graphCanvasSlots;
GraphCanvas::NodeRequestBus::EventResult(graphCanvasSlots, GetEntityId(), &GraphCanvas::NodeRequests::GetSlotIds);
for (const AZ::EntityId& graphCanvasId : graphCanvasSlots)
{
AZStd::any* slotData = nullptr;
GraphCanvas::SlotRequestBus::EventResult(slotData, graphCanvasId, &GraphCanvas::SlotRequests::GetUserData);
if (slotData
&& slotData->is< ScriptCanvas::SlotId >())
{
ScriptCanvas::SlotId currentSlotId = (*AZStd::any_cast<ScriptCanvas::SlotId>(slotData));
if (currentSlotId == slotId)
{
GraphCanvas::SlotRequestBus::Event(graphCanvasId, &GraphCanvas::SlotRequests::SetTranslationKeyedName, TranslationHelper::GetEBusSenderBusIdNameKey());
GraphCanvas::SlotRequestBus::Event(graphCanvasId, &GraphCanvas::SlotRequests::SetTranslationKeyedTooltip, TranslationHelper::GetEBusSenderBusIdTooltipKey());
break;
}
}
}
}
}
UpdateTitles();
}
void ScriptEventSenderNodeDescriptorComponent::UpdateTitles()
{
if (m_assetId.IsValid())
{
AZ::Data::Asset<ScriptEvents::ScriptEventsAsset> asset = AZ::Data::AssetManager::Instance().GetAsset<ScriptEvents::ScriptEventsAsset>(m_assetId, AZ::Data::AssetLoadBehavior::Default);
asset.BlockUntilLoadComplete();
if (asset.IsReady())
{
const ScriptEvents::ScriptEvent& definition = asset.Get()->m_definition;
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetSubTitle, definition.GetName());
for (auto eventDefinition : definition.GetMethods())
{
if (eventDefinition.GetEventId() == m_eventId)
{
GraphCanvas::NodeRequestBus::Event(GetEntityId(), &GraphCanvas::NodeRequests::SetTooltip, eventDefinition.GetTooltip());
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, eventDefinition.GetName());
}
}
}
}
}
void ScriptEventSenderNodeDescriptorComponent::SignalNeedsVersionConversion()
{
AZ::EntityId graphCanvasGraphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphCanvasGraphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
ScriptCanvas::ScriptCanvasId scriptCanvasId;
GeneralRequestBus::BroadcastResult(scriptCanvasId, &GeneralRequests::GetScriptCanvasId, graphCanvasGraphId);
EditorGraphRequestBus::Event(scriptCanvasId, &EditorGraphRequests::QueueVersionUpdate, GetEntityId());
}
}
@@ -0,0 +1,64 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h>
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <ScriptEvents/ScriptEventsAsset.h>
namespace ScriptCanvasEditor
{
class ScriptEventSenderNodeDescriptorComponent
: public NodeDescriptorComponent
, public AZ::Data::AssetBus::Handler
, public EditorNodeNotificationBus::Handler
{
public:
AZ_COMPONENT(ScriptEventSenderNodeDescriptorComponent, "{7EB63D67-4F32-40E5-8B15-4C3E28D886F9}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
ScriptEventSenderNodeDescriptorComponent();
ScriptEventSenderNodeDescriptorComponent(const AZ::Data::AssetId& assetId, const ScriptCanvas::EBusEventId& eventId);
~ScriptEventSenderNodeDescriptorComponent() = default;
// Component
void Activate() override;
void Deactivate() override;
////
// AZ::Data::AssetBus::Handler
void OnAssetUnloaded(const AZ::Data::AssetId assetId, const AZ::Data::AssetType assetType) override;
void OnAssetReloaded(AZ::Data::Asset<AZ::Data::AssetData> asset) override;
////
// VersionControlledNodeRequestBus::Handler
void OnVersionConversionBegin() override;
void OnVersionConversionEnd() override;
////
protected:
void OnAddedToGraphCanvasGraph(const GraphCanvas::GraphId& graphId, const AZ::EntityId& scriptCanvasNodeId) override;
private:
void UpdateTitles();
void SignalNeedsVersionConversion();
AZ::EntityId m_scriptCanvasId;
AZ::Data::AssetId m_assetId;
ScriptCanvas::EBusEventId m_eventId;
};
}
@@ -0,0 +1,55 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Component/ComponentApplicationBus.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/SetVariableNodeDescriptorComponent.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/View/Widgets/PropertyGridBus.h>
#include <ScriptCanvas/Libraries/Core/SetVariable.h>
#include <ScriptCanvas/Variable/VariableData.h>
namespace ScriptCanvasEditor
{
///////////////////////////////////////
// SetVariableNodeDescriptorComponent
///////////////////////////////////////
void SetVariableNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<SetVariableNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(1)
;
}
}
SetVariableNodeDescriptorComponent::SetVariableNodeDescriptorComponent()
: VariableNodeDescriptorComponent(NodeDescriptorType::SetVariable)
{
}
void SetVariableNodeDescriptorComponent::UpdateTitle(AZStd::string_view variableName)
{
AZStd::string titleName = AZStd::string::format("Set %s", variableName.data());
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetTitle, titleName);
}
}
@@ -0,0 +1,34 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/VariableNodeDescriptorComponent.h>
#include <ScriptCanvas/Variable/VariableBus.h>
namespace ScriptCanvasEditor
{
class SetVariableNodeDescriptorComponent
: public VariableNodeDescriptorComponent
{
public:
AZ_COMPONENT(SetVariableNodeDescriptorComponent, "{5C1183AC-09E9-4D43-A6F4-76B4F3EE18ED}", VariableNodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
SetVariableNodeDescriptorComponent();
protected:
void UpdateTitle(AZStd::string_view variableName) override;
};
}
@@ -0,0 +1,40 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Serialization/SerializeContext.h>
#include "UserDefinedNodeDescriptorComponent.h"
namespace ScriptCanvasEditor
{
///////////////////////////////////////
// UserDefinedNodeDescriptorComponent
///////////////////////////////////////
void UserDefinedNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<UserDefinedNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(2)
;
}
}
UserDefinedNodeDescriptorComponent::UserDefinedNodeDescriptorComponent()
: NodeDescriptorComponent(NodeDescriptorType::UserDefined)
{
}
}
@@ -0,0 +1,28 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h"
namespace ScriptCanvasEditor
{
class UserDefinedNodeDescriptorComponent
: public NodeDescriptorComponent
{
public:
AZ_COMPONENT(UserDefinedNodeDescriptorComponent, "{24109899-2026-4981-BFA1-38DB134246A2}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
UserDefinedNodeDescriptorComponent();
~UserDefinedNodeDescriptorComponent() = default;
};
}
@@ -0,0 +1,245 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "precompiled.h"
#include <AzCore/Component/ComponentApplicationBus.h>
#include <GraphCanvas/Components/Connections/ConnectionBus.h>
#include <GraphCanvas/Components/Nodes/NodeTitleBus.h>
#include <GraphCanvas/Components/SceneBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/VariableNodeDescriptorComponent.h>
#include <Editor/Include/ScriptCanvas/Bus/RequestBus.h>
#include <Editor/Translation/TranslationHelper.h>
#include <Editor/View/Widgets/PropertyGridBus.h>
#include <ScriptCanvas/Bus/EditorScriptCanvasBus.h>
#include <ScriptCanvas/Bus/RequestBus.h>
namespace ScriptCanvasEditor
{
////////////////////////////////////
// VariableNodeDescriptorComponent
////////////////////////////////////
void VariableNodeDescriptorComponent::Reflect(AZ::ReflectContext* reflectContext)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(reflectContext);
if (serializeContext)
{
serializeContext->Class<VariableNodeDescriptorComponent, NodeDescriptorComponent>()
->Version(1)
;
}
}
VariableNodeDescriptorComponent::VariableNodeDescriptorComponent(NodeDescriptorType descriptorType)
: NodeDescriptorComponent(descriptorType)
{
}
void VariableNodeDescriptorComponent::Activate()
{
NodeDescriptorComponent::Activate();
GraphCanvas::SceneMemberNotificationBus::Handler::BusConnect(GetEntityId());
VariableNodeDescriptorRequestBus::Handler::BusConnect(GetEntityId());
}
void VariableNodeDescriptorComponent::Deactivate()
{
ScriptCanvas::VariableNodeNotificationBus::Handler::BusDisconnect();
VariableNodeDescriptorRequestBus::Handler::BusDisconnect();
GraphCanvas::SceneMemberNotificationBus::Handler::BusDisconnect();
NodeDescriptorComponent::Deactivate();
}
void VariableNodeDescriptorComponent::OnVariableRenamed(AZStd::string_view variableName)
{
UpdateTitle(variableName);
}
void VariableNodeDescriptorComponent::OnVariableRemoved()
{
AZ_Error("ScriptCanvas", false, "Removing a variable from node that is still in use. Deleting node");
AZStd::unordered_set< AZ::EntityId > deleteIds = { GetEntityId() };
AZ::EntityId graphId;
GraphCanvas::SceneMemberRequestBus::EventResult(graphId, GetEntityId(), &GraphCanvas::SceneMemberRequests::GetScene);
// After this call the component is no longer valid.
GraphCanvas::SceneRequestBus::Event(graphId, &GraphCanvas::SceneRequests::Delete, deleteIds);
}
void VariableNodeDescriptorComponent::OnVariableIdChanged(const ScriptCanvas::VariableId& /*oldVariableId*/, const ScriptCanvas::VariableId& newVariableId)
{
ScriptCanvas::ScriptCanvasId scriptCanvasId;
AZ::EntityId scriptCanvasNodeId = FindScriptCanvasNodeId();
ScriptCanvas::NodeRequestBus::EventResult(scriptCanvasId, scriptCanvasNodeId, &ScriptCanvas::NodeRequests::GetOwningScriptCanvasId);
ScriptCanvas::VariableNotificationBus::Handler::BusDisconnect();
ScriptCanvas::GraphScopedVariableId newScopedVariableId = ScriptCanvas::GraphScopedVariableId(scriptCanvasId, newVariableId);
ScriptCanvas::VariableNotificationBus::Handler::BusConnect(newScopedVariableId);
ScriptCanvas::Data::Type scriptCanvasType;
ScriptCanvas::VariableRequestBus::EventResult(scriptCanvasType, newScopedVariableId, &ScriptCanvas::VariableRequests::GetType);
const AZStd::string typeName = TranslationHelper::GetSafeTypeName(scriptCanvasType);
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetSubTitle, typeName);
AZ::Uuid dataType = ScriptCanvas::Data::ToAZType(scriptCanvasType);
GraphCanvas::NodeTitleRequestBus::Event(GetEntityId(), &GraphCanvas::NodeTitleRequests::SetDataPaletteOverride, dataType);
AZStd::string_view variableName;
ScriptCanvas::VariableRequestBus::EventResult(variableName, newScopedVariableId, &ScriptCanvas::VariableRequests::GetName);
UpdateTitle(variableName);
PropertyGridRequestBus::Broadcast(&PropertyGridRequests::RebuildPropertyGrid);
}
void VariableNodeDescriptorComponent::OnAddedToGraphCanvasGraph([[maybe_unused]] const AZ::EntityId& sceneId, const AZ::EntityId& scriptCanvasNodeId)
{
OnVariableIdChanged({}, GetVariableId());
ScriptCanvas::VariableNodeNotificationBus::Handler::BusConnect(scriptCanvasNodeId);
}
void VariableNodeDescriptorComponent::OnSceneMemberAboutToSerialize(GraphCanvas::GraphSerialization& graphSerialization)
{
auto& userDataMapRef = graphSerialization.GetUserDataMapRef();
auto mapIter = userDataMapRef.find(ScriptCanvas::CopiedVariableData::k_variableKey);
ScriptCanvas::GraphVariableMapping* variableConfigurations = nullptr;
if (mapIter == userDataMapRef.end())
{
ScriptCanvas::CopiedVariableData variableData;
auto insertResult = userDataMapRef.emplace(ScriptCanvas::CopiedVariableData::k_variableKey, variableData);
ScriptCanvas::CopiedVariableData* copiedVariableData = AZStd::any_cast<ScriptCanvas::CopiedVariableData>(&insertResult.first->second);
variableConfigurations = (&copiedVariableData->m_variableMapping);
}
else
{
ScriptCanvas::CopiedVariableData* copiedVariableData = AZStd::any_cast<ScriptCanvas::CopiedVariableData>(&mapIter->second);
variableConfigurations = (&copiedVariableData->m_variableMapping);
}
ScriptCanvas::VariableId variableId = GetVariableId();
if (variableConfigurations->find(variableId) == variableConfigurations->end())
{
ScriptCanvas::ScriptCanvasId scriptCanvasId;
GeneralRequestBus::BroadcastResult(scriptCanvasId, &GeneralRequests::GetActiveScriptCanvasId);
ScriptCanvas::GraphVariable* configuration = nullptr;
ScriptCanvas::GraphVariableManagerRequestBus::EventResult(configuration, scriptCanvasId, &ScriptCanvas::GraphVariableManagerRequests::FindVariableById, variableId);
if (configuration)
{
variableConfigurations->emplace(GetVariableId(), (*configuration));
}
}
}
void VariableNodeDescriptorComponent::OnSceneMemberDeserialized(const AZ::EntityId& graphCanvasGraphId, const GraphCanvas::GraphSerialization& graphSerialization)
{
ScriptCanvas::ScriptCanvasId scriptCanvasId;
GeneralRequestBus::BroadcastResult(scriptCanvasId, &GeneralRequests::GetScriptCanvasId, graphCanvasGraphId);
ScriptCanvas::GraphVariable* graphVariable = nullptr;
ScriptCanvas::GraphVariableManagerRequestBus::EventResult(graphVariable, scriptCanvasId, &ScriptCanvas::GraphVariableManagerRequests::FindVariableById, GetVariableId());
// If the variable is null. We need to create it from our copied data.
if (graphVariable == nullptr)
{
const auto& userDataMapRef = graphSerialization.GetUserDataMapRef();
auto mapIter = userDataMapRef.find(ScriptCanvas::CopiedVariableData::k_variableKey);
if (mapIter != userDataMapRef.end())
{
const ScriptCanvas::CopiedVariableData* copiedVariableData = AZStd::any_cast<ScriptCanvas::CopiedVariableData>(&mapIter->second);
const ScriptCanvas::GraphVariableMapping* mapping = (&copiedVariableData->m_variableMapping);
ScriptCanvas::VariableId originalVariable = GetVariableId();
auto variableIter = mapping->find(originalVariable);
if (variableIter != mapping->end())
{
ScriptCanvas::ScriptCanvasId scriptCanvasId2;
GeneralRequestBus::BroadcastResult(scriptCanvasId2, &GeneralRequests::GetScriptCanvasId, graphCanvasGraphId);
const ScriptCanvas::GraphVariable& variableConfiguration = variableIter->second;
AZ::Outcome<ScriptCanvas::VariableId, AZStd::string> remapVariableOutcome = AZ::Failure(AZStd::string());
ScriptCanvas::GraphVariableManagerRequestBus::EventResult(remapVariableOutcome, scriptCanvasId2, &ScriptCanvas::GraphVariableManagerRequests::RemapVariable, variableConfiguration);
if (remapVariableOutcome)
{
SetVariableId(remapVariableOutcome.GetValue());
bool runtimeGraph = false;
EditorGraphRequestBus::EventResult(runtimeGraph, scriptCanvasId2, &EditorGraphRequests::IsRuntimeGraph);
ScriptCanvas::GraphVariable* variable = nullptr;
ScriptCanvas::GraphVariableManagerRequestBus::EventResult(variable, scriptCanvasId2, &ScriptCanvas::GraphVariableManagerRequests::FindVariableById, remapVariableOutcome.GetValue());
if (variable)
{
variable->RemoveScope(ScriptCanvas::VariableFlags::Scope::Output);
}
}
}
}
}
}
ScriptCanvas::VariableId VariableNodeDescriptorComponent::GetVariableId() const
{
ScriptCanvas::VariableId variableId;
AZStd::any* userData = nullptr;
GraphCanvas::NodeRequestBus::EventResult(userData, GetEntityId(), &GraphCanvas::NodeRequests::GetUserData);
AZ::EntityId* scNodeId = AZStd::any_cast<AZ::EntityId>(userData);
if (scNodeId)
{
ScriptCanvas::VariableNodeRequestBus::EventResult(variableId, *scNodeId, &ScriptCanvas::VariableNodeRequests::GetId);
}
return variableId;
}
void VariableNodeDescriptorComponent::UpdateTitle([[maybe_unused]] AZStd::string_view variableName)
{
AZ_Error("ScriptCanvas", false, "Should be pure virtual function, but Pure Virtual functions on components are disallowed.");
}
void VariableNodeDescriptorComponent::SetVariableId(const ScriptCanvas::VariableId& variableId)
{
AZStd::any* userData = nullptr;
GraphCanvas::NodeRequestBus::EventResult(userData, GetEntityId(), &GraphCanvas::NodeRequests::GetUserData);
AZ::EntityId* scNodeId = AZStd::any_cast<AZ::EntityId>(userData);
if (scNodeId)
{
ScriptCanvas::VariableNodeRequestBus::Event(*scNodeId, &ScriptCanvas::VariableNodeRequests::SetId, variableId);
}
}
}
@@ -0,0 +1,72 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GraphCanvas/Components/Nodes/NodeBus.h>
#include <GraphCanvas/Components/SceneBus.h>
#include <Editor/GraphCanvas/Components/NodeDescriptors/NodeDescriptorComponent.h>
#include <ScriptCanvas/Variable/VariableBus.h>
#include <Editor/Include/ScriptCanvas/GraphCanvas/NodeDescriptorBus.h>
namespace ScriptCanvasEditor
{
class VariableNodeDescriptorComponent
: public NodeDescriptorComponent
, public GraphCanvas::SceneMemberNotificationBus::Handler
, public ScriptCanvas::VariableNotificationBus::Handler
, public ScriptCanvas::VariableNodeNotificationBus::Handler
, public VariableNodeDescriptorRequestBus::Handler
{
public:
AZ_COMPONENT(VariableNodeDescriptorComponent, "{80CB9400-E40D-4DC7-B185-412F766C8565}", NodeDescriptorComponent);
static void Reflect(AZ::ReflectContext* reflectContext);
VariableNodeDescriptorComponent() = default;
VariableNodeDescriptorComponent(NodeDescriptorType descriptorType);
~VariableNodeDescriptorComponent() = default;
// Component
void Activate() override;
void Deactivate() override;
////
// VariableNotificationBus
void OnVariableRenamed(AZStd::string_view variableName) override;
void OnVariableRemoved() override;
////
// VariableNodeNotificationBus
void OnVariableIdChanged(const ScriptCanvas::VariableId& oldVariableId, const ScriptCanvas::VariableId& newVariableId) override;
////
// SceneMemberNotifications
void OnSceneMemberAboutToSerialize(GraphCanvas::GraphSerialization& graphSerialization) override;
void OnSceneMemberDeserialized(const AZ::EntityId& graphId, const GraphCanvas::GraphSerialization& graphSerialization) override;
////
// VariableNodeDescriptorBus
ScriptCanvas::VariableId GetVariableId() const;
////
protected:
void OnAddedToGraphCanvasGraph(const AZ::EntityId& sceneId, const AZ::EntityId& scriptCanvasEntityId) override;
virtual void UpdateTitle(AZStd::string_view variableName);
private:
void SetVariableId(const ScriptCanvas::VariableId& variableId);
};
}