2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#include "BlueprintGraphPrivatePCH.h"
|
2014-05-29 16:42:22 -04:00
|
|
|
#include "Kismet/KismetMathLibrary.h"
|
2014-09-17 05:39:56 -04:00
|
|
|
#include "Kismet/KismetStringLibrary.h"
|
2014-05-29 16:42:22 -04:00
|
|
|
#include "K2Node_SwitchString.h"
|
2014-07-14 13:29:38 -04:00
|
|
|
#include "BlueprintNodeSpawner.h"
|
2014-08-23 20:16:29 -04:00
|
|
|
#include "BlueprintActionDatabaseRegistrar.h"
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-10-14 10:29:11 -04:00
|
|
|
UK2Node_SwitchString::UK2Node_SwitchString(const FObjectInitializer& ObjectInitializer)
|
|
|
|
|
: Super(ObjectInitializer)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
bIsCaseSensitive = false;
|
2015-04-24 14:26:51 -04:00
|
|
|
SetupCaseSensitivityFunction();
|
2014-03-14 14:13:41 -04:00
|
|
|
FunctionClass = UKismetStringLibrary::StaticClass();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UK2Node_SwitchString::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
|
|
|
|
|
{
|
|
|
|
|
bool bIsDirty = false;
|
|
|
|
|
FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
|
|
|
|
|
if (PropertyName == TEXT("PinNames"))
|
|
|
|
|
{
|
|
|
|
|
bIsDirty = true;
|
|
|
|
|
}
|
|
|
|
|
else if (PropertyName == TEXT("bIsCaseSensitive"))
|
|
|
|
|
{
|
2015-04-24 14:26:51 -04:00
|
|
|
SetupCaseSensitivityFunction();
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
FunctionClass = UKismetStringLibrary::StaticClass();
|
|
|
|
|
bIsDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bIsDirty)
|
|
|
|
|
{
|
|
|
|
|
ReconstructNode();
|
|
|
|
|
GetGraph()->NotifyGraphChanged();
|
|
|
|
|
}
|
|
|
|
|
Super::PostEditChangeProperty(PropertyChangedEvent);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-24 14:26:51 -04:00
|
|
|
void UK2Node_SwitchString::SetupCaseSensitivityFunction()
|
|
|
|
|
{
|
|
|
|
|
FunctionName = (bIsCaseSensitive == true)
|
|
|
|
|
? TEXT("NotEqual_StrStr")
|
|
|
|
|
: TEXT("NotEqual_StriStri");
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-23 18:30:37 -04:00
|
|
|
FText UK2Node_SwitchString::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-04-23 18:30:37 -04:00
|
|
|
return NSLOCTEXT("K2Node", "Switch_String", "Switch on String");
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-03 18:14:09 -04:00
|
|
|
FText UK2Node_SwitchString::GetTooltipText() const
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-09-03 18:14:09 -04:00
|
|
|
return NSLOCTEXT("K2Node", "SwitchString_ToolTip", "Selects an output that matches the input value");
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-08-23 20:16:29 -04:00
|
|
|
void UK2Node_SwitchString::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
|
2014-07-14 13:29:38 -04:00
|
|
|
{
|
2014-09-10 17:09:26 -04:00
|
|
|
// actions get registered under specific object-keys; the idea is that
|
|
|
|
|
// actions might have to be updated (or deleted) if their object-key is
|
|
|
|
|
// mutated (or removed)... here we use the node's class (so if the node
|
|
|
|
|
// type disappears, then the action should go with it)
|
|
|
|
|
UClass* ActionKey = GetClass();
|
|
|
|
|
// to keep from needlessly instantiating a UBlueprintNodeSpawner, first
|
|
|
|
|
// check to make sure that the registrar is looking for actions of this type
|
|
|
|
|
// (could be regenerating actions for a specific asset, and therefore the
|
|
|
|
|
// registrar would only accept actions corresponding to that asset)
|
|
|
|
|
if (ActionRegistrar.IsOpenForRegistration(ActionKey))
|
|
|
|
|
{
|
|
|
|
|
UBlueprintNodeSpawner* NodeSpawner = UBlueprintNodeSpawner::Create(GetClass());
|
|
|
|
|
check(NodeSpawner != nullptr);
|
2014-07-14 13:29:38 -04:00
|
|
|
|
2014-09-10 17:09:26 -04:00
|
|
|
ActionRegistrar.AddBlueprintAction(ActionKey, NodeSpawner);
|
|
|
|
|
}
|
2014-07-14 13:29:38 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
void UK2Node_SwitchString::CreateSelectionPin()
|
|
|
|
|
{
|
|
|
|
|
const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
|
2014-09-16 10:25:25 -04:00
|
|
|
UEdGraphPin* Pin = CreatePin(EGPD_Input, K2Schema->PC_String, TEXT(""), NULL, false, false, TEXT("Selection"));
|
|
|
|
|
K2Schema->SetPinDefaultValueBasedOnType(Pin);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-16 14:26:32 -04:00
|
|
|
FEdGraphPinType UK2Node_SwitchString::GetPinType() const
|
|
|
|
|
{
|
|
|
|
|
FEdGraphPinType PinType;
|
2014-09-16 15:31:59 -04:00
|
|
|
PinType.PinCategory = UEdGraphSchema_K2::PC_String;
|
2014-09-16 14:26:32 -04:00
|
|
|
return PinType;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
FString UK2Node_SwitchString::GetPinNameGivenIndex(int32 Index)
|
|
|
|
|
{
|
|
|
|
|
check(Index);
|
|
|
|
|
return PinNames[Index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UK2Node_SwitchString::CreateCasePins()
|
|
|
|
|
{
|
|
|
|
|
const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
|
|
|
|
|
for( TArray<FString>::TIterator it(PinNames); it; ++it )
|
|
|
|
|
{
|
|
|
|
|
CreatePin(EGPD_Output, K2Schema->PC_Exec, TEXT(""), NULL, false, false, *it);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString UK2Node_SwitchString::GetUniquePinName()
|
|
|
|
|
{
|
|
|
|
|
FString NewPinName;
|
|
|
|
|
int32 Index = 0;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
NewPinName = FString::Printf(TEXT("Case_%d"), Index++);
|
|
|
|
|
if (!FindPin(NewPinName))
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NewPinName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UK2Node_SwitchString::AddPinToSwitchNode()
|
|
|
|
|
{
|
|
|
|
|
FString PinName = GetUniquePinName();
|
|
|
|
|
PinNames.Add(PinName);
|
|
|
|
|
|
|
|
|
|
const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
|
|
|
|
|
CreatePin(EGPD_Output, K2Schema->PC_Exec, TEXT(""), NULL, false, false, PinName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UK2Node_SwitchString::RemovePin(UEdGraphPin* TargetPin)
|
|
|
|
|
{
|
|
|
|
|
checkSlow(TargetPin);
|
|
|
|
|
|
|
|
|
|
// Clean-up pin name array
|
|
|
|
|
PinNames.Remove(TargetPin->PinName);
|
|
|
|
|
}
|