Added UI Enhancements

This commit is contained in:
Philip W 2023-03-23 00:30:17 +00:00
parent 99d97c8729
commit 50edc1aa0a
8 changed files with 93 additions and 42 deletions

Binary file not shown.

Binary file not shown.

BIN
COMP250_1_2101327_AI/Content/Main.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -29,7 +29,7 @@ UWorldState* UGOAPAction::ApplyEffects(UWorldState* WorldState)
return NewWorldState; return NewWorldState;
} }
int UGOAPAction::Perform() TMap<FString, int> UGOAPAction::Perform()
{ {
return Effects["PlayerHealth"]; return Effects;
} }

View File

@ -24,7 +24,7 @@ public:
UFUNCTION() UFUNCTION()
UWorldState* ApplyEffects(UWorldState* WorldState); UWorldState* ApplyEffects(UWorldState* WorldState);
UFUNCTION() UFUNCTION()
virtual int Perform(); virtual TMap<FString, int> Perform();
UPROPERTY() UPROPERTY()
TMap<FString, int> PreConditions; TMap<FString, int> PreConditions;

View File

@ -21,10 +21,12 @@ ATurnBaseCombatV2::ATurnBaseCombatV2()
{ {
static ConstructorHelpers::FClassFinder<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI")); static ConstructorHelpers::FClassFinder<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI"));
HUDWidget = HUDWidgetClass.Class; HUDWidget = HUDWidgetClass.Class;
static ConstructorHelpers::FClassFinder<UUserWidget> ActionItemWidgetClass(TEXT("/Game/Blueprints/Combat_UI/ActionItem"));
ActionPlanItemWidget = ActionItemWidgetClass.Class;
static ConstructorHelpers::FClassFinder<UStatusEffect> StatusEffectThornsClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_Thorns")); static ConstructorHelpers::FClassFinder<UStatusEffect> StatusEffectThornsClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_Thorns"));
ThornsStatusEffect = StatusEffectThornsClassFinder.Class; ThornsStatusEffect = StatusEffectThornsClassFinder.Class;
static ConstructorHelpers::FClassFinder<UStatusEffect> StatusEffectDOTClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime")); static ConstructorHelpers::FClassFinder<UStatusEffect> StatusEffectDotClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime"));
DOTStatusEffect = StatusEffectDOTClassFinder.Class; DOTStatusEffect = StatusEffectDotClassFinder.Class;
//static ConstructorHelpers::FClassFinder<UUserWidget> DeathScreenWidgetClass(TEXT("/Game/Blueprints/Death_UI/Death_UI")); //static ConstructorHelpers::FClassFinder<UUserWidget> DeathScreenWidgetClass(TEXT("/Game/Blueprints/Death_UI/Death_UI"));
//DeathScreenWidgetSubclass = DeathScreenWidgetClass.Class; //DeathScreenWidgetSubclass = DeathScreenWidgetClass.Class;
@ -34,7 +36,7 @@ ATurnBaseCombatV2::ATurnBaseCombatV2()
void ATurnBaseCombatV2::StartCombat(AActor* Enemy) void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
{ {
if (Enemy == nullptr) return; if (Enemy == nullptr) return;
FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health")); const FProperty* HealthProperty = Enemy->GetClass()->FindPropertyByName(FName("Health"));
int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr<int32>(Enemy); int32* EnemyHealthPtr = HealthProperty->ContainerPtrToValuePtr<int32>(Enemy);
EnemyHealth = EnemyHealthPtr; EnemyHealth = EnemyHealthPtr;
@ -68,9 +70,10 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
UpdateActionPoints(); UpdateActionPoints();
UpdateResourceBars(); UpdateResourceBars();
ClearBattleLog(); ClearBattleLog();
EnemyGOAPAgent = Cast<UGOAPAgent>(EnemyActor->GetComponentByClass(UGOAPAgent::StaticClass())); EnemyGOAPAgent = Cast<UGOAPAgent>(EnemyActor->GetComponentByClass(UGOAPAgent::StaticClass()));
EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals); EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals);
UpdateActionPlanWidget();
} }
void ATurnBaseCombatV2::EndCombat() void ATurnBaseCombatV2::EndCombat()
@ -122,20 +125,23 @@ void ATurnBaseCombatV2::BeginPlay()
EisResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EisResourceBar")); EisResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EisResourceBar"));
AzosResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("AzosResourceBar")); AzosResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("AzosResourceBar"));
IroquoidResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("IroquoidResourceBar")); IroquoidResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("IroquoidResourceBar"));
EnemyProbertiumResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("ProbertiumResourceBar_E"));
EnemyEisResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EisResourceBar_E"));
EnemyAzosResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("AzosResourceBar_E"));
EnemyIroquoidResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("IroquoidResourceBar_E"));
CastButton = Cast<UButton>(HUD->GetWidgetFromName("CastButton")); CastButton = Cast<UButton>(HUD->GetWidgetFromName("CastButton"));
PButton = Cast<UButton>(HUD->GetWidgetFromName("PButton")); PButton = Cast<UButton>(HUD->GetWidgetFromName("PButton"));
EButton = Cast<UButton>(HUD->GetWidgetFromName("EButton")); EButton = Cast<UButton>(HUD->GetWidgetFromName("EButton"));
AButton = Cast<UButton>(HUD->GetWidgetFromName("AButton")); AButton = Cast<UButton>(HUD->GetWidgetFromName("AButton"));
IButton = Cast<UButton>(HUD->GetWidgetFromName("IButton")); IButton = Cast<UButton>(HUD->GetWidgetFromName("IButton"));
BackspaceButton = Cast<UButton>(HUD->GetWidgetFromName("BackspaceButton")); BackspaceButton = Cast<UButton>(HUD->GetWidgetFromName("BackspaceButton"));
//RunButton = Cast<UButton>(HUD->GetWidgetFromName("RunButton"));
CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::CastButtonOnClick); CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::CastButtonOnClick);
PButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::PButtonOnClick); PButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::PButtonOnClick);
EButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::EButtonOnClick); EButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::EButtonOnClick);
AButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::AButtonOnClick); AButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::AButtonOnClick);
IButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::IButtonOnClick); IButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::IButtonOnClick);
BackspaceButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::BackspaceButtonOnClick); BackspaceButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::BackspaceButtonOnClick);
//RunButton->OnClicked.AddDynamic(this, &ATurnBaseCombatV2::RunButtonOnClick); ActionPlanWrapBox = Cast<UWrapBox>(HUD->GetWidgetFromName("ActionPlan_Box"));
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Enemy"), AllCharacterActorsInScene); UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Enemy"), AllCharacterActorsInScene);
for (AActor* Actor : AllCharacterActorsInScene) for (AActor* Actor : AllCharacterActorsInScene)
@ -205,14 +211,9 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
case true: case true:
// Player Turn // Player Turn
DamageEnemy(*ValidCombos.Find(Combo)); DamageEnemy(*ValidCombos.Find(Combo));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("Enemy Damaged %d"), *ValidCombos.Find(Combo)));
OnPlayerTurn.Broadcast(PlayerActor, EnemyActor); OnPlayerTurn.Broadcast(PlayerActor, EnemyActor);
break; break;
case false: 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; break;
} }
@ -225,7 +226,6 @@ void ATurnBaseCombatV2::ExecuteCast(FString Combo)
} }
if (*PlayerHealth <= 0) if (*PlayerHealth <= 0)
{ {
//EndCombat();
DeathScreenWidget = CreateWidget<UUserWidget>(GetWorld(), DeathScreenWidgetSubclass); DeathScreenWidget = CreateWidget<UUserWidget>(GetWorld(), DeathScreenWidgetSubclass);
DeathScreenWidget->AddToViewport(); DeathScreenWidget->AddToViewport();
return; return;
@ -288,15 +288,11 @@ bool ATurnBaseCombatV2::IsSpecialCombo(const FString Combo) const
void ATurnBaseCombatV2::SwitchTurn() void ATurnBaseCombatV2::SwitchTurn()
{ {
//TurnIndicatorTextBlock->SetText(FText::FromString(bIsPlayerTurn ? "Enemy Turn" : "Player Turn"));
//bIsPlayerTurn = !bIsPlayerTurn;
TurnIndicatorTextBlock->SetText(FText::FromString("Enemy Turn")); TurnIndicatorTextBlock->SetText(FText::FromString("Enemy Turn"));
ToggleButtons(); ToggleButtons();
FTimerHandle UnusedHandle; FTimerHandle UnusedHandle;
GetWorldTimerManager().SetTimer(UnusedHandle, this, &ATurnBaseCombatV2::EnemyTurn, 2.0f, false); GetWorldTimerManager().SetTimer(UnusedHandle, this, &ATurnBaseCombatV2::EnemyTurn, 2.0f, false);
//activeActor = bIsPlayerTurn ? enemyActor : playerActor;
} }
void ATurnBaseCombatV2::CastButtonOnClick() void ATurnBaseCombatV2::CastButtonOnClick()
@ -409,14 +405,6 @@ void ATurnBaseCombatV2::BackspaceButtonOnClick()
UpdateResourceBars(); UpdateResourceBars();
} }
// void ATurnBaseCombatV2::RunButtonOnClick()
// {
// UBlackboardComponent* EnemyBlackboard = Cast<AAIController>(EnemyActor->GetInstigatorController())->GetBlackboardComponent();
//
// EnemyBlackboard->SetValueAsBool("IsInCombat", false);
// EndCombat();
// }
void ATurnBaseCombatV2::UpdateComboString(FString NewCombo) const void ATurnBaseCombatV2::UpdateComboString(FString NewCombo) const
{ {
CurrentComboTextBlock->SetText(FText::FromString(NewCombo)); CurrentComboTextBlock->SetText(FText::FromString(NewCombo));
@ -454,6 +442,10 @@ void ATurnBaseCombatV2::UpdateResourceBars() const
EisResourceBar->SetPercent(EisResource / 10.0f); EisResourceBar->SetPercent(EisResource / 10.0f);
AzosResourceBar->SetPercent(AzosResource / 10.0f); AzosResourceBar->SetPercent(AzosResource / 10.0f);
IroquoidResourceBar->SetPercent(IroquoidResource / 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 void ATurnBaseCombatV2::ToggleButtons() const
@ -464,16 +456,37 @@ void ATurnBaseCombatV2::ToggleButtons() const
IButton->SetIsEnabled(!IButton->GetIsEnabled()); IButton->SetIsEnabled(!IButton->GetIsEnabled());
BackspaceButton->SetIsEnabled(!BackspaceButton->GetIsEnabled()); BackspaceButton->SetIsEnabled(!BackspaceButton->GetIsEnabled());
CastButton->SetIsEnabled(!CastButton->GetIsEnabled()); CastButton->SetIsEnabled(!CastButton->GetIsEnabled());
//RunButton->SetIsEnabled(!RunButton->GetIsEnabled());
} }
void ATurnBaseCombatV2::EnemyTurn() void ATurnBaseCombatV2::EnemyTurn()
{ {
//DamagePlayer(10);
if (EnemyActionPlan.Num() > 0) if (EnemyActionPlan.Num() > 0)
{ {
DamagePlayer(EnemyActionPlan[0]->Perform(), EnemyActionPlan[0]->ActionName); TMap<FString, int> ActionEffects = EnemyActionPlan[0]->Perform();
DamagePlayer(ActionEffects["PlayerHealth"], EnemyActionPlan[0]->ActionName);
for (const TTuple<FString, int> 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); EnemyActionPlan.RemoveAt(0);
UpdateResourceBars();
} }
else else
{ {
@ -495,3 +508,19 @@ UWorldState* ATurnBaseCombatV2::GetWorldState() const
WorldState->State.Add("IroquoidResource", EnemyIroquoidResource); WorldState->State.Add("IroquoidResource", EnemyIroquoidResource);
return WorldState; return WorldState;
} }
void ATurnBaseCombatV2::UpdateActionPlanWidget()
{
for (UGOAPAction* Action : EnemyActionPlan)
{
UUserWidget* ActionWidget = CreateWidget<UUserWidget>(GetWorld(), ActionPlanItemWidget);
ActionPlanWidgets.Add(ActionWidget);
Cast<UTextBlock>(ActionWidget->GetWidgetFromName("ActionName"))->SetText(FText::FromString(Action->ActionName));
ActionPlanWrapBox->AddChild(ActionWidget);
}
}
void ATurnBaseCombatV2::ClearActionPlanWidget()
{
return;
}

View File

@ -3,14 +3,15 @@
#pragma once #pragma once
#include "CoreMinimal.h" #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/Button.h"
#include "Components/ProgressBar.h" #include "Components/ProgressBar.h"
#include "Components/TextBlock.h" #include "Components/TextBlock.h"
#include "StatusEffect.h" #include "Components/WrapBox.h"
#include "NiagaraComponent.h"
#include "NiagaraFunctionLibrary.h"
#include "GameFramework/GameStateBase.h" #include "GameFramework/GameStateBase.h"
#include "COMP250_1_2101327_AI/GOAP/GOAPAgent.h"
#include "TurnBaseCombatV2.generated.h" #include "TurnBaseCombatV2.generated.h"
//class UNiagaraSystem; //class UNiagaraSystem;
@ -135,6 +136,9 @@ private:
UPROPERTY() UPROPERTY()
TSubclassOf<UStatusEffect> DOTStatusEffect; TSubclassOf<UStatusEffect> DOTStatusEffect;
UPROPERTY()
TSubclassOf<UUserWidget> ActionPlanItemWidget;
UPROPERTY() UPROPERTY()
TArray<UStatusEffect*> StatusEffects; TArray<UStatusEffect*> StatusEffects;
@ -168,6 +172,14 @@ private:
UProgressBar* AzosResourceBar; UProgressBar* AzosResourceBar;
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
UProgressBar* IroquoidResourceBar; UProgressBar* IroquoidResourceBar;
UPROPERTY(VisibleAnywhere)
UProgressBar* EnemyProbertiumResourceBar;
UPROPERTY(VisibleAnywhere)
UProgressBar* EnemyEisResourceBar;
UPROPERTY(VisibleAnywhere)
UProgressBar* EnemyAzosResourceBar;
UPROPERTY(VisibleAnywhere)
UProgressBar* EnemyIroquoidResourceBar;
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
UButton* CastButton; UButton* CastButton;
@ -200,8 +212,6 @@ private:
UFUNCTION() UFUNCTION()
void BackspaceButtonOnClick(); void BackspaceButtonOnClick();
//UFUNCTION()
//void RunButtonOnClick();
void UpdateComboString(FString NewCombo) const; void UpdateComboString(FString NewCombo) const;
void UpdateActionPoints() const; void UpdateActionPoints() const;
@ -222,7 +232,16 @@ private:
UGOAPAgent* EnemyGOAPAgent; UGOAPAgent* EnemyGOAPAgent;
UPROPERTY() UPROPERTY()
TArray<UGOAPAction*> EnemyActionPlan; TArray<UGOAPAction*> EnemyActionPlan;
UFUNCTION() UFUNCTION()
UWorldState* GetWorldState() const; UWorldState* GetWorldState() const;
UPROPERTY()
TArray<UUserWidget*> ActionPlanWidgets;
UPROPERTY()
UWrapBox* ActionPlanWrapBox;
UFUNCTION()
void UpdateActionPlanWidget();
UFUNCTION()
void ClearActionPlanWidget();
}; };