////////////////////////////////////////////////////////////
//
// FormatMessage.h
//
// Two K2Nodes: FormatMessage and FormatLogMessage.
// FormatMessage outputs a formatted string as a pin.
// FormatLogMessage outputs it to the log instead.
//
// FormatLogMessage is a derived class that just sets
// a flag to alter the base class behavior.
//
////////////////////////////////////////////////////////////

#pragma once

#include "BreakToDebugger.h"
#include "FormatDataLibrary.h"
#include "LuprexK2Node.h"

#include "FormatMessage.generated.h"

class FBlueprintActionDatabaseRegistrar;
class FString;
class UEdGraph;
class UObject;

////////////////////////////////////////////////////////////
//
// UK2Node_FormatMessage
//
////////////////////////////////////////////////////////////

UCLASS(MinimalAPI)
class UK2Node_FormatMessage : public UlxK2Node
{
	GENERATED_BODY()

public:
	//~ Begin UEdGraphNode Interface.
	virtual void AllocateDefaultPins() override;
	virtual FText GetNodeTitle(ENodeTitleType::Type TitleType) const override;
	virtual bool ShouldShowNodeProperties() const override { return true; }
	virtual void PinConnectionListChanged(UEdGraphPin* Pin) override;
	virtual void PinDefaultValueChanged(UEdGraphPin* Pin) override;
	virtual FText GetTooltipText() const override;
	virtual FText GetPinDisplayName(const UEdGraphPin* Pin) const override;
	//~ End UEdGraphNode Interface.

	//~ Begin UK2Node Interface.
	virtual bool IsNodePure() const override { return false; }
	virtual void ReconstructNode() override;
	virtual void PostReconstructNode() override;
	virtual bool NodeCausesStructuralBlueprintChange() const override { return true; }
	virtual void ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph) override;
	virtual ERedirectType DoPinsMatchForReconstruction(const UEdGraphPin* NewPin, int32 NewPinIndex, const UEdGraphPin* OldPin, int32 OldPinIndex) const override;
	virtual bool IsConnectionDisallowed(const UEdGraphPin* MyPin, const UEdGraphPin* OtherPin, FString& OutReason) const override;
	virtual void GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const override;
	virtual FText GetMenuCategory() const override;
	virtual int32 GetNodeRefreshPriority() const override { return EBaseNodeRefreshPriority::Low_UsesDependentWildcard; }
	//~ End UK2Node Interface.

protected:
	// Synchronize the type of the given argument pin
	// with the type its connected to, or reset it to
	// a wildcard pin if there's no connection.
	//
	void SynchronizeArgumentPinType(UEdGraphPin* Pin);

	// During ExpandNode, expand a single argument pin into
	// a converter node. Returns the converter's output pin.
	//
	UEdGraphPin* ExpandArgumentPin(UEdGraphPin* ArgumentPin, class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph);

	// Derived class sets this to true, altering
	// the behavior of this K2Node.
	//
	virtual bool IsFormatErrorMessage() const { return false; }

private:
	static const FName VerbosityPinName;
	static const FName FormatPinName;
	static const FName ResultPinName;

protected:
	// Whenever the format pin value changes, we call
	// ReconstructNode, which backs up the value into this
	// property.  This cache is needed because during
	// ReconstructNode, we blow away the format pin.  The
	// format pin is also absent when the node is first
	// created.
	//
	UPROPERTY()
	FString FormatPattern = TEXT("Message");

};

////////////////////////////////////////////////////////////
//
// UK2Node_FormatLogMessage
//
// Derives from FormatMessage. Sets a flag to make
// the base class output to the log instead of to
// a pin.
//
////////////////////////////////////////////////////////////

UCLASS(MinimalAPI)
class UK2Node_FormatLogMessage : public UK2Node_FormatMessage
{
	GENERATED_BODY()

	virtual bool IsFormatErrorMessage() const override { return true; }
};
