// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "DialogueChoiceNode.h"
#include "DialogueTextNode.h"
#include "Components/ActorComponent.h"
#include "AC_PlayerDialogueInterpreter.generated.h"


UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class ENDLESSVENDETTA_API UAC_PlayerDialogueInterpreter : public UActorComponent
{
	GENERATED_BODY()

public:
	// Sets default values for this component's properties
	UAC_PlayerDialogueInterpreter();

	DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnStartDialogue, UDialogueTextNode*, StartingNode);

	DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnNextDialogue, UDialogueTextNode*, NextNode);

	DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnChoiceDialogue, UDialogueChoiceNode*, ChoiceNode);

	DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnEndDialogue);

	UPROPERTY(BlueprintAssignable, Category = "Dialogue")
	FOnStartDialogue OnStartDialogue;
	UPROPERTY(BlueprintAssignable, Category = "Dialogue")
	FOnNextDialogue OnNextDialogue;
	UPROPERTY(BlueprintAssignable, Category = "Dialogue")
	FOnChoiceDialogue OnChoiceDialogue;
	UPROPERTY(BlueprintAssignable, Category = "Dialogue")
	FOnEndDialogue OnEndDialogue;

	UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Dialogue")
	UDialogueTree* CurrentDialogueTree;
	UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Dialogue")
	FDialogueCharacter CurrentCharacterSpeaking;

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

private:
	UPROPERTY()
	UDialogueTextNode* CurrentTextNode;
	UPROPERTY()
	UDialogueChoiceNode* CurrentChoiceNode;
	FDialogueCharacter* GetCharacterSpeakingFromEnum(ECharacterSpeaking CharacterSpeakingEnum) const;

public:
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

	UFUNCTION(BlueprintCallable, Category = "Dialogue")
	void StartDialogue(UDialogueTree* DialogueTree);
	UFUNCTION(BlueprintCallable, Category = "Dialogue")
	void NextDialogue();
	UFUNCTION(BlueprintCallable, Category = "Dialogue")
	void MakeChoiceDialogue(int Choice);
	UFUNCTION(BlueprintCallable, Category = "Dialogue")
	void EndDialogue();
};
