Event node pins are now generated in a more automatic way and without having a bunch of duplicate code.
This commit is contained in:
parent
7ed3df2cc8
commit
29f7346ea8
@ -26,16 +26,47 @@
|
|||||||
|
|
||||||
#define LOCTEXT_NAMESPACE "K2Node_ComboAction"
|
#define LOCTEXT_NAMESPACE "K2Node_ComboAction"
|
||||||
|
|
||||||
#define COMBO_ACTION_ACTIVATED_PIN_NAME TEXT("Activated")
|
|
||||||
#define COMBO_ACTION_RELEASED_PIN_NAME TEXT("Released")
|
|
||||||
#define COMBO_ACTION_OBJECT_PIN_NAME TEXT("ComboAction")
|
#define COMBO_ACTION_OBJECT_PIN_NAME TEXT("ComboAction")
|
||||||
|
|
||||||
|
|
||||||
|
void ForEachEventPinName(TFunctionRef<void(EComboActionTriggerEvent Event, FName PinName)> PinLambda)
|
||||||
|
{
|
||||||
|
UEnum *EventEnum = StaticEnum<EComboActionTriggerEvent>();
|
||||||
|
for (int32 i = 0; i < EventEnum->NumEnums() - 1; ++i)
|
||||||
|
{
|
||||||
|
if (!EventEnum->HasMetaData(TEXT("Hidden"), i))
|
||||||
|
{
|
||||||
|
PinLambda(EComboActionTriggerEvent(EventEnum->GetValueByIndex(i)), *EventEnum->GetNameStringByIndex(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UK2Node_ComboAction::AllocateDefaultPins()
|
void UK2Node_ComboAction::AllocateDefaultPins()
|
||||||
{
|
{
|
||||||
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, COMBO_ACTION_ACTIVATED_PIN_NAME);
|
const UEdGraphSchema_K2 *Schema = GetDefault<UEdGraphSchema_K2>();
|
||||||
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, COMBO_ACTION_RELEASED_PIN_NAME);
|
|
||||||
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Object, UComboAction::StaticClass(), COMBO_ACTION_OBJECT_PIN_NAME);
|
this->AdvancedPinDisplay = ENodeAdvancedPins::Hidden;
|
||||||
|
|
||||||
|
ForEachEventPinName([this](EComboActionTriggerEvent Event, FName PinName)
|
||||||
|
{
|
||||||
|
static const UEnum *EventEnum = StaticEnum<EComboActionTriggerEvent>();
|
||||||
|
|
||||||
|
UEdGraphPin *NewPin = this->CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, PinName);
|
||||||
|
NewPin->PinToolTip = EventEnum->GetToolTipTextByIndex(EventEnum->GetIndexByValue(static_cast<uint8>(Event))).ToString();
|
||||||
|
NewPin->bAdvancedView = (Event > EComboActionTriggerEvent::Activated);
|
||||||
|
});
|
||||||
|
|
||||||
|
UEdGraphPin *ComboActionPin = this->CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Object, UComboAction::StaticClass(), COMBO_ACTION_OBJECT_PIN_NAME);
|
||||||
|
ComboActionPin->bAdvancedView = true;
|
||||||
|
|
||||||
|
Schema->SetPinAutogeneratedDefaultValueBasedOnType(ComboActionPin);
|
||||||
|
|
||||||
|
if (this->ComboAction)
|
||||||
|
{
|
||||||
|
ComboActionPin->DefaultObject = const_cast<UObject *>(Cast<UObject>(this->ComboAction));
|
||||||
|
ComboActionPin->DefaultValue = this->ComboAction->GetName();
|
||||||
|
Schema->ConstructBasicPinTooltip(*ComboActionPin, LOCTEXT("ComboActionPinDescription", "The combo action that caused this event to fire"), ComboActionPin->PinToolTip);
|
||||||
|
}
|
||||||
|
|
||||||
Super::AllocateDefaultPins();
|
Super::AllocateDefaultPins();
|
||||||
}
|
}
|
||||||
@ -128,49 +159,43 @@ void UK2Node_ComboAction::ExpandNode(FKismetCompilerContext &CompilerContext, UE
|
|||||||
{
|
{
|
||||||
Super::ExpandNode(CompilerContext, SourceGraph);
|
Super::ExpandNode(CompilerContext, SourceGraph);
|
||||||
|
|
||||||
UEdGraphPin *ComboActionActivatedPin = this->FindPin(COMBO_ACTION_ACTIVATED_PIN_NAME);
|
|
||||||
UEdGraphPin *ComboActionReleasedPin = this->FindPin(COMBO_ACTION_RELEASED_PIN_NAME);
|
|
||||||
|
|
||||||
struct EventPinData
|
|
||||||
{
|
|
||||||
EventPinData(UEdGraphPin *InPin, EComboActionTriggerEvent InEvent) { this->Pin = InPin; this->TriggerEvent = InEvent; }
|
|
||||||
UEdGraphPin *GetPin() const { return this->Pin; }
|
|
||||||
const EComboActionTriggerEvent &GetTriggerEvent() { return this->TriggerEvent; }
|
|
||||||
private:
|
|
||||||
UEdGraphPin *Pin;
|
|
||||||
EComboActionTriggerEvent TriggerEvent;
|
|
||||||
};
|
|
||||||
|
|
||||||
TArray<EventPinData> ActivePins;
|
|
||||||
if ((ComboActionActivatedPin != nullptr) && (ComboActionActivatedPin->LinkedTo.Num() > 0))
|
|
||||||
{
|
|
||||||
ActivePins.Add(EventPinData(ComboActionActivatedPin, EComboActionTriggerEvent::Activated));
|
|
||||||
}
|
|
||||||
if ((ComboActionReleasedPin != nullptr) && (ComboActionReleasedPin->LinkedTo.Num() > 0))
|
|
||||||
{
|
|
||||||
ActivePins.Add(EventPinData(ComboActionReleasedPin, EComboActionTriggerEvent::Released));
|
|
||||||
}
|
|
||||||
|
|
||||||
const UEdGraphSchema_K2 *Schema = CompilerContext.GetSchema();
|
const UEdGraphSchema_K2 *Schema = CompilerContext.GetSchema();
|
||||||
|
|
||||||
// If more than one is linked we have to do more complicated behaviors
|
|
||||||
//if (ActivePins.Num() > 1)
|
|
||||||
//{
|
|
||||||
// Create a temporary variable to copy Key in to
|
// Create a temporary variable to copy Key in to
|
||||||
UK2Node_TemporaryVariable *ComboActionObjectVar = CompilerContext.SpawnIntermediateNode<UK2Node_TemporaryVariable>(this, SourceGraph);
|
UK2Node_TemporaryVariable *ComboActionObjectVar = CompilerContext.SpawnIntermediateNode<UK2Node_TemporaryVariable>(this, SourceGraph);
|
||||||
ComboActionObjectVar->VariableType.PinCategory = UEdGraphSchema_K2::PC_Object;
|
ComboActionObjectVar->VariableType.PinCategory = UEdGraphSchema_K2::PC_Object;
|
||||||
ComboActionObjectVar->VariableType.PinSubCategoryObject = UComboAction::StaticClass();
|
ComboActionObjectVar->VariableType.PinSubCategoryObject = UComboAction::StaticClass();
|
||||||
ComboActionObjectVar->AllocateDefaultPins();
|
ComboActionObjectVar->AllocateDefaultPins();
|
||||||
|
|
||||||
for (auto PinIt = ActivePins.CreateIterator(); PinIt; ++PinIt)
|
// Establish active pins
|
||||||
|
struct ActivePinData
|
||||||
{
|
{
|
||||||
UEdGraphPin *EachPin = (*PinIt).GetPin();
|
ActivePinData(UEdGraphPin *InPin, EComboActionTriggerEvent InTriggerEvent) : Pin(InPin), TriggerEvent(InTriggerEvent){}
|
||||||
|
UEdGraphPin *Pin;
|
||||||
|
EComboActionTriggerEvent TriggerEvent;
|
||||||
|
};
|
||||||
|
|
||||||
|
TArray<ActivePinData> ActivePins;
|
||||||
|
ForEachEventPinName([this, &ActivePins, &CompilerContext](EComboActionTriggerEvent Event, FName PinName)
|
||||||
|
{
|
||||||
|
UEdGraphPin *InputActionPin = this->FindPin(PinName, EEdGraphPinDirection::EGPD_Output);
|
||||||
|
if (InputActionPin && InputActionPin->LinkedTo.Num() > 0)
|
||||||
|
{
|
||||||
|
ActivePins.Add(ActivePinData(InputActionPin, Event));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for(const ActivePinData &PinData : ActivePins)
|
||||||
|
{
|
||||||
|
UEdGraphPin *ComboActionPin = PinData.Pin;
|
||||||
|
|
||||||
|
if (ComboActionPin->LinkedTo.Num() > 0)
|
||||||
|
{
|
||||||
// Create the combo action event
|
// Create the combo action event
|
||||||
UK2Node_ComboActionEvent *ComboActionEvent = CompilerContext.SpawnIntermediateEventNode<UK2Node_ComboActionEvent>(this, EachPin, SourceGraph);
|
UK2Node_ComboActionEvent *ComboActionEvent = CompilerContext.SpawnIntermediateEventNode<UK2Node_ComboActionEvent>(this, ComboActionPin, SourceGraph);
|
||||||
ComboActionEvent->CustomFunctionName = FName(*FString::Printf(TEXT("ComboActionEvent_%s_%s"), *this->GetActionName().ToString(), *ComboActionEvent->GetName()));
|
ComboActionEvent->CustomFunctionName = FName(*FString::Printf(TEXT("ComboActionEvent_%s_%s"), *this->GetActionName().ToString(), *ComboActionEvent->GetName()));
|
||||||
ComboActionEvent->ComboAction = this->ComboAction;
|
ComboActionEvent->ComboAction = this->ComboAction;
|
||||||
ComboActionEvent->TriggerEvent = (*PinIt).GetTriggerEvent();
|
ComboActionEvent->TriggerEvent = PinData.TriggerEvent;
|
||||||
ComboActionEvent->EventReference.SetExternalDelegateMember(FName(TEXT("ComboActionHandlerDynamicSignature__DelegateSignature")));
|
ComboActionEvent->EventReference.SetExternalDelegateMember(FName(TEXT("ComboActionHandlerDynamicSignature__DelegateSignature")));
|
||||||
ComboActionEvent->bInternalEvent = true;
|
ComboActionEvent->bInternalEvent = true;
|
||||||
ComboActionEvent->AllocateDefaultPins();
|
ComboActionEvent->AllocateDefaultPins();
|
||||||
@ -180,35 +205,17 @@ void UK2Node_ComboAction::ExpandNode(FKismetCompilerContext &CompilerContext, UE
|
|||||||
ComboActionObjectInitialize->AllocateDefaultPins();
|
ComboActionObjectInitialize->AllocateDefaultPins();
|
||||||
Schema->TryCreateConnection(ComboActionObjectVar->GetVariablePin(), ComboActionObjectInitialize->GetVariablePin());
|
Schema->TryCreateConnection(ComboActionObjectVar->GetVariablePin(), ComboActionObjectInitialize->GetVariablePin());
|
||||||
Schema->TryCreateConnection(ComboActionObjectInitialize->GetValuePin(), ComboActionEvent->FindPinChecked(COMBO_ACTION_OBJECT_PIN_NAME));
|
Schema->TryCreateConnection(ComboActionObjectInitialize->GetValuePin(), ComboActionEvent->FindPinChecked(COMBO_ACTION_OBJECT_PIN_NAME));
|
||||||
|
|
||||||
// Connect the events to the assign key nodes
|
// Connect the events to the assign key nodes
|
||||||
Schema->TryCreateConnection(Schema->FindExecutionPin(*ComboActionEvent, EGPD_Output), ComboActionObjectInitialize->GetExecPin());
|
Schema->TryCreateConnection(Schema->FindExecutionPin(*ComboActionEvent, EGPD_Output), ComboActionObjectInitialize->GetExecPin());
|
||||||
|
|
||||||
// Move the original event connections to the then pin of the key assign
|
// Move the original event connections to the then pin of the key assign
|
||||||
CompilerContext.MovePinLinksToIntermediate(*EachPin, *ComboActionObjectInitialize->GetThenPin());
|
CompilerContext.MovePinLinksToIntermediate(*ComboActionPin, *ComboActionObjectInitialize->GetThenPin());
|
||||||
|
|
||||||
// Move the original event variable connections to the intermediate nodes
|
// Move the original event variable connections to the intermediate nodes
|
||||||
CompilerContext.MovePinLinksToIntermediate(*this->FindPin(COMBO_ACTION_OBJECT_PIN_NAME), *ComboActionObjectVar->GetVariablePin());
|
CompilerContext.MovePinLinksToIntermediate(*this->FindPin(COMBO_ACTION_OBJECT_PIN_NAME), *ComboActionObjectVar->GetVariablePin());
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
//else if (ActivePins.Num() == 1)
|
|
||||||
//{
|
|
||||||
// UEdGraphPin *ComboActionPin = ActivePins[0].GetPin();
|
|
||||||
// EComboActionTriggerEvent ComboActionTriggerEvent = ActivePins[0].GetTriggerEvent();
|
|
||||||
|
|
||||||
// if (ComboActionPin->LinkedTo.Num() > 0)
|
|
||||||
// {
|
|
||||||
// UK2Node_ComboActionEvent *ComboActionEvent = CompilerContext.SpawnIntermediateEventNode<UK2Node_ComboActionEvent>(this, ComboActionPin, SourceGraph);
|
|
||||||
// ComboActionEvent->CustomFunctionName = FName(*FString::Printf(TEXT("ComboActionEvent_%s_%s"), *this->GetActionName().ToString(), *ComboActionEvent->GetName()));
|
|
||||||
// ComboActionEvent->ComboAction = this->ComboAction;
|
|
||||||
// ComboActionEvent->TriggerEvent = ComboActionTriggerEvent;
|
|
||||||
// ComboActionEvent->EventReference.SetExternalDelegateMember(FName(TEXT("ComboActionHandlerDynamicSignature__DelegateSignature")));
|
|
||||||
// ComboActionEvent->bInternalEvent = true;
|
|
||||||
// ComboActionEvent->AllocateDefaultPins();
|
|
||||||
|
|
||||||
// CompilerContext.MovePinLinksToIntermediate(*ComboActionPin, *Schema->FindExecutionPin(*ComboActionEvent, EGPD_Output));
|
|
||||||
// CompilerContext.MovePinLinksToIntermediate(*this->FindPin(COMBO_ACTION_OBJECT_PIN_NAME), *ComboActionEvent->FindPin(COMBO_ACTION_OBJECT_PIN_NAME));
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UK2Node_ComboAction::GetMenuActions(FBlueprintActionDatabaseRegistrar &ActionRegistrar) const
|
void UK2Node_ComboAction::GetMenuActions(FBlueprintActionDatabaseRegistrar &ActionRegistrar) const
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user