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 "OptionsUIWidget.h"
#include <Kismet/KismetSystemLibrary.h>
#include "GameFramework/GameUserSettings.h" #include "GameFramework/GameUserSettings.h"
void UOptionsUIWidget::NativeConstruct() void UOptionsUIWidget::NativeConstruct()
@ -29,6 +31,16 @@ void UOptionsUIWidget::NativeConstruct()
this, &UOptionsUIWidget::OnFullscreenCheckboxChanged); this, &UOptionsUIWidget::OnFullscreenCheckboxChanged);
} }
if (RefreshRateButton)
{
if (RefreshRateTextBlock)
{
SetRefreshRateTextBlock(GEngine->GameUserSettings->GetFrameRateLimit());
}
RefreshRateButton->OnClicked.AddUniqueDynamic(this, &UOptionsUIWidget::OnRefreshRateSelectorChanged);
}
if (VsyncCheckBox) if (VsyncCheckBox)
{ {
VsyncCheckBox->SetCheckedState(GEngine->GameUserSettings->IsVSyncEnabled() VsyncCheckBox->SetCheckedState(GEngine->GameUserSettings->IsVSyncEnabled()
@ -89,9 +101,6 @@ void UOptionsUIWidget::OnResolutionSelectorChanged()
switch (GEngine->GameUserSettings->GetScreenResolution().Y) switch (GEngine->GameUserSettings->GetScreenResolution().Y)
{ {
case 480:
screenResolution.Y = 720;
break;
case 720: case 720:
screenResolution.Y = 1080; screenResolution.Y = 1080;
break; break;
@ -102,7 +111,7 @@ void UOptionsUIWidget::OnResolutionSelectorChanged()
screenResolution.Y = 2160; screenResolution.Y = 2160;
break; break;
case 2160: case 2160:
screenResolution.Y = 480; screenResolution.Y = 720;
break; break;
default: default:
screenResolution.Y = 1080; screenResolution.Y = 1080;
@ -120,6 +129,11 @@ void UOptionsUIWidget::OnResolutionSelectorChanged()
GEngine->GameUserSettings->ApplySettings(true); 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) void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked)
{ {
if (bIsChecked) if (bIsChecked)
@ -134,6 +148,30 @@ void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked)
GEngine->GameUserSettings->ApplySettings(true); 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) void UOptionsUIWidget::OnVsyncCheckboxChanged(bool bIsChecked)
{ {
GEngine->GameUserSettings->SetVSyncEnabled(bIsChecked); GEngine->GameUserSettings->SetVSyncEnabled(bIsChecked);

View File

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