Updated StatusSystem for Base UI and Time Functionality
This commit is contained in:
parent
56b61bd1d2
commit
adba724dba
@ -3,9 +3,10 @@
|
||||
|
||||
#include "StatusEffect.h"
|
||||
|
||||
void UStatusEffect::Invoke(ACharacter* Character)
|
||||
void UStatusEffect::Invoke(AActor* Character)
|
||||
{
|
||||
}
|
||||
|
||||
void UStatusEffect::OnExpiry(AActor* Character)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,13 +15,18 @@ class THE_TWILIGHT_ABYSS_API UStatusEffect : public UObject
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY()
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FString Name;
|
||||
UPROPERTY()
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FString Description;
|
||||
UPROPERTY()
|
||||
UStaticMesh* Icon;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
float BaseDuration;
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UTexture2D* Icon;
|
||||
|
||||
UFUNCTION()
|
||||
virtual void Invoke(ACharacter* Character);
|
||||
virtual void Invoke(AActor* Character);
|
||||
|
||||
UFUNCTION()
|
||||
virtual void OnExpiry(AActor* Character);
|
||||
};
|
||||
|
@ -4,6 +4,10 @@
|
||||
#include "StatusSystem.h"
|
||||
#include <Runtime/Engine/Classes/Kismet/GameplayStatics.h>
|
||||
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Components/Image.h"
|
||||
#include "Components/TextBlock.h"
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UStatusSystem::UStatusSystem()
|
||||
{
|
||||
@ -11,7 +15,13 @@ UStatusSystem::UStatusSystem()
|
||||
// off to improve performance if you don't need them.
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
|
||||
// ...
|
||||
if (HUDStatusIndicatorsWidget != nullptr)
|
||||
{
|
||||
static ConstructorHelpers::FClassFinder<UUserWidget> HUDStatusIndicatorsWidgetClassFinder(TEXT("/Game/Blueprints/Status_UI/StatusIndicator"));
|
||||
HUDStatusIndicatorsWidget = HUDStatusIndicatorsWidgetClassFinder.Class;
|
||||
static ConstructorHelpers::FClassFinder<UUserWidget> HUDStatusIconWidgetClassFinder(TEXT("/Game/Blueprints/Status_UI/StatusIcon"));
|
||||
HUDStatusIconWidget = HUDStatusIconWidgetClassFinder.Class;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,8 +30,9 @@ void UStatusSystem::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// ...
|
||||
|
||||
HUDStatusIndicators = CreateWidget<UUserWidget>(GetWorld(), HUDStatusIndicatorsWidget);
|
||||
HUDStatusIndicators->AddToViewport();
|
||||
StatusIconsBox = Cast<UWrapBox>(HUDStatusIndicators->GetWidgetFromName(TEXT("StatusIndicators")));
|
||||
}
|
||||
|
||||
|
||||
@ -30,12 +41,38 @@ void UStatusSystem::TickComponent(float DeltaTime, ELevelTick TickType, FActorCo
|
||||
{
|
||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||
|
||||
for (FActiveStatusEffect StatusEffect : ActiveStatusEffects)
|
||||
for (FActiveStatusEffect ActiveStatusEffect : ActiveStatusEffects)
|
||||
{
|
||||
if (StatusEffect.TimeTillExpiry > UGameplayStatics::GetRealTimeSeconds(GetWorld()))
|
||||
if (ActiveStatusEffect.TimeTillExpiry >= UGameplayStatics::GetRealTimeSeconds(GetWorld()))
|
||||
{
|
||||
ActiveStatusEffects.Remove(StatusEffect);
|
||||
ActiveStatusEffect.StatusEffect->OnExpiry(GetOwner());
|
||||
ActiveStatusEffects.Remove(ActiveStatusEffect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UStatusSystem::AddStatusEffect(UStatusEffect* StatusEffect, const float DurationMultiplier)
|
||||
{
|
||||
FActiveStatusEffect NewStatusEffect;
|
||||
NewStatusEffect.StatusEffect = StatusEffect;
|
||||
NewStatusEffect.TimeInitiated = UGameplayStatics::GetRealTimeSeconds(GetWorld());
|
||||
NewStatusEffect.TimeTillExpiry = UGameplayStatics::GetRealTimeSeconds(GetWorld()) + StatusEffect->BaseDuration * DurationMultiplier;
|
||||
NewStatusEffect.StatusIcon = CreateWidget<UUserWidget>(GetWorld(), HUDStatusIconWidget);
|
||||
UImage* StatusIconImage = Cast<UImage>(NewStatusEffect.StatusIcon->GetWidgetFromName(TEXT("StatusIconImage")));
|
||||
StatusIconImage->SetBrushFromTexture(StatusEffect->Icon);
|
||||
StatusIconsBox->AddChild(NewStatusEffect.StatusIcon);
|
||||
|
||||
ActiveStatusEffects.Add(NewStatusEffect);
|
||||
}
|
||||
|
||||
void UStatusSystem::RemoveStatusEffect(UStatusEffect* StatusEffect)
|
||||
{
|
||||
if (ActiveStatusEffects.Contains(FActiveStatusEffect{0, 0, StatusEffect, nullptr}))
|
||||
{
|
||||
ActiveStatusEffects.Remove(FActiveStatusEffect{0, 0, StatusEffect, nullptr});
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("StatusEffect not found in ActiveStatusEffects"));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "StatusEffect.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Components/WrapBox.h"
|
||||
#include "StatusSystem.generated.h"
|
||||
|
||||
USTRUCT()
|
||||
@ -20,6 +22,9 @@ struct FActiveStatusEffect
|
||||
UPROPERTY()
|
||||
UStatusEffect* StatusEffect;
|
||||
|
||||
UPROPERTY()
|
||||
UUserWidget* StatusIcon;
|
||||
|
||||
bool operator==(const FActiveStatusEffect& Comp) const
|
||||
{
|
||||
return StatusEffect == Comp.StatusEffect;
|
||||
@ -35,6 +40,15 @@ public:
|
||||
// Sets default values for this component's properties
|
||||
UStatusSystem();
|
||||
|
||||
UPROPERTY()
|
||||
TSubclassOf<UUserWidget> HUDStatusIndicatorsWidget;
|
||||
UPROPERTY()
|
||||
TSubclassOf<UUserWidget> HUDStatusIconWidget;
|
||||
UPROPERTY()
|
||||
UUserWidget* HUDStatusIndicators;
|
||||
UPROPERTY()
|
||||
UWrapBox* StatusIconsBox;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<FActiveStatusEffect> ActiveStatusEffects;
|
||||
|
||||
@ -46,5 +60,9 @@ public:
|
||||
// Called every frame
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
|
||||
UFUNCTION()
|
||||
void AddStatusEffect(UStatusEffect* StatusEffect, float DurationMultiplier = 1.0f);
|
||||
|
||||
UFUNCTION()
|
||||
void RemoveStatusEffect(UStatusEffect* StatusEffect);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user