Files
KingshearthLegacy/Source/KingshearthLegacy/UI/StatBarWidget.h
T
2026-08-27 21:42:15 +02:00

62 lines
2.0 KiB
C++

#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "StatBarWidget.generated.h"
class USegmentedBarWidget;
/**
* Generic "current / max" bar widget (health, stamina, mana, posture, ...),
* with a third "penalty" value (fatigue, a max-value debuff, ...) that eats
* into the bar from the right edge. Subclasses feed CurrentValue/MaxValue in
* via SetStatValue and PenaltyPercent via SetPenaltyPercent, either from a
* live gameplay component or from hardcoded defaults.
*
* The actual 3-segment visual is delegated to a single bound USegmentedBarWidget
* (WBP_SegmentedBar) so that visual tree is only built once, not duplicated
* across every stat bar.
*/
UCLASS(abstract)
class UStatBarWidget : public UUserWidget
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Stat Bar")
void SetStatValue(float InCurrent, float InMax);
UFUNCTION(BlueprintCallable, Category = "Stat Bar")
void SetPenaltyPercent(float InPenaltyPercent);
UFUNCTION(BlueprintPure, Category = "Stat Bar")
float GetPercent() const;
UFUNCTION(BlueprintPure, Category = "Stat Bar")
float GetCurrentValue() const { return CurrentValue; }
UFUNCTION(BlueprintPure, Category = "Stat Bar")
float GetMaxValue() const { return MaxValue; }
UFUNCTION(BlueprintPure, Category = "Stat Bar")
float GetPenaltyPercent() const { return PenaltyPercent; }
protected:
/** Bound to a widget named "Bar" (a WBP_SegmentedBar instance) in the designer tree, if present. */
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional = true))
TObjectPtr<USegmentedBarWidget> Bar;
/** Called after CurrentValue/MaxValue/PenaltyPercent and Bar are updated. Hook for Blueprint-side visual polish. */
UFUNCTION(BlueprintImplementableEvent, Category = "Stat Bar")
void OnStatValueChanged(float Percent);
float CurrentValue = 0.0f;
float MaxValue = 1.0f;
/** 0-1 fraction of Max currently locked/unusable (fatigue, a max-value debuff, ...). */
float PenaltyPercent = 0.0f;
private:
void UpdateBar();
};