Updated TurnBaseCombat for Button Functionality
This commit is contained in:
parent
3b627518ca
commit
329cf183b9
@ -94,4 +94,7 @@ GlobalDefaultServerGameMode=None
|
|||||||
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.playerHealth",NewName="/Script/the_twilight_abyss.TurnBaseCombat.PlayerHealth")
|
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.playerHealth",NewName="/Script/the_twilight_abyss.TurnBaseCombat.PlayerHealth")
|
||||||
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.enemyHealth",NewName="/Script/the_twilight_abyss.TurnBaseCombat.EnemyHealth")
|
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.enemyHealth",NewName="/Script/the_twilight_abyss.TurnBaseCombat.EnemyHealth")
|
||||||
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.defaultActionPoints",NewName="/Script/the_twilight_abyss.TurnBaseCombat.DefaultActionPoints")
|
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.defaultActionPoints",NewName="/Script/the_twilight_abyss.TurnBaseCombat.DefaultActionPoints")
|
||||||
|
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.TestButton",NewName="/Script/the_twilight_abyss.TurnBaseCombat.CastButton")
|
||||||
|
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.CurrentCombo",NewName="/Script/the_twilight_abyss.TurnBaseCombat.CurrentComboTextBlock")
|
||||||
|
+PropertyRedirects=(OldName="/Script/the_twilight_abyss.TurnBaseCombat.TurnIndicator",NewName="/Script/the_twilight_abyss.TurnBaseCombat.TurnIndicatorTextBlock")
|
||||||
|
|
||||||
|
@ -24,14 +24,23 @@ void ATurnBaseCombat::BeginPlay()
|
|||||||
|
|
||||||
TArray<AActor*> AllCharacterActorsInScene;
|
TArray<AActor*> AllCharacterActorsInScene;
|
||||||
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Character"), AllCharacterActorsInScene);
|
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Character"), AllCharacterActorsInScene);
|
||||||
ActiveActionPoints = DefaultActionPoints;
|
|
||||||
|
|
||||||
UUserWidget* HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
UUserWidget* HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
||||||
HUD->AddToViewport();
|
HUD->AddToViewport();
|
||||||
|
|
||||||
TurnIndicator = Cast<UTextBlock>(HUD->GetWidgetFromName("TurnIndicator"));
|
TurnIndicatorTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("TurnIndicator"));
|
||||||
|
CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo"));
|
||||||
|
ActionPointsTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("ActionPoints"));
|
||||||
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"));
|
||||||
|
FButton = Cast<UButton>(HUD->GetWidgetFromName("FButton"));
|
||||||
|
WButton = Cast<UButton>(HUD->GetWidgetFromName("WButton"));
|
||||||
|
BackspaceButton = Cast<UButton>(HUD->GetWidgetFromName("BackspaceButton"));
|
||||||
|
CastButton->OnClicked.AddDynamic(this, &ATurnBaseCombat::CastButtonOnClick);
|
||||||
|
FButton->OnClicked.AddDynamic(this, &ATurnBaseCombat::FButtonOnClick);
|
||||||
|
WButton->OnClicked.AddDynamic(this, &ATurnBaseCombat::WButtonOnClick);
|
||||||
|
BackspaceButton->OnClicked.AddDynamic(this, &ATurnBaseCombat::BackspaceButtonOnClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATurnBaseCombat::ExecuteCast(FString Combo)
|
void ATurnBaseCombat::ExecuteCast(FString Combo)
|
||||||
@ -39,9 +48,18 @@ void ATurnBaseCombat::ExecuteCast(FString Combo)
|
|||||||
if (!IsValidCombo(Combo))
|
if (!IsValidCombo(Combo))
|
||||||
{
|
{
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Invalid Combo"));
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Invalid Combo"));
|
||||||
|
CurrentComboString = "";
|
||||||
|
UpdateComboString(CurrentComboString);
|
||||||
|
RevertActionPoints();
|
||||||
|
UpdateActionPoints();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CurrentComboString = "";
|
||||||
|
UpdateComboString(CurrentComboString);
|
||||||
|
RevertActionPoints();
|
||||||
|
UpdateActionPoints();
|
||||||
|
|
||||||
switch (bIsPlayerTurn)
|
switch (bIsPlayerTurn)
|
||||||
{
|
{
|
||||||
case true:
|
case true:
|
||||||
@ -59,35 +77,38 @@ void ATurnBaseCombat::ExecuteCast(FString Combo)
|
|||||||
|
|
||||||
void ATurnBaseCombat::UseActionPoint()
|
void ATurnBaseCombat::UseActionPoint()
|
||||||
{
|
{
|
||||||
ActiveActionPoints -= 1;
|
ActiveActionPoints += 1;
|
||||||
ActiveActionPoints = FMath::Clamp(ActiveActionPoints, 0, DefaultActionPoints);
|
UpdateActionPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATurnBaseCombat::ReuseActionPoint()
|
void ATurnBaseCombat::ReuseActionPoint()
|
||||||
{
|
{
|
||||||
ActiveActionPoints += 1;
|
ActiveActionPoints -= 1;
|
||||||
ActiveActionPoints = FMath::Clamp(ActiveActionPoints, 0, DefaultActionPoints);
|
UpdateActionPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATurnBaseCombat::RevertActionPoints()
|
void ATurnBaseCombat::RevertActionPoints()
|
||||||
{
|
{
|
||||||
ActiveActionPoints = DefaultActionPoints;
|
ActiveActionPoints = 0;
|
||||||
|
UpdateActionPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATurnBaseCombat::DamagePlayer(int Damage)
|
void ATurnBaseCombat::DamagePlayer(int Damage)
|
||||||
{
|
{
|
||||||
PlayerHealth -= FMath::Clamp(Damage, 0, 100);
|
PlayerHealth -= FMath::Clamp(Damage, 0, 100);
|
||||||
|
UpdateProgressBars();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATurnBaseCombat::DamageEnemy(int Damage)
|
void ATurnBaseCombat::DamageEnemy(int Damage)
|
||||||
{
|
{
|
||||||
EnemyHealth -= FMath::Clamp(Damage, 0, 100);
|
EnemyHealth -= FMath::Clamp(Damage, 0, 100);
|
||||||
|
UpdateProgressBars();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATurnBaseCombat::UpdateProgressBars() const
|
void ATurnBaseCombat::UpdateProgressBars() const
|
||||||
{
|
{
|
||||||
PlayerHealthBar->SetPercent(PlayerHealth / 100);
|
PlayerHealthBar->SetPercent(PlayerHealth / 100.0f);
|
||||||
EnemyHealthBar->SetPercent(EnemyHealth / 100);
|
EnemyHealthBar->SetPercent(EnemyHealth / 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ATurnBaseCombat::IsValidCombo(FString Combo) const
|
bool ATurnBaseCombat::IsValidCombo(FString Combo) const
|
||||||
@ -97,5 +118,57 @@ bool ATurnBaseCombat::IsValidCombo(FString Combo) const
|
|||||||
|
|
||||||
void ATurnBaseCombat::SwitchTurn()
|
void ATurnBaseCombat::SwitchTurn()
|
||||||
{
|
{
|
||||||
activeActor = bIsPlayerTurn ? enemyActor : playerActor;
|
TurnIndicatorTextBlock->SetText(FText::FromString(bIsPlayerTurn ? "Enemy Turn" : "Player Turn"));
|
||||||
|
//activeActor = bIsPlayerTurn ? enemyActor : playerActor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATurnBaseCombat::CastButtonOnClick()
|
||||||
|
{
|
||||||
|
ExecuteCast(CurrentComboString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATurnBaseCombat::FButtonOnClick()
|
||||||
|
{
|
||||||
|
if (ActiveActionPoints >= DefaultActionPoints)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("No More Action Points"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UseActionPoint();
|
||||||
|
CurrentComboString.AppendChar('F');
|
||||||
|
UpdateComboString(CurrentComboString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATurnBaseCombat::WButtonOnClick()
|
||||||
|
{
|
||||||
|
if (ActiveActionPoints >= DefaultActionPoints)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("No More Action Points"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UseActionPoint();
|
||||||
|
CurrentComboString.AppendChar('W');
|
||||||
|
UpdateComboString(CurrentComboString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATurnBaseCombat::BackspaceButtonOnClick()
|
||||||
|
{
|
||||||
|
if (CurrentComboString.Len() <= 0)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("Blank Combo"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ReuseActionPoint();
|
||||||
|
CurrentComboString.RemoveAt(CurrentComboString.Len() - 1);
|
||||||
|
UpdateComboString(CurrentComboString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATurnBaseCombat::UpdateComboString(FString NewCombo)
|
||||||
|
{
|
||||||
|
CurrentComboTextBlock->SetText(FText::FromString(NewCombo));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATurnBaseCombat::UpdateActionPoints()
|
||||||
|
{
|
||||||
|
ActionPointsTextBlock->SetText(FText::FromString(FString::FromInt(ActiveActionPoints)));
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Components/Button.h"
|
||||||
#include "Components/ProgressBar.h"
|
#include "Components/ProgressBar.h"
|
||||||
#include "Components/TextBlock.h"
|
#include "Components/TextBlock.h"
|
||||||
#include "GameFramework/GameStateBase.h"
|
#include "GameFramework/GameStateBase.h"
|
||||||
@ -25,6 +26,7 @@ public:
|
|||||||
int EnemyHealth = 100;
|
int EnemyHealth = 100;
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
int DefaultActionPoints = 3;
|
int DefaultActionPoints = 3;
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
int ActiveActionPoints = 0;
|
int ActiveActionPoints = 0;
|
||||||
|
|
||||||
AActor* playerActor;
|
AActor* playerActor;
|
||||||
@ -33,7 +35,6 @@ public:
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
Reference Action Library
|
|
||||||
Reference Player Inventory
|
Reference Player Inventory
|
||||||
Reference Combat Logging System
|
Reference Combat Logging System
|
||||||
*/
|
*/
|
||||||
@ -59,13 +60,54 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool IsValidCombo(FString Combo) const;
|
bool IsValidCombo(FString Combo) const;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
bool bIsPlayerTurn = true;
|
bool bIsPlayerTurn = true;
|
||||||
void SwitchTurn();
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UTextBlock* TurnIndicator;
|
FString CurrentComboString = "";
|
||||||
|
|
||||||
|
void SwitchTurn();
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UTextBlock* TurnIndicatorTextBlock;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UTextBlock* CurrentComboTextBlock;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UTextBlock* ActionPointsTextBlock;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UProgressBar* PlayerHealthBar;
|
UProgressBar* PlayerHealthBar;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UProgressBar* EnemyHealthBar;
|
UProgressBar* EnemyHealthBar;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UButton* CastButton;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UButton* FButton;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UButton* WButton;
|
||||||
|
|
||||||
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
UButton* BackspaceButton;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void CastButtonOnClick();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void FButtonOnClick();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void WButtonOnClick();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void BackspaceButtonOnClick();
|
||||||
|
|
||||||
|
void UpdateComboString(FString NewCombo);
|
||||||
|
void UpdateActionPoints();
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user