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")); TurnIndicatorTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("TurnIndicator"));
CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo")); CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo"));
ActionPointsTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("ActionPoints")); ActionPointsTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("ActionPoints"));
BattleLogTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("BattleLog"));
PlayerHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("PlayerHealthBar")); PlayerHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("PlayerHealthBar"));
EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar")); EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar"));
CastButton = Cast<UButton>(HUD->GetWidgetFromName("CastButton")); CastButton = Cast<UButton>(HUD->GetWidgetFromName("CastButton"));
@ -107,12 +108,14 @@ void ATurnBaseCombat::DamagePlayer(int Damage)
{ {
PlayerHealth -= FMath::Clamp(Damage, 0, 100); PlayerHealth -= FMath::Clamp(Damage, 0, 100);
UpdateProgressBars(); UpdateProgressBars();
AddBattleLogMessage("Player was damaged for " + FString::FromInt(Damage) + " damage.");
} }
void ATurnBaseCombat::DamageEnemy(int Damage) void ATurnBaseCombat::DamageEnemy(int Damage)
{ {
EnemyHealth -= FMath::Clamp(Damage, 0, 100); EnemyHealth -= FMath::Clamp(Damage, 0, 100);
UpdateProgressBars(); UpdateProgressBars();
AddBattleLogMessage("Enemy was damaged for " + FString::FromInt(Damage) + " damage.");
} }
void ATurnBaseCombat::UpdateProgressBars() const void ATurnBaseCombat::UpdateProgressBars() const
@ -189,8 +192,23 @@ void ATurnBaseCombat::UpdateActionPoints() const
void ATurnBaseCombat::AddBattleLogMessage(FString Message) void ATurnBaseCombat::AddBattleLogMessage(FString Message)
{ {
FString* tempTextBlock; BattleLog.Append(Message + "\n");
BattleLog.Enqueue(Message); UpdateBattleLog();
tempTextBlock = BattleLog.Peek(); }
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} {"FW", 20}
}; };
TQueue<FString> BattleLog; FString BattleLog;
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
@ -77,6 +77,9 @@ private:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
UTextBlock* CurrentComboTextBlock; UTextBlock* CurrentComboTextBlock;
UPROPERTY(VisibleAnywhere)
UTextBlock* BattleLogTextBlock;
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
UTextBlock* ActionPointsTextBlock; UTextBlock* ActionPointsTextBlock;
@ -114,4 +117,6 @@ private:
void UpdateActionPoints() const; void UpdateActionPoints() const;
void AddBattleLogMessage(FString Message); void AddBattleLogMessage(FString Message);
void ClearBattleLog();
void UpdateBattleLog();
}; };