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>
116 lines
4.6 KiB
C++
116 lines
4.6 KiB
C++
// Copyright IHY. Universal Bars plugin.
|
|
// HUD container that stacks a combined health bar (HP + hunger/weight/cold
|
|
// penalty zones) and a stamina bar. Exposes high-level, animated stat setters
|
|
// and registers itself with UUniversalBarsSubsystem for global access.
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Blueprint/UserWidget.h"
|
|
#include "UniversalHUDWidget.generated.h"
|
|
|
|
class UUniversalBarWidget;
|
|
class UPanelWidget;
|
|
class UCanvasPanel;
|
|
class UImage;
|
|
class UUniversalBarsTheme;
|
|
|
|
UCLASS()
|
|
class UNIVERSALBARS_API UUniversalHUDWidget : public UUserWidget
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
// Place a WBP_UniversalBar named "HealthBar" / "StaminaBar" in the HUD WBP.
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UUniversalBarWidget> HealthBar = nullptr;
|
|
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UUniversalBarWidget> StaminaBar = nullptr;
|
|
|
|
// Optional container for status chips (filled in the designer with placeholders).
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UPanelWidget> ChipsPanel = nullptr;
|
|
|
|
// PEAK-style markers that sit ABOVE the health bar, over their zone. Place
|
|
// these inside a CanvasPanel ("ChipCanvas") overlaid on HealthBar; they are
|
|
// moved every tick to track the (animated) zone boundaries.
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UCanvasPanel> ChipCanvas = nullptr;
|
|
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UImage> ChipHeart = nullptr; // tracks usable-HP end
|
|
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UImage> ChipHunger = nullptr; // tracks "Hunger" zone
|
|
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UImage> ChipWeight = nullptr; // tracks "Weight" zone
|
|
|
|
UPROPERTY(meta=(BindWidgetOptional))
|
|
TObjectPtr<UImage> ChipCold = nullptr; // tracks "Cold" zone (hidden if absent)
|
|
|
|
// Optional central palette/geometry; applied on construct when set.
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="HUD")
|
|
TObjectPtr<UUniversalBarsTheme> Theme = nullptr;
|
|
|
|
// Penalty-zone colours used by the hunger/weight/cold helpers (overridden by Theme if set).
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="HUD|Colors")
|
|
FLinearColor HungerColor = FLinearColor(0.90f, 0.60f, 0.20f, 1.f);
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="HUD|Colors")
|
|
FLinearColor WeightColor = FLinearColor(0.82f, 0.23f, 0.23f, 1.f);
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="HUD|Colors")
|
|
FLinearColor ColdColor = FLinearColor(0.40f, 0.70f, 1.00f, 1.f);
|
|
|
|
// ===== high-level animated API =====
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void SetHealth(float Percent); // 0..1
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void SetStamina(float Percent); // 0..1
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void SetShield(float Percent); // 0..1 (overlay above HP)
|
|
|
|
// Penalty fractions of the full track (eat into max HP). 0 hides the zone.
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void SetHunger(float Amount);
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void SetWeight(float Amount);
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void SetCold(float Amount);
|
|
|
|
// Deltas (positive = heal/up, negative = damage/down) with the right flash.
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void DamageHealth(float Delta);
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void HealHealth(float Delta);
|
|
|
|
UFUNCTION(BlueprintPure, Category="HUD") float GetHealth() const;
|
|
|
|
// Re-tint and re-shape all bars + chips from the assigned Theme.
|
|
UFUNCTION(BlueprintCallable, Category="HUD") void ApplyTheme();
|
|
|
|
// ===== self-test / study driver =====
|
|
// When on, NativeTick cycles through every stat change so you can watch the
|
|
// animations live in PIE. Defaults ON for this study HUD — uncheck "Demo Mode"
|
|
// in the WBP Class Defaults (or call SetDemoMode(false)) for shipping.
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="HUD|Demo")
|
|
bool bDemoMode = true;
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="HUD|Demo", meta=(ClampMin="0.2"))
|
|
float DemoStepInterval = 1.6f;
|
|
|
|
UFUNCTION(BlueprintCallable, Category="HUD|Demo")
|
|
void SetDemoMode(bool bEnable);
|
|
|
|
// Runs one demo step (damage / heal / hunger / weight / stamina). Called by
|
|
// the demo tick, but also handy to fire manually from BP.
|
|
UFUNCTION(BlueprintCallable, Category="HUD|Demo")
|
|
void DemoStepNow();
|
|
|
|
protected:
|
|
virtual void NativeConstruct() override;
|
|
virtual void NativeDestruct() override;
|
|
virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;
|
|
|
|
// Slides each chip to sit above the centre of its zone on the health bar.
|
|
void PositionChips();
|
|
|
|
private:
|
|
float DemoTimer = 0.f;
|
|
int32 DemoStep = 0;
|
|
bool bDemoInit = false;
|
|
};
|