Add FrameRate Limit to Options Menu

This commit is contained in:
baz 2023-10-11 22:00:33 +01:00
parent 1c467d14f4
commit 12c8d7b6f0
3 changed files with 57 additions and 7 deletions

BIN
Content/UI/Options/OptionsMenu.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -3,6 +3,8 @@
#include "OptionsUIWidget.h"
#include <Kismet/KismetSystemLibrary.h>
#include "GameFramework/GameUserSettings.h"
void UOptionsUIWidget::NativeConstruct()
@ -29,6 +31,16 @@ void UOptionsUIWidget::NativeConstruct()
this, &UOptionsUIWidget::OnFullscreenCheckboxChanged);
}
if (RefreshRateButton)
{
if (RefreshRateTextBlock)
{
SetRefreshRateTextBlock(GEngine->GameUserSettings->GetFrameRateLimit());
}
RefreshRateButton->OnClicked.AddUniqueDynamic(this, &UOptionsUIWidget::OnRefreshRateSelectorChanged);
}
if (VsyncCheckBox)
{
VsyncCheckBox->SetCheckedState(GEngine->GameUserSettings->IsVSyncEnabled()
@ -89,9 +101,6 @@ void UOptionsUIWidget::OnResolutionSelectorChanged()
switch (GEngine->GameUserSettings->GetScreenResolution().Y)
{
case 480:
screenResolution.Y = 720;
break;
case 720:
screenResolution.Y = 1080;
break;
@ -102,7 +111,7 @@ void UOptionsUIWidget::OnResolutionSelectorChanged()
screenResolution.Y = 2160;
break;
case 2160:
screenResolution.Y = 480;
screenResolution.Y = 720;
break;
default:
screenResolution.Y = 1080;
@ -120,6 +129,11 @@ void UOptionsUIWidget::OnResolutionSelectorChanged()
GEngine->GameUserSettings->ApplySettings(true);
}
void UOptionsUIWidget::SetRefreshRateTextBlock(float RefreshRateText)
{
RefreshRateTextBlock->SetText(RefreshRateText == 0.0f ? FText::FromString("Unlimited") : FText::AsNumber(RefreshRateText));
}
void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked)
{
if (bIsChecked)
@ -134,6 +148,30 @@ void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked)
GEngine->GameUserSettings->ApplySettings(true);
}
void UOptionsUIWidget::OnRefreshRateSelectorChanged()
{
switch (static_cast<int>(GEngine->GameUserSettings->GetFrameRateLimit()))
{
case 0:
GEngine->GameUserSettings->SetFrameRateLimit(60);
break;
case 60:
GEngine->GameUserSettings->SetFrameRateLimit(144);
break;
case 144:
GEngine->GameUserSettings->SetFrameRateLimit(240);
break;
case 240:
GEngine->GameUserSettings->SetFrameRateLimit(0);
break;
default:
GEngine->GameUserSettings->SetFrameRateLimit(0);
}
SetRefreshRateTextBlock(GEngine->GameUserSettings->GetFrameRateLimit());
GEngine->GameUserSettings->ApplySettings(true);
}
void UOptionsUIWidget::OnVsyncCheckboxChanged(bool bIsChecked)
{
GEngine->GameUserSettings->SetVSyncEnabled(bIsChecked);

View File

@ -30,6 +30,12 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UCheckBox* VsyncCheckBox;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* RefreshRateButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* RefreshRateTextBlock;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UCheckBox* DynamicResolutionCheckBox;
@ -59,9 +65,15 @@ private:
UFUNCTION()
void OnResolutionSelectorChanged();
UFUNCTION()
void SetRefreshRateTextBlock(float RefreshRateText);
UFUNCTION()
void OnFullscreenCheckboxChanged(bool bIsChecked);
UFUNCTION()
void OnRefreshRateSelectorChanged();
UFUNCTION()
void OnVsyncCheckboxChanged(bool bIsChecked);