Files
UnrealEngineUWP/Engine/Plugins/Runtime/Metasound/Source/MetasoundEditor/Private/SMetasoundGraphPin.h

264 lines
7.4 KiB
C
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "EditorStyleSet.h"
#include "KismetPins/SGraphPinBool.h"
#include "KismetPins/SGraphPinNum.h"
#include "KismetPins/SGraphPinInteger.h"
#include "KismetPins/SGraphPinObject.h"
#include "KismetPins/SGraphPinString.h"
#include "MetasoundEditorGraph.h"
#include "MetasoundEditorGraphBuilder.h"
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
#include "MetasoundEditorGraphMemberDefaults.h"
#include "MetasoundEditorGraphNode.h"
#include "MetasoundFrontendController.h"
#include "SGraphPin.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/SBoxPanel.h"
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
#include "Widgets/SNullWidget.h"
#include "Widgets/SWidget.h"
#define LOCTEXT_NAMESPACE "MetasoundEditor"
namespace Metasound
{
namespace Editor
{
template <typename ParentPinType>
class METASOUNDEDITOR_API TMetasoundGraphPin : public ParentPinType
{
public:
SLATE_BEGIN_ARGS(TMetasoundGraphPin<ParentPinType>)
{
}
SLATE_END_ARGS()
Frontend::FConstInputHandle GetConstInputHandle() const
{
using namespace Frontend;
const bool bIsInput = (ParentPinType::GetDirection() == EGPD_Input);
if (bIsInput)
{
if (const UEdGraphPin* Pin = ParentPinType::GetPinObj())
{
if (const UMetasoundEditorGraphNode* MetasoundEditorNode = Cast<UMetasoundEditorGraphNode>(Pin->GetOwningNode()))
{
FConstNodeHandle NodeHandle = MetasoundEditorNode->GetConstNodeHandle();
return NodeHandle->GetConstInputWithVertexName(Pin->GetFName());
}
}
}
return IInputController::GetInvalidHandle();
}
Frontend::FInputHandle GetInputHandle()
{
using namespace Frontend;
const bool bIsInput = (ParentPinType::GetDirection() == EGPD_Input);
if (bIsInput)
{
if (UEdGraphPin* Pin = ParentPinType::GetPinObj())
{
if (UMetasoundEditorGraphNode* MetasoundEditorNode = Cast<UMetasoundEditorGraphNode>(Pin->GetOwningNode()))
{
FNodeHandle NodeHandle = MetasoundEditorNode->GetNodeHandle();
return NodeHandle->GetInputWithVertexName(Pin->GetFName());
}
}
}
return IInputController::GetInvalidHandle();
}
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
bool ShowDefaultValueWidget() const
{
UEdGraphPin* Pin = ParentPinType::GetPinObj();
if (!Pin)
{
return true;
}
UMetasoundEditorGraphMemberNode* Node = Cast<UMetasoundEditorGraphMemberNode>(Pin->GetOwningNode());
if (!Node)
{
return true;
}
UMetasoundEditorGraphMember* Member = Node->GetMember();
if (!Member)
{
return true;
}
UMetasoundEditorGraphMemberDefaultFloat* DefaultFloat = Cast<UMetasoundEditorGraphMemberDefaultFloat>(Member->GetLiteral());
if (!DefaultFloat)
{
return true;
}
return DefaultFloat->WidgetType == EMetasoundMemberDefaultWidget::None;
}
virtual TSharedRef<SWidget> GetDefaultValueWidget() override
{
using namespace Frontend;
TSharedRef<SWidget> DefaultWidget = ParentPinType::GetDefaultValueWidget();
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
if (!ShowDefaultValueWidget())
{
return SNullWidget::NullWidget;
}
// For now, arrays do not support literals.
// TODO: Support array literals by displaying
// default literals (non-array too) in inspector window.
FConstInputHandle InputHandle = GetConstInputHandle();
if (!InputHandle->IsValid() || ParentPinType::IsArray())
{
return DefaultWidget;
}
return SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.VAlign(VAlign_Center)
[
DefaultWidget
]
+ SHorizontalBox::Slot()
.AutoWidth()
.VAlign(VAlign_Center)
[
SNew(SButton)
.ToolTipText(LOCTEXT("ResetToClassDefaultToolTip", "Reset to class default"))
.ButtonStyle(FEditorStyle::Get(), TEXT("NoBorder"))
.ContentPadding(0.0f)
.Visibility(TAttribute<EVisibility>::Create([this]
{
using namespace Frontend;
if (!ParentPinType::IsConnected())
{
FConstInputHandle InputHandle = GetConstInputHandle();
if (const FMetasoundFrontendLiteral* Literal = InputHandle->GetLiteral())
{
const bool bIsDefaultConstructed = Literal->GetType() == EMetasoundFrontendLiteralType::None;
const bool bIsTriggerDataType = InputHandle->GetDataType() == GetMetasoundDataTypeName<FTrigger>();
if (!bIsDefaultConstructed && !bIsTriggerDataType)
{
return EVisibility::Visible;
}
}
}
return EVisibility::Collapsed;
}))
.OnClicked(FOnClicked::CreateLambda([this]()
{
using namespace Frontend;
if (UEdGraphPin* Pin = ParentPinType::GetPinObj())
{
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
if (UMetasoundEditorGraphNode* Node = Cast<UMetasoundEditorGraphNode>(Pin->GetOwningNode()))
{
if (UMetasoundEditorGraph* MetaSoundGraph = CastChecked<UMetasoundEditorGraph>(Node->GetGraph()))
{
UObject& MetaSound = MetaSoundGraph->GetMetasoundChecked();
{
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
const FScopedTransaction Transaction(LOCTEXT("MetaSoundEditorResetToClassDefault", "Reset to Class Default"));
MetaSound.Modify();
MetaSoundGraph->Modify();
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
if (UMetasoundEditorGraphMemberNode* MemberNode = Cast<UMetasoundEditorGraphMemberNode>(Node))
{
UMetasoundEditorGraphMember* Member = MemberNode->GetMember();
if (ensure(Member))
{
Member->ResetToClassDefault();
}
}
else
{
FInputHandle InputHandle = GetInputHandle();
InputHandle->ClearLiteral();
}
}
- Rename & redirect MetaSoundEditorGraph<Input>Literals to MetaSoundEditorGraph<DefaultMember>Literals - First pass at consolidating editor code for API members/vertices where possible - Make Variables & Output now use default literal for input value (so user doesn't have to hunt down literal box in graph) Various bug fixes: - Fixes crash in post undo after updating a variable default - Fixes ':Array' flavor showing up in new SearchableComboBox when selecting `Is Array` for literal type - Synchronize variable setter default literal with variable interface default literal - Provide default literal field for outputs & variables for consistency - Added win is widget support for single input/output types (i.e. floats for now) - Don't show trigger simulate option on non-transmissible inputs (ex. OnPlay) - Set simulate button visibility to only show when parameter transmission is supported by input - Make simulate buttons in graph only visible when sound plays - Start sounds automatically when clicking simulate in inspector - Fixed initial condition "holding" trigger state for trigger routing now that Transmission System is only used inter-MetaSound (not intra-MetaSound) and we are deprecating Send/Receives #rb phil.popp #rnx #jira UE-135813 #jira UE-132900 #jira UE-135844 #jira UE-116867 #jira UE-135366 #jira UE-137310 #preflight 61b7afe4fc570891338fea08 #ROBOMERGE-AUTHOR: rob.gay #ROBOMERGE-SOURCE: CL 18450046 in //UE5/Release-5.0/... via CL 18450065 #ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v897-18405271) [CL 18450072 by rob gay in ue5-release-engine-test branch]
2021-12-13 18:15:01 -05:00
// Full node synchronization required as custom
// node-level widgets may need to be refreshed
MetaSoundGraph->SetSynchronizationRequired();
}
}
}
return FReply::Handled();
}))
.Content()
[
SNew(SImage)
.Image(FEditorStyle::GetBrush("PropertyWindow.DiffersFromDefault"))
]
];
}
};
class SMetasoundGraphPin : public TMetasoundGraphPin<SGraphPin>
{
public:
void Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
{
SGraphPin::Construct(SGraphPin::FArguments(), InGraphPinObj);
}
};
class SMetasoundGraphPinBool : public TMetasoundGraphPin<SGraphPinBool>
{
public:
void Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
{
SGraphPinBool::Construct(SGraphPinBool::FArguments(), InGraphPinObj);
}
};
class SMetasoundGraphPinFloat : public TMetasoundGraphPin<SGraphPinNum<float>>
{
public:
void Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
{
SGraphPinNum<float>::Construct(SGraphPinNum<float>::FArguments(), InGraphPinObj);
}
};
class SMetasoundGraphPinInteger : public TMetasoundGraphPin<SGraphPinInteger>
{
public:
void Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
{
SGraphPinInteger::Construct(SGraphPinInteger::FArguments(), InGraphPinObj);
}
};
class SMetasoundGraphPinObject : public TMetasoundGraphPin<SGraphPinObject>
{
public:
void Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
{
SGraphPinObject::Construct(SGraphPinObject::FArguments(), InGraphPinObj);
}
};
class SMetasoundGraphPinString : public TMetasoundGraphPin<SGraphPinString>
{
public:
void Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
{
SGraphPinString::Construct(SGraphPinString::FArguments(), InGraphPinObj);
}
};
} // namespace Editor
} // namespace Metasound
#undef LOCTEXT_NAMESPACE