From 50edc1aa0aa87e2584d65c5afa3b152a1c4ec574 Mon Sep 17 00:00:00 2001 From: PHILIP White Date: Thu, 23 Mar 2023 00:30:17 +0000 Subject: [PATCH] Added UI Enhancements --- .../Blueprints/Combat_UI/ActionItem.uasset | 3 + .../Blueprints/Combat_UI/Combat_UI.uasset | 4 +- COMP250_1_2101327_AI/Content/Main.umap | 2 +- .../HDRI/HDRI_Epic_Courtyard_Daylight.uasset | 4 +- .../COMP250_1_2101327_AI/GOAP/GOAPAction.cpp | 4 +- .../COMP250_1_2101327_AI/GOAP/GOAPAction.h | 2 +- .../TurnBasedCombatV2/TurnBaseCombatV2.cpp | 83 +++++++++++++------ .../TurnBasedCombatV2/TurnBaseCombatV2.h | 33 ++++++-- 8 files changed, 93 insertions(+), 42 deletions(-) create mode 100644 COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/ActionItem.uasset diff --git a/COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/ActionItem.uasset b/COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/ActionItem.uasset new file mode 100644 index 0000000..25bd529 --- /dev/null +++ b/COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/ActionItem.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96d9ce97196929f035a815edce275ec0be96edc728af06020eff0785b14a6ab4 +size 25438 diff --git a/COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/Combat_UI.uasset b/COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/Combat_UI.uasset index d2ef75d..9d1f3c5 100644 --- a/COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/Combat_UI.uasset +++ b/COMP250_1_2101327_AI/Content/Blueprints/Combat_UI/Combat_UI.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c47bb8a8e50d3ad4ae0cfb77fb7766211b51c1b64390fe65cea3b4170aa1e476 -size 69842 +oid sha256:783b6597e3ff31f571413b7986c4d991dca9b6a428190d82d7030a227a5a69d0 +size 104361 diff --git a/COMP250_1_2101327_AI/Content/Main.umap b/COMP250_1_2101327_AI/Content/Main.umap index 25efbee..fa0fc15 100644 --- a/COMP250_1_2101327_AI/Content/Main.umap +++ b/COMP250_1_2101327_AI/Content/Main.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4dabd96b91e537f957841dd9c905d313433780c6ffa20dcbad3898e6f45e6b2c +oid sha256:ea44d851fecbed5e482837f20b5e2a8f4d741460b1ac4dc30af5bcc660570916 size 40330 diff --git a/COMP250_1_2101327_AI/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset b/COMP250_1_2101327_AI/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset index 247f8ac..0f99058 100644 --- a/COMP250_1_2101327_AI/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset +++ b/COMP250_1_2101327_AI/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4968d566c351d87791abe40d2d98f3486eb4a0d57318255bea33eaf37850fc13 -size 66790690 +oid sha256:bc35eb2d43a47427d30aba0196f9eac90d089dd3abca319528c5d25c83510d0d +size 72364642 diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp index f135419..3026de0 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.cpp @@ -29,7 +29,7 @@ UWorldState* UGOAPAction::ApplyEffects(UWorldState* WorldState) return NewWorldState; } -int UGOAPAction::Perform() +TMap UGOAPAction::Perform() { - return Effects["PlayerHealth"]; + return Effects; } diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h index 9b9e324..af421bc 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/GOAP/GOAPAction.h @@ -24,7 +24,7 @@ public: UFUNCTION() UWorldState* ApplyEffects(UWorldState* WorldState); UFUNCTION() - virtual int Perform(); + virtual TMap Perform(); UPROPERTY() TMap PreConditions; diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp index 4a04b67..49df134 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.cpp @@ -21,10 +21,12 @@ ATurnBaseCombatV2::ATurnBaseCombatV2() { static ConstructorHelpers::FClassFinder HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI")); HUDWidget = HUDWidgetClass.Class; + static ConstructorHelpers::FClassFinder ActionItemWidgetClass(TEXT("/Game/Blueprints/Combat_UI/ActionItem")); + ActionPlanItemWidget = ActionItemWidgetClass.Class; static ConstructorHelpers::FClassFinder StatusEffectThornsClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_Thorns")); ThornsStatusEffect = StatusEffectThornsClassFinder.Class; - static ConstructorHelpers::FClassFinder StatusEffectDOTClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime")); - DOTStatusEffect = StatusEffectDOTClassFinder.Class; + static ConstructorHelpers::FClassFinder StatusEffectDotClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime")); + DOTStatusEffect = StatusEffectDotClassFinder.Class; //static ConstructorHelpers::FClassFinder DeathScreenWidgetClass(TEXT("/Game/Blueprints/Death_UI/Death_UI")); //DeathScreenWidgetSubclass = DeathScreenWidgetClass.Class; @@ -34,7 +36,7 @@ ATurnBaseCombatV2::ATurnBaseCombatV2() void ATurnBaseCombatV2::StartCombat(AActor* Enemy) { if (Enemy == nullptr) return; - FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); + const FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr(Enemy); EnemyHealth = EnemyHealthPtr; @@ -68,9 +70,10 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy) UpdateActionPoints(); UpdateResourceBars(); ClearBattleLog(); - + EnemyGOAPAgent = Cast(EnemyActor->GetComponentByClass(UGOAPAgent::StaticClass())); EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals); + UpdateActionPlanWidget(); } void ATurnBaseCombatV2::EndCombat() @@ -122,20 +125,23 @@ void ATurnBaseCombatV2::BeginPlay() EisResourceBar = Cast(HUD->GetWidgetFromName("EisResourceBar")); AzosResourceBar = Cast(HUD->GetWidgetFromName("AzosResourceBar")); IroquoidResourceBar = Cast(HUD->GetWidgetFromName("IroquoidResourceBar")); + EnemyProbertiumResourceBar = Cast(HUD->GetWidgetFromName("ProbertiumResourceBar_E")); + EnemyEisResourceBar = Cast(HUD->GetWidgetFromName("EisResourceBar_E")); + EnemyAzosResourceBar = Cast(HUD->GetWidgetFromName("AzosResourceBar_E")); + EnemyIroquoidResourceBar = Cast(HUD->GetWidgetFromName("IroquoidResourceBar_E")); CastButton = Cast(HUD->GetWidgetFromName("CastButton")); PButton = Cast(HUD->GetWidgetFromName("PButton")); EButton = Cast(HUD->GetWidgetFromName("EButton")); AButton = Cast(HUD->GetWidgetFromName("AButton")); IButton = Cast(HUD->GetWidgetFromName("IButton")); BackspaceButton = Cast(HUD->GetWidgetFromName("BackspaceButton")); - //RunButton = Cast(HUD->GetWidgetFromName("RunButton")); CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::CastButtonOnClick); PButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::PButtonOnClick); EButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::EButtonOnClick); AButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::AButtonOnClick); IButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::IButtonOnClick); BackspaceButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::BackspaceButtonOnClick); - //RunButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::RunButtonOnClick); + ActionPlanWrapBox = Cast(HUD->GetWidgetFromName("ActionPlan_Box")); UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Enemy"), AllCharacterActorsInScene); for (AActor* Actor : AllCharacterActorsInScene) @@ -205,14 +211,9 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) case true: // Player Turn DamageEnemy(*ValidCombos.Find(Combo)); - GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Enemy Damaged %d"), *ValidCombos.Find(Combo))); OnPlayerTurn.Broadcast(PlayerActor, EnemyActor); break; case false: - // Enemy Turn - // DamagePlayer(*ValidCombos.Find(Combo)); - // GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Player Damaged %d"), *ValidCombos.Find(Combo))); - // OnEnemyTurn.Broadcast(EnemyActor, PlayerActor); break; } @@ -225,7 +226,6 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo) } if (*PlayerHealth <= 0) { - //EndCombat(); DeathScreenWidget = CreateWidget(GetWorld(), DeathScreenWidgetSubclass); DeathScreenWidget->AddToViewport(); return; @@ -288,15 +288,11 @@ bool ATurnBaseCombatV2::IsSpecialCombo(const FString Combo) const void ATurnBaseCombatV2::SwitchTurn() { - //TurnIndicatorTextBlock->SetText(FText::FromString(bIsPlayerTurn ? "Enemy Turn" : "Player Turn")); - //bIsPlayerTurn = !bIsPlayerTurn; TurnIndicatorTextBlock->SetText(FText::FromString("Enemy Turn")); ToggleButtons(); FTimerHandle UnusedHandle; GetWorldTimerManager().SetTimer(UnusedHandle, this, &ATurnBaseCombatV2::EnemyTurn, 2.0f, false); - - //activeActor = bIsPlayerTurn ? enemyActor : playerActor; } void ATurnBaseCombatV2::CastButtonOnClick() @@ -409,14 +405,6 @@ void ATurnBaseCombatV2::BackspaceButtonOnClick() UpdateResourceBars(); } -// void ATurnBaseCombatV2::RunButtonOnClick() -// { -// UBlackboardComponent* EnemyBlackboard = Cast(EnemyActor->GetInstigatorController())->GetBlackboardComponent(); -// -// EnemyBlackboard->SetValueAsBool("IsInCombat", false); -// EndCombat(); -// } - void ATurnBaseCombatV2::UpdateComboString(FString NewCombo) const { CurrentComboTextBlock->SetText(FText::FromString(NewCombo)); @@ -454,6 +442,10 @@ void ATurnBaseCombatV2::UpdateResourceBars() const EisResourceBar->SetPercent(EisResource / 10.0f); AzosResourceBar->SetPercent(AzosResource / 10.0f); IroquoidResourceBar->SetPercent(IroquoidResource / 10.0f); + EnemyProbertiumResourceBar->SetPercent(EnemyProbertiumResource / 10.0f); + EnemyEisResourceBar->SetPercent(EnemyEisResource / 10.0f); + EnemyAzosResourceBar->SetPercent(EnemyAzosResource / 10.0f); + EnemyIroquoidResourceBar->SetPercent(EnemyIroquoidResource / 10.0f); } void ATurnBaseCombatV2::ToggleButtons() const @@ -464,16 +456,37 @@ void ATurnBaseCombatV2::ToggleButtons() const IButton->SetIsEnabled(!IButton->GetIsEnabled()); BackspaceButton->SetIsEnabled(!BackspaceButton->GetIsEnabled()); CastButton->SetIsEnabled(!CastButton->GetIsEnabled()); - //RunButton->SetIsEnabled(!RunButton->GetIsEnabled()); } void ATurnBaseCombatV2::EnemyTurn() { - //DamagePlayer(10); if (EnemyActionPlan.Num() > 0) { - DamagePlayer(EnemyActionPlan[0]->Perform(), EnemyActionPlan[0]->ActionName); + TMap ActionEffects = EnemyActionPlan[0]->Perform(); + DamagePlayer(ActionEffects["PlayerHealth"], EnemyActionPlan[0]->ActionName); + + for (const TTuple Effect : ActionEffects) + { + if (Effect.Key == "ProbertiumResource") + { + EnemyProbertiumResource -= Effect.Value; + } + else if (Effect.Key == "EisResource") + { + EnemyEisResource -= Effect.Value; + } + else if (Effect.Key == "AzosResource") + { + EnemyAzosResource -= Effect.Value; + } + else if (Effect.Key == "IroquoidResource") + { + EnemyIroquoidResource -= Effect.Value; + } + } + EnemyActionPlan.RemoveAt(0); + UpdateResourceBars(); } else { @@ -495,3 +508,19 @@ UWorldState* ATurnBaseCombatV2::GetWorldState() const WorldState->State.Add("IroquoidResource", EnemyIroquoidResource); return WorldState; } + +void ATurnBaseCombatV2::UpdateActionPlanWidget() +{ + for (UGOAPAction* Action : EnemyActionPlan) + { + UUserWidget* ActionWidget = CreateWidget(GetWorld(), ActionPlanItemWidget); + ActionPlanWidgets.Add(ActionWidget); + Cast(ActionWidget->GetWidgetFromName("ActionName"))->SetText(FText::FromString(Action->ActionName)); + ActionPlanWrapBox->AddChild(ActionWidget); + } +} + +void ATurnBaseCombatV2::ClearActionPlanWidget() +{ + return; +} diff --git a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h index c03ca7b..4ba6245 100644 --- a/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h +++ b/COMP250_1_2101327_AI/Source/COMP250_1_2101327_AI/TurnBasedCombatV2/TurnBaseCombatV2.h @@ -3,14 +3,15 @@ #pragma once #include "CoreMinimal.h" +#include "NiagaraComponent.h" +#include "NiagaraFunctionLibrary.h" +#include "StatusEffect.h" +#include "COMP250_1_2101327_AI/GOAP/GOAPAgent.h" #include "Components/Button.h" #include "Components/ProgressBar.h" #include "Components/TextBlock.h" -#include "StatusEffect.h" -#include "NiagaraComponent.h" -#include "NiagaraFunctionLibrary.h" +#include "Components/WrapBox.h" #include "GameFramework/GameStateBase.h" -#include "COMP250_1_2101327_AI/GOAP/GOAPAgent.h" #include "TurnBaseCombatV2.generated.h" //class UNiagaraSystem; @@ -135,6 +136,9 @@ private: UPROPERTY() TSubclassOf DOTStatusEffect; + UPROPERTY() + TSubclassOf ActionPlanItemWidget; + UPROPERTY() TArray StatusEffects; @@ -168,6 +172,14 @@ private: UProgressBar* AzosResourceBar; UPROPERTY(VisibleAnywhere) UProgressBar* IroquoidResourceBar; + UPROPERTY(VisibleAnywhere) + UProgressBar* EnemyProbertiumResourceBar; + UPROPERTY(VisibleAnywhere) + UProgressBar* EnemyEisResourceBar; + UPROPERTY(VisibleAnywhere) + UProgressBar* EnemyAzosResourceBar; + UPROPERTY(VisibleAnywhere) + UProgressBar* EnemyIroquoidResourceBar; UPROPERTY(VisibleAnywhere) UButton* CastButton; @@ -200,8 +212,6 @@ private: UFUNCTION() void BackspaceButtonOnClick(); - //UFUNCTION() - //void RunButtonOnClick(); void UpdateComboString(FString NewCombo) const; void UpdateActionPoints() const; @@ -222,7 +232,16 @@ private: UGOAPAgent* EnemyGOAPAgent; UPROPERTY() TArray EnemyActionPlan; - + UFUNCTION() UWorldState* GetWorldState() const; + + UPROPERTY() + TArray ActionPlanWidgets; + UPROPERTY() + UWrapBox* ActionPlanWrapBox; + UFUNCTION() + void UpdateActionPlanWidget(); + UFUNCTION() + void ClearActionPlanWidget(); };