32. Overlay Widget Controller
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
5
Project/Source/Gasa/UI/GasaHUD_Inlines.h
Normal file
5
Project/Source/Gasa/UI/GasaHUD_Inlines.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include "GasaHUD.h"
|
||||
#include "GasaDevOptions.h"
|
||||
#include "HostWidgetController.h"
|
||||
#include "HUDHostWidget.h"
|
@ -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();
|
||||
|
1
Project/Source/Gasa/UI/HUDHostWidget.cpp
Normal file
1
Project/Source/Gasa/UI/HUDHostWidget.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "HUDHostWidget.h"
|
@ -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:
|
1
Project/Source/Gasa/UI/HostWIdgetController.cpp
Normal file
1
Project/Source/Gasa/UI/HostWIdgetController.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "HostWidgetController.h"
|
12
Project/Source/Gasa/UI/HostWidgetController.h
Normal file
12
Project/Source/Gasa/UI/HostWidgetController.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "WidgetController.h"
|
||||
|
||||
#include "HostWidgetController.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class GASA_API UHostWidgetController : public UWidgetController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
};
|
@ -1 +0,0 @@
|
||||
#include "UI_HostWidget.h"
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user