Add methods to set and remove options menu from viewport
This commit is contained in:
parent
122c3998fd
commit
23af466085
|
@ -59,53 +59,65 @@ void UOptionsUIWidget::NativeConstruct()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UOptionsUIWidget::SetReturnScreen(UUserWidget* userWidget)
|
||||||
|
{
|
||||||
|
if (userWidget)
|
||||||
|
{
|
||||||
|
PreviousScreen = userWidget;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UOptionsUIWidget::BackButtonOnClicked()
|
void UOptionsUIWidget::BackButtonOnClicked()
|
||||||
{
|
{
|
||||||
// TODO: Implement Functionality
|
// TODO: Implement Functionality
|
||||||
GEngine->GameUserSettings->SaveSettings();
|
GEngine->GameUserSettings->ApplySettings(true);
|
||||||
|
|
||||||
|
this->RemoveFromParent();
|
||||||
|
PreviousScreen->AddToViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UOptionsUIWidget::ResetToDefaultsButtonOnClicked()
|
void UOptionsUIWidget::ResetToDefaultsButtonOnClicked()
|
||||||
{
|
{
|
||||||
GEngine->GameUserSettings->SetToDefaults(); // :)
|
GEngine->GameUserSettings->SetToDefaults(); // :)
|
||||||
GEngine->GameUserSettings->SaveSettings();
|
GEngine->GameUserSettings->ApplySettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UOptionsUIWidget::OnResolutionSelectorChanged()
|
void UOptionsUIWidget::OnResolutionSelectorChanged()
|
||||||
{
|
{
|
||||||
FIntPoint screenResolution = GEngine->GameUserSettings->GetDesktopResolution();
|
FIntPoint screenResolution = GEngine->GameUserSettings->GetDesktopResolution();
|
||||||
float widthScale = screenResolution.Y / screenResolution.X;
|
float widthScale = static_cast<float>(screenResolution.X) / static_cast<float>(screenResolution.Y);
|
||||||
|
|
||||||
switch (GEngine->GameUserSettings->GetScreenResolution().Y)
|
switch (GEngine->GameUserSettings->GetScreenResolution().Y)
|
||||||
{
|
{
|
||||||
case 480:
|
case 480:
|
||||||
screenResolution.Y = 480;
|
|
||||||
break;
|
|
||||||
case 720:
|
|
||||||
screenResolution.Y = 720;
|
screenResolution.Y = 720;
|
||||||
break;
|
break;
|
||||||
case 1080:
|
case 720:
|
||||||
screenResolution.Y = 1080;
|
screenResolution.Y = 1080;
|
||||||
break;
|
break;
|
||||||
case 1440:
|
case 1080:
|
||||||
screenResolution.Y = 1440;
|
screenResolution.Y = 1440;
|
||||||
break;
|
break;
|
||||||
case 2160:
|
case 1440:
|
||||||
screenResolution.Y = 2160;
|
screenResolution.Y = 2160;
|
||||||
break;
|
break;
|
||||||
|
case 2160:
|
||||||
|
screenResolution.Y = 480;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
GEngine->GameUserSettings->SetScreenResolution(FIntPoint(1920, 1080));
|
screenResolution.Y = 1080;
|
||||||
}
|
}
|
||||||
|
|
||||||
screenResolution.X = widthScale * screenResolution.Y;
|
screenResolution.X = widthScale * screenResolution.Y;
|
||||||
GEngine->GameUserSettings->SetScreenResolution(screenResolution);
|
GEngine->GameUserSettings->SetScreenResolution(screenResolution);
|
||||||
|
|
||||||
|
|
||||||
if (ResolutionTextBlock)
|
if (ResolutionTextBlock)
|
||||||
{
|
{
|
||||||
ResolutionTextBlock->SetText(FText::AsNumber(screenResolution.Y));
|
ResolutionTextBlock->SetText(FText::AsNumber(screenResolution.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
GEngine->GameUserSettings->SaveSettings();
|
GEngine->GameUserSettings->ApplySettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked)
|
void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked)
|
||||||
|
@ -119,17 +131,17 @@ void UOptionsUIWidget::OnFullscreenCheckboxChanged(bool bIsChecked)
|
||||||
GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Windowed);
|
GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Windowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
GEngine->GameUserSettings->SaveSettings();
|
GEngine->GameUserSettings->ApplySettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UOptionsUIWidget::OnVsyncCheckboxChanged(bool bIsChecked)
|
void UOptionsUIWidget::OnVsyncCheckboxChanged(bool bIsChecked)
|
||||||
{
|
{
|
||||||
GEngine->GameUserSettings->SetVSyncEnabled(bIsChecked);
|
GEngine->GameUserSettings->SetVSyncEnabled(bIsChecked);
|
||||||
GEngine->GameUserSettings->SaveSettings();
|
GEngine->GameUserSettings->ApplySettings(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UOptionsUIWidget::OnDynamicResolutionCheckboxChanged(bool bIsChecked)
|
void UOptionsUIWidget::OnDynamicResolutionCheckboxChanged(bool bIsChecked)
|
||||||
{
|
{
|
||||||
GEngine->GameUserSettings->SetDynamicResolutionEnabled(bIsChecked);
|
GEngine->GameUserSettings->SetDynamicResolutionEnabled(bIsChecked);
|
||||||
GEngine->GameUserSettings->SaveSettings();
|
GEngine->GameUserSettings->ApplySettings(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,9 +39,15 @@ public:
|
||||||
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
UButton* ResetToDefaultsButton;
|
UButton* ResetToDefaultsButton;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UUserWidget* PreviousScreen;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
|
void SetReturnScreen(UUserWidget* userWidget);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
|
|
|
@ -62,8 +62,10 @@ void UPauseUIWidget::OptionsButtonOnClicked()
|
||||||
// TODO: Implement Functionality
|
// TODO: Implement Functionality
|
||||||
if (OptionsMenuWidget)
|
if (OptionsMenuWidget)
|
||||||
{
|
{
|
||||||
currentOptionsMenuWidget = CreateWidget<UUserWidget>(GetWorld(), OptionsMenuWidget);
|
currentOptionsMenuWidget = CreateWidget<UOptionsUIWidget>(GetWorld(), OptionsMenuWidget);
|
||||||
currentOptionsMenuWidget->AddToViewport();
|
currentOptionsMenuWidget->AddToViewport();
|
||||||
|
currentOptionsMenuWidget->SetReturnScreen(this);
|
||||||
|
this->RemoveFromParent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "OptionsUIWidget.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "Components/Button.h"
|
#include "Components/Button.h"
|
||||||
#include "PauseUIWidget.generated.h"
|
#include "PauseUIWidget.generated.h"
|
||||||
|
@ -35,7 +36,7 @@ public:
|
||||||
TSubclassOf<class UUserWidget> OptionsMenuWidget;
|
TSubclassOf<class UUserWidget> OptionsMenuWidget;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UUserWidget* currentOptionsMenuWidget;
|
UOptionsUIWidget* currentOptionsMenuWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void NativeConstruct() override;
|
virtual void NativeConstruct() override;
|
||||||
|
|
Loading…
Reference in New Issue