// Project Lab - NHTV Igad
#pragma once

#include "KismetCompiler.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "SpawnActorBaseNode.Generated.h"

UCLASS()
class ATestObject : public AActor
{
	GENERATED_BODY()
};

UCLASS()
class UK2Node_SpawnActorBaseNode : public UK2Node
{
	GENERATED_UCLASS_BODY()

	// Begin UEdGraphNode interface.
	virtual void AllocateDefaultPins() override;
	virtual FLinearColor GetNodeTitleColor() const override;
	virtual FText GetNodeTitle(ENodeTitleType::Type TitleType) const override;
	virtual void PinDefaultValueChanged(UEdGraphPin* Pin) override;
	virtual void PinConnectionListChanged(UEdGraphPin* Pin) override;
	virtual FText GetTooltipText() const override;
	virtual void ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) override;
	virtual bool HasExternalDependencies(TArray<class UStruct*>* OptionalOutput) const override;
	virtual FName GetPaletteIcon(FLinearColor& OutColor) const override{ return TEXT("GraphEditor.SpawnActor_16x"); }
	virtual bool IsCompatibleWithGraph(const UEdGraph* TargetGraph) const override;
	virtual void PostPlacedNewNode() override;
	// End UEdGraphNode interface.

	// Begin UK2Node interface
	virtual bool IsNodeSafeToIgnore() const override { return true; }
	virtual void ReallocatePinsDuringReconstruction(TArray<UEdGraphPin*>& OldPins) override;
	virtual void GetNodeAttributes(TArray<TKeyValuePair<FString, FString>>& OutNodeAttributes) const override;
	virtual void GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const override;
	virtual FText GetMenuCategory() const override;
	virtual class FNodeHandlingFunctor* CreateNodeHandler(class FKismetCompilerContext& CompilerContext) const override;
	// End UK2Node interface


	void CreatePinsForClass(UClass* InClass, TArray<UEdGraphPin*>& OutClassPins);
	bool IsSpawnVarPin(UEdGraphPin* Pin);

	UEdGraphPin* GetThenPin() const;
	UEdGraphPin* GetClassPin(const TArray<UEdGraphPin*>* InPinsToSearch = NULL) const;
	UEdGraphPin* GetWorldContextPin() const;
	UEdGraphPin* GetSpawnTransformPin() const;
	UEdGraphPin* GetResultPin() const;

	UClass* GetClassToSpawn(const TArray<UEdGraphPin*>* InPinsToSearch = NULL) const;

protected:
	virtual FName GetBeginSpawningFunction() const { return "BeginSpawning2"; }
	virtual FName GetFinishSpawningFunction() const { return "FinishSpawning2"; }
	virtual FString GetObjectName() const { return "Custom"; }
	virtual UClass* GetActorClass() const { return AActor::StaticClass(); }
	virtual bool SpawningFunctionHasTransform() const { return false; }
	virtual void RegisterAdditionalPins(const class UEdGraphSchema_K2* K2Schema) {};
	virtual bool IsAdditionalPin(class UEdGraphPin* pin) { return false; };
	virtual void ConnectAdditionalPins(class FKismetCompilerContext& CompilerContext, UK2Node* last, UK2Node* dst) {};

	void OnClassPinChanged();

	FText NodeTooltip;

	FNodeTextCache m_cachedNodeTitle;
};

UCLASS()
class USpawnGroupNode : public UK2Node_SpawnActorBaseNode
{
	GENERATED_BODY()

	virtual FName GetBeginSpawningFunction() const { return "BeginSpawningGroup"; }
	virtual FName GetFinishSpawningFunction() const { return "FinishSpawningGroup"; }
	virtual FString GetObjectName() const { return "Group"; }
	virtual UClass* GetActorClass() const;
	virtual bool SpawningFunctionHasTransform() const { return false; }
};
UCLASS()
class USpawnModifierNode : public UK2Node_SpawnActorBaseNode
{
	GENERATED_BODY()

	virtual FName GetBeginSpawningFunction() const { return "BeginSpawningModifier"; }
	virtual FName GetFinishSpawningFunction() const { return "FinishSpawningModifier"; }
	virtual FString GetObjectName() const { return "Modifier"; }
	virtual UClass* GetActorClass() const;
	virtual bool SpawningFunctionHasTransform() const { return false; }

	virtual void RegisterAdditionalPins(const class UEdGraphSchema_K2* K2Schema) override;
	virtual bool IsAdditionalPin(class UEdGraphPin* pin) override;
	virtual void ConnectAdditionalPins(class FKismetCompilerContext& CompilerContext, UK2Node* last, UK2Node* dst) override;
};
UCLASS()
class USpawnTriggerNode : public UK2Node_SpawnActorBaseNode
{
	GENERATED_BODY()

	virtual FName GetBeginSpawningFunction() const { return "BeginSpawningTrigger"; }
	virtual FName GetFinishSpawningFunction() const { return "FinishSpawningTrigger"; }
	virtual FString GetObjectName() const { return "Trigger"; }
	virtual UClass* GetActorClass() const;
	virtual bool SpawningFunctionHasTransform() const { return true; }
};

UCLASS()
class USpawnProjectileNode : public UK2Node_SpawnActorBaseNode
{
	GENERATED_BODY()

	virtual FName GetBeginSpawningFunction() const { return "BeginSpawningProjectile"; }
	virtual FName GetFinishSpawningFunction() const { return "FinishSpawningProjectile"; }
	virtual FString GetObjectName() const { return "Projectile"; }
	virtual UClass* GetActorClass() const;
	virtual bool SpawningFunctionHasTransform() const { return true; }
};