100 lines
3.1 KiB
C++
100 lines
3.1 KiB
C++
// Copyright Pacificao. All Rights Reserved.
|
|
|
|
#include "AgrarianDebugHUD.h"
|
|
#include "AgrarianGameCharacter.h"
|
|
#include "AgrarianInventoryComponent.h"
|
|
#include "AgrarianSurvivalComponent.h"
|
|
#include "Engine/Canvas.h"
|
|
|
|
void AAgrarianDebugHUD::DrawHUD()
|
|
{
|
|
Super::DrawHUD();
|
|
|
|
if (!Canvas)
|
|
{
|
|
return;
|
|
}
|
|
|
|
const AAgrarianGameCharacter* AgrarianCharacter = Cast<AAgrarianGameCharacter>(GetOwningPawn());
|
|
if (!AgrarianCharacter)
|
|
{
|
|
return;
|
|
}
|
|
|
|
DrawInteractionPrompt(AgrarianCharacter);
|
|
|
|
if (bShowDebugHUD)
|
|
{
|
|
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::DrawInteractionPrompt(const AAgrarianGameCharacter* AgrarianCharacter)
|
|
{
|
|
if (!bShowInteractionPrompt || !AgrarianCharacter || !AgrarianCharacter->HasInteractionPrompt() || !Canvas)
|
|
{
|
|
return;
|
|
}
|
|
|
|
const FString Prompt = FString::Printf(TEXT("[E] %s"), *AgrarianCharacter->GetInteractionPromptText().ToString());
|
|
float TextWidth = 0.0f;
|
|
float TextHeight = 0.0f;
|
|
GetTextSize(Prompt, TextWidth, TextHeight, nullptr, PromptTextScale);
|
|
|
|
const float X = (Canvas->ClipX - TextWidth) * 0.5f;
|
|
const float Y = Canvas->ClipY * 0.62f;
|
|
DrawText(Prompt, FColor(245, 245, 225), X, Y, nullptr, PromptTextScale, true);
|
|
}
|
|
|
|
void AAgrarianDebugHUD::DrawSurvival(const UAgrarianSurvivalComponent* SurvivalComponent, float X, float& Y)
|
|
{
|
|
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)
|
|
{
|
|
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)
|
|
{
|
|
DrawText(Text, Color, X, Y, nullptr, TextScale, false);
|
|
Y += 18.0f * TextScale;
|
|
}
|