32. Overlay Widget Controller

This commit is contained in:
2024-04-21 18:56:57 -04:00
parent 1f47e94a64
commit 7db411586e
38 changed files with 321 additions and 155 deletions

View File

@ -1,7 +1,6 @@
#pragma once
#include "AbilitySystemComponent.h"
#include "AbilitySystemInterface.h"
#include "GasaCommon.h"
@ -14,16 +13,3 @@ class GASA_API UGasaAbilitySystemComp : public UAbilitySystemComponent
GENERATED_BODY()
public:
};
namespace Gasa
{
inline
UGasaAbilitySystemComp* GetAbilitySystem(UObject* Object)
{
if (Object->Implements<UAbilitySystemInterface>())
{
return Cast<UGasaAbilitySystemComp>( Cast<IAbilitySystemInterface>(Object)->GetAbilitySystemComponent() );
}
return nullptr;
}
}

View File

@ -0,0 +1,16 @@
#pragma once
#include "GasaAbilitySystemComponent.h"
#include "AbilitySystemInterface.h"
namespace Gasa
{
inline
UGasaAbilitySystemComp* GetAbilitySystem(UObject* Object)
{
if (Object->Implements<UAbilitySystemInterface>())
{
return Cast<UGasaAbilitySystemComp>( Cast<IAbilitySystemInterface>(Object)->GetAbilitySystemComponent() );
}
return nullptr;
}
}

View File

@ -1,5 +1,6 @@
// This was generated by GasaGen/GasaGen.cpp
// Generated by GasaGen/GasaGen_UGasaAttributeSet.cpp
#include "GasaAttributeSet.h"
#include "GasaAttributeSet_Inlines.h"
#include "AbilitySystemComponent.h"
#include "Net/UnrealNetwork.h"

View File

@ -1,7 +1,7 @@
// This was generated by GasaGen/GasaGen.cpp
// Generated by GasaGen/GasaGen_UGasaAttributeSet.cpp
#pragma once
#include "AttributeSet.h"
#include "AbilitySystemComponent.h"
#include "GasaAttributeSet.generated.h"
UCLASS()
@ -53,6 +53,7 @@ public:
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) );
return Prop;
}
FORCEINLINE float GetHealth() const { return Health.GetCurrentValue(); }
FORCEINLINE float GetMaxHealth() const { return MaxHealth.GetCurrentValue(); }
FORCEINLINE float GetMana() const { return Mana.GetCurrentValue(); }
@ -61,38 +62,11 @@ public:
#pragma region Setters
FORCEINLINE void
SetHealth( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetHealthAttribute(), NewVal );
};
}
FORCEINLINE void SetMaxHealth( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetMaxHealthAttribute(), NewVal );
};
}
FORCEINLINE void SetMana( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetManaAttribute(), NewVal );
};
}
FORCEINLINE void SetMaxMana( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetMaxManaAttribute(), NewVal );
};
}
SetHealth( float NewVal );
FORCEINLINE void SetMaxHealth( float NewVal );
FORCEINLINE void SetMana( float NewVal );
FORCEINLINE void SetMaxMana( float NewVal );
FORCEINLINE void InitHealth( float NewVal )
{
Health.SetBaseValue( NewVal );
@ -121,11 +95,3 @@ public:
GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const override;
#pragma endregion UObject
};
namespace Gasa
{
inline UGasaAttributeSet const* GetAttributeSet( UAbilitySystemComponent* ASC )
{
return Cast<UGasaAttributeSet>( ASC->GetAttributeSet( UGasaAttributeSet::StaticClass() ) );
}
}

View File

@ -0,0 +1,51 @@
// Generated by GasaGen/GasaGen_UGasaAttributeSet.cpp
#pragma once
#include "GasaAttributeSet.h"
#include "AbilitySystemComponent.h"
FORCEINLINE
void UGasaAttributeSet::SetHealth( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetHealthAttribute(), NewVal );
};
}
FORCEINLINE
void UGasaAttributeSet::SetMaxHealth( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetMaxHealthAttribute(), NewVal );
};
}
FORCEINLINE
void UGasaAttributeSet::SetMana( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetManaAttribute(), NewVal );
};
}
FORCEINLINE
void UGasaAttributeSet::SetMaxMana( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
{
AbilityComp->SetNumericAttributeBase( GetMaxManaAttribute(), NewVal );
};
}
namespace Gasa
{
inline UGasaAttributeSet const* GetAttributeSet( UAbilitySystemComponent* ASC )
{
return Cast<UGasaAttributeSet>( ASC->GetAttributeSet( UGasaAttributeSet::StaticClass() ) );
}
}

