// Project Lab - NHTV Igad

#include "UnrealProject.h"
#include "AbilityButton.h"
#include "NetworkCharacter.h"
#include "AbilityInfo.h"
#include "AbilityState.h"

void UAbilityButton::NativeConstruct()
{
	m_globalEnable = true;
	Super::NativeConstruct();
	SetCooldown(1.0f);
	SetToggled(false);
	SetupButton(nullptr, false);
}

UAbilityInfo* UAbilityButton::GetAbility()
{
	return m_abilityInfo;
}

void UAbilityButton::InitButton(class UAbilityInfo* info, int32 index, bool alt)
{
	if (info)
	{
		SetCooldown(1.0f);
		SetToggled(false);
		SetupButton(info, false);
		SetIndex(index, alt);
		SetAbilityAvailable(true);
		m_index = index;
		m_abilityInfo = info;
	}
}

bool UAbilityButton::IsAssigned() const
{
	return m_abilityInfo != nullptr;
}

void UAbilityButton::UpdateState(class AAbilityState* state, ANetworkCharacter* character)
{
	SetToggled(state->toggleState);
	SetCooldown(state->cooldownRate);
	SetAbilityAvailable(character->GetMana() >= state->info->mana);
}

void UAbilityButton::SetButtonEnabled(bool enabled)
{
	m_enabled = enabled;
	if (m_abilityInfo)
	{
		SetupButton(m_abilityInfo, m_enabled && m_globalEnable);
	}
}
void UAbilityButton::SetGlobalEnable(bool enabled)
{
	m_globalEnable = enabled;
	SetupButton(m_abilityInfo, m_enabled && m_globalEnable);
}