31. Aura HUD (plus other stuff)

- Enabled a few more plugins
- Added clang formatting straight from the GasaGen cpp.
- Setup auto-generation of the DevOptionsCache
- Messed around with generating widgettree hiearchy from template widget
This commit is contained in:
2024-04-21 09:51:51 -04:00
parent 466adc5bd9
commit 6765478a9d
64 changed files with 2757 additions and 1551 deletions

View File

@ -33,9 +33,10 @@ void UGasaAttributeSet::Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMan
GAMEPLAYATTRIBUTE_REPNOTIFY( UGasaAttributeSet, MaxMana, PrevMaxMana )
}
void UGasaAttributeSet::GetLifetimeReplicatedProps( TArray< FLifetimeProperty >& OutLifetimeProps ) const
void UGasaAttributeSet::GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const
{
Super::GetLifetimeReplicatedProps( OutLifetimeProps );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Health );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, MaxHealth );
DOREPLIFETIME_DEFAULT_GAS( UGasaAttributeSet, Mana );

View File

@ -4,7 +4,8 @@
#include "AbilitySystemComponent.h"
#include "GasaAttributeSet.generated.h"
UCLASS() class GASA_API UGasaAttributeSet : public UAttributeSet
UCLASS()
class GASA_API UGasaAttributeSet : public UAttributeSet
{
GENERATED_BODY()
public:
@ -21,6 +22,7 @@ public:
FGameplayAttributeData MaxMana;
UGasaAttributeSet();
UFUNCTION()
void Client_OnRep_Health( FGameplayAttributeData& PrevHealth );
UFUNCTION()
@ -31,55 +33,35 @@ public:
void Client_OnRep_MaxMana( FGameplayAttributeData& PrevMaxMana );
#pragma region Getters
static FGameplayAttribute GetHealthAttribute()
{
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) );
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Health ) );
return Prop;
}
static FGameplayAttribute GetMaxHealthAttribute()
{
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) );
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxHealth ) );
return Prop;
}
static FGameplayAttribute GetManaAttribute()
{
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) );
static FProperty* Prop = FindFieldChecked<FProperty>( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, Mana ) );
return Prop;
}
static FGameplayAttribute GetMaxManaAttribute()
{
static FProperty* Prop = FindFieldChecked< FProperty >( UGasaAttributeSet::StaticClass(), GET_MEMBER_NAME_CHECKED( UGasaAttributeSet, MaxMana ) );
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();
}
FORCEINLINE float GetMaxMana() const
{
return MaxMana.GetCurrentValue();
}
#pragma endregion Getters
FORCEINLINE float GetHealth() const { return Health.GetCurrentValue(); }
FORCEINLINE float GetMaxHealth() const { return MaxHealth.GetCurrentValue(); }
FORCEINLINE float GetMana() const { return Mana.GetCurrentValue(); }
FORCEINLINE float GetMaxMana() const { return MaxMana.GetCurrentValue(); }
#pragma endregion Getters
#pragma region Setters
FORCEINLINE void SetHealth( float NewVal )
FORCEINLINE void
SetHealth( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
if ( ensure( AbilityComp ) )
@ -87,7 +69,6 @@ public:
AbilityComp->SetNumericAttributeBase( GetHealthAttribute(), NewVal );
};
}
FORCEINLINE void SetMaxHealth( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
@ -96,7 +77,6 @@ public:
AbilityComp->SetNumericAttributeBase( GetMaxHealthAttribute(), NewVal );
};
}
FORCEINLINE void SetMana( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
@ -105,7 +85,6 @@ public:
AbilityComp->SetNumericAttributeBase( GetManaAttribute(), NewVal );
};
}
FORCEINLINE void SetMaxMana( float NewVal )
{
UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();
@ -114,44 +93,39 @@ public:
AbilityComp->SetNumericAttributeBase( GetMaxManaAttribute(), NewVal );
};
}
FORCEINLINE void InitHealth( float NewVal )
{
Health.SetBaseValue( NewVal );
Health.SetCurrentValue( NewVal );
}
FORCEINLINE void InitMaxHealth( float NewVal )
{
MaxHealth.SetBaseValue( NewVal );
MaxHealth.SetCurrentValue( NewVal );
}
FORCEINLINE void InitMana( float NewVal )
{
Mana.SetBaseValue( NewVal );
Mana.SetCurrentValue( NewVal );
}
FORCEINLINE void InitMaxMana( float NewVal )
{
MaxMana.SetBaseValue( NewVal );
MaxMana.SetCurrentValue( NewVal );
}
#pragma endregion Setters
#pragma endregion Setters
#pragma region UObject
void GetLifetimeReplicatedProps( TArray< FLifetimeProperty >& OutLifetimeProps ) const override;
void
GetLifetimeReplicatedProps( TArray<FLifetimeProperty>& OutLifetimeProps ) const override;
#pragma endregion UObject
};
namespace Gasa
{
inline UGasaAttributeSet const* GetAttributeSet( UAbilitySystemComponent* ASC )
{
return Cast< UGasaAttributeSet >( ASC->GetAttributeSet( UGasaAttributeSet::StaticClass() ) );
return Cast<UGasaAttributeSet>( ASC->GetAttributeSet( UGasaAttributeSet::StaticClass() ) );
}
}

View File

@ -4,6 +4,7 @@
#include "Engine/LocalPlayer.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "GasaDevOptions.h"
#include "GasaPlayerState.h"
#include "Actors/CameraMount.h"
#include "Camera/CameraComponent.h"
@ -12,6 +13,8 @@
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/KismetSystemLibrary.h"
using namespace Gasa;
AGasaPlayerController::AGasaPlayerController()
{
PrimaryActorTick.bCanEverTick = true;
@ -21,11 +24,14 @@ AGasaPlayerController::AGasaPlayerController()
bReplicates = true;
}
#pragma region Input
void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
{
APawn* pawn = GetPawn<APawn>();
if (pawn == nullptr )
return;
// Note(Ed): I did the follow optimization for practice, they are completely unnecessary for this context.
#if 0
@ -63,6 +69,13 @@ void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
pawn->AddMovementInput( MoveDir );
#endif
}
#pragma endregion Input
#pragma region PlayerController
void AGasaPlayerController::SpawnDefaultHUD()
{
Super::SpawnDefaultHUD();
}
void AGasaPlayerController::OnPossess(APawn* InPawn)
{
@ -86,7 +99,6 @@ void AGasaPlayerController::OnUnPossess()
Super::OnUnPossess();
}
#pragma region PlayerController
void AGasaPlayerController::PlayerTick(float DeltaTime)
{
Super::PlayerTick(DeltaTime);
@ -162,7 +174,7 @@ void AGasaPlayerController::PostInitializeComponents()
{
Super::PostInitializeComponents();
Cam = GetWorld()->SpawnActor<ACameraMount>(CamClass, FActorSpawnParameters() );
Cam = GetWorld()->SpawnActor<ACameraMount>(GetDevOptions()->Template_PlayerCamera.Get(), FActorSpawnParameters() );
SetViewTarget(Cam);
}

View File

@ -12,9 +12,6 @@ class GASA_API AGasaPlayerController : public APlayerController
GENERATED_BODY()
public:
#pragma region Camera
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<ACameraMount> CamClass;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<ACameraMount> Cam;
#pragma endregion Camera
@ -60,6 +57,8 @@ public:
}
#pragma region PlayerController
void SpawnDefaultHUD() override;
void OnPossess(APawn* InPawn) override;
void OnUnPossess() override;

View File

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

View File

@ -0,0 +1,12 @@
#pragma once
#include "Engine/GameViewportClient.h"
#include "GasaViewport.generated.h"
UCLASS()
class GASA_API UGasaViewport : public UGameViewportClient
{
GENERATED_BODY()
public:
};

View File

@ -33,9 +33,17 @@ public class Gasa : ModuleRules
"NetCore",
"Niagara",
"SlateCore",
"UMG",
"UMG",
});
#endregion Engine
if (Target.bBuildEditor)
{
PrivateDependencyModuleNames.AddRange( new string[] {
"UnrealEd",
"UMGEditor",
});
}
#endregion Engine
#region Plugins
if (Target.Configuration != UnrealTargetConfiguration.Shipping && Target.Type != TargetRules.TargetType.Server)
@ -66,5 +74,6 @@ public class Gasa : ModuleRules
#endregion Plugins
PublicIncludePaths.Add("Gasa");
PublicIncludePathModuleNames.Add("Gasa");
}
}

View File

@ -48,6 +48,7 @@ class UGasaImage;
class UGasaOverlay;
class UGasaProgressBar;
class UGasaSizeBox;
class UUI_HostWidget;
#pragma endregion Forwards
#pragma region Logging
@ -98,7 +99,7 @@ DECLARE_LOG_CATEGORY_EXTERN(LogGasa, Log, All);
namespace Gasa
{
using ELogV = EGasaVerbosity;
//◞ ‸ ◟//
// Works for Unreal 5.4, Win64 MSVC (untested in other scenarios, for now)
inline
@ -111,7 +112,7 @@ namespace Gasa
{
#if !UE_BUILD_SHIPPING && !NO_LOGGING
ELogVerbosity::Type EngineVerbosity = (ELogVerbosity::Type) Verbosity;
static UE::Logging::Private::FStaticBasicLogDynamicData LOG_Dynamic;
static UE::Logging::Private::FStaticBasicLogRecord
LOG_Static(TEXT("%s -- %hs %hs(%d)"), File, Line, EngineVerbosity, LOG_Dynamic);
@ -132,13 +133,13 @@ namespace Gasa
}
}
#define GASA_Fatal(Message) UE_LOG( Gasa, Fatal, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_FILE(), __func__, __builtin_LINE() );
#define GASA_Error(Message) UE_LOG( Gasa, Error, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Warning(Message) UE_LOG( Gasa, Warning, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Display(Message) UE_LOG( Gasa, Display, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Log(Message) UE_LOG( Gasa, Log, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Verbose(Message) UE_LOG( Gasa, Verbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_VeryVerbose(Message) UE_LOG( Gasa, VeryVerbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Fatal(Message) UE_LOG( LogGasa, Fatal, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_FILE(), __func__, __builtin_LINE() );
#define GASA_Error(Message) UE_LOG( LogGasa, Error, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Warning(Message) UE_LOG( LogGasa, Warning, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Display(Message) UE_LOG( LogGasa, Display, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Log(Message) UE_LOG( LogGasa, Log, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_Verbose(Message) UE_LOG( LogGasa, Verbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#define GASA_VeryVerbose(Message) UE_LOG( LogGasa, VeryVerbose, TEXT("%s -- %hs %hs(%d)"), *Message, __builtin_File(), __func__, __builtin_LINE() );
#pragma endregion Logging
#pragma region Timing
@ -154,8 +155,8 @@ namespace Gasa
constexpr float _80Hz = .013f;
constexpr float _90Hz = .011f;
constexpr float _100Hz = .010f;
constexpr float _120Hz = .083f;
constexpr float _120Hz = .008f;
constexpr float _240Hz = .004f;
constexpr float _480Hz = .002f;
}
#pragma endregion Timing
#pragma endregion Timing

View File

@ -1,18 +1,11 @@
#include "GasaDevOptions.h"
#include "GasaDevOptions.h"
#include "GasaDevOptionsCache.h"
#include "Actors/CameraMount.h"
#include "UI/UI_HostWidget.h"
using namespace Gasa;
namespace Gasa
{
global FName Tag_GlobalPPV;
}
void FGasaDevOptionsCache::CachedDevOptions()
{
using namespace Gasa;
UGasaDevOptions const* DevOs = GetDevOptions();
Tag_GlobalPPV = DevOs->Tag_GlobalPPV;
}

View File

@ -1,7 +1,9 @@
#pragma once
#pragma once
#include "Engine/DeveloperSettings.h"
#include "GasaCommon.h"
#include "GasaDevOptions.generated.h"
UCLASS(Config=Game, DefaultConfig, meta=(DisplayName="Gasa"))
@ -9,6 +11,16 @@ class GASA_API UGasaDevOptions : public UDeveloperSettings
{
GENERATED_BODY()
public:
// NOTE(Ed): Any Soft-References must have their includes defined in GasaDevOptions.cpp
// They are used by GasaGen for the GasaDevOptionsCache
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="UI")
TSoftClassPtr<ACameraMount> Template_PlayerCamera;
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="UI")
TSoftClassPtr<UUI_HostWidget> Template_HUD_HostUI;
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="Tags")
FName Tag_GlobalPPV;
};
@ -19,11 +31,11 @@ namespace Gasa
FORCEINLINE
UGasaDevOptions const* GetDevOptions() {
return GetDefault<UGasaDevOptions>();
return GetDefault<UGasaDevOptions>();
}
FORCEINLINE
UGasaDevOptions* GetMutDevOptions() {
return GetMutableDefault<UGasaDevOptions>();
return GetMutableDefault<UGasaDevOptions>();
}
}

View File

@ -0,0 +1,17 @@
// This was generated by GasaGen/GasaGen.cpp
#include "GasaDevOptionsCache.h"
#include "GasaDevOptions.h"
#include "Actors/CameraMount.h"
#include "UI/UI_HostWidget.h"
using namespace Gasa;
void FGasaDevOptionsCache::CachedDevOptions()
{
UGasaDevOptions* DevOpts = GetMutDevOptions();
Template_PlayerCamera = DevOpts->Template_PlayerCamera.LoadSynchronous();
Template_HUD_HostUI = DevOpts->Template_HUD_HostUI.LoadSynchronous();
Tag_GlobalPPV = DevOpts->Tag_GlobalPPV;
}

View File

@ -1,6 +1,5 @@
#pragma once
#include "GasaCommon.h"
// This was generated by GasaGen/GasaGen.cpp
#pragma once
#include "GasaDevOptionsCache.generated.h"
@ -8,6 +7,11 @@ USTRUCT()
struct GASA_API FGasaDevOptionsCache
{
GENERATED_BODY()
UPROPERTY()
UClass* Template_PlayerCamera;
UPROPERTY()
UClass* Template_HUD_HostUI;
void CachedDevOptions();
};

View File

@ -2,7 +2,7 @@
#include "Blueprint/GameViewportSubsystem.h"
#include "GasaViewport.generated.h"
#include "GasaViewportSubsystem.generated.h"
UCLASS()
class GASA_API UGasaViewportSubsystem : public UGameViewportSubsystem
@ -12,4 +12,4 @@ public:
// UGasaViewportSubsystem();
};
};

View File

@ -1,9 +0,0 @@
// Don't keep this included anywhere
// Purely for inspection purposes
#include "GasaCommon.h"
void test()
{
UObject::StaticClass()->PropertiesSize
}

View File

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

View File

@ -0,0 +1,12 @@
#pragma once
#include "Engine/Canvas.h"
#include "GasaCanvas.generated.h"
UCLASS()
class GASA_API UGasaCanvas : public UCanvas
{
GENERATED_BODY()
public:
};

View File

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

View File

@ -0,0 +1,12 @@
#pragma once
#include "Components/CanvasPanel.h"
#include "GasaCanvasPanel.generated.h"
UCLASS()
class GASA_API UGasaCanvasPanel : public UCanvasPanel
{
GENERATED_BODY()
public:
};

View File

@ -0,0 +1,31 @@
#include "GasaHUD.h"
#include "GasaDevOptions.h"
#include "UI_HostWidget.h"
#include "Blueprint/UserWidget.h"
using namespace Gasa;
#pragma region HUD
void AGasaHUD::ShowHUD()
{
Super::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

@ -0,0 +1,25 @@
#pragma once
#include "GasaCommon.h"
#include "GameFramework/HUD.h"
#include "GasaHUD.generated.h"
UCLASS()
class GASA_API AGasaHUD : public AHUD
{
GENERATED_BODY()
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
TObjectPtr<UUI_HostWidget> HostWidget;
#pragma region HUD
void ShowHUD() override;
#pragma endregion HUD
#pragma region Actor
void BeginPlay() override;
#pragma endregion Actor
};

View File

@ -0,0 +1,22 @@
#include "GasaProgressBar.h"
#include "GasaCommon.h"
using namespace Gasa;
#pragma region Object
void UGasaProgressBar::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
}
void UGasaProgressBar::Serialize(FArchive& Ar)
{
Super::Serialize(Ar);
}
void UGasaProgressBar::Serialize(FStructuredArchive::FRecord Record)
{
Super::Serialize(Record);
}
#pragma endregion Object

View File

@ -10,4 +10,10 @@ class GASA_API UGasaProgressBar : public UProgressBar
GENERATED_BODY()
public:
#pragma region Object
void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
void Serialize(FArchive& Ar) override;
void Serialize(FStructuredArchive::FRecord Record) override;
#pragma endregion Object
};

View File

@ -1,7 +1,310 @@
#include "GasaUserWidget.h"
#include "Blueprint/WidgetBlueprintGeneratedClass.h"
#include "Blueprint/WidgetTree.h"
#include "Components/HorizontalBoxSlot.h"
#include "Components/Overlay.h"
#include "Components/OverlaySlot.h"
#include "Components/ScaleBoxSlot.h"
#include "Components/ScrollBoxSlot.h"
#include "Components/SizeBoxSlot.h"
#include "Components/VerticalBoxSlot.h"
#if WITH_EDITOR
#include "WidgetBlueprint.h"
#include "Kismet2/BlueprintEditorUtils.h"
#endif
#if 0
UWidget* UMyModalDialog::DeepDuplicateWidget(UWidget *pUWidget)
{
UWidget *pNewWidget = DuplicateObject<UWidget>(pUWidget, this);
UPanelWidget *pNewUPanelWidget = Cast<UPanelWidget>(pNewWidget);
if (pNewUPanelWidget)
{
const TArray<UPanelSlot*>& slots = pNewUPanelWidget->GetSlots();
for (int32 iSlotNum = 0; iSlotNum < slots.Num(); ++iSlotNum)
{
slots[iSlotNum]->Content = nullptr;
}
pNewUPanelWidget->ClearChildren();
UPanelWidget *pUPanelWidget = Cast<UPanelWidget>(pUWidget);
for (int ii = 0; ii < pUPanelWidget->GetChildrenCount(); ++ii)
{
UWidget *pChildUWidget = pUPanelWidget->GetChildAt(ii);
UWidget *pNewChildWidget = DeepDuplicateWidget(pChildUWidget);
UPanelSlot *pUPanelSlot = pNewUPanelWidget->AddChild(pNewChildWidget);
UHorizontalBoxSlot *pNewUHorizontalBoxSlot = Cast<UHorizontalBoxSlot>(pUPanelSlot);
if (pNewUHorizontalBoxSlot)
{
UHorizontalBoxSlot *pUHorizontalBoxSlot = Cast<UHorizontalBoxSlot>(pChildUWidget->Slot);
pNewUHorizontalBoxSlot->SetHorizontalAlignment(pUHorizontalBoxSlot->HorizontalAlignment);
pNewUHorizontalBoxSlot->SetVerticalAlignment(pUHorizontalBoxSlot->VerticalAlignment);
}
USizeBoxSlot *pNewUSizeBoxSlot = Cast<USizeBoxSlot>(pUPanelSlot);
if (pNewUSizeBoxSlot)
{
USizeBoxSlot *pUSizeBoxSlot = Cast<USizeBoxSlot>(pChildUWidget->Slot);
pNewUSizeBoxSlot->SetHorizontalAlignment(pUSizeBoxSlot->HorizontalAlignment);
pNewUSizeBoxSlot->SetVerticalAlignment(pUSizeBoxSlot->VerticalAlignment);
}
}
}
return pNewWidget;
}
#endif
void UGasaUserWidget::OnLooseParentCompiled(UBlueprint* BP)
{
GenerateParentHierarchyFromLooseParent();
}
// This was just an experiment to see how possible it would be to generate a WidgetTree from a parent reference without using the usual blueprint inheritance.
void UGasaUserWidget::GenerateParentHierarchyFromLooseParent()
{
#if WITH_EDITOR
UWidgetBlueprintGeneratedClass* WBG_ParentClass = Cast<UWidgetBlueprintGeneratedClass>(LooseParent);
UWidgetBlueprintGeneratedClass* WBG_Class = Cast<UWidgetBlueprintGeneratedClass>(GetClass());
if (WBG_ParentClass == nullptr)
return;
if (WBG_Class == nullptr)
return;
UPackage* Package = WBG_Class->GetPackage();
UWidgetBlueprint* BP = Cast<UWidgetBlueprint>(Package->FindAssetInPackage());
UWidgetTree* WT = BP->WidgetTree;
UPackage* UserParentPackage = WBG_ParentClass->GetPackage();
UWidgetBlueprint* UserParentBP = Cast<UWidgetBlueprint>(UserParentPackage->FindAssetInPackage());
UWidgetTree* UserParentWT = UserParentBP->WidgetTree;
TArray<UWidget*> UserParentWidgets;
UserParentWT->GetAllWidgets(UserParentWidgets);
for (UWidget* UserParentWidget : UserParentWidgets)
{
UWidget* OldWidget = nullptr;
UWidget* Widget = WT->FindWidget(UserParentWidget->GetFName());
TArray<UWidget*> Children;
UPanelWidget* Parent = nullptr;
if (Widget == nullptr)
{
if (UserParentWidget->GetClass()->IsChildOf(UUserWidget::StaticClass()))
Widget = CreateWidget<UUserWidget>(WT, UserParentWidget->GetClass(), UserParentWidget->GetFName());
else
Widget = NewObject<UWidget>(WT, UserParentWidget->GetClass(), UserParentWidget->GetFName(), RF_Transactional, UserParentWidget);
if (WT->RootWidget == nullptr)
{
WT->RootWidget = Widget;
}
else
{
Parent = WT->FindWidget<UPanelWidget>(UserParentWidget->GetParent()->GetFName());
}
}
else
{
// The widget existed previously (most likely already ran this before or manually created)
// Try to preserve widget heiarchy attached to this if possible
Parent = Widget->GetParent();
UPanelWidget* Panel = Cast<UPanelWidget>(Widget);
if (Panel)
{
Children = Panel->GetAllChildren();
}
OldWidget = Widget;
Widget = DuplicateObject<UWidget>(UserParentWidget, WT, UserParentWidget->GetFName());
}
UPanelWidget* NewPanel = Cast<UPanelWidget>(Widget);
if (NewPanel)
{
const TArray<UPanelSlot*>& Slots = NewPanel->GetSlots();
for (int32 Id = 0; Id < Slots.Num(); ++Id)
{
Slots[Id]->Content = nullptr;
}
NewPanel->ClearChildren();
}
if (Parent)
{
UPanelSlot* PSlot = Parent->AddChild(Widget);
UScaleBoxSlot* SlotScale = Cast<UScaleBoxSlot>(PSlot);
UScrollBoxSlot* SlotScroll = Cast<UScrollBoxSlot>(PSlot);
UOverlaySlot* SlotOverlay = Cast<UOverlaySlot>(PSlot);
UHorizontalBoxSlot* SlotHB = Cast<UHorizontalBoxSlot>(PSlot);
USizeBoxSlot* SlotSB = Cast<USizeBoxSlot>(PSlot);
UVerticalBoxSlot* SlobVB = Cast<UVerticalBoxSlot>(PSlot);
if (SlotOverlay)
{
UOverlay* UPW_ParentOverlay = Cast<UOverlay>(UserParentWidget->GetParent());
UOverlaySlot* ParentSlot = Cast<UOverlaySlot>(UPW_ParentOverlay->GetSlots()[Parent->GetSlots().Num() - 1]);
SlotOverlay->SetPadding( ParentSlot->GetPadding());
SlotOverlay->SetHorizontalAlignment( ParentSlot->GetHorizontalAlignment());
SlotOverlay->SetVerticalAlignment( ParentSlot->GetVerticalAlignment());
}
}
//This may not need to happen since the children check to see if they need to be added back.
for (UWidget* Child : Children)
{
if (UserParentWT->FindWidget(Child->GetFName()))
continue;
UPanelSlot* PSlot = Cast<UPanelWidget>(Widget)->AddChild(Child);
UScaleBoxSlot* SlotScale = Cast<UScaleBoxSlot>(PSlot);
UScrollBoxSlot* SlotScroll = Cast<UScrollBoxSlot>(PSlot);
UOverlaySlot* SlotOverlay = Cast<UOverlaySlot>(PSlot);
UHorizontalBoxSlot* SlotHB = Cast<UHorizontalBoxSlot>(PSlot);
USizeBoxSlot* SlotSB = Cast<USizeBoxSlot>(PSlot);
UVerticalBoxSlot* SlobVB = Cast<UVerticalBoxSlot>(PSlot);
// I'm not entirely sure if this is possible this way...
if (SlotOverlay)
{
UOverlay* ParentOverlay = Cast<UOverlay>(OldWidget->GetParent());
UOverlaySlot* ParentSlot = Cast<UOverlaySlot>(ParentOverlay->GetSlots()[Parent->GetSlots().Num() - 1]);
SlotOverlay->SetPadding( ParentSlot->GetPadding());
SlotOverlay->SetHorizontalAlignment( ParentSlot->GetHorizontalAlignment());
SlotOverlay->SetVerticalAlignment( ParentSlot->GetVerticalAlignment());
}
}
if (OldWidget)
OldWidget->RemoveFromParent();
}
BP->Modify();
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(BP);
#endif
}
UGasaUserWidget::UGasaUserWidget(FObjectInitializer const& ObjectInitializer)
: UUserWidget(ObjectInitializer)
{
{
}
bool UGasaUserWidget::Initialize()
{
// If it's not initialized initialize it, as long as it's not the CDO, we never initialize the CDO.
if (!bInitialized && !HasAnyFlags(RF_ClassDefaultObject))
{
// If this is a sub-widget of another UserWidget, default designer flags and player context to match those of the owning widget
if (UUserWidget* OwningUserWidget = GetTypedOuter<UUserWidget>())
{
#if WITH_EDITOR
SetDesignerFlags(OwningUserWidget->GetDesignerFlags());
#endif
SetPlayerContext(OwningUserWidget->GetPlayerContext());
}
UWidgetBlueprintGeneratedClass* BGClass = Cast<UWidgetBlueprintGeneratedClass>(GetClass());
// Only do this if this widget is of a blueprint class
if (BGClass)
{
BGClass->InitializeWidget(this);
}
else
{
InitializeNativeClassData();
}
if ( WidgetTree == nullptr )
{
WidgetTree = NewObject<UWidgetTree>(this, TEXT("WidgetTree"), RF_Transient);
}
else
{
WidgetTree->SetFlags(RF_Transient);
InitializeNamedSlots();
}
// For backward compatibility, run the initialize event on widget that doesn't have a player context only when the class authorized it.
bool bClassWantsToRunInitialized = BGClass && BGClass->bCanCallInitializedWithoutPlayerContext;
if (!IsDesignTime() && (PlayerContext.IsValid() || bClassWantsToRunInitialized))
{
NativeOnInitialized();
}
#if WITH_EDITOR
if (LooseParent && bUpdateOnParentCompile)
{
UWidgetBlueprintGeneratedClass* WBG_ParentClass = Cast<UWidgetBlueprintGeneratedClass>(LooseParent);
UPackage* UserParentPackage = WBG_ParentClass->GetPackage();
UWidgetBlueprint* UserParentBP = Cast<UWidgetBlueprint>(UserParentPackage->FindAssetInPackage());
UWidgetTree* UserParentWT = UserParentBP->WidgetTree;
if ( ! UserParentBP->OnCompiled().IsBoundToObject(this))
{
UserParentBP->OnCompiled().AddUObject(this, & ThisClass::OnLooseParentCompiled);
}
}
#endif
bInitialized = true;
return true;
}
return false;
}
void UGasaUserWidget::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
if (PropertyName == GET_MEMBER_NAME_CHECKED(UGasaUserWidget, LooseParent)
|| PropertyName == GET_MEMBER_NAME_CHECKED(UGasaUserWidget, bUpdateOnParentCompile) )
{
#if WITH_EDITOR
if (LooseParent && bUpdateOnParentCompile)
{
UWidgetBlueprintGeneratedClass* WBG_ParentClass = Cast<UWidgetBlueprintGeneratedClass>(LooseParent);
if (WBG_ParentClass == nullptr)
return;
UPackage* UserParentPackage = WBG_ParentClass->GetPackage();
UWidgetBlueprint* UserParentBP = Cast<UWidgetBlueprint>(UserParentPackage->FindAssetInPackage());
UWidgetTree* UserParentWT = UserParentBP->WidgetTree;
if ( ! UserParentBP->OnCompiled().IsBoundToObject(this))
{
UserParentBP->OnCompiled().AddUObject(this, & ThisClass::OnLooseParentCompiled);
}
}
#endif
}
}
void UGasaUserWidget::NativeOnInitialized()
{
Super::NativeOnInitialized();
}
void UGasaUserWidget::NativePreConstruct()
{
Super::NativePreConstruct();
#if 0
if (LooseParent)
{
UWidgetBlueprintGeneratedClass* WBG_ParentClass = Cast<UWidgetBlueprintGeneratedClass>(LooseParent);
UPackage* UserParentPackage = WBG_ParentClass->GetPackage();
UWidgetBlueprint* UserParentBP = Cast<UWidgetBlueprint>(UserParentPackage->FindAssetInPackage());
UWidgetTree* UserParentWT = UserParentBP->WidgetTree;
UserParentBP->OnCompiled().AddLambda( [this](UBlueprint* BP) {
if (this)
{
this->GenerateParentHierarchyFromLooseParent();
}
});
}
#endif
}

View File

@ -9,6 +9,19 @@ class GASA_API UGasaUserWidget : public UUserWidget
GENERATED_BODY()
public:
UFUNCTION()
void OnLooseParentCompiled(UBlueprint* BP);
UFUNCTION(CallInEditor, Category="Parent (Expriemental)", meta=(
ToolTip="Exprimental: This will overrite the current LooseParent widgets or create them in this user widget. Beware it will be destructive changes"))
void GenerateParentHierarchyFromLooseParent();
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Parent (Expriemental)")
bool bUpdateOnParentCompile = false;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Parent (Expriemental)")
TSubclassOf<UGasaUserWidget> LooseParent;
UPROPERTY(BlueprintReadOnly)
TObjectPtr<UObject> WidgetController;
@ -23,4 +36,13 @@ public:
UFUNCTION(BlueprintImplementableEvent)
void OnWidgetControllerSet();
#pragma region UserWidget
bool Initialize() override;
void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
void NativeOnInitialized() override;
void NativePreConstruct() override;
#pragma endregion UserWidget
};

View File

@ -1,17 +1,70 @@
#include "GlobeProgressBar.h"
#include "GasaImage.h"
#include "GasaOverlay.h"
#include "GasaProgressBar.h"
#include "GasaSizeBox.h"
#include "Components/OverlaySlot.h"
#include "Blueprint/WidgetBlueprintGeneratedClass.h"
#include "Blueprint/WidgetTree.h"
#include "Extensions/WidgetBlueprintGeneratedClassExtension.h"
#if WITH_EDITOR
#include "WidgetBlueprint.h"
#include "Kismet2/BlueprintEditorUtils.h"
#endif
using namespace Gasa;
// UGlobeProgressBar::UGlobeProgressBar(FObjectInitializer const& ObjectInitializer)
// {
// }
void UGlobeProgressBar::SetBackgroundStyle(FSlateBrush brush)
void UGlobeProgressBar::GenerateDesignerWidgetTemplate()
{
BG->SetBrush( brush );
#if WITH_EDITOR
UWidgetBlueprintGeneratedClass* WBG_Class = Cast<UWidgetBlueprintGeneratedClass>(GetClass());
UPackage* Package = WBG_Class->GetPackage();
UWidgetBlueprint* AssetBP = Cast<UWidgetBlueprint>(Package->FindAssetInPackage());
UWidgetTree* WT = AssetBP->WidgetTree;
UWidget* AssetRoot = AssetBP->WidgetTree->RootWidget;
UGasaSizeBox* Asset_SB = WT->FindWidget<UGasaSizeBox>("Root");
UGasaOverlay* Asset_Overlay = WT->FindWidget<UGasaOverlay>("Overlay");
UGasaImage* Asset_Bezel = WT->FindWidget<UGasaImage>("Bezel");
UGasaImage* Asset_Glass = WT->FindWidget<UGasaImage>("Glass");
UGasaProgressBar* Asset_Bar = WT->FindWidget<UGasaProgressBar>("Bar");
if (Root_SB == nullptr)
Asset_SB = WT->ConstructWidget<UGasaSizeBox>(UGasaSizeBox::StaticClass(), FName("Root_SB"));
if (Overlay == nullptr)
Asset_Overlay = WT->ConstructWidget<UGasaOverlay>(UGasaOverlay::StaticClass(), FName("Overlay"));
if (Bezel == nullptr)
Asset_Bezel = WT->ConstructWidget<UGasaImage>(UGasaImage::StaticClass(), FName("Bezel"));
if (Glass == nullptr)
Asset_Glass = WT->ConstructWidget<UGasaImage>(UGasaImage::StaticClass(), FName("Glass"));
if (Bar == nullptr)
Asset_Bar = WT->ConstructWidget<UGasaProgressBar>(UGasaProgressBar::StaticClass(), FName("Bar"));
WT->RootWidget = Asset_SB;
Asset_SB->ClearChildren();
Asset_Overlay->ClearChildren();
Asset_SB->AddChild(Asset_Overlay);
Asset_Overlay->AddChild(Asset_Bezel);
Asset_Overlay->AddChild(Asset_Glass);
Asset_Overlay->AddChild(Asset_Bar);
AssetBP->Modify();
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(AssetBP);
#endif
}
#pragma region Bindings
void UGlobeProgressBar::SetBezelStyle(FSlateBrush brush)
{
Bezel->SetBrush( brush );
}
void UGlobeProgressBar::SetBarPadding(FMargin margin )
@ -38,24 +91,52 @@ void UGlobeProgressBar::SetGlassStyle(FSlateBrush brush)
void UGlobeProgressBar::SetSize(float width, float height)
{
SizeBox_Root->SetWidthOverride( width );
SizeBox_Root->SetHeightOverride( height );
Root_SB->SetWidthOverride( width );
Root_SB->SetHeightOverride( height );
}
#pragma endregion Bindings
#pragma region Widget
void UGlobeProgressBar::SynchronizeProperties()
{
Super::SynchronizeProperties();
}
#if 0
void UGlobeProgressBar::UpdateSize()
void UGlobeProgressBar::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
}
void UGlobeProgressBar::UpdateBackground()
{
}
#endif
#pragma endregion Widget
#pragma region UserWidget
void UGlobeProgressBar::NativePreConstruct()
{
Super::NativePreConstruct();
// Super::NativePreConstruct(); - Inlined
LLM_SCOPE_BYTAG(UI_UMG);
const bool bIsDesignTime = IsDesignTime();
UWidgetBlueprintGeneratedClass* WBG_Class = Cast<UWidgetBlueprintGeneratedClass>(GetClass());
if (WBG_Class)
{
WBG_Class->ForEachExtension([this, bIsDesignTime](UWidgetBlueprintGeneratedClassExtension* Extension)
{
Extension->PreConstruct(this, bIsDesignTime);
});
}
DesiredFocusWidget.Resolve(WidgetTree);
// Blueprint Callback
PreConstruct(bIsDesignTime);
}
void UGlobeProgressBar::Serialize(FArchive& Ar)
{
Super::Serialize(Ar);
}
void UGlobeProgressBar::Serialize(FStructuredArchive::FRecord Record)
{
Super::Serialize(Record);
}
#pragma endregion UserWidget

View File

@ -11,25 +11,29 @@ class GASA_API UGlobeProgressBar : public UGasaUserWidget
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget), Category="Globe")
UGasaSizeBox* SizeBox_Root;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget), Category="Globe")
UGasaOverlay* Overlay_Root;
// Just learning: https://benui.ca/unreal/build-widgets-in-editor/?utm_medium=social&utm_source=Discord
UFUNCTION(CallInEditor, Category="Generate Designer Widget Template")
void GenerateDesignerWidgetTemplate();
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget), Category="Globe")
UGasaImage* Glass;
#pragma region Bindings
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional), Category="Globe")
UGasaSizeBox* Root_SB;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional), Category="Globe")
UGasaOverlay* Overlay;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget), Category="Globe")
UGasaImage* BG;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional), Category="Globe")
UGasaImage* Bezel;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget), Category="Globe")
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional), Category="Globe")
UGasaProgressBar* Bar;
// UGlobeProgressBar(FObjectInitializer const& ObjectInitializer);
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidgetOptional), Category="Globe")
UGasaImage* Glass;
UFUNCTION(BlueprintCallable, Category="Globe")
void SetBackgroundStyle(FSlateBrush brush);
void SetBezelStyle(FSlateBrush brush);
UFUNCTION(BlueprintCallable, Category="Globe")
void SetBarPadding( FMargin margin );
@ -45,16 +49,22 @@ public:
UFUNCTION(BlueprintCallable, Category="Globe")
void SetSize(float width, float height);
#if 0
UFUNCTION(BlueprintCallable, Category="Globe")
void UpdateSize();
#pragma endregion Bindings
UFUNCTION(BlueprintCallable, Category="Globe")
void UpdateBackground();
#endif
// UGlobeProgressBar(FObjectInitializer const& ObjectInitializer);
#pragma region Widget
void SynchronizeProperties() override;
#pragma endregion Widget
void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#pragma region UserWidget
void NativePreConstruct() override;
#pragma endregion UserWidget
#pragma region Object
void Serialize(FArchive& Ar) override;
void Serialize(FStructuredArchive::FRecord Record) override;
#pragma endregion Object
};

View File

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

View File

@ -0,0 +1,13 @@
#pragma once
#include "GasaUserWidget.h"
#include "UI_HostWidget.generated.h"
UCLASS()
class GASA_API UUI_HostWidget : public UGasaUserWidget
{
GENERATED_BODY()
public:
// #pragma region
};

View File

@ -4,7 +4,7 @@
#include "WidgetController.generated.h"
UCLASS(BlueprintType)
class GASA_API UWdgetController : public UObject
class GASA_API UWidgetController : public UObject
{
GENERATED_BODY()
public: