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;
}
int UGOAPAction::Perform()
TMap<FString, int> UGOAPAction::Perform()
{
return Effects["PlayerHealth"];
return Effects;
}

View File

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

View File

@ -21,10 +21,12 @@ ATurnBaseCombatV2::ATurnBaseCombatV2()
{
static ConstructorHelpers::FClassFinder<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI"));
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"));
ThornsStatusEffect = StatusEffectThornsClassFinder.Class;
static ConstructorHelpers::FClassFinder<UStatusEffect> StatusEffectDOTClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime"));
DOTStatusEffect = StatusEffectDOTClassFinder.Class;
static ConstructorHelpers::FClassFinder<UStatusEffect> StatusEffectDotClassFinder(TEXT("/Game/Blueprints/StatusEffects/BP_DamageOverTime"));
DOTStatusEffect = StatusEffectDotClassFinder.Class;
//static ConstructorHelpers::FClassFinder<UUserWidget> 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<int32>(Enemy);
EnemyHealth = EnemyHealthPtr;
@ -68,9 +70,10 @@ void ATurnBaseCombatV2::StartCombat(AActor* Enemy)
UpdateActionPoints();
UpdateResourceBars();
ClearBattleLog();
EnemyGOAPAgent = Cast<UGOAPAgent>(EnemyActor->GetComponentByClass(UGOAPAgent::StaticClass()));
EnemyActionPlan = EnemyGOAPAgent->Plan(GetWorldState(), EnemyGOAPAgent->Goals);
UpdateActionPlanWidget();
}
void ATurnBaseCombatV2::EndCombat()
@ -122,20 +125,23 @@ void ATurnBaseCombatV2::BeginPlay()
EisResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EisResourceBar"));
AzosResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("AzosResourceBar"));
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"));
PButton = Cast<UButton>(HUD->GetWidgetFromName("PButton"));
EButton = Cast<UButton>(HUD->GetWidgetFromName("EButton"));
AButton = Cast<UButton>(HUD->GetWidgetFromName("AButton"));
IButton = Cast<UButton>(HUD->GetWidgetFromName("IButton"));
BackspaceButton = Cast<UButton>(HUD->GetWidgetFromName("BackspaceButton"));
//RunButton = Cast<UButton>(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<UWrapBox>(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<UUserWidget>(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<AAIController>(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<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);
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<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
#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<UStatusEffect> DOTStatusEffect;
UPROPERTY()
TSubclassOf<UUserWidget> ActionPlanItemWidget;
UPROPERTY()
TArray<UStatusEffect*> 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<UGOAPAction*> EnemyActionPlan;
UFUNCTION()
UWorldState* GetWorldState() const;
UPROPERTY()
TArray<UUserWidget*> ActionPlanWidgets;
UPROPERTY()
UWrapBox* ActionPlanWrapBox;
UFUNCTION()
void UpdateActionPlanWidget();
UFUNCTION()
void ClearActionPlanWidget();
};