Add MVP crafting HUD

This commit is contained in:
2026-05-17 17:57:17 -07:00
parent ef658a380e
commit 3509641df8
10 changed files with 254 additions and 10 deletions
+96 -5
View File
@@ -1,6 +1,7 @@
// Copyright Pacificao. All Rights Reserved.
#include "AgrarianDebugHUD.h"
#include "AgrarianCraftingComponent.h"
#include "AgrarianGameCharacter.h"
#include "AgrarianInventoryComponent.h"
#include "AgrarianSurvivalComponent.h"
@@ -24,7 +25,8 @@ void AAgrarianDebugHUD::DrawHUD()
DrawInteractionPrompt(AgrarianCharacter);
DrawCriticalStats(AgrarianCharacter->GetSurvivalComponent());
DrawInventoryPanel(AgrarianCharacter);
const float InventoryBottomY = DrawInventoryPanel(AgrarianCharacter);
DrawCraftingPanel(AgrarianCharacter, InventoryBottomY + 16.0f);
if (bShowDebugHUD)
{
@@ -110,17 +112,17 @@ void AAgrarianDebugHUD::DrawCriticalStats(const UAgrarianSurvivalComponent* Surv
DrawScaledLine(FString::Printf(TEXT("Sickness %3.0f"), Survival.SicknessSeverity), X, Y, CriticalStatsTextScale, StatusColor(Survival.SicknessSeverity, true));
}
void AAgrarianDebugHUD::DrawInventoryPanel(const AAgrarianGameCharacter* AgrarianCharacter)
float AAgrarianDebugHUD::DrawInventoryPanel(const AAgrarianGameCharacter* AgrarianCharacter)
{
if (!bShowInventoryHUD || !AgrarianCharacter || !Canvas)
{
return;
return 32.0f;
}
const UAgrarianInventoryComponent* InventoryComponent = AgrarianCharacter->GetInventoryComponent();
if (!InventoryComponent)
{
return;
return 32.0f;
}
const float Scale = FMath::Max(0.25f, InventoryTextScale);
@@ -152,7 +154,7 @@ void AAgrarianDebugHUD::DrawInventoryPanel(const AAgrarianGameCharacter* Agraria
if (InventoryComponent->Items.IsEmpty())
{
DrawText(TEXT("Empty"), FColor::Silver, X, Y, nullptr, Scale, false);
return;
return (32.0f + PanelHeight);
}
for (int32 Index = 0; Index < VisibleRows; ++Index)
@@ -175,6 +177,95 @@ void AAgrarianDebugHUD::DrawInventoryPanel(const AAgrarianGameCharacter* Agraria
false);
Y += LineHeight;
}
return (32.0f + PanelHeight);
}
void AAgrarianDebugHUD::DrawCraftingPanel(const AAgrarianGameCharacter* AgrarianCharacter, float TopY)
{
if (!bShowCraftingHUD || !AgrarianCharacter || !Canvas)
{
return;
}
const UAgrarianCraftingComponent* CraftingComponent = AgrarianCharacter->GetCraftingComponent();
const UAgrarianInventoryComponent* InventoryComponent = AgrarianCharacter->GetInventoryComponent();
if (!CraftingComponent || !InventoryComponent)
{
return;
}
TArray<FAgrarianRecipe> Recipes;
CraftingComponent->GetKnownRecipes(Recipes);
const float Scale = FMath::Max(0.25f, InventoryTextScale);
const float PanelWidth = 420.0f * Scale;
const float X = FMath::Max(32.0f, Canvas->ClipX - PanelWidth - 32.0f);
float Y = FMath::Max(32.0f, TopY);
const int32 VisibleRows = Recipes.IsEmpty()
? 1
: FMath::Min(Recipes.Num(), FMath::Max(1, MaxCraftingPanelRows));
const float LineHeight = 18.0f * Scale;
const float PanelHeight = (56.0f * Scale) + (VisibleRows * LineHeight);
DrawRect(FLinearColor(0.02f, 0.025f, 0.02f, 0.72f), X - (12.0f * Scale), Y - (10.0f * Scale), PanelWidth, PanelHeight);
DrawText(
FString::Printf(TEXT("CRAFTING %d recipes"), Recipes.Num()),
FColor(160, 220, 140),
X,
Y,
nullptr,
Scale,
false);
Y += 24.0f * Scale;
if (Recipes.IsEmpty())
{
DrawText(TEXT("No known recipes"), FColor::Silver, X, Y, nullptr, Scale, false);
return;
}
for (int32 Index = 0; Index < VisibleRows; ++Index)
{
const FAgrarianRecipe& Recipe = Recipes[Index];
FText FailureReason;
const bool bCanCraft = CraftingComponent->CanCraft(Recipe.RecipeId, FailureReason);
FString RecipeName = Recipe.DisplayName.IsEmpty() ? Recipe.RecipeId.ToString() : Recipe.DisplayName.ToString();
if (RecipeName.Len() > 18)
{
RecipeName = RecipeName.Left(15) + TEXT("...");
}
FString IngredientSummary;
for (const FAgrarianItemStack& Ingredient : Recipe.Ingredients)
{
if (!IngredientSummary.IsEmpty())
{
IngredientSummary += TEXT(" ");
}
IngredientSummary += FString::Printf(
TEXT("%s %d/%d"),
*Ingredient.ItemId.ToString(),
InventoryComponent->GetItemCount(Ingredient.ItemId),
Ingredient.Quantity);
}
if (IngredientSummary.Len() > 28)
{
IngredientSummary = IngredientSummary.Left(25) + TEXT("...");
}
DrawText(
FString::Printf(TEXT("%02d %-18s %-28s"), Index + 1, *RecipeName, *IngredientSummary),
bCanCraft ? FColor(225, 235, 220) : FColor(170, 150, 125),
X,
Y,
nullptr,
Scale,
false);
Y += LineHeight;
}
}
void AAgrarianDebugHUD::DrawPlayerStatus(const AAgrarianGameCharacter* AgrarianCharacter, float X, float& Y)