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


#include "HUDWidget.h"
#include "Components/ProgressBar.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"
#include "NakedDesire/Stats/StatsManager.h"

void UHUDWidget::NativeConstruct()
{
	Super::NativeConstruct();

	const ANakedDesireCharacter* Player = Cast<ANakedDesireCharacter>(GetOwningPlayerPawn());
	if (!Player)
		return;
	
	Player->StatsManager->EmbarrassmentUpdate.AddUniqueDynamic(this, &UHUDWidget::OnEmbarrassmentUpdated);
	Player->StatsManager->EnergyUpdate.AddUniqueDynamic(this, &UHUDWidget::OnEnergyUpdated);
	Player->StatsManager->StaminaUpdate.AddUniqueDynamic(this, &UHUDWidget::OnStaminaUpdated);
}

void UHUDWidget::OnEmbarrassmentUpdated(float CurrentValue, float MaxValue)
{
	EmbarrassmentBar->SetPercent(CurrentValue / MaxValue);
}

void UHUDWidget::OnEnergyUpdated(float CurrentValue, float MaxValue)
{
	EnergyBar->SetPercent(CurrentValue / MaxValue);
}

void UHUDWidget::OnStaminaUpdated(float CurrentValue, float MaxValue)
{
	StaminaBar->SetPercent(CurrentValue / MaxValue);
}
