Add initial options to Options menu
This commit is contained in:
parent
bb6ad4b9f7
commit
df20b42b17
BIN
Content/Widgets/Options/BP_OptionsMenuWidget.uasset
(Stored with Git LFS)
BIN
Content/Widgets/Options/BP_OptionsMenuWidget.uasset
(Stored with Git LFS)
Binary file not shown.
@ -3,19 +3,32 @@
|
||||
|
||||
#include "OptionsMenuWidget.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Components/Button.h"
|
||||
#include "Components/ComboBoxString.h"
|
||||
#include "GameFramework/GameUserSettings.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
|
||||
#include "RHI.h"
|
||||
|
||||
void UOptionsMenuWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
GenerateWindowTypeOptions();
|
||||
WindowTypeComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnWindowTypeSelectionChanged);
|
||||
|
||||
GenerateResolutionOptions();
|
||||
ResolutionComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnResolutionSelectionChanged);
|
||||
|
||||
GenerateDynamicResolutionOptions();
|
||||
DynamicResolutionComboBox->OnSelectionChanged.AddDynamic(
|
||||
this, &UOptionsMenuWidget::OnDynamicResolutionSelectionChanged);
|
||||
|
||||
GenerateVsyncOptions();
|
||||
VsyncComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnVsyncSelectionChanged);
|
||||
|
||||
GenerateRefreshRateOptions();
|
||||
RefreshRateComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnRefreshRateSelectionChanged);
|
||||
|
||||
if (ReturnButton)
|
||||
{
|
||||
@ -30,6 +43,15 @@ void UOptionsMenuWidget::NativeConstruct()
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::GenerateWindowTypeOptions()
|
||||
{
|
||||
WindowTypeComboBox->ClearOptions();
|
||||
WindowTypeComboBox->AddOption(LexToString(EWindowMode::Fullscreen));
|
||||
WindowTypeComboBox->AddOption(LexToString(EWindowMode::WindowedFullscreen));
|
||||
WindowTypeComboBox->AddOption(LexToString(EWindowMode::Windowed));
|
||||
WindowTypeComboBox->SetSelectedOption(LexToString(GEngine->GameUserSettings->GetFullscreenMode()));
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::GenerateResolutionOptions()
|
||||
{
|
||||
ResolutionComboBox->ClearOptions();
|
||||
@ -52,6 +74,167 @@ void UOptionsMenuWidget::GenerateResolutionOptions()
|
||||
ResolutionComboBox->SetSelectedOption(ResolutionString);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::GenerateDynamicResolutionOptions()
|
||||
{
|
||||
DynamicResolutionComboBox->ClearOptions();
|
||||
DynamicResolutionComboBox->AddOption("Enabled");
|
||||
DynamicResolutionComboBox->AddOption("Disabled");
|
||||
|
||||
if (GEngine->GameUserSettings->IsDynamicResolutionEnabled())
|
||||
{
|
||||
DynamicResolutionComboBox->SetSelectedOption("Enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
DynamicResolutionComboBox->SetSelectedOption("Disabled");
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::GenerateVsyncOptions()
|
||||
{
|
||||
VsyncComboBox->ClearOptions();
|
||||
VsyncComboBox->AddOption("Enabled");
|
||||
VsyncComboBox->AddOption("Disabled");
|
||||
|
||||
if (GEngine->GameUserSettings->IsVSyncEnabled())
|
||||
{
|
||||
VsyncComboBox->SetSelectedOption("Enabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
VsyncComboBox->SetSelectedOption("Disabled");
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::GenerateRefreshRateOptions()
|
||||
{
|
||||
RefreshRateComboBox->ClearOptions();
|
||||
|
||||
FScreenResolutionArray ScreenResolutions;
|
||||
RHIGetAvailableResolutions(ScreenResolutions, false);
|
||||
TArray<uint32> RefreshRates;
|
||||
for (FScreenResolutionRHI ScreenResolution : ScreenResolutions)
|
||||
{
|
||||
RefreshRates.AddUnique(ScreenResolution.RefreshRate);
|
||||
}
|
||||
|
||||
RefreshRates.Sort();
|
||||
for (uint32 RefreshRate : RefreshRates)
|
||||
{
|
||||
RefreshRateComboBox->AddOption(FString::FromInt(RefreshRate));
|
||||
}
|
||||
|
||||
RefreshRateComboBox->AddOption("Unlimited");
|
||||
|
||||
float FrameRateLimit = GEngine->GameUserSettings->GetFrameRateLimit();
|
||||
|
||||
if (FrameRateLimit > 0.0f)
|
||||
{
|
||||
RefreshRateComboBox->SetSelectedOption(FString::FromInt(FrameRateLimit));
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshRateComboBox->SetSelectedOption("Unlimited");
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
|
||||
{
|
||||
FString Horizontal;
|
||||
FString Vertical;
|
||||
SelectedItem.Split("x", &Horizontal, &Vertical);
|
||||
|
||||
int32 HorizontalInt = FCString::Atoi(*Horizontal);
|
||||
int32 VerticalInt = FCString::Atoi(*Vertical);
|
||||
|
||||
if (HorizontalInt > 0 && VerticalInt > 0)
|
||||
{
|
||||
GEngine->GameUserSettings->SetScreenResolution({HorizontalInt, VerticalInt});
|
||||
}
|
||||
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
|
||||
|
||||
void UOptionsMenuWidget::OnWindowTypeSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
|
||||
{
|
||||
if (SelectedItem == LexToString(EWindowMode::Fullscreen))
|
||||
{
|
||||
SetWindowModeFullscreen();
|
||||
}
|
||||
else if (SelectedItem == LexToString(EWindowMode::WindowedFullscreen))
|
||||
{
|
||||
SetWindowModeWindowedFullscreen();
|
||||
}
|
||||
else if (SelectedItem == LexToString(EWindowMode::Windowed))
|
||||
{
|
||||
SetWindowModeWindowed();
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::SetWindowModeFullscreen()
|
||||
{
|
||||
GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Fullscreen);
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::SetWindowModeWindowedFullscreen()
|
||||
{
|
||||
GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::WindowedFullscreen);
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::SetWindowModeWindowed()
|
||||
{
|
||||
GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Windowed);
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
|
||||
FVector2D Resolution = FVector2D::ZeroVector;
|
||||
GEngine->GameViewport->GetViewportSize(Resolution);
|
||||
|
||||
FString ResolutionString = FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y);
|
||||
if (ResolutionComboBox->FindOptionIndex(ResolutionString) == -1)
|
||||
{
|
||||
ResolutionComboBox->AddOption(ResolutionString);
|
||||
}
|
||||
|
||||
ResolutionComboBox->SetSelectedOption(ResolutionString);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::OnDynamicResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
|
||||
{
|
||||
if (SelectedItem == "Enabled")
|
||||
{
|
||||
GEngine->GameUserSettings->SetDynamicResolutionEnabled(true);
|
||||
}
|
||||
else if (SelectedItem == "Disabled")
|
||||
{
|
||||
GEngine->GameUserSettings->SetDynamicResolutionEnabled(false);
|
||||
}
|
||||
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::OnVsyncSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
|
||||
{
|
||||
if (SelectedItem == "Enabled")
|
||||
{
|
||||
GEngine->GameUserSettings->SetVSyncEnabled(true);
|
||||
}
|
||||
else if (SelectedItem == "Disabled")
|
||||
{
|
||||
GEngine->GameUserSettings->SetVSyncEnabled(false);
|
||||
}
|
||||
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::OnRefreshRateSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
|
||||
{
|
||||
GEngine->GameUserSettings->SetFrameRateLimit(FCString::Atoi(*SelectedItem));
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::ReturnButtonOnClicked()
|
||||
{
|
||||
if (MainMenuMenuWidget)
|
||||
|
@ -7,8 +7,6 @@
|
||||
#include "OptionsMenuWidget.generated.h"
|
||||
|
||||
class UComboBoxString;
|
||||
class UComboBox;
|
||||
class UComboBox;
|
||||
class UButton;
|
||||
/**
|
||||
*
|
||||
@ -17,8 +15,7 @@ UCLASS()
|
||||
class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UComboBoxString> ResolutionComboBox;
|
||||
|
||||
@ -33,13 +30,13 @@ public:
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UComboBoxString> RefreshRateComboBox;
|
||||
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UComboBoxString> DynamicResolutionComboBox;
|
||||
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UButton> ReturnButton;
|
||||
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UTextBlock> ReturnBlock;
|
||||
|
||||
@ -56,8 +53,34 @@ protected:
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
void GenerateWindowTypeOptions();
|
||||
|
||||
void GenerateResolutionOptions();
|
||||
|
||||
|
||||
void GenerateDynamicResolutionOptions();
|
||||
|
||||
void GenerateVsyncOptions();
|
||||
|
||||
void GenerateRefreshRateOptions();
|
||||
|
||||
UFUNCTION()
|
||||
void OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
|
||||
|
||||
UFUNCTION()
|
||||
void OnWindowTypeSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
|
||||
void SetWindowModeFullscreen();
|
||||
void SetWindowModeWindowedFullscreen();
|
||||
void SetWindowModeWindowed();
|
||||
|
||||
UFUNCTION()
|
||||
void OnDynamicResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
|
||||
|
||||
UFUNCTION()
|
||||
void OnVsyncSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
|
||||
|
||||
UFUNCTION()
|
||||
void OnRefreshRateSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
|
||||
|
||||
UFUNCTION()
|
||||
void ReturnButtonOnClicked();
|
||||
|
||||
|
@ -7,17 +7,20 @@ public class vampires : ModuleRules
|
||||
public vampires(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "Paper2D", "Niagara" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
PublicDependencyModuleNames.AddRange(new[]
|
||||
{
|
||||
"Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "Paper2D", "Niagara", "SlateCore", "RHI"
|
||||
});
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
|
||||
// Uncomment if you are using online features
|
||||
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
|
||||
|
||||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user