// Project Lab - NHTV Igad

#pragma once

#include "Blueprint/UserWidget.h"
#include <map>
#include "Minimap.h"
#include "MiniMapWidget.generated.h"

/**
 * 
 */
UCLASS()
class UNREALPROJECT_API UMiniMapWidget : public UUserWidget
{
	GENERATED_BODY()
	
public:
	UMiniMapWidget(const FObjectInitializer& init);

	UFUNCTION(BlueprintNativeEvent, Category = "MiniMap")
	void SetObjectIcon(class UTexture2D* texture, class UMiniMapIconWidget* widget);

	virtual void NativeConstruct() override;
	virtual void NativeTick(const FGeometry& geometry, float deltaTime) override;

	UPROPERTY(EditAnywhere, Category = "MiniMap")
	float viewRadius;

	UPROPERTY(EditAnywhere, Category = "Minimap")
	FLinearColor playerColor;
	UPROPERTY(EditAnywhere, Category = "Minimap")
	FLinearColor allyColor;
	UPROPERTY(EditAnywhere, Category = "Minimap")
	FLinearColor enemyColor;
	UPROPERTY(EditAnywhere, Category = "Minimap")
	FLinearColor neutralColor;

	UPROPERTY(EditAnywhere, Category = "MiniMap")
	UTexture2D* playerIcon;
	UPROPERTY(EditAnywhere, Category = "MiniMap")
	UTexture2D* creatureIcon;
	UPROPERTY(EditAnywhere, Category = "MiniMap")
	UTexture2D* bossIcon;
	UPROPERTY(EditAnywhere, Category = "MiniMap")
	UTexture2D* campIcon;
	UPROPERTY(EditAnywhere, Category = "MiniMap")
	UTexture2D* arrowIcon;

	UFUNCTION(BlueprintNativeEvent, Category = "MiniMap")
	void SetMinimapInfo(FVector2D player0, FVector2D player1, float radius);

	FVector2D ConvertWorldToMinimap(const FVector2D& pos);

	UPROPERTY(EditAnywhere, Category = "MiniMap")
	TSubclassOf<class UMiniMapIconWidget> iconWidget;
	UPROPERTY(EditAnywhere, Category = "MiniMap")
	TSubclassOf<class UMiniMapVisionCircle> visionCircleWidget;
	UPROPERTY(BlueprintReadWrite, Category = "MiniMap")
	UCanvasPanel* iconLayer;
	UPROPERTY(BlueprintReadWrite, Category = "MiniMap")
	UCanvasPanel* arrowLayer;
	UPROPERTY(BlueprintReadWrite, Category = "MiniMap")
	UTexture2D* backgroundTexture;
	UPROPERTY(BlueprintReadWrite, Category = "MiniMap")
	UCanvasPanel* visionLayer;

private:
	void m_DrawCreature(const FGeometry& geometry, UMiniMapIconWidget* widget, class ACharacterBase* character);
	UMiniMapIconWidget* m_AllocateWidget();
	UMiniMapIconWidget* m_AllocateArrow();
	UMiniMapVisionCircle* m_AllocateVisionCircle();

	TArray<class UMiniMapIconWidget*> m_miniMapIconWidgetPool;
	TArray<class UMiniMapIconWidget*> m_arrowMapIconWidgetPool;
	TArray<class UMiniMapVisionCircle*> m_viewCircleWidgetPool;
	TArray<MiniMap::MinimapHandle*> m_handleBuffer;

	FVector2D m_min;
	FVector2D m_max;
	float m_size;
	float m_viewRadius;
	float m_arrowAnim;
	int32 m_localTeam;

	int32 m_widgetIndex;
	int32 m_arrowIndex;
	int32 m_circleIndex;
};