View File

@ -1,8 +1,8 @@
#include "GasaEffectActor.h"
#include "AbilitySystemComponent.h"
#include "AbilitySystemInterface.h"
#include "GasaAttributeSet.h"
#include "GasaAttributeSet_Inlines.h"
#include "Components/SphereComponent.h"

View File

@ -1,6 +1,9 @@
#include "PlayerCharacter.h"
#include "AbilitySystemComponent.h"
#include "Game/GasaPlayerController.h"
#include "UI/GasaHUD.h"
#include "UI/WidgetController.h"
APlayerCharacter::APlayerCharacter()
{
@ -9,6 +12,7 @@ APlayerCharacter::APlayerCharacter()
bAutoAbilitySystem = false;
}
// TODO(Ed): We need to setup Net Slime...
void APlayerCharacter::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
@ -20,8 +24,14 @@ void APlayerCharacter::PossessedBy(AController* NewController)
Attributes = PS->Attributes;
AbilitySystem->InitAbilityActorInfo(PS, this);
}
AGasaPlayerController* PC = GetController<AGasaPlayerController>();
AGasaHUD* HUD = PC->GetHUD<AGasaHUD>();
FWidgetControllerData Data = { PC, PS, AbilitySystem, Attributes };
HUD->InitOverlay(& Data);
}
// TODO(Ed): We need to setup Net Slime...
void APlayerCharacter::OnRep_PlayerState()
{
Super::OnRep_PlayerState();
@ -33,4 +43,12 @@ void APlayerCharacter::OnRep_PlayerState()
Attributes = PS->Attributes;
AbilitySystem->InitAbilityActorInfo(PS, this);
}
if (IsLocallyControlled())
{
AGasaPlayerController* PC = GetController<AGasaPlayerController>();
AGasaHUD* HUD = PC->GetHUD<AGasaHUD>();
FWidgetControllerData Data = { PC, PS, AbilitySystem, Attributes };
HUD->InitOverlay(& Data);
}
}

View File

@ -1,4 +1,5 @@
#include "GasaPlayerController.h"
#include "GasaPlayerController_Inlines.h"
#include "AbilitySystemComponent.h"
#include "Engine/LocalPlayer.h"
@ -12,7 +13,6 @@
#include "Components/CapsuleComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/KismetSystemLibrary.h"
using namespace Gasa;
AGasaPlayerController::AGasaPlayerController()
@ -24,6 +24,8 @@ AGasaPlayerController::AGasaPlayerController()
bReplicates = true;
}
#pragma region Input
void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
{
@ -31,8 +33,6 @@ void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
if (pawn == nullptr )
return;
// Note(Ed): I did the follow optimization for practice, they are completely unnecessary for this context.
#if 0
FVector2D AxisV = ActionValue.Get<FVector2D>();
@ -77,6 +77,7 @@ void AGasaPlayerController::SpawnDefaultHUD()
Super::SpawnDefaultHUD();
}
// TODO(Ed): We need to setup Net Slime...
void AGasaPlayerController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);

View File

@ -1,7 +1,6 @@
#pragma once
#include "GasaCommon.h"
#include "GasaPlayerState.h"
#include "GameFramework/PlayerController.h"
#include "GasaPlayerController.generated.h"
@ -51,10 +50,7 @@ public:
AGasaPlayerController();
AGasaPlayerState* GetPlayerState()
{
return Cast<AGasaPlayerState>( PlayerState );
}
inline AGasaPlayerState* GetPlayerState();
#pragma region PlayerController
void SpawnDefaultHUD() override;

View File

@ -0,0 +1,8 @@
#include "GasaPlayerController.h"
#include "GasaPlayerState.h"
inline
AGasaPlayerState* AGasaPlayerController::GetPlayerState()
{
return Cast<AGasaPlayerState>( PlayerState );
}

View File

@ -40,6 +40,7 @@ class AGasaGameInstance;
class AGasaGameState;
class AGasaLevelScriptActor;
class AGasaPlayerController;
class AGasaPlayerState;
class UGasaAbilitySystemComp;
class UGasaAttributeSet;
@ -48,7 +49,11 @@ class UGasaImage;
class UGasaOverlay;
class UGasaProgressBar;
class UGasaSizeBox;
class UUI_HostWidget;
class UHostWidgetController;
class UHUDHostWidget;
class UWidgetController;
struct FWidgetControllerData;
#pragma endregion Forwards
#pragma region Logging

