From 9d72f602088ba20b5af3c98c122ee2453d16e04a Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Tue, 15 Nov 2022 01:12:45 +0000 Subject: [PATCH] Updated TurnBaseCombat for ResourceBar Functionality --- Content/Blueprints/Combat_UI/Combat_UI.uasset | 4 +-- .../TurnBasedCombat/TurnBaseCombat.cpp | 36 ++++++++++++++++++- .../TurnBasedCombat/TurnBaseCombat.h | 11 ++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Content/Blueprints/Combat_UI/Combat_UI.uasset b/Content/Blueprints/Combat_UI/Combat_UI.uasset index fa506ce..aae01ca 100644 --- a/Content/Blueprints/Combat_UI/Combat_UI.uasset +++ b/Content/Blueprints/Combat_UI/Combat_UI.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4fdf3d35b3617fe978aca3de1a70d9ee6ae78df938ccdf6f3a08111a8fb4c20e -size 56607 +oid sha256:545b239dc38454f274d0f4ff5310ec6655a045999eb17764ed0e9bf31e17fa42 +size 56768 diff --git a/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.cpp b/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.cpp index 01aa6ad..70b1bc7 100644 --- a/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.cpp +++ b/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.cpp @@ -53,6 +53,8 @@ void ATurnBaseCombat::BeginPlay() BattleLogTextBlock = Cast(HUD->GetWidgetFromName("BattleLog")); PlayerHealthBar = Cast(HUD->GetWidgetFromName("PlayerHealthBar")); EnemyHealthBar = Cast(HUD->GetWidgetFromName("EnemyHealthBar")); + IronResourceBar = Cast(HUD->GetWidgetFromName("IronResourceBar")); + SulfurResourceBar = Cast(HUD->GetWidgetFromName("SulfurResourceBar")); CastButton = Cast(HUD->GetWidgetFromName("CastButton")); FButton = Cast(HUD->GetWidgetFromName("FButton")); WButton = Cast(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; } @@ -105,7 +120,7 @@ void ATurnBaseCombat::ExecuteCast(FString Combo) EndCombat(); return; } - + SwitchTurn(); } @@ -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); +} diff --git a/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.h b/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.h index c94c185..ccde118 100644 --- a/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.h +++ b/Source/the_twilight_abyss/TurnBasedCombat/TurnBaseCombat.h @@ -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; };