UniversalBars plugin: PEAK-style universal UMG bars
Procedural M_UI_UniversalBar material (SDF rounded-rect, fill/delayed/shield/ penalty-zones/stripes/segments/flash/pulse), 6 preset instances, animated UUniversalBarWidget + UUniversalHUDWidget + global UUniversalBarsSubsystem API, UUniversalBarsTheme DataAsset, and a ready WBP_HUD_InGame with zone-tracking status chips. See README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
59
Source/UniversalBars/Private/UniversalBarsSubsystem.cpp
Normal file
59
Source/UniversalBars/Private/UniversalBarsSubsystem.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
// Copyright IHY. Universal Bars plugin.
|
||||
#include "UniversalBarsSubsystem.h"
|
||||
#include "UniversalHUDWidget.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Engine/World.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
|
||||
UUniversalBarsSubsystem* UUniversalBarsSubsystem::Get(const UObject* WorldContextObject)
|
||||
{
|
||||
if (!WorldContextObject)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if (const UWorld* World = WorldContextObject->GetWorld())
|
||||
{
|
||||
return World->GetSubsystem<UUniversalBarsSubsystem>();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UUniversalHUDWidget* UUniversalBarsSubsystem::CreateHUD(APlayerController* Owner, TSubclassOf<UUniversalHUDWidget> HUDClass, int32 ZOrder)
|
||||
{
|
||||
if (!HUDClass)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
UUniversalHUDWidget* Widget = CreateWidget<UUniversalHUDWidget>(Owner ? Cast<APlayerController>(Owner) : GetWorld()->GetFirstPlayerController(), HUDClass);
|
||||
if (Widget)
|
||||
{
|
||||
Widget->AddToViewport(ZOrder);
|
||||
RegisterHUD(Widget); // also registered in NativeConstruct; idempotent
|
||||
}
|
||||
return Widget;
|
||||
}
|
||||
|
||||
void UUniversalBarsSubsystem::RegisterHUD(UUniversalHUDWidget* InHUD)
|
||||
{
|
||||
if (InHUD)
|
||||
{
|
||||
HUD = InHUD;
|
||||
}
|
||||
}
|
||||
|
||||
void UUniversalBarsSubsystem::UnregisterHUD(UUniversalHUDWidget* InHUD)
|
||||
{
|
||||
if (HUD.Get() == InHUD)
|
||||
{
|
||||
HUD.Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void UUniversalBarsSubsystem::SetHealth(float Percent) { if (UUniversalHUDWidget* H = HUD.Get()) { H->SetHealth(Percent); } }
|
||||
void UUniversalBarsSubsystem::SetStamina(float Percent) { if (UUniversalHUDWidget* H = HUD.Get()) { H->SetStamina(Percent); } }
|
||||
void UUniversalBarsSubsystem::SetShield(float Percent) { if (UUniversalHUDWidget* H = HUD.Get()) { H->SetShield(Percent); } }
|
||||
void UUniversalBarsSubsystem::SetHunger(float Amount) { if (UUniversalHUDWidget* H = HUD.Get()) { H->SetHunger(Amount); } }
|
||||
void UUniversalBarsSubsystem::SetWeight(float Amount) { if (UUniversalHUDWidget* H = HUD.Get()) { H->SetWeight(Amount); } }
|
||||
void UUniversalBarsSubsystem::SetCold(float Amount) { if (UUniversalHUDWidget* H = HUD.Get()) { H->SetCold(Amount); } }
|
||||
void UUniversalBarsSubsystem::DamageHealth(float Delta) { if (UUniversalHUDWidget* H = HUD.Get()) { H->DamageHealth(Delta); } }
|
||||
void UUniversalBarsSubsystem::HealHealth(float Delta) { if (UUniversalHUDWidget* H = HUD.Get()) { H->HealHealth(Delta); } }
|
||||
Reference in New Issue
Block a user