143 lines
5.0 KiB
C++
143 lines
5.0 KiB
C++
|
|
// Copyright 2022 Just2Devs. All Rights Reserved.
|
|||
|
|
|
|||
|
|
#include "K2Node_WidgetSlotCast.h"
|
|||
|
|
#include "BlueprintActionDatabaseRegistrar.h"
|
|||
|
|
#include "BlueprintNodeSpawner.h"
|
|||
|
|
#include "K2Node_CallFunction.h"
|
|||
|
|
#include "K2Node_IfThenElse.h"
|
|||
|
|
#include "Editor/BlueprintGraph/Classes/K2Node_SwitchEnum.h"
|
|||
|
|
#include "KismetCompiler.h"
|
|||
|
|
#include "WidgetFL.h"
|
|||
|
|
#include "Async/IAsyncTask.h"
|
|||
|
|
|
|||
|
|
FName UK2Node_WidgetSlotCast::SuccessfulCastPinName("Successful");
|
|||
|
|
FName UK2Node_WidgetSlotCast::FailedCastPinName("Failed");
|
|||
|
|
FName UK2Node_WidgetSlotCast::WidgetPinName("Widget");
|
|||
|
|
FName UK2Node_WidgetSlotCast::CastResultPinName("CastResult");
|
|||
|
|
FName UK2Node_WidgetSlotCast::SlotPinName("Slot");
|
|||
|
|
|
|||
|
|
#define LOCTEXT_NAMESPACE "K2Node_WidgetSlotCast"
|
|||
|
|
|
|||
|
|
void UK2Node_WidgetSlotCast::AllocateDefaultPins()
|
|||
|
|
{
|
|||
|
|
Super::AllocateDefaultPins();
|
|||
|
|
|
|||
|
|
// Create exec pin
|
|||
|
|
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Execute);
|
|||
|
|
|
|||
|
|
UEdGraphPin* ThenPin = CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Then);
|
|||
|
|
ThenPin->PinFriendlyName = FText::FromString("Successful");
|
|||
|
|
|
|||
|
|
// Create widget pin
|
|||
|
|
UEdGraphPin* WidgetPin = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Object, UWidget::StaticClass(), WidgetPinName);
|
|||
|
|
WidgetPin->PinType.bIsReference = true;
|
|||
|
|
|
|||
|
|
// Create failed pin
|
|||
|
|
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, FailedCastPinName);
|
|||
|
|
|
|||
|
|
// Create output slot pin
|
|||
|
|
check(IsValid(PinSlotType));
|
|||
|
|
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Object, PinSlotType, SlotPinName);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FText UK2Node_WidgetSlotCast::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
|||
|
|
{
|
|||
|
|
FText NodeTitle = FText::FromName(FunctionNodeTitle);
|
|||
|
|
return NodeTitle;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FSlateIcon UK2Node_WidgetSlotCast::GetIconAndTint(FLinearColor& OutColor) const
|
|||
|
|
{
|
|||
|
|
static FSlateIcon Icon("EditorStyle", "GraphEditor.Cast_16x");
|
|||
|
|
return Icon;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FLinearColor UK2Node_WidgetSlotCast::GetNodeTitleColor() const
|
|||
|
|
{
|
|||
|
|
return FLinearColor(0.0f, 0.55f, 0.62f);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FText UK2Node_WidgetSlotCast::GetTooltipText() const
|
|||
|
|
{
|
|||
|
|
return LOCTEXT("WidgetSlotCastK2Node_Tooltip", "Cast the widget passed in to the slot.");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UK2Node_WidgetSlotCast::GetPinHoverText(const UEdGraphPin& Pin, FString& HoverTextOut) const
|
|||
|
|
{
|
|||
|
|
if(Pin.PinFriendlyName.EqualTo(FText::FromName(SuccessfulCastPinName)))
|
|||
|
|
{
|
|||
|
|
HoverTextOut = TEXT("Successful fires if the widget passed in is castable to the slot of this cast.");
|
|||
|
|
}
|
|||
|
|
else if(Pin.PinName.IsEqual(FailedCastPinName))
|
|||
|
|
{
|
|||
|
|
HoverTextOut = TEXT("Failed fires if the widget passed in is not castable to the slot of this cast.");
|
|||
|
|
}
|
|||
|
|
else if(Pin.PinName.IsEqual(WidgetPinName))
|
|||
|
|
{
|
|||
|
|
HoverTextOut = TEXT("The widget the node tries to cast to a slot.");
|
|||
|
|
}
|
|||
|
|
else if(Pin.PinName.IsEqual(SlotPinName))
|
|||
|
|
{
|
|||
|
|
HoverTextOut = TEXT("The slot the widget was casted to.");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FText UK2Node_WidgetSlotCast::GetMenuCategory() const
|
|||
|
|
{
|
|||
|
|
return LOCTEXT("WidgetSlotCastK2Node_NodeCategory", "Widget Function Library|Cast Slots");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UK2Node_WidgetSlotCast::ExpandNode(FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
|
|||
|
|
{
|
|||
|
|
Super::ExpandNode(CompilerContext, SourceGraph);
|
|||
|
|
|
|||
|
|
const UEdGraphSchema_K2* Schema = CompilerContext.GetSchema();
|
|||
|
|
check(SourceGraph && Schema);
|
|||
|
|
|
|||
|
|
UK2Node_CallFunction* CastFunction = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph);
|
|||
|
|
CastFunction->SetFromFunction(UWidgetFL::StaticClass()->FindFunctionByName(FunctionName));
|
|||
|
|
CastFunction->AllocateDefaultPins();
|
|||
|
|
|
|||
|
|
// Connect exec pin
|
|||
|
|
CompilerContext.MovePinLinksToIntermediate(*GetExecPin(), *CastFunction->GetExecPin());
|
|||
|
|
|
|||
|
|
// Connect widget pin
|
|||
|
|
UEdGraphPin* WidgetPin = FindPin(WidgetPinName);
|
|||
|
|
UEdGraphPin* CastFunctionWidgetPin = CastFunction->FindPin(WidgetPinName);
|
|||
|
|
CompilerContext.MovePinLinksToIntermediate(*WidgetPin, *CastFunctionWidgetPin);
|
|||
|
|
|
|||
|
|
// Connect output slot pin
|
|||
|
|
UEdGraphPin* SlotPin = FindPin(SlotPinName);
|
|||
|
|
UEdGraphPin* CastFunctionSlotPin = CastFunction->FindPin(SlotPinName);
|
|||
|
|
CompilerContext.MovePinLinksToIntermediate(*SlotPin, *CastFunctionSlotPin);
|
|||
|
|
|
|||
|
|
// Create branch node
|
|||
|
|
UK2Node_IfThenElse* BranchNode = CompilerContext.SpawnIntermediateNode<UK2Node_IfThenElse>(this, SourceGraph);
|
|||
|
|
BranchNode->AllocateDefaultPins();
|
|||
|
|
|
|||
|
|
UEdGraphPin* CastFunctionThenPin = CastFunction->FindPin(UEdGraphSchema_K2::PN_Then);
|
|||
|
|
Schema->TryCreateConnection(CastFunctionThenPin, BranchNode->GetExecPin());
|
|||
|
|
Schema->TryCreateConnection(CastFunction->GetReturnValuePin(), BranchNode->GetConditionPin());
|
|||
|
|
|
|||
|
|
UEdGraphPin* ThenPin = FindPin(UEdGraphSchema_K2::PN_Then);
|
|||
|
|
CompilerContext.MovePinLinksToIntermediate(*ThenPin, *BranchNode->GetThenPin());
|
|||
|
|
CompilerContext.MovePinLinksToIntermediate(*FindPin(FailedCastPinName), *BranchNode->GetElsePin());
|
|||
|
|
|
|||
|
|
BreakAllNodeLinks();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void UK2Node_WidgetSlotCast::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
|
|||
|
|
{
|
|||
|
|
const UClass* Action = GetClass();
|
|||
|
|
|
|||
|
|
if (ActionRegistrar.IsOpenForRegistration(Action))
|
|||
|
|
{
|
|||
|
|
UBlueprintNodeSpawner* Spawner = UBlueprintNodeSpawner::Create(GetClass());
|
|||
|
|
check(Spawner != nullptr);
|
|||
|
|
|
|||
|
|
ActionRegistrar.AddBlueprintAction(Action, Spawner);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#undef LOCTEXT_NAMESPACE
|