34. Listening for Attribute Changes

This commit is contained in:
2024-04-22 00:30:29 -04:00
parent 7db411586e
commit a6dc269630
24 changed files with 305 additions and 44 deletions

View File

@ -8,9 +8,9 @@
UGasaAttributeSet::UGasaAttributeSet()
{
InitHealth( 100.f );
InitHealth( 80.f );
InitMaxHealth( 100.f );
InitMana( 50.f );
InitMana( 20.f );
InitMaxMana( 50.f );
}
@ -33,7 +33,6 @@ void UGasaAttributeSet::Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMan
{
GAMEPLAYATTRIBUTE_REPNOTIFY( UGasaAttributeSet, MaxMana, PrevMaxMana )
}
void UGasaAttributeSet::GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const
{
Super::GetLifetimeReplicatedProps( OutLifetimeProps );

View File

@ -90,7 +90,6 @@ public:
#pragma endregion Setters
#pragma region UObject
void
GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const override;
#pragma endregion UObject

View File

@ -28,7 +28,7 @@ void APlayerCharacter::PossessedBy(AController* NewController)
AGasaPlayerController* PC = GetController<AGasaPlayerController>();
AGasaHUD* HUD = PC->GetHUD<AGasaHUD>();
FWidgetControllerData Data = { PC, PS, AbilitySystem, Attributes };
HUD->InitOverlay(& Data);
HUD->InitHostWidget(& Data);
}
// TODO(Ed): We need to setup Net Slime...
@ -49,6 +49,6 @@ void APlayerCharacter::OnRep_PlayerState()
AGasaPlayerController* PC = GetController<AGasaPlayerController>();
AGasaHUD* HUD = PC->GetHUD<AGasaHUD>();
FWidgetControllerData Data = { PC, PS, AbilitySystem, Attributes };
HUD->InitOverlay(& Data);
HUD->InitHostWidget(& Data);
}
}

View File

@ -6,14 +6,16 @@
#include "Blueprint/UserWidget.h"
using namespace Gasa;
void AGasaHUD::InitOverlay(FWidgetControllerData const* WidgetControllerData)
void AGasaHUD::InitHostWidget(FWidgetControllerData const* WidgetControllerData)
{
HostWidget = CreateWidget<UHUDHostWidget>( GetWorld()
, GetDevOptions()->Template_HUD_HostUI.LoadSynchronous() );
HostWidgetController = NewObject<UHostWidgetController>(this, GetDevOptions()->Template_HostWidgetController.Get());
HostWidgetController->Data = (* WidgetControllerData);
HostWidget->SetWidgetController(HostWidgetController);
HostWidgetController->BroadcastInitialValues();
HostWidget->AddToViewport();
}

View File

@ -19,7 +19,7 @@ public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
TObjectPtr<UHostWidgetController> HostWidgetController;
void InitOverlay(FWidgetControllerData const* WidgetControllerData);
void InitHostWidget(FWidgetControllerData const* WidgetControllerData);
#pragma region HUD
void ShowHUD() override;

View File

@ -89,6 +89,11 @@ void UGlobeProgressBar::SetGlassStyle(FSlateBrush brush)
Glass->SetBrush(brush);
}
void UGlobeProgressBar::SetPercentage(float CurrentValue, float MaxValue)
{
Bar->SetPercent( MaxValue > 0.f ? CurrentValue / MaxValue : 0.f );
}
void UGlobeProgressBar::SetSize(float width, float height)
{
Root_SB->SetWidthOverride( width );

View File

@ -46,6 +46,9 @@ public:
UFUNCTION(BlueprintCallable, Category="Globe")
void SetGlassStyle(FSlateBrush brush);
UFUNCTION(BlueprintCallable, Category="Globe")
void SetPercentage(float CurrentValue, float MaxValue);
UFUNCTION(BlueprintCallable, Category="Globe")
void SetSize(float width, float height);

View File

@ -1 +1,14 @@
#include "HostWidgetController.h"
#include "HostWidgetController.h"
#include "AbilitySystem/GasaAttributeSet.h"
void UHostWidgetController::BroadcastInitialValues()
{
Super::BroadcastInitialValues();
UGasaAttributeSet* GasaAttribs = Cast<UGasaAttributeSet>( Data.Attributes );
if ( GasaAttribs )
{
Event_OnHealthChanged.Broadcast( GasaAttribs->GetHealth() );
Event_OnMaxHealthChanged.Broadcast( GasaAttribs->GetMaxHealth() );
Event_OnManaChanged.Broadcast( GasaAttribs->GetMana() );
Event_OnMaxManaChanged.Broadcast( GasaAttribs->GetMaxMana() );
}
}

View File

@ -1,12 +1,31 @@
#pragma once
#pragma once
#include "WidgetController.h"
#include "HostWidgetController.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam( FAttributeFloatChangedSig, float, NewValue );
UCLASS()
UCLASS( Blueprintable, BlueprintType )
class GASA_API UHostWidgetController : public UWidgetController
{
GENERATED_BODY()
public:
#pragma region Attribute Events
// Attribute Events are generated by GasaGen/GasaGen_HostWidgetController.cpp
UPROPERTY( BlueprintAssignable, Category = "Attributes" )
FAttributeFloatChangedSig Event_OnHealthChanged;
UPROPERTY( BlueprintAssignable, Category = "Attributes" )
FAttributeFloatChangedSig Event_OnMaxHealthChanged;
UPROPERTY( BlueprintAssignable, Category = "Attributes" )
FAttributeFloatChangedSig Event_OnManaChanged;
UPROPERTY( BlueprintAssignable, Category = "Attributes" )
FAttributeFloatChangedSig Event_OnMaxManaChanged;
#pragma endregion Attribute Events
#pragma region WidgetController
void BroadcastInitialValues() override;
#pragma endregion WidgetController
};

View File

@ -7,27 +7,19 @@ USTRUCT(BlueprintType)
struct GASA_API FWidgetControllerData
{
GENERATED_BODY()
public:
FWidgetControllerData() = default;
FWidgetControllerData(AGasaPlayerController* Controller
, AGasaPlayerState* PlayerState
, UAbilitySystemComponent* AbilitySystem
, UAttributeSet* Attributes )
#if 1
FWidgetControllerData
( AGasaPlayerController* Controller
, AGasaPlayerState* PlayerState
, UAbilitySystemComponent* AbilitySystem
, UAttributeSet* Attributes )
: Controller(Controller)
, PlayerState(PlayerState)
, AbilitySystem(AbilitySystem)
, Attributes(Attributes)
#endif
{
#if 0
this->Controller = Controller;
this->PlayerState = PlayerState;
this->AbilitySystem = AbilitySystem;
this->Attributes = Attributes;
#endif
}
{}
UPROPERTY(BlueprintReadOnly, Category="Player")
TObjectPtr<AGasaPlayerController> Controller;
@ -50,4 +42,7 @@ public:
UPROPERTY(BlueprintReadOnly, Category="Player")
FWidgetControllerData Data;
UFUNCTION()
virtual void BroadcastInitialValues() {};
};