Skip to content

Commit

Permalink
pressing 'Escape' or 'M' while the RaceHUD is on pause the game (and …
Browse files Browse the repository at this point in the history
…the time) or unpause it
  • Loading branch information
yosmont committed Jan 16, 2023
1 parent ecf6255 commit d3d9c9e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
Binary file modified Content/BP/WBP_RaceHUD.uasset
Binary file not shown.
26 changes: 5 additions & 21 deletions Source/KO_Racing/MyRaceUserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void UMyRaceUserWidget::Init()
SetLapMax(3);
_beforeStartTimerTxt->ChangeValue(3);
_pauseTxt->SetVisibility(ESlateVisibility::Hidden);
UGameplayStatics::GetPlayerController(GetWorld(), 0)->InputComponent->BindAction("PauseAction", IE_Pressed, this, &UMyRaceUserWidget::TogglePause).bExecuteWhenPaused = true;
}

void UMyRaceUserWidget::ChangeRankValue(float value)
Expand Down Expand Up @@ -93,27 +94,10 @@ FString UMyRaceUserWidget::GenTimerFString(float time)

void UMyRaceUserWidget::TogglePause()
{
APlayerController* PC = UGameplayStatics::GetPlayerController(GetWorld(), 0);

GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, (nullptr != PC) ? TEXT("PC found") : TEXT("PC not found"), true);
if (nullptr != PC) {
UE_LOG(LogTemp, Warning, TEXT("PC found"));
} else {
UE_LOG(LogTemp, Warning, TEXT("PC not found"));
}

if (nullptr != PC && PC->IsInputKeyDown(FKey("PauseAction")) && !_pauseWaitKeyRelease) {

GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("paused"), true);
UE_LOG(LogTemp, Warning, TEXT("paused"));

_pauseWaitKeyRelease = true;
_isPaused = !_isPaused;
_pauseTxt->SetVisibility((_isPaused) ? ESlateVisibility::Visible : ESlateVisibility::Hidden);
(!_isPaused) ? ResumeTimer() : PauseTimer();
UGameplayStatics::SetGamePaused(GetWorld(), _isPaused);
} else if (nullptr != PC && !PC->IsInputKeyDown(FKey("PauseAction")) && _pauseWaitKeyRelease)
_pauseWaitKeyRelease = false;
_isPaused = !_isPaused;
_pauseTxt->SetVisibility((_isPaused) ? ESlateVisibility::Visible : ESlateVisibility::Hidden);
(!_isPaused) ? ResumeTimer() : PauseTimer();
UGameplayStatics::SetGamePaused(GetWorld(), _isPaused);
}

std::string UMyRaceUserWidget::GenTimerString(float time)
Expand Down
1 change: 0 additions & 1 deletion Source/KO_Racing/MyRaceUserWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ class KO_RACING_API UMyRaceUserWidget : public UUserWidget
bool _timerIsStarted = false;
TArray<float> _lapTime;
float _lastLapTimer = 0;
bool _pauseWaitKeyRelease = false;
};

0 comments on commit d3d9c9e

Please sign in to comment.