View File

@ -1,7 +1,8 @@
#include "GasaDevOptions.h"
#include "Actors/CameraMount.h"
#include "UI/UI_HostWidget.h"
#include "UI/HUDHostWidget.h"
#include "UI/HostWidgetController.h"
using namespace Gasa;

View File

@ -19,7 +19,10 @@ public:
TSoftClassPtr<ACameraMount> Template_PlayerCamera;
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="UI")
TSoftClassPtr<UUI_HostWidget> Template_HUD_HostUI;
TSoftClassPtr<UHUDHostWidget> Template_HUD_HostUI;
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="UI")
TSoftClassPtr<UHostWidgetController> Template_HostWidgetController;
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="Tags")
FName Tag_GlobalPPV;

View File

@ -1,9 +1,10 @@
// This was generated by GasaGen/GasaGen.cpp
// Generated by GasaGen/GasaGen_DevOptionsCache.cpp
#include "GasaDevOptionsCache.h"
#include "GasaDevOptions.h"
#include "Actors/CameraMount.h"
#include "UI/UI_HostWidget.h"
#include "UI/HUDHostWidget.h"
#include "UI/HostWidgetController.h"
using namespace Gasa;
void FGasaDevOptionsCache::CachedDevOptions()
@ -11,7 +12,13 @@ void FGasaDevOptionsCache::CachedDevOptions()
UGasaDevOptions* DevOpts = GetMutDevOptions();
Template_PlayerCamera = DevOpts->Template_PlayerCamera.LoadSynchronous();
Template_HUD_HostUI = DevOpts->Template_HUD_HostUI.LoadSynchronous();
ensureMsgf( Template_PlayerCamera != nullptr, TEXT( "Template_PlayerCamera is null, DO NOT RUN PIE or else you may get a crash if not handled in BP or C++" ) );
Template_HUD_HostUI = DevOpts->Template_HUD_HostUI.LoadSynchronous();
ensureMsgf( Template_HUD_HostUI != nullptr, TEXT( "Template_HUD_HostUI is null, DO NOT RUN PIE or else you may get a crash if not handled in BP or C++" ) );
Template_HostWidgetController = DevOpts->Template_HostWidgetController.LoadSynchronous();
ensureMsgf( Template_HostWidgetController != nullptr, TEXT( "Template_HostWidgetController is null, DO NOT RUN PIE or else you may get a crash if not handled in BP or C++" ) );
Tag_GlobalPPV = DevOpts->Tag_GlobalPPV;
}

View File

@ -1,4 +1,4 @@
// This was generated by GasaGen/GasaGen.cpp
// Generated by GasaGen/GasaGen_DevOptionsCache.cpp
#pragma once
#include "GasaDevOptionsCache.generated.h"
@ -12,6 +12,8 @@ struct GASA_API FGasaDevOptionsCache
UClass* Template_PlayerCamera;
UPROPERTY()
UClass* Template_HUD_HostUI;
UPROPERTY()
UClass* Template_HostWidgetController;
void CachedDevOptions();
};

View File

@ -1,11 +1,21 @@
#include "GasaHUD.h"
#include "GasaHUD_Inlines.h"
#include "GasaDevOptions.h"
#include "UI_HostWidget.h"
#include "HUDHostWidget.h"
#include "Blueprint/UserWidget.h"
using namespace Gasa;
void AGasaHUD::InitOverlay(FWidgetControllerData const* WidgetControllerData)
{
HostWidget = CreateWidget<UHUDHostWidget>( GetWorld()
, GetDevOptions()->Template_HUD_HostUI.LoadSynchronous() );
HostWidgetController = NewObject<UHostWidgetController>(this, GetDevOptions()->Template_HostWidgetController.Get());
HostWidget->SetWidgetController(HostWidgetController);
HostWidget->AddToViewport();
}
#pragma region HUD
void AGasaHUD::ShowHUD()
@ -15,17 +25,8 @@ void AGasaHUD::ShowHUD()
#pragma endregion HUD
#pragma region Actor
UE_DISABLE_OPTIMIZATION
void AGasaHUD::BeginPlay()
{
Super::BeginPlay();
HostWidget = CreateWidget<UUI_HostWidget>( GetWorld()
, GetDevOptions()->Template_HUD_HostUI.LoadSynchronous() );
HostWidget->AddToViewport();
bool bHostVis = HostWidget->IsVisible();
Log(FString::Printf(TEXT("HostVIs: %s"), *FString::FromInt(bHostVis)));
}
UE_ENABLE_OPTIMIZATION
#pragma endregion Actor

