diff --git a/Source/Nakatomi/OptionsUIWidget.cpp b/Source/Nakatomi/OptionsUIWidget.cpp index 9365a2e..1ebd9f3 100644 --- a/Source/Nakatomi/OptionsUIWidget.cpp +++ b/Source/Nakatomi/OptionsUIWidget.cpp @@ -59,53 +59,65 @@ void UOptionsUIWidget::NativeConstruct() } } +void UOptionsUIWidget::SetReturnScreen(UUserWidget* userWidget) +{ + if (userWidget) + { + PreviousScreen = userWidget; + } +} + void UOptionsUIWidget::BackButtonOnClicked() { // TODO: Implement Functionality - GEngine->GameUserSettings->SaveSettings(); + GEngine->GameUserSettings->ApplySettings(true); + + this->RemoveFromParent(); + PreviousScreen->AddToViewport(); } void UOptionsUIWidget::ResetToDefaultsButtonOnClicked() { GEngine->GameUserSettings->SetToDefaults(); // :) - GEngine->GameUserSettings->SaveSettings(); + GEngine->GameUserSettings->ApplySettings(true); } void UOptionsUIWidget::OnResolutionSelectorChanged() { FIntPoint screenResolution = GEngine->GameUserSettings->GetDesktopResolution(); - float widthScale = screenResolution.Y / screenResolution.X; + float widthScale = static_cast(screenResolution.X) / static_cast(screenResolution.Y); switch (GEngine->GameUserSettings->GetScreenResolution().Y) { case 480: - screenResolution.Y = 480; - break; - case 720: screenResolution.Y = 720; break; - case 1080: + case 720: screenResolution.Y = 1080; break; - case 1440: + case 1080: screenResolution.Y = 1440; break; - case 2160: + case 1440: screenResolution.Y = 2160; break; + case 2160: + screenResolution.Y = 480; + break; default: - GEngine->GameUserSettings->SetScreenResolution(FIntPoint(1920, 1080)); + screenResolution.Y = 1080; } screenResolution.X = widthScale * screenResolution.Y; GEngine->GameUserSettings->SetScreenResolution(screenResolution); + if (ResolutionTextBlock) { ResolutionTextBlock->SetText(FText::AsNumber(screenResolution.Y)); } - GEngine->GameUserSettings->SaveSettings(); + GEngine->GameUserSettings->ApplySettings(true); } void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked) @@ -119,17 +131,17 @@ void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked) GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Windowed); } - GEngine->GameUserSettings->SaveSettings(); + GEngine->GameUserSettings->ApplySettings(true); } void UOptionsUIWidget::OnVsyncCheckboxChanged(bool bIsChecked) { GEngine->GameUserSettings->SetVSyncEnabled(bIsChecked); - GEngine->GameUserSettings->SaveSettings(); + GEngine->GameUserSettings->ApplySettings(true); } void UOptionsUIWidget::OnDynamicResolutionCheckboxChanged(bool bIsChecked) { GEngine->GameUserSettings->SetDynamicResolutionEnabled(bIsChecked); - GEngine->GameUserSettings->SaveSettings(); + GEngine->GameUserSettings->ApplySettings(true); } diff --git a/Source/Nakatomi/OptionsUIWidget.h b/Source/Nakatomi/OptionsUIWidget.h index 8465977..b535ba3 100644 --- a/Source/Nakatomi/OptionsUIWidget.h +++ b/Source/Nakatomi/OptionsUIWidget.h @@ -39,9 +39,15 @@ public: UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UButton* ResetToDefaultsButton; +private: + + UUserWidget* PreviousScreen; + public: virtual void NativeConstruct() override; + void SetReturnScreen(UUserWidget* userWidget); + private: UFUNCTION() diff --git a/Source/Nakatomi/PauseUIWidget.cpp b/Source/Nakatomi/PauseUIWidget.cpp index 08ff11c..c15427c 100644 --- a/Source/Nakatomi/PauseUIWidget.cpp +++ b/Source/Nakatomi/PauseUIWidget.cpp @@ -62,8 +62,10 @@ void UPauseUIWidget::OptionsButtonOnClicked() // TODO: Implement Functionality if (OptionsMenuWidget) { - currentOptionsMenuWidget = CreateWidget(GetWorld(), OptionsMenuWidget); + currentOptionsMenuWidget = CreateWidget(GetWorld(), OptionsMenuWidget); currentOptionsMenuWidget->AddToViewport(); + currentOptionsMenuWidget->SetReturnScreen(this); + this->RemoveFromParent(); } } diff --git a/Source/Nakatomi/PauseUIWidget.h b/Source/Nakatomi/PauseUIWidget.h index c58d7bd..94ea56c 100644 --- a/Source/Nakatomi/PauseUIWidget.h +++ b/Source/Nakatomi/PauseUIWidget.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "OptionsUIWidget.h" #include "Blueprint/UserWidget.h" #include "Components/Button.h" #include "PauseUIWidget.generated.h" @@ -35,7 +36,7 @@ public: TSubclassOf OptionsMenuWidget; private: - UUserWidget* currentOptionsMenuWidget; + UOptionsUIWidget* currentOptionsMenuWidget; public: virtual void NativeConstruct() override;