// REALMS IN RUIN. Copyright (c) 2025 Trevor Edwards. All rights reserved. #include "UI/HUD/RIRHUD.h" #include "UI/Widgets/RIRUserWidget.h" #include "UI/WidgetController/OverlayWidgetController.h" UOverlayWidgetController* ARIRHUD::GetOverlayWidgetController(const FWidgetControllerParams& WCParams) { if (OverlayWidgetController == nullptr) { OverlayWidgetController = NewObject(this, OverlayWidgetControllerClass); OverlayWidgetController->SetWidgetControllerParams(WCParams); OverlayWidgetController->BindCallbacksToDependencies(); return OverlayWidgetController; } return OverlayWidgetController; } void ARIRHUD::InitOverlay(APlayerController* PC, APlayerState* PS, UAbilitySystemComponent* ASC, UAttributeSet* AS) { // Ensure that both the widget and its controller class are properly assigned in the editor or constructor checkf(OverlayWidgetClass, TEXT("Overlay Widget Class uninitialized, please fill out WBP_PlayerHUD")); checkf(OverlayWidgetControllerClass, TEXT("Overlay Widget Controller Class uninitialized, please fill out WBP_PlayerHUD")); // Create the UMG overlay widget from the specified class UUserWidget* Widget = CreateWidget(GetWorld(), OverlayWidgetClass); OverlayWidget = Cast(Widget); // Package the controller parameters (used to bind player data to the UI) const FWidgetControllerParams WidgetControllerParams(PC, PS, ASC, AS); UOverlayWidgetController* WidgetController = GetOverlayWidgetController(WidgetControllerParams); // Assign the controller to the widget so it can bind and respond to gameplay data OverlayWidget->SetWidgetController(WidgetController); // Broadcast Initial Attribute values WidgetController->BroadcastInitialInitialValues(); // Add the widget to the viewport to make it visible to the player Widget->AddToViewport(); }