Add MVP crafting HUD
This commit is contained in:
@@ -133,6 +133,27 @@ bool UAgrarianCraftingComponent::FindRecipe(FName RecipeId, FAgrarianRecipe& Out
|
||||
return false;
|
||||
}
|
||||
|
||||
void UAgrarianCraftingComponent::GetKnownRecipes(TArray<FAgrarianRecipe>& OutRecipes) const
|
||||
{
|
||||
OutRecipes.Reset();
|
||||
|
||||
for (const UAgrarianRecipeDataAsset* RecipeAsset : KnownRecipeAssets)
|
||||
{
|
||||
if (RecipeAsset && RecipeAsset->Recipe.RecipeId != NAME_None)
|
||||
{
|
||||
OutRecipes.Add(RecipeAsset->Recipe);
|
||||
}
|
||||
}
|
||||
|
||||
for (const FAgrarianRecipe& Recipe : KnownRecipes)
|
||||
{
|
||||
if (Recipe.RecipeId != NAME_None)
|
||||
{
|
||||
OutRecipes.Add(Recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UAgrarianInventoryComponent* UAgrarianCraftingComponent::GetInventory() const
|
||||
{
|
||||
return GetOwner() ? GetOwner()->FindComponentByClass<UAgrarianInventoryComponent>() : nullptr;
|
||||
|
||||
@@ -48,6 +48,9 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Crafting")
|
||||
bool FindRecipe(FName RecipeId, FAgrarianRecipe& OutRecipe) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Agrarian|Crafting")
|
||||
void GetKnownRecipes(TArray<FAgrarianRecipe>& OutRecipes) const;
|
||||
|
||||
protected:
|
||||
UAgrarianInventoryComponent* GetInventory() const;
|
||||
void FailCraft(FName RecipeId, const FText& Reason);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "AgrarianDebugHUD.generated.h"
|
||||
|
||||
class UAgrarianInventoryComponent;
|
||||
class UAgrarianCraftingComponent;
|
||||
class UAgrarianSurvivalComponent;
|
||||
|
||||
UCLASS()
|
||||
@@ -26,6 +27,9 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD")
|
||||
bool bShowInventoryHUD = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD")
|
||||
bool bShowCraftingHUD = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD", meta = (ClampMin = "0.25"))
|
||||
float TextScale = 1.0f;
|
||||
|
||||
@@ -38,6 +42,9 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD", meta = (ClampMin = "1", ClampMax = "12"))
|
||||
int32 MaxInventoryPanelRows = 6;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD", meta = (ClampMin = "1", ClampMax = "12"))
|
||||
int32 MaxCraftingPanelRows = 8;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD")
|
||||
bool bShowInteractionPrompt = true;
|
||||
|
||||
@@ -47,7 +54,8 @@ public:
|
||||
protected:
|
||||
void DrawInteractionPrompt(const class AAgrarianGameCharacter* AgrarianCharacter);
|
||||
void DrawCriticalStats(const UAgrarianSurvivalComponent* SurvivalComponent);
|
||||
void DrawInventoryPanel(const class AAgrarianGameCharacter* AgrarianCharacter);
|
||||
float DrawInventoryPanel(const class AAgrarianGameCharacter* AgrarianCharacter);
|
||||
void DrawCraftingPanel(const class AAgrarianGameCharacter* AgrarianCharacter, float TopY);
|
||||
void DrawPlayerStatus(const class AAgrarianGameCharacter* AgrarianCharacter, float X, float& Y);
|
||||
void DrawSurvival(const UAgrarianSurvivalComponent* SurvivalComponent, float X, float& Y);
|
||||
void DrawInventory(const UAgrarianInventoryComponent* InventoryComponent, float X, float& Y);
|
||||
|
||||
Reference in New Issue
Block a user