Updated RealTimeCombat to Map Functions to Keys
This commit is contained in:
parent
09ec1cb181
commit
d73a0fbd83
@ -11,11 +11,10 @@
|
|||||||
|
|
||||||
ARealTimeCombat::ARealTimeCombat()
|
ARealTimeCombat::ARealTimeCombat()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (HUDWidget == nullptr)
|
if (HUDWidget == nullptr)
|
||||||
{
|
{
|
||||||
// Load the HUD widget from the specified path
|
// Load the HUD widget from the specified path
|
||||||
static ConstructorHelpers::FClassFinder<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI"));
|
static ConstructorHelpers::FClassFinder<UUserWidget> HUDWidgetClass(TEXT("/Game/Blueprints/Combat_UI/Combat_UI_RT"));
|
||||||
HUDWidget = HUDWidgetClass.Class;
|
HUDWidget = HUDWidgetClass.Class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,6 +39,49 @@ void ARealTimeCombat::EndCombat()
|
|||||||
HUD->RemoveFromViewport();
|
HUD->RemoveFromViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ARealTimeCombat::OnMouseClick()
|
||||||
|
{
|
||||||
|
ExecuteCast(CurrentComboString);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARealTimeCombat::OnQPress()
|
||||||
|
{
|
||||||
|
if (ActiveActionPoints >= HeldActionPoints)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Action Points"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IronResource <= 0)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Iron"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UseActionPoint();
|
||||||
|
CurrentComboString.AppendChar('F');
|
||||||
|
UpdateComboString(CurrentComboString);
|
||||||
|
IronResource -= 1;
|
||||||
|
UpdateResourceBars();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARealTimeCombat::OnEPress()
|
||||||
|
{
|
||||||
|
if (ActiveActionPoints >= HeldActionPoints)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Action Points"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (IronResource <= 0)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Sulfur"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UseActionPoint();
|
||||||
|
CurrentComboString.AppendChar('W');
|
||||||
|
UpdateComboString(CurrentComboString);
|
||||||
|
SulfurResource -= 1;
|
||||||
|
UpdateResourceBars();
|
||||||
|
}
|
||||||
|
|
||||||
void ARealTimeCombat::BeginPlay()
|
void ARealTimeCombat::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
@ -49,7 +91,6 @@ void ARealTimeCombat::BeginPlay()
|
|||||||
|
|
||||||
HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
||||||
|
|
||||||
TurnIndicatorTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("TurnIndicator"));
|
|
||||||
CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo"));
|
CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo"));
|
||||||
ActionPointsTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("ActionPoints"));
|
ActionPointsTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("ActionPoints"));
|
||||||
BattleLogTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("BattleLog"));
|
BattleLogTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("BattleLog"));
|
||||||
@ -57,14 +98,7 @@ void ARealTimeCombat::BeginPlay()
|
|||||||
EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar"));
|
EnemyHealthBar = Cast<UProgressBar>(HUD->GetWidgetFromName("EnemyHealthBar"));
|
||||||
IronResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("IronResourceBar"));
|
IronResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("IronResourceBar"));
|
||||||
SulfurResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("SulfurResourceBar"));
|
SulfurResourceBar = Cast<UProgressBar>(HUD->GetWidgetFromName("SulfurResourceBar"));
|
||||||
CastButton = Cast<UButton>(HUD->GetWidgetFromName("CastButton"));
|
ActionPointsBar = Cast<UProgressBar>(HUD->GetWidgetFromName("ActionPointsBar"));
|
||||||
FButton = Cast<UButton>(HUD->GetWidgetFromName("FButton"));
|
|
||||||
WButton = Cast<UButton>(HUD->GetWidgetFromName("WButton"));
|
|
||||||
BackspaceButton = Cast<UButton>(HUD->GetWidgetFromName("BackspaceButton"));
|
|
||||||
CastButton->OnClicked.AddDynamic(this, &ARealTimeCombat::CastButtonOnClick);
|
|
||||||
FButton->OnClicked.AddDynamic(this, &ARealTimeCombat::FButtonOnClick);
|
|
||||||
WButton->OnClicked.AddDynamic(this, &ARealTimeCombat::WButtonOnClick);
|
|
||||||
BackspaceButton->OnClicked.AddDynamic(this, &ARealTimeCombat::BackspaceButtonOnClick);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARealTimeCombat::ExecuteCast(FString Combo)
|
void ARealTimeCombat::ExecuteCast(FString Combo)
|
||||||
@ -123,24 +157,27 @@ void ARealTimeCombat::ExecuteCast(FString Combo)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchTurn();
|
// SwitchTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARealTimeCombat::UseActionPoint()
|
void ARealTimeCombat::UseActionPoint()
|
||||||
|
{
|
||||||
|
if (HeldActionPoints > 0 && ActiveActionPoints < MaxActionPoints)
|
||||||
|
{
|
||||||
|
ActiveActionPoints -= 1;
|
||||||
|
UpdateActionPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ARealTimeCombat::ReuseActionPoint()
|
||||||
{
|
{
|
||||||
ActiveActionPoints += 1;
|
ActiveActionPoints += 1;
|
||||||
UpdateActionPoints();
|
UpdateActionPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARealTimeCombat::ReuseActionPoint()
|
|
||||||
{
|
|
||||||
ActiveActionPoints -= 1;
|
|
||||||
UpdateActionPoints();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ARealTimeCombat::RevertActionPoints()
|
void ARealTimeCombat::RevertActionPoints()
|
||||||
{
|
{
|
||||||
ActiveActionPoints = 0;
|
ActiveActionPoints = HeldActionPoints;
|
||||||
UpdateActionPoints();
|
UpdateActionPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,88 +201,26 @@ void ARealTimeCombat::UpdateProgressBars() const
|
|||||||
EnemyHealthBar->SetPercent(EnemyHealth / 100.0f);
|
EnemyHealthBar->SetPercent(EnemyHealth / 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ARealTimeCombat::Tick(float DeltaSeconds)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaSeconds);
|
||||||
|
//Every second add 1 action point
|
||||||
|
if (ActionPointsTimer >= 1.0f && ActiveActionPoints < MaxActionPoints)
|
||||||
|
{
|
||||||
|
HeldActionPoints += 1;
|
||||||
|
ActionPointsTimer = 0.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ActionPointsTimer += DeltaSeconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ARealTimeCombat::IsValidCombo(FString Combo) const
|
bool ARealTimeCombat::IsValidCombo(FString Combo) const
|
||||||
{
|
{
|
||||||
return ValidCombos.Contains(Combo);
|
return ValidCombos.Contains(Combo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARealTimeCombat::SwitchTurn()
|
|
||||||
{
|
|
||||||
//TurnIndicatorTextBlock->SetText(FText::FromString(bIsPlayerTurn ? "Enemy Turn" : "Player Turn"));
|
|
||||||
//bIsPlayerTurn = !bIsPlayerTurn;
|
|
||||||
TurnIndicatorTextBlock->SetText(FText::FromString("Enemy Turn"));
|
|
||||||
ToggleButtons();
|
|
||||||
//wait for 2 seconds
|
|
||||||
FTimerHandle UnusedHandle;
|
|
||||||
GetWorldTimerManager().SetTimer(UnusedHandle, this, &ARealTimeCombat::EnemyTurn, 2.0f, false);
|
|
||||||
|
|
||||||
//activeActor = bIsPlayerTurn ? enemyActor : playerActor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ARealTimeCombat::CastButtonOnClick()
|
|
||||||
{
|
|
||||||
ExecuteCast(CurrentComboString);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ARealTimeCombat::FButtonOnClick()
|
|
||||||
{
|
|
||||||
if (ActiveActionPoints >= DefaultActionPoints)
|
|
||||||
{
|
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Action Points"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (IronResource <= 0)
|
|
||||||
{
|
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Iron"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
UseActionPoint();
|
|
||||||
CurrentComboString.AppendChar('F');
|
|
||||||
UpdateComboString(CurrentComboString);
|
|
||||||
IronResource -= 1;
|
|
||||||
UpdateResourceBars();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ARealTimeCombat::WButtonOnClick()
|
|
||||||
{
|
|
||||||
if (ActiveActionPoints >= DefaultActionPoints)
|
|
||||||
{
|
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Action Points"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (SulfurResource <= 0)
|
|
||||||
{
|
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("No More Sulfur"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
UseActionPoint();
|
|
||||||
CurrentComboString.AppendChar('W');
|
|
||||||
UpdateComboString(CurrentComboString);
|
|
||||||
SulfurResource -= 1;
|
|
||||||
UpdateResourceBars();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ARealTimeCombat::BackspaceButtonOnClick()
|
|
||||||
{
|
|
||||||
if (CurrentComboString.Len() <= 0)
|
|
||||||
{
|
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Blank Combo"));
|
|
||||||
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 ARealTimeCombat::UpdateComboString(FString NewCombo) const
|
void ARealTimeCombat::UpdateComboString(FString NewCombo) const
|
||||||
{
|
{
|
||||||
CurrentComboTextBlock->SetText(FText::FromString(NewCombo));
|
CurrentComboTextBlock->SetText(FText::FromString(NewCombo));
|
||||||
@ -282,18 +257,3 @@ void ARealTimeCombat::UpdateResourceBars() const
|
|||||||
IronResourceBar->SetPercent(IronResource / 10.0f);
|
IronResourceBar->SetPercent(IronResource / 10.0f);
|
||||||
SulfurResourceBar->SetPercent(SulfurResource / 10.0f);
|
SulfurResourceBar->SetPercent(SulfurResource / 10.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ARealTimeCombat::ToggleButtons() const
|
|
||||||
{
|
|
||||||
FButton->SetIsEnabled(!FButton->bIsEnabled);
|
|
||||||
WButton->SetIsEnabled(!WButton->bIsEnabled);
|
|
||||||
BackspaceButton->SetIsEnabled(!BackspaceButton->bIsEnabled);
|
|
||||||
CastButton->SetIsEnabled(!CastButton->bIsEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ARealTimeCombat::EnemyTurn()
|
|
||||||
{
|
|
||||||
DamagePlayer(10);
|
|
||||||
TurnIndicatorTextBlock->SetText(FText::FromString("Player Turn"));
|
|
||||||
ToggleButtons();
|
|
||||||
}
|
|
@ -20,7 +20,7 @@ class THE_TWILIGHT_ABYSS_API ARealTimeCombat : public AActor
|
|||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
int EnemyHealth = 100;
|
int EnemyHealth = 100;
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
int DefaultActionPoints = 3;
|
int MaxActionPoints = 3;
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
int ActiveActionPoints = 0;
|
int ActiveActionPoints = 0;
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
@ -55,6 +55,12 @@ class THE_TWILIGHT_ABYSS_API ARealTimeCombat : public AActor
|
|||||||
void StartCombat(AActor* Enemy);
|
void StartCombat(AActor* Enemy);
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void EndCombat();
|
void EndCombat();
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void OnMouseClick();
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void OnQPress();
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void OnEPress();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
@ -65,9 +71,14 @@ protected:
|
|||||||
void DamagePlayer(int Damage);
|
void DamagePlayer(int Damage);
|
||||||
void DamageEnemy(int Damage);
|
void DamageEnemy(int Damage);
|
||||||
void UpdateProgressBars() const;
|
void UpdateProgressBars() const;
|
||||||
|
virtual void Tick(float DeltaSeconds) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool IsValidCombo(FString Combo) const;
|
bool IsValidCombo(FString Combo) const;
|
||||||
|
float ActionPointsTimer = 0.0f;
|
||||||
|
int HeldActionPoints = 0;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
UUserWidget* HUD;
|
UUserWidget* HUD;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
@ -76,11 +87,6 @@ private:
|
|||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
FString CurrentComboString = "";
|
FString CurrentComboString = "";
|
||||||
|
|
||||||
void SwitchTurn();
|
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
|
||||||
UTextBlock* TurnIndicatorTextBlock;
|
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UTextBlock* CurrentComboTextBlock;
|
UTextBlock* CurrentComboTextBlock;
|
||||||
|
|
||||||
@ -103,28 +109,7 @@ private:
|
|||||||
UProgressBar* SulfurResourceBar;
|
UProgressBar* SulfurResourceBar;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UButton* CastButton;
|
UProgressBar* ActionPointsBar;
|
||||||
|
|
||||||
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) const;
|
void UpdateComboString(FString NewCombo) const;
|
||||||
void UpdateActionPoints() const;
|
void UpdateActionPoints() const;
|
||||||
@ -133,6 +118,4 @@ private:
|
|||||||
void ClearBattleLog();
|
void ClearBattleLog();
|
||||||
void UpdateBattleLog();
|
void UpdateBattleLog();
|
||||||
void UpdateResourceBars() const;
|
void UpdateResourceBars() const;
|
||||||
void ToggleButtons() const;
|
|
||||||
void EnemyTurn();
|
|
||||||
};
|
};
|
||||||
|
@ -73,6 +73,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool IsValidCombo(FString Combo) const;
|
bool IsValidCombo(FString Combo) const;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
UUserWidget* HUD;
|
UUserWidget* HUD;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
@ -70,6 +70,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool IsValidCombo(FString Combo) const;
|
bool IsValidCombo(FString Combo) const;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
UUserWidget* HUD;
|
UUserWidget* HUD;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
Loading…
Reference in New Issue
Block a user