diff --git a/Source/Nakatomi/OptionsUIWidget.cpp b/Source/Nakatomi/OptionsUIWidget.cpp index ed3ad40..9365a2e 100644 --- a/Source/Nakatomi/OptionsUIWidget.cpp +++ b/Source/Nakatomi/OptionsUIWidget.cpp @@ -9,9 +9,43 @@ void UOptionsUIWidget::NativeConstruct() { Super::NativeConstruct(); - if (ApplyButton) + if (ResolutionButton) { - ApplyButton->OnClicked.AddUniqueDynamic(this, &UOptionsUIWidget::ApplyButtonOnClicked); + if (ResolutionTextBlock) + { + ResolutionTextBlock->SetText(FText::AsNumber(GEngine->GameUserSettings->GetScreenResolution().Y)); + } + + ResolutionButton->OnClicked.AddUniqueDynamic(this, &UOptionsUIWidget::OnResolutionSelectorChanged); + } + + if (FullscreenCheckBox) + { + FullscreenCheckBox->SetCheckedState(GEngine->GameUserSettings->GetFullscreenMode() == EWindowMode::Fullscreen + ? ECheckBoxState::Checked + : ECheckBoxState::Unchecked); + + FullscreenCheckBox->OnCheckStateChanged.AddUniqueDynamic( + this, &UOptionsUIWidget::OnFullscreenCheckboxChanged); + } + + if (VsyncCheckBox) + { + VsyncCheckBox->SetCheckedState(GEngine->GameUserSettings->IsVSyncEnabled() + ? ECheckBoxState::Checked + : ECheckBoxState::Unchecked); + + VsyncCheckBox->OnCheckStateChanged.AddUniqueDynamic(this, &UOptionsUIWidget::OnVsyncCheckboxChanged); + } + + if (DynamicResolutionCheckBox) + { + DynamicResolutionCheckBox->SetCheckedState(GEngine->GameUserSettings->IsDynamicResolutionEnabled() + ? ECheckBoxState::Checked + : ECheckBoxState::Unchecked); + + DynamicResolutionCheckBox->OnCheckStateChanged.AddUniqueDynamic( + this, &UOptionsUIWidget::OnDynamicResolutionCheckboxChanged); } if (BackButton) @@ -23,42 +57,79 @@ void UOptionsUIWidget::NativeConstruct() { ResetToDefaultsButton->OnClicked.AddUniqueDynamic(this, &UOptionsUIWidget::ResetToDefaultsButtonOnClicked); } - - if (FullscreenBox) - { - switch (GEngine->GameUserSettings->GetFullscreenMode()) - { - case EWindowMode::Fullscreen: - FullscreenBox->SetCheckedState(ECheckBoxState::Checked); - break; - case EWindowMode::WindowedFullscreen: - FullscreenBox->SetCheckedState(ECheckBoxState::Unchecked); - break; - case EWindowMode::Windowed: - FullscreenBox->SetCheckedState(ECheckBoxState::Unchecked); - break; - case EWindowMode::NumWindowModes: - FullscreenBox->SetCheckedState(ECheckBoxState::Unchecked); - break; - default: - FullscreenBox->SetCheckedState(ECheckBoxState::Unchecked); - } - } -} - -void UOptionsUIWidget::ApplyButtonOnClicked() -{ - // TODO: Implement Functionality } void UOptionsUIWidget::BackButtonOnClicked() { // TODO: Implement Functionality + GEngine->GameUserSettings->SaveSettings(); } void UOptionsUIWidget::ResetToDefaultsButtonOnClicked() { - // TODO: Implement Functionality - GEngine->GameUserSettings->SetToDefaults(); // :) + GEngine->GameUserSettings->SaveSettings(); +} + +void UOptionsUIWidget::OnResolutionSelectorChanged() +{ + FIntPoint screenResolution = GEngine->GameUserSettings->GetDesktopResolution(); + float widthScale = screenResolution.Y / screenResolution.X; + + switch (GEngine->GameUserSettings->GetScreenResolution().Y) + { + case 480: + screenResolution.Y = 480; + break; + case 720: + screenResolution.Y = 720; + break; + case 1080: + screenResolution.Y = 1080; + break; + case 1440: + screenResolution.Y = 1440; + break; + case 2160: + screenResolution.Y = 2160; + break; + default: + GEngine->GameUserSettings->SetScreenResolution(FIntPoint(1920, 1080)); + } + + screenResolution.X = widthScale * screenResolution.Y; + GEngine->GameUserSettings->SetScreenResolution(screenResolution); + + if (ResolutionTextBlock) + { + ResolutionTextBlock->SetText(FText::AsNumber(screenResolution.Y)); + } + + GEngine->GameUserSettings->SaveSettings(); +} + +void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked) +{ + if (bIsChecked) + { + GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Fullscreen); + } + else + { + GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Windowed); + } + + GEngine->GameUserSettings->SaveSettings(); +} + +void UOptionsUIWidget::OnVsyncCheckboxChanged(bool bIsChecked) +{ + GEngine->GameUserSettings->SetVSyncEnabled(bIsChecked); + GEngine->GameUserSettings->SaveSettings(); +} + +void UOptionsUIWidget::OnDynamicResolutionCheckboxChanged(bool bIsChecked) +{ + GEngine->GameUserSettings->SetDynamicResolutionEnabled(bIsChecked); + GEngine->GameUserSettings->SaveSettings(); } diff --git a/Source/Nakatomi/OptionsUIWidget.h b/Source/Nakatomi/OptionsUIWidget.h index 0028e0e..8465977 100644 --- a/Source/Nakatomi/OptionsUIWidget.h +++ b/Source/Nakatomi/OptionsUIWidget.h @@ -4,9 +4,9 @@ #include "CoreMinimal.h" #include "Blueprint/UserWidget.h" -#include "Components/ComboBox.h" #include "Components/CheckBox.h" #include "Components/Button.h" +#include "Components/TextBlock.h" #include "OptionsUIWidget.generated.h" /** @@ -19,14 +19,20 @@ class NAKATOMI_API UOptionsUIWidget : public UUserWidget public: UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) - UComboBox* ResolutionSelector; + UButton* ResolutionButton; UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) - UCheckBox* FullscreenBox; + UTextBlock* ResolutionTextBlock; UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) - UButton* ApplyButton; + UCheckBox* FullscreenCheckBox; + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UCheckBox* VsyncCheckBox; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UCheckBox* DynamicResolutionCheckBox; + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UButton* BackButton; @@ -37,13 +43,22 @@ public: virtual void NativeConstruct() override; private: - UFUNCTION() - void ApplyButtonOnClicked(); UFUNCTION() void BackButtonOnClicked(); - UFUNCTION() void ResetToDefaultsButtonOnClicked(); + + UFUNCTION() + void OnResolutionSelectorChanged(); + + UFUNCTION() + void OnFullscreenCheckboxChanged(bool bIsChecked); + + UFUNCTION() + void OnVsyncCheckboxChanged(bool bIsChecked); + + UFUNCTION() + void OnDynamicResolutionCheckboxChanged(bool bIsChecked); };