Add MVP inventory HUD panel
This commit is contained in:
@@ -24,6 +24,7 @@ void AAgrarianDebugHUD::DrawHUD()
|
||||
|
||||
DrawInteractionPrompt(AgrarianCharacter);
|
||||
DrawCriticalStats(AgrarianCharacter->GetSurvivalComponent());
|
||||
DrawInventoryPanel(AgrarianCharacter);
|
||||
|
||||
if (bShowDebugHUD)
|
||||
{
|
||||
@@ -109,6 +110,73 @@ 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)
|
||||
{
|
||||
if (!bShowInventoryHUD || !AgrarianCharacter || !Canvas)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const UAgrarianInventoryComponent* InventoryComponent = AgrarianCharacter->GetInventoryComponent();
|
||||
if (!InventoryComponent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const float Scale = FMath::Max(0.25f, InventoryTextScale);
|
||||
const float PanelWidth = 360.0f * Scale;
|
||||
const float X = FMath::Max(32.0f, Canvas->ClipX - PanelWidth - 32.0f);
|
||||
float Y = 32.0f;
|
||||
|
||||
const int32 VisibleRows = InventoryComponent->Items.IsEmpty()
|
||||
? 1
|
||||
: FMath::Min(InventoryComponent->Items.Num(), FMath::Max(1, MaxInventoryPanelRows));
|
||||
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("INVENTORY %d/%d slots %.1f wt"),
|
||||
InventoryComponent->Items.Num(),
|
||||
InventoryComponent->MaxSlots,
|
||||
InventoryComponent->GetTotalWeight()),
|
||||
FColor(160, 220, 140),
|
||||
X,
|
||||
Y,
|
||||
nullptr,
|
||||
Scale,
|
||||
false);
|
||||
Y += 24.0f * Scale;
|
||||
|
||||
if (InventoryComponent->Items.IsEmpty())
|
||||
{
|
||||
DrawText(TEXT("Empty"), FColor::Silver, X, Y, nullptr, Scale, false);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32 Index = 0; Index < VisibleRows; ++Index)
|
||||
{
|
||||
const FAgrarianItemStack& Stack = InventoryComponent->Items[Index];
|
||||
const FText DisplayName = Stack.DisplayName.IsEmpty() ? FText::FromName(Stack.ItemId) : Stack.DisplayName;
|
||||
FString ItemName = DisplayName.ToString();
|
||||
if (ItemName.Len() > 24)
|
||||
{
|
||||
ItemName = ItemName.Left(21) + TEXT("...");
|
||||
}
|
||||
|
||||
DrawText(
|
||||
FString::Printf(TEXT("%02d %-24s x%-3d %5.1f"), Index + 1, *ItemName, Stack.Quantity, Stack.UnitWeight * Stack.Quantity),
|
||||
FColor(225, 235, 220),
|
||||
X,
|
||||
Y,
|
||||
nullptr,
|
||||
Scale,
|
||||
false);
|
||||
Y += LineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianDebugHUD::DrawPlayerStatus(const AAgrarianGameCharacter* AgrarianCharacter, float X, float& Y)
|
||||
{
|
||||
if (!AgrarianCharacter)
|
||||
|
||||
@@ -23,12 +23,21 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD")
|
||||
bool bShowCriticalStatsHUD = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD")
|
||||
bool bShowInventoryHUD = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD", meta = (ClampMin = "0.25"))
|
||||
float TextScale = 1.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD", meta = (ClampMin = "0.25"))
|
||||
float CriticalStatsTextScale = 1.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD", meta = (ClampMin = "0.25"))
|
||||
float InventoryTextScale = 0.9f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD", meta = (ClampMin = "1", ClampMax = "12"))
|
||||
int32 MaxInventoryPanelRows = 6;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|HUD")
|
||||
bool bShowInteractionPrompt = true;
|
||||
|
||||
@@ -38,6 +47,7 @@ public:
|
||||
protected:
|
||||
void DrawInteractionPrompt(const class AAgrarianGameCharacter* AgrarianCharacter);
|
||||
void DrawCriticalStats(const UAgrarianSurvivalComponent* SurvivalComponent);
|
||||
void DrawInventoryPanel(const class AAgrarianGameCharacter* AgrarianCharacter);
|
||||
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