From 12c8d7b6f010acd8a828846b2edfa34cfc61ac2d Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 11 Oct 2023 22:00:33 +0100 Subject: [PATCH] Add FrameRate Limit to Options Menu --- Content/UI/Options/OptionsMenu.uasset | 4 +-- Source/Nakatomi/OptionsUIWidget.cpp | 48 ++++++++++++++++++++++++--- Source/Nakatomi/OptionsUIWidget.h | 12 +++++++ 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/Content/UI/Options/OptionsMenu.uasset b/Content/UI/Options/OptionsMenu.uasset index df887ec..b3871c6 100644 --- a/Content/UI/Options/OptionsMenu.uasset +++ b/Content/UI/Options/OptionsMenu.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5273519ce0257a4fd2be58f12ef76c8afd85db7bd8748accc4b6555be7fac611 -size 48475 +oid sha256:a4dbe3720e7ebc2f69f9453adb8de852341a478380ed4c68e1204037b18e425b +size 52416 diff --git a/Source/Nakatomi/OptionsUIWidget.cpp b/Source/Nakatomi/OptionsUIWidget.cpp index 1ebd9f3..18a5cf1 100644 --- a/Source/Nakatomi/OptionsUIWidget.cpp +++ b/Source/Nakatomi/OptionsUIWidget.cpp @@ -3,6 +3,8 @@ #include "OptionsUIWidget.h" +#include + #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,12 +111,12 @@ void UOptionsUIWidget::OnResolutionSelectorChanged() screenResolution.Y = 2160; break; case 2160: - screenResolution.Y = 480; + screenResolution.Y = 720; break; default: screenResolution.Y = 1080; } - + screenResolution.X = widthScale * screenResolution.Y; GEngine->GameUserSettings->SetScreenResolution(screenResolution); @@ -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(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); diff --git a/Source/Nakatomi/OptionsUIWidget.h b/Source/Nakatomi/OptionsUIWidget.h index b535ba3..b5fb964 100644 --- a/Source/Nakatomi/OptionsUIWidget.h +++ b/Source/Nakatomi/OptionsUIWidget.h @@ -29,6 +29,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; @@ -58,10 +64,16 @@ private: UFUNCTION() void OnResolutionSelectorChanged(); + + UFUNCTION() + void SetRefreshRateTextBlock(float RefreshRateText); UFUNCTION() void OnFullscreenCheckboxChanged(bool bIsChecked); + UFUNCTION() + void OnRefreshRateSelectorChanged(); + UFUNCTION() void OnVsyncCheckboxChanged(bool bIsChecked);