Implement interaction prompt

This commit is contained in:
2026-05-15 15:43:37 -07:00
parent f508b7d494
commit 3132ed462e
9 changed files with 176 additions and 17 deletions
+29 -6
View File
@@ -4,12 +4,13 @@
#include "AgrarianGameCharacter.h"
#include "AgrarianInventoryComponent.h"
#include "AgrarianSurvivalComponent.h"
#include "Engine/Canvas.h"
void AAgrarianDebugHUD::DrawHUD()
{
Super::DrawHUD();
if (!bShowDebugHUD || !Canvas)
if (!Canvas)
{
return;
}
@@ -20,12 +21,34 @@ void AAgrarianDebugHUD::DrawHUD()
return;
}
float Y = 32.0f;
constexpr float X = 32.0f;
DrawInteractionPrompt(AgrarianCharacter);
DrawLine(TEXT("AGRARIAN DEV HUD"), X, Y, FColor(160, 220, 140));
DrawSurvival(AgrarianCharacter->GetSurvivalComponent(), X, Y);
DrawInventory(AgrarianCharacter->GetInventoryComponent(), X, Y);
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)