Add initial options to Options menu

This commit is contained in:
baz 2025-08-08 01:13:00 +01:00
parent bb6ad4b9f7
commit df20b42b17
4 changed files with 227 additions and 18 deletions

Binary file not shown.

View File

@ -3,19 +3,32 @@
#include "OptionsMenuWidget.h" #include "OptionsMenuWidget.h"
#include <string>
#include "Components/Button.h" #include "Components/Button.h"
#include "Components/ComboBoxString.h" #include "Components/ComboBoxString.h"
#include "GameFramework/GameUserSettings.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h" #include "Kismet/KismetSystemLibrary.h"
#include "RHI.h"
void UOptionsMenuWidget::NativeConstruct() void UOptionsMenuWidget::NativeConstruct()
{ {
Super::NativeConstruct(); Super::NativeConstruct();
GenerateWindowTypeOptions();
WindowTypeComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnWindowTypeSelectionChanged);
GenerateResolutionOptions(); 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) 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() void UOptionsMenuWidget::GenerateResolutionOptions()
{ {
ResolutionComboBox->ClearOptions(); ResolutionComboBox->ClearOptions();
@ -52,6 +74,167 @@ void UOptionsMenuWidget::GenerateResolutionOptions()
ResolutionComboBox->SetSelectedOption(ResolutionString); 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() void UOptionsMenuWidget::ReturnButtonOnClicked()
{ {
if (MainMenuMenuWidget) if (MainMenuMenuWidget)

View File

@ -7,8 +7,6 @@
#include "OptionsMenuWidget.generated.h" #include "OptionsMenuWidget.generated.h"
class UComboBoxString; class UComboBoxString;
class UComboBox;
class UComboBox;
class UButton; class UButton;
/** /**
* *
@ -17,8 +15,7 @@ UCLASS()
class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> ResolutionComboBox; TObjectPtr<UComboBoxString> ResolutionComboBox;
@ -33,13 +30,13 @@ public:
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> RefreshRateComboBox; TObjectPtr<UComboBoxString> RefreshRateComboBox;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> DynamicResolutionComboBox; TObjectPtr<UComboBoxString> DynamicResolutionComboBox;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UButton> ReturnButton; TObjectPtr<UButton> ReturnButton;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UTextBlock> ReturnBlock; TObjectPtr<UTextBlock> ReturnBlock;
@ -56,8 +53,34 @@ protected:
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
private: private:
void GenerateWindowTypeOptions();
void GenerateResolutionOptions(); 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() UFUNCTION()
void ReturnButtonOnClicked(); void ReturnButtonOnClicked();

View File

@ -7,17 +7,20 @@ public class vampires : ModuleRules
public vampires(ReadOnlyTargetRules Target) : base(Target) public vampires(ReadOnlyTargetRules Target) : base(Target)
{ {
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; 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 // Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features // Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem"); // PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
} }
} }