Espelho do AttributeSystem do servidor (Game/MMO/Modules/AttributeSystem).
Sub-modulo C++ Source/ZMMOAttributes/ (Runtime, LoadingPhase=PreDefault)
isolando o cliente do AttributeSystem em pasta propria — pavimentando o
caminho para futuros Inventory/Skills/Combat virem como sub-modulos peer.
Componentes:
- FZMMOAttributesSnapshot (USTRUCT Blueprint, espelha
FZeusAttributesPayload do plugin ZeusNetwork)
- UZMMOAttributeComponent (UActorComponent ligado ao player):
ApplySnapshot / ApplyHpSpUpdate / NotifyLevelUp + 3 delegates
dinamicos (OnAttributesChanged / OnHpSpChanged / OnLevelUp) +
helpers GetHpRatio / GetSpRatio
- UZMMOAttributeNetworkHandler (UWorldSubsystem): ponte
UZeusNetworkSubsystem -> componente via lookup por EntityId
- UZMMOHudHpSpWidget (UUserWidget base): BindWidget (HpBar, SpBar) +
BindWidgetOptional (HpText, SpText, LevelText). NativeConstruct
binda nos delegates do componente; NativeDestruct desliga.
OnSnapshotApplied / OnHpSpDelta (BlueprintNativeEvent) com impl
C++ atualizando progress bars e textos.
Integracao no PlayerCharacter:
- CreateDefaultSubobject<UZMMOAttributeComponent> no ctor
- HudHpSpWidgetClass (TSubclassOf) resolvido via
ConstructorHelpers::FClassFinder em /Game/ZMMO/UI/HUD/WBP_HUD_HpSpBar
- HandleLocalSpawnReady seed do EntityId no componente + spawn do HUD
(CreateWidget + AddToViewport + BindToAttributeComponent)
- EndPlay remove widget do parent
WBP_HUD_HpSpBar (UMG, criado via MCP):
- Overlay root + SizeBox (320x120) + VerticalBox
- 5 widgets BindWidget: LevelText, HpBar (vermelho), HpText,
SpBar (azul), SpText
- Herda de UZMMOHudHpSpWidget
Verificacao (smoke test):
- PIE login -> server envia S_ATTRIBUTE_SNAPSHOT_FULL
- Cliente recebe via OnAttributeSnapshotFull -> handler roteia pra
componente do entity -> ApplySnapshot dispara OnAttributesChanged ->
widget atualiza ProgressBars + TextBlocks
- HUD aparece no canto inferior esquerdo da tela com valores
correspondentes ao DB
Refs:
- Plano: C:/Users/mateu/.claude/plans/temos-uma-lab-input-nested-diffie.md
- Server companion commit: feat(attributes): AttributeSystem modular
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
86 lines
3.0 KiB
C++
86 lines
3.0 KiB
C++
#pragma once
|
|
|
|
#include "Blueprint/UserWidget.h"
|
|
#include "CoreMinimal.h"
|
|
#include "ZMMOAttributeTypes.h"
|
|
#include "ZMMOHudHpSpWidget.generated.h"
|
|
|
|
class UProgressBar;
|
|
class UTextBlock;
|
|
class UZMMOAttributeComponent;
|
|
|
|
/**
|
|
* Widget base do HUD de atributos (HP/SP/level). Spawnada por
|
|
* `AZMMOPlayerCharacter::BeginPlay` quando o pawn local virou autoritativo.
|
|
*
|
|
* Layout (cor, textos, ancoras) vem do WBP filho via UMG.
|
|
* Comportamento (binding com AttributeComponent + refresh on delegate)
|
|
* vive aqui em C++ — permite que outros modulos consumam esta API
|
|
* sem precisar abrir o WBP. Sub-classe via Blueprint apenas para skin
|
|
* visual e disposicao dos sub-widgets.
|
|
*
|
|
* Convencao `meta=(BindWidget)`: o WBP filho DEVE ter widgets com os
|
|
* mesmos nomes (HpBar, SpBar). `BindWidgetOptional` permite ao WBP
|
|
* omitir o widget (ex.: HUD compacto sem texto numerico).
|
|
*/
|
|
UCLASS(Abstract, Blueprintable, BlueprintType)
|
|
class ZMMOATTRIBUTES_API UZMMOHudHpSpWidget : public UUserWidget
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
/**
|
|
* Liga o widget a um `UZMMOAttributeComponent`. Subscreve aos delegates
|
|
* e faz um refresh imediato com o snapshot corrente. Idempotente —
|
|
* chamar com outro componente desliga do anterior.
|
|
* Se `InComponent` for nullptr, desliga sem religar.
|
|
*/
|
|
UFUNCTION(BlueprintCallable, Category = "Zeus|HUD")
|
|
void BindToAttributeComponent(UZMMOAttributeComponent* InComponent);
|
|
|
|
UFUNCTION(BlueprintPure, Category = "Zeus|HUD")
|
|
UZMMOAttributeComponent* GetBoundComponent() const { return BoundComponent.Get(); }
|
|
|
|
protected:
|
|
virtual void NativeDestruct() override;
|
|
|
|
/**
|
|
* Hook BlueprintNativeEvent para skin visual reagir a um snapshot novo
|
|
* (cores, animacao de level up, etc.). Implementacao default em C++
|
|
* apenas atualiza progress bars + textos via `BindWidget`/`BindWidgetOptional`.
|
|
*/
|
|
UFUNCTION(BlueprintNativeEvent, Category = "Zeus|HUD")
|
|
void OnSnapshotApplied(const FZMMOAttributesSnapshot& Snapshot);
|
|
virtual void OnSnapshotApplied_Implementation(const FZMMOAttributesSnapshot& Snapshot);
|
|
|
|
UFUNCTION(BlueprintNativeEvent, Category = "Zeus|HUD")
|
|
void OnHpSpDelta(int32 Hp, int32 Sp);
|
|
virtual void OnHpSpDelta_Implementation(int32 Hp, int32 Sp);
|
|
|
|
// === BindWidget — devem existir no WBP com EXATAMENTE estes nomes ===
|
|
UPROPERTY(BlueprintReadOnly, meta = (BindWidget), Category = "Zeus|HUD")
|
|
UProgressBar* HpBar = nullptr;
|
|
|
|
UPROPERTY(BlueprintReadOnly, meta = (BindWidget), Category = "Zeus|HUD")
|
|
UProgressBar* SpBar = nullptr;
|
|
|
|
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional), Category = "Zeus|HUD")
|
|
UTextBlock* HpText = nullptr;
|
|
|
|
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional), Category = "Zeus|HUD")
|
|
UTextBlock* SpText = nullptr;
|
|
|
|
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional), Category = "Zeus|HUD")
|
|
UTextBlock* LevelText = nullptr;
|
|
|
|
private:
|
|
UFUNCTION()
|
|
void HandleAttributesChanged(const FZMMOAttributesSnapshot& Snapshot);
|
|
|
|
UFUNCTION()
|
|
void HandleHpSpChanged(int32 Hp, int32 Sp);
|
|
|
|
UPROPERTY()
|
|
TWeakObjectPtr<UZMMOAttributeComponent> BoundComponent;
|
|
};
|