Implement pause menu
This commit is contained in:
@@ -84,11 +84,18 @@ void ASpaceShooterHUD::DrawHUD()
|
||||
ASpaceShooterGameMode* GameMode = GetGameMode();
|
||||
if (!GameMode) return;
|
||||
|
||||
if (!GameMode->IsGameOver())
|
||||
APlayerController* PC = GetWorld()->GetFirstPlayerController();
|
||||
bool bIsPaused = PC && PC->IsPaused();
|
||||
|
||||
if (!GameMode->IsGameOver() && bIsPaused)
|
||||
{
|
||||
DrawPauseScreen();
|
||||
}
|
||||
if (!GameMode->IsGameOver() && !bIsPaused)
|
||||
{
|
||||
DrawGameplayHUD();
|
||||
}
|
||||
else
|
||||
if (GameMode->IsGameOver())
|
||||
{
|
||||
DrawGameOverScreen();
|
||||
}
|
||||
@@ -113,6 +120,51 @@ void ASpaceShooterHUD::DrawGameplayHUD()
|
||||
DrawStatusBars();
|
||||
}
|
||||
|
||||
void ASpaceShooterHUD::DrawPauseScreen()
|
||||
{
|
||||
if (!Canvas) return;
|
||||
|
||||
// Draw semi-transparent dark overlay (this creates a "blur-like" effect)
|
||||
FCanvasBoxItem BoxItem(FVector2D(0, 0), FVector2D(Canvas->SizeX, Canvas->SizeY));
|
||||
BoxItem.SetColor(FLinearColor(0.0f, 0.0f, 0.0f, 0.75f)); // More opaque for better readability
|
||||
Canvas->DrawItem(BoxItem);
|
||||
|
||||
// Draw "GAME PAUSED" text
|
||||
FString PauseText = TEXT("GAME PAUSED");
|
||||
float TextWidth, TextHeight;
|
||||
GetTextSize(PauseText, TextWidth, TextHeight, TextFont, PauseTextScale);
|
||||
|
||||
// Center the text
|
||||
float PosX = (Canvas->SizeX - TextWidth) * 0.5f;
|
||||
float PosY = (Canvas->SizeY - TextHeight) * 0.5f;
|
||||
|
||||
// Draw text shadow for better visibility
|
||||
DrawText(PauseText,
|
||||
FLinearColor(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
PosX + 2.0f,
|
||||
PosY + 2.0f,
|
||||
TextFont,
|
||||
PauseTextScale);
|
||||
|
||||
// Draw main text
|
||||
DrawText(PauseText,
|
||||
FLinearColor(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
PosX,
|
||||
PosY,
|
||||
TextFont,
|
||||
PauseTextScale);
|
||||
|
||||
// Draw "Press ESC to Resume" text
|
||||
FString ResumeText = TEXT("Press ESC to Resume");
|
||||
GetTextSize(ResumeText, TextWidth, TextHeight, TextFont);
|
||||
|
||||
DrawText(ResumeText,
|
||||
FLinearColor(1.0f, 1.0f, 1.0f, 0.8f),
|
||||
(Canvas->SizeX - TextWidth) * 0.5f,
|
||||
PosY + TextHeight * 3,
|
||||
TextFont);
|
||||
}
|
||||
|
||||
void ASpaceShooterHUD::DrawGameOverBackground()
|
||||
{
|
||||
if (!Canvas) return;
|
||||
|
||||
Reference in New Issue
Block a user