Updated Combat_UI for Battle Log

This commit is contained in:
Philip W 2022-11-14 22:30:31 +00:00
parent b765f633d6
commit f2857b3c57
3 changed files with 50 additions and 27 deletions

Binary file not shown.

View File

@ -40,6 +40,7 @@ void ATurnBaseCombat::BeginPlay()
TurnIndicatorTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("TurnIndicator"));
CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo"));
ActionPointsTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("ActionPoints"));
BattleLogTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("BattleLog"));
PlayerHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("PlayerHealthBar"));
EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar"));
CastButton = Cast<UButton>(HUD->GetWidgetFromName("CastButton"));
@ -107,12 +108,14 @@ void ATurnBaseCombat::DamagePlayer(int Damage)
{
PlayerHealth -= FMath::Clamp(Damage, 0, 100);
UpdateProgressBars();
AddBattleLogMessage("Player was damaged for " + FString::FromInt(Damage) + " damage.");
}
void ATurnBaseCombat::DamageEnemy(int Damage)
{
EnemyHealth -= FMath::Clamp(Damage, 0, 100);
UpdateProgressBars();
AddBattleLogMessage("Enemy was damaged for " + FString::FromInt(Damage) + " damage.");
}
void ATurnBaseCombat::UpdateProgressBars() const
@ -189,8 +192,23 @@ void ATurnBaseCombat::UpdateActionPoints() const
void ATurnBaseCombat::AddBattleLogMessage(FString Message)
{
FString* tempTextBlock;
BattleLog.Enqueue(Message);
tempTextBlock = BattleLog.Peek();
BattleLog.Append(Message + "\n");
UpdateBattleLog();
}
void ATurnBaseCombat::ClearBattleLog()
{
BattleLog = "";
}
void ATurnBaseCombat::UpdateBattleLog()
{
TArray<FString> tempArray;
//Get the amount of lines in the battle log
int32 LineCount = BattleLog.ParseIntoArray(tempArray, TEXT("\n"), true);
if (LineCount > 10) //If there are more than 10 lines
{
ClearBattleLog();
}
BattleLogTextBlock->SetText(FText::FromString(BattleLog));
}

View File

@ -48,7 +48,7 @@ public:
{"FW", 20}
};
TQueue<FString> BattleLog;
FString BattleLog;
protected:
virtual void BeginPlay() override;
@ -77,6 +77,9 @@ private:
UPROPERTY(VisibleAnywhere)
UTextBlock* CurrentComboTextBlock;
UPROPERTY(VisibleAnywhere)
UTextBlock* BattleLogTextBlock;
UPROPERTY(VisibleAnywhere)
UTextBlock* ActionPointsTextBlock;
@ -114,4 +117,6 @@ private:
void UpdateActionPoints() const;
void AddBattleLogMessage(FString Message);
void ClearBattleLog();
void UpdateBattleLog();
};