Add Agrarian debug HUD
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// Copyright Pacificao. All Rights Reserved.
|
||||
|
||||
#include "AgrarianDebugHUD.h"
|
||||
#include "AgrarianGameCharacter.h"
|
||||
#include "AgrarianInventoryComponent.h"
|
||||
#include "AgrarianSurvivalComponent.h"
|
||||
|
||||
void AAgrarianDebugHUD::DrawHUD()
|
||||
{
|
||||
Super::DrawHUD();
|
||||
|
||||
if (!bShowDebugHUD || !Canvas)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const AAgrarianGameCharacter* AgrarianCharacter = Cast<AAgrarianGameCharacter>(GetOwningPawn());
|
||||
if (!AgrarianCharacter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float Y = 32.0f;
|
||||
constexpr float X = 32.0f;
|
||||
|
||||
DrawLine(TEXT("AGRARIAN DEV HUD"), X, Y, FColor(160, 220, 140));
|
||||
DrawSurvival(AgrarianCharacter->GetSurvivalComponent(), X, Y);
|
||||
DrawInventory(AgrarianCharacter->GetInventoryComponent(), X, Y);
|
||||
}
|
||||
|
||||
void AAgrarianDebugHUD::DrawSurvival(const UAgrarianSurvivalComponent* SurvivalComponent, float X, float& Y) const
|
||||
{
|
||||
if (!SurvivalComponent)
|
||||
{
|
||||
DrawLine(TEXT("Survival: unavailable"), X, Y, FColor::Red);
|
||||
return;
|
||||
}
|
||||
|
||||
const FAgrarianSurvivalSnapshot& Survival = SurvivalComponent->Survival;
|
||||
DrawLine(FString::Printf(TEXT("Health: %.0f"), Survival.Health), X, Y);
|
||||
DrawLine(FString::Printf(TEXT("Stamina: %.0f"), Survival.Stamina), X, Y);
|
||||
DrawLine(FString::Printf(TEXT("Hunger: %.0f"), Survival.Hunger), X, Y);
|
||||
DrawLine(FString::Printf(TEXT("Thirst: %.0f"), Survival.Thirst), X, Y);
|
||||
DrawLine(FString::Printf(TEXT("Temp: %.1f C"), Survival.BodyTemperature), X, Y);
|
||||
DrawLine(FString::Printf(TEXT("Injury: %.0f"), Survival.InjurySeverity), X, Y);
|
||||
Y += 10.0f * TextScale;
|
||||
}
|
||||
|
||||
void AAgrarianDebugHUD::DrawInventory(const UAgrarianInventoryComponent* InventoryComponent, float X, float& Y) const
|
||||
{
|
||||
if (!InventoryComponent)
|
||||
{
|
||||
DrawLine(TEXT("Inventory: unavailable"), X, Y, FColor::Red);
|
||||
return;
|
||||
}
|
||||
|
||||
DrawLine(FString::Printf(TEXT("Inventory: %d/%d slots"), InventoryComponent->Items.Num(), InventoryComponent->MaxSlots), X, Y, FColor(160, 220, 140));
|
||||
|
||||
if (InventoryComponent->Items.IsEmpty())
|
||||
{
|
||||
DrawLine(TEXT("- empty"), X, Y, FColor::Silver);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const FAgrarianItemStack& Stack : InventoryComponent->Items)
|
||||
{
|
||||
const FText DisplayName = Stack.DisplayName.IsEmpty() ? FText::FromName(Stack.ItemId) : Stack.DisplayName;
|
||||
DrawLine(FString::Printf(TEXT("- %s x%d"), *DisplayName.ToString(), Stack.Quantity), X, Y);
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianDebugHUD::DrawLine(const FString& Text, float X, float& Y, const FColor& Color) const
|
||||
{
|
||||
DrawText(Text, Color, X, Y, nullptr, TextScale, false);
|
||||
Y += 18.0f * TextScale;
|
||||
}
|
||||
Reference in New Issue
Block a user