Updated TurnBaseCombat for ResourceBar Functionality

This commit is contained in:
Philip W 2022-11-15 01:12:45 +00:00
parent 189b6d25b8
commit 9d72f60208
3 changed files with 48 additions and 3 deletions

Binary file not shown.

View File

@ -53,6 +53,8 @@ void ATurnBaseCombat::BeginPlay()
BattleLogTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("BattleLog"));
PlayerHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("PlayerHealthBar"));
EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar"));
IronResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("IronResourceBar"));
SulfurResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("SulfurResourceBar"));
CastButton = Cast<UButton>(HUD->GetWidgetFromName("CastButton"));
FButton = Cast<UButton>(HUD->GetWidgetFromName("FButton"));
WButton = Cast<UButton>(HUD->GetWidgetFromName("WButton"));
@ -68,10 +70,23 @@ void ATurnBaseCombat::ExecuteCast(FString Combo)
if (!IsValidCombo(Combo))
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Invalid Combo"));
//For each character in the current combo add back the resource
for (int i = 0; i < Combo.Len(); i++)
{
if (Combo[i] == 'F')
{
IronResource += 1;
}
else if (Combo[i] == 'W')
{
SulfurResource += 1;
}
}
CurrentComboString = "";
UpdateComboString(CurrentComboString);
RevertActionPoints();
UpdateActionPoints();
UpdateResourceBars();
return;
}
@ -177,6 +192,8 @@ void ATurnBaseCombat::FButtonOnClick()
UseActionPoint();
CurrentComboString.AppendChar('F');
UpdateComboString(CurrentComboString);
IronResource -= 1;
UpdateResourceBars();
}
void ATurnBaseCombat::WButtonOnClick()
@ -189,6 +206,8 @@ void ATurnBaseCombat::WButtonOnClick()
UseActionPoint();
CurrentComboString.AppendChar('W');
UpdateComboString(CurrentComboString);
SulfurResource -= 1;
UpdateResourceBars();
}
void ATurnBaseCombat::BackspaceButtonOnClick()
@ -199,8 +218,17 @@ void ATurnBaseCombat::BackspaceButtonOnClick()
return;
}
ReuseActionPoint();
if (CurrentComboString.Right(1) == "F")
{
IronResource += 1;
}
else if (CurrentComboString.Right(1) == "W")
{
SulfurResource += 1;
}
CurrentComboString.RemoveAt(CurrentComboString.Len() - 1);
UpdateComboString(CurrentComboString);
UpdateResourceBars();
}
void ATurnBaseCombat::UpdateComboString(FString NewCombo) const
@ -233,3 +261,9 @@ void ATurnBaseCombat::UpdateBattleLog()
}
BattleLogTextBlock->SetText(FText::FromString(BattleLog));
}
void ATurnBaseCombat::UpdateResourceBars() const
{
IronResourceBar->SetPercent(IronResource / 10.0f);
SulfurResourceBar->SetPercent(SulfurResource / 10.0f);
}

View File

@ -28,6 +28,10 @@ public:
int DefaultActionPoints = 3;
UPROPERTY(EditDefaultsOnly)
int ActiveActionPoints = 0;
UPROPERTY(EditDefaultsOnly)
int IronResource = 10; // F
UPROPERTY(EditDefaultsOnly)
int SulfurResource = 10; // W
// AActor* PlayerActor;
UPROPERTY(VisibleAnywhere)
@ -97,6 +101,12 @@ private:
UPROPERTY(VisibleAnywhere)
UProgressBar* EnemyHealthBar;
UPROPERTY(VisibleAnywhere)
UProgressBar* IronResourceBar;
UPROPERTY(VisibleAnywhere)
UProgressBar* SulfurResourceBar;
UPROPERTY(VisibleAnywhere)
UButton* CastButton;
@ -127,4 +137,5 @@ private:
void AddBattleLogMessage(FString Message);
void ClearBattleLog();
void UpdateBattleLog();
void UpdateResourceBars() const;
};