// Copyright Pacificao. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "AgrarianMvpFrontendWidget.generated.h"

UENUM(BlueprintType)
enum class EAgrarianMvpFrontendScreen : uint8
{
	MainMenu,
	CharacterSelection,
	JoinServer,
	Loading
};

UENUM(BlueprintType)
enum class EAgrarianMvpCharacterArchetype : uint8
{
	YoungAdultMale,
	YoungAdultFemale
};

UCLASS()
class AGRARIANGAME_API UAgrarianMvpFrontendWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI")
	EAgrarianMvpFrontendScreen ActiveScreen = EAgrarianMvpFrontendScreen::MainMenu;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI")
	EAgrarianMvpCharacterArchetype SelectedCharacterArchetype = EAgrarianMvpCharacterArchetype::YoungAdultMale;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI")
	FText MainMenuTitle = FText::FromString(TEXT("Agrarian"));

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI")
	FText MainMenuSubtitle = FText::FromString(TEXT("MVP investor build"));

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI")
	FText PrimaryActionLabel = FText::FromString(TEXT("Begin"));

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI")
	FText JoinServerAddress = FText::FromString(TEXT("play.agrariangame.com:7777"));

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|MVP UI", meta = (ClampMin = "0.75", ClampMax = "1.5"))
	float UiScale = 1.0f;

	UFUNCTION(BlueprintCallable, Category = "Agrarian|MVP UI")
	void SetActiveScreen(EAgrarianMvpFrontendScreen NewScreen);

	UFUNCTION(BlueprintCallable, Category = "Agrarian|MVP UI")
	void SetSelectedCharacterArchetype(EAgrarianMvpCharacterArchetype NewArchetype);

protected:
	virtual void NativeConstruct() override;

	virtual FReply NativeOnKeyDown(const FGeometry& InGeometry, const FKeyEvent& InKeyEvent) override;

	virtual int32 NativePaint(
		const FPaintArgs& Args,
		const FGeometry& AllottedGeometry,
		const FSlateRect& MyCullingRect,
		FSlateWindowElementList& OutDrawElements,
		int32 LayerId,
		const FWidgetStyle& InWidgetStyle,
		bool bParentEnabled) const override;

private:
	void DrawMainMenu(
		FSlateWindowElementList& OutDrawElements,
		int32& LayerId,
		const FGeometry& AllottedGeometry,
		const FVector2D& PanelPosition,
		const FVector2D& PanelSize,
		float Scale) const;

	void DrawCharacterSelection(
		FSlateWindowElementList& OutDrawElements,
		int32& LayerId,
		const FGeometry& AllottedGeometry,
		const FVector2D& PanelPosition,
		const FVector2D& PanelSize,
		float Scale) const;

	void DrawJoinServer(
		FSlateWindowElementList& OutDrawElements,
		int32& LayerId,
		const FGeometry& AllottedGeometry,
		const FVector2D& PanelPosition,
		const FVector2D& PanelSize,
		float Scale) const;

	void DrawLoading(
		FSlateWindowElementList& OutDrawElements,
		int32& LayerId,
		const FGeometry& AllottedGeometry,
		const FVector2D& PanelPosition,
		const FVector2D& PanelSize,
		float Scale) const;

	FText GetSelectedCharacterLabel() const;

	void DrawTextAt(
		FSlateWindowElementList& OutDrawElements,
		int32& LayerId,
		const FGeometry& AllottedGeometry,
		const FText& Text,
		const FVector2D& Position,
		float Width,
		const FSlateFontInfo& Font,
		const FLinearColor& Color) const;
};