View File

@ -12,14 +12,20 @@ class GASA_API AGasaHUD : public AHUD
GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
TObjectPtr<UUI_HostWidget> HostWidget;
TObjectPtr<UHUDHostWidget> HostWidget;
// This should only be accessed AFTER InitOverlay is called. Otherwise, it will be null
// See references to InitOverlay or docs for lifetime.
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
TObjectPtr<UHostWidgetController> HostWidgetController;
void InitOverlay(FWidgetControllerData const* WidgetControllerData);
#pragma region HUD
void ShowHUD() override;
#pragma endregion HUD
#pragma region Actor
void BeginPlay() override;
#pragma endregion Actor
};

View File

@ -0,0 +1,5 @@
#pragma once
#include "GasaHUD.h"
#include "GasaDevOptions.h"
#include "HostWidgetController.h"
#include "HUDHostWidget.h"

View File

@ -1,8 +1,10 @@
#pragma once
#include "Blueprint/UserWidget.h"
#include "GasaCommon.h"
#include "GasaUserWidget.generated.h"
UCLASS(Blueprintable)
class GASA_API UGasaUserWidget : public UUserWidget
{
@ -23,12 +25,15 @@ public:
TSubclassOf<UGasaUserWidget> LooseParent;
UPROPERTY(BlueprintReadOnly)
TObjectPtr<UObject> WidgetController;
TObjectPtr<UWidgetController> WidgetController;
UGasaUserWidget(FObjectInitializer const& ObjectInitializer);
template<typename WidgetControllerType>
FORCEINLINE WidgetControllerType* GetWidgetController() { return Cast<WidgetControllerType>(WidgetController); }
UFUNCTION(BlueprintCallable)
void SetWidgetController(UObject* Controller)
void SetWidgetController(UWidgetController* Controller)
{
WidgetController = Controller;
OnWidgetControllerSet();

View File

@ -0,0 +1 @@
#include "HUDHostWidget.h"

View File

@ -2,10 +2,10 @@
#include "GasaUserWidget.h"
#include "UI_HostWidget.generated.h"
#include "HUDHostWidget.generated.h"
UCLASS()
class GASA_API UUI_HostWidget : public UGasaUserWidget
class GASA_API UHUDHostWidget : public UGasaUserWidget
{
GENERATED_BODY()
public:

View File

@ -0,0 +1 @@
#include "HostWidgetController.h"

View File

@ -0,0 +1,12 @@
#pragma once
#include "WidgetController.h"
#include "HostWidgetController.generated.h"
UCLASS()
class GASA_API UHostWidgetController : public UWidgetController
{
GENERATED_BODY()
public:
};

View File

@ -1 +0,0 @@
#include "UI_HostWidget.h"

View File

@ -3,17 +3,37 @@
#include "GasaCommon.h"
#include "WidgetController.generated.h"
UCLASS(BlueprintType)
class GASA_API UWidgetController : public UObject
USTRUCT(BlueprintType)
struct GASA_API FWidgetControllerData
{
GENERATED_BODY()
public:
FWidgetControllerData() = default;
FWidgetControllerData(AGasaPlayerController* Controller
, AGasaPlayerState* PlayerState
, UAbilitySystemComponent* AbilitySystem
, UAttributeSet* Attributes )
#if 1
: 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;
UPROPERTY(BlueprintReadOnly, Category="Player")
TObjectPtr<APlayerController> Controller;
UPROPERTY(BlueprintReadOnly, Category="Player")
TObjectPtr<APlayerState> PlayerState;
TObjectPtr<AGasaPlayerState> PlayerState;
UPROPERTY(BlueprintReadOnly, Category="Player")
TObjectPtr<UAbilitySystemComponent> AbilitySystem;
@ -21,3 +41,13 @@ public:
UPROPERTY(BlueprintReadOnly, Category="Player")
TObjectPtr<UAttributeSet> Attributes;
};
UCLASS(Blueprintable)
class GASA_API UWidgetController : public UObject
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly, Category="Player")
FWidgetControllerData Data;
};