Add keyboard controls to Options menu

This commit is contained in:
baz 2025-09-05 21:10:12 +01:00
parent 3171771876
commit a6ce1e5c1b
9 changed files with 331 additions and 99 deletions

BIN
Content/Widgets/BP_CustomComboBoxString.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Widgets/BP_CustomSlider.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,40 @@
// Louis Hobbs | 2024-2025
#include "CustomComboBoxString.h"
#include "Components/ComboBoxString.h"
void UCustomComboBoxString::NativeConstruct()
{
Super::NativeConstruct();
SetIsFocusable(true);
ComboBox->OnSelectionChanged.AddDynamic(this, &UCustomComboBoxString::OnComboBoxSelectionChanged);
ComboBox->OnOpening.AddDynamic(this, &UCustomComboBoxString::OnComboBoxOpening);
SetDesiredFocusWidget(ComboBox);
}
void UCustomComboBoxString::NativeOnAddedToFocusPath(const FFocusEvent& InFocusEvent)
{
Super::NativeOnAddedToFocusPath(InFocusEvent);
OnFocused.Broadcast(InFocusEvent);
}
void UCustomComboBoxString::NativeOnRemovedFromFocusPath(const FFocusEvent& InFocusEvent)
{
Super::NativeOnRemovedFromFocusPath(InFocusEvent);
OnUnfocused.Broadcast(InFocusEvent);
}
void UCustomComboBoxString::OnComboBoxOpening()
{
OnOpening.Broadcast();
}
void UCustomComboBoxString::OnComboBoxSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
{
OnSelectionChanged.Broadcast(SelectedItem, SelectionType);
}

View File

@ -0,0 +1,55 @@
// Louis Hobbs | 2024-2025
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "CustomComboBoxString.generated.h"
class UComboBoxString;
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnComboBoxOpeningCustom);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnComboBoxSelectionChangedCustom,
FString, SelectedItem,
ESelectInfo::Type, SelectionType);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCustomComboBoxFocusPath, FFocusEvent, InFocusEvent);
/**
*
*/
UCLASS()
class VAMPIRES_API UCustomComboBoxString : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintAssignable)
FOnComboBoxOpeningCustom OnOpening;
UPROPERTY(BlueprintAssignable)
FOnComboBoxSelectionChangedCustom OnSelectionChanged;
UPROPERTY(BlueprintAssignable)
FCustomComboBoxFocusPath OnFocused;
UPROPERTY(BlueprintAssignable)
FCustomComboBoxFocusPath OnUnfocused;
UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> ComboBox;
protected:
virtual void NativeConstruct() override;
virtual void NativeOnAddedToFocusPath(const FFocusEvent& InFocusEvent) override;
virtual void NativeOnRemovedFromFocusPath(const FFocusEvent& InFocusEvent) override;
UFUNCTION()
void OnComboBoxOpening();
UFUNCTION()
void OnComboBoxSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
};

View File

@ -0,0 +1,34 @@
// Louis Hobbs | 2024-2025
#include "CustomSlider.h"
#include "Components/Slider.h"
void UCustomSlider::NativeConstruct()
{
Super::NativeConstruct();
SetIsFocusable(true);
SliderBody->OnValueChanged.AddDynamic(this, &UCustomSlider::OnSliderValueChanged);
SetDesiredFocusWidget(SliderBody);
}
void UCustomSlider::NativeOnAddedToFocusPath(const FFocusEvent& InFocusEvent)
{
Super::NativeOnAddedToFocusPath(InFocusEvent);
OnFocused.Broadcast(InFocusEvent);
}
void UCustomSlider::NativeOnRemovedFromFocusPath(const FFocusEvent& InFocusEvent)
{
Super::NativeOnRemovedFromFocusPath(InFocusEvent);
OnUnfocused.Broadcast(InFocusEvent);
}
void UCustomSlider::OnSliderValueChanged(float Value)
{
OnValueChanged.Broadcast(Value);
}

View File

@ -0,0 +1,47 @@
// Louis Hobbs | 2024-2025
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "CustomSlider.generated.h"
class USlider;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnFloatValueChangedEventCustom, float, Value);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCustomSliderFocusPath, FFocusEvent, InFocusEvent);
/**
*
*/
UCLASS()
class VAMPIRES_API UCustomSlider : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintAssignable)
FOnFloatValueChangedEventCustom OnValueChanged;
UPROPERTY(BlueprintAssignable)
FCustomSliderFocusPath OnFocused;
UPROPERTY(BlueprintAssignable)
FCustomSliderFocusPath OnUnfocused;
UPROPERTY(meta = (BindWidget))
TObjectPtr<USlider> SliderBody;
protected:
virtual void NativeConstruct() override;
virtual void NativeOnAddedToFocusPath(const FFocusEvent& InFocusEvent) override;
virtual void NativeOnRemovedFromFocusPath(const FFocusEvent& InFocusEvent) override;
UFUNCTION()
void OnSliderValueChanged(float Value);
};

View File

@ -3,12 +3,16 @@
#include "OptionsMenuWidget.h" #include "OptionsMenuWidget.h"
#include "CustomButton.h"
#include "CustomComboBoxString.h"
#include "CustomSlider.h"
#include "Components/Button.h" #include "Components/Button.h"
#include "Components/ComboBoxString.h"
#include "GameFramework/GameUserSettings.h" #include "GameFramework/GameUserSettings.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h" #include "Kismet/KismetSystemLibrary.h"
#include "RHI.h" #include "RHI.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Components/ComboBoxString.h"
#include "Components/Slider.h" #include "Components/Slider.h"
#include "Components/TextBlock.h" #include "Components/TextBlock.h"
#include "Sound/SoundClass.h" #include "Sound/SoundClass.h"
@ -19,104 +23,127 @@ void UOptionsMenuWidget::NativeConstruct()
GenerateWindowTypeOptions(); GenerateWindowTypeOptions();
WindowTypeComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnWindowTypeSelectionChanged); WindowTypeComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnWindowTypeSelectionChanged);
WindowTypeComboBox->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnWindowTypeFocused);
GenerateResolutionOptions(); GenerateResolutionOptions();
ResolutionComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnResolutionSelectionChanged); ResolutionComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnResolutionSelectionChanged);
ResolutionComboBox->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnResolutionFocused);
GenerateDynamicResolutionOptions(); GenerateDynamicResolutionOptions();
DynamicResolutionComboBox->OnSelectionChanged.AddDynamic( DynamicResolutionComboBox->OnSelectionChanged.AddDynamic(
this, &UOptionsMenuWidget::OnDynamicResolutionSelectionChanged); this, &UOptionsMenuWidget::OnDynamicResolutionSelectionChanged);
DynamicResolutionComboBox->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnDynamicResolutionFocused);
GenerateVsyncOptions(); GenerateVsyncOptions();
VsyncComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnVsyncSelectionChanged); VsyncComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnVsyncSelectionChanged);
VsyncComboBox->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnVsyncFocused);
GenerateRefreshRateOptions(); GenerateRefreshRateOptions();
RefreshRateComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnRefreshRateSelectionChanged); RefreshRateComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnRefreshRateSelectionChanged);
RefreshRateComboBox->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnRefreshRateFocused);
GenerateAudioLevelOptions(); GenerateAudioLevelOptions();
MasterAudioSlider->OnValueChanged.AddDynamic(this, &UOptionsMenuWidget::OnAudioLeverValueChanged); MasterAudioSlider->OnValueChanged.AddDynamic(this, &UOptionsMenuWidget::OnAudioLeverValueChanged);
MasterAudioSlider->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnAudioFocused);
if (ResetToDefaultsButton) if (ResetToDefaultsButton)
{ {
ResetToDefaultsButton->OnClicked.AddUniqueDynamic(this, &UOptionsMenuWidget::ResetToDefaultsOnClicked); ResetToDefaultsButton->OnClicked.AddUniqueDynamic(this, &UOptionsMenuWidget::ResetToDefaultsOnClicked);
ResetToDefaultsButton->OnHovered.AddUniqueDynamic(this, &UOptionsMenuWidget::ResetToDefaultsButtonOnHovered); ResetToDefaultsButton->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnResetToDefaultsFocused);
ResetToDefaultsButton->OnUnhovered.AddUniqueDynamic(this, &UOptionsMenuWidget::ResetToDefaultsButtonOnUnhovered);
} }
if (ReturnButton) if (ReturnButton)
{ {
ReturnButton->OnClicked.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnButtonOnClicked); ReturnButton->OnClicked.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnButtonOnClicked);
ReturnButton->OnHovered.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnButtonOnHovered); ReturnButton->OnFocused.AddDynamic(this, &UOptionsMenuWidget::OnReturnButtonFocused);
ReturnButton->OnUnhovered.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnButtonOnUnhovered);
} }
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerController, WindowTypeComboBox,
EMouseLockMode::LockAlways);
PlayerController->bShowMouseCursor = true;
}
WindowTypeComboBox->SetKeyboardFocus();
}
FReply UOptionsMenuWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
if (CurrentFocus)
{
CurrentFocus->SetKeyboardFocus();
}
return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent);
} }
void UOptionsMenuWidget::GenerateWindowTypeOptions() void UOptionsMenuWidget::GenerateWindowTypeOptions()
{ {
WindowTypeComboBox->ClearOptions(); WindowTypeComboBox->ComboBox->ClearOptions();
WindowTypeComboBox->AddOption(LexToString(EWindowMode::Fullscreen)); WindowTypeComboBox->ComboBox->AddOption(LexToString(EWindowMode::Fullscreen));
WindowTypeComboBox->AddOption(LexToString(EWindowMode::WindowedFullscreen)); WindowTypeComboBox->ComboBox->AddOption(LexToString(EWindowMode::WindowedFullscreen));
WindowTypeComboBox->AddOption(LexToString(EWindowMode::Windowed)); WindowTypeComboBox->ComboBox->AddOption(LexToString(EWindowMode::Windowed));
WindowTypeComboBox->SetSelectedOption(LexToString(GEngine->GameUserSettings->GetFullscreenMode())); WindowTypeComboBox->ComboBox->SetSelectedOption(LexToString(GEngine->GameUserSettings->GetFullscreenMode()));
} }
void UOptionsMenuWidget::GenerateResolutionOptions() void UOptionsMenuWidget::GenerateResolutionOptions()
{ {
ResolutionComboBox->ClearOptions(); ResolutionComboBox->ComboBox->ClearOptions();
TArray<FIntPoint> Resolutions; TArray<FIntPoint> Resolutions;
UKismetSystemLibrary::GetSupportedFullscreenResolutions(Resolutions); UKismetSystemLibrary::GetSupportedFullscreenResolutions(Resolutions);
for (FIntPoint Resolution : Resolutions) for (FIntPoint Resolution : Resolutions)
{ {
ResolutionComboBox->AddOption(FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y)); ResolutionComboBox->ComboBox->AddOption(FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y));
} }
FVector2D Resolution = FVector2D::ZeroVector; FVector2D Resolution = FVector2D::ZeroVector;
GEngine->GameViewport->GetViewportSize(Resolution); GEngine->GameViewport->GetViewportSize(Resolution);
FString ResolutionString = FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y); FString ResolutionString = FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y);
if (ResolutionComboBox->FindOptionIndex(ResolutionString) == -1) if (ResolutionComboBox->ComboBox->FindOptionIndex(ResolutionString) == -1)
{ {
ResolutionComboBox->AddOption(ResolutionString); ResolutionComboBox->ComboBox->AddOption(ResolutionString);
} }
ResolutionComboBox->SetSelectedOption(ResolutionString); ResolutionComboBox->ComboBox->SetSelectedOption(ResolutionString);
} }
void UOptionsMenuWidget::GenerateDynamicResolutionOptions() void UOptionsMenuWidget::GenerateDynamicResolutionOptions()
{ {
DynamicResolutionComboBox->ClearOptions(); DynamicResolutionComboBox->ComboBox->ClearOptions();
DynamicResolutionComboBox->AddOption("Enabled"); DynamicResolutionComboBox->ComboBox->AddOption("Enabled");
DynamicResolutionComboBox->AddOption("Disabled"); DynamicResolutionComboBox->ComboBox->AddOption("Disabled");
if (GEngine->GameUserSettings->IsDynamicResolutionEnabled()) if (GEngine->GameUserSettings->IsDynamicResolutionEnabled())
{ {
DynamicResolutionComboBox->SetSelectedOption("Enabled"); DynamicResolutionComboBox->ComboBox->SetSelectedOption("Enabled");
} }
else else
{ {
DynamicResolutionComboBox->SetSelectedOption("Disabled"); DynamicResolutionComboBox->ComboBox->SetSelectedOption("Disabled");
} }
} }
void UOptionsMenuWidget::GenerateVsyncOptions() void UOptionsMenuWidget::GenerateVsyncOptions()
{ {
VsyncComboBox->ClearOptions(); VsyncComboBox->ComboBox->ClearOptions();
VsyncComboBox->AddOption("Enabled"); VsyncComboBox->ComboBox->AddOption("Enabled");
VsyncComboBox->AddOption("Disabled"); VsyncComboBox->ComboBox->AddOption("Disabled");
if (GEngine->GameUserSettings->IsVSyncEnabled()) if (GEngine->GameUserSettings->IsVSyncEnabled())
{ {
VsyncComboBox->SetSelectedOption("Enabled"); VsyncComboBox->ComboBox->SetSelectedOption("Enabled");
} }
else else
{ {
VsyncComboBox->SetSelectedOption("Disabled"); VsyncComboBox->ComboBox->SetSelectedOption("Disabled");
} }
} }
void UOptionsMenuWidget::GenerateRefreshRateOptions() void UOptionsMenuWidget::GenerateRefreshRateOptions()
{ {
RefreshRateComboBox->ClearOptions(); RefreshRateComboBox->ComboBox->ClearOptions();
TArray<uint32> RefreshRates; TArray<uint32> RefreshRates;
@ -124,20 +151,20 @@ void UOptionsMenuWidget::GenerateRefreshRateOptions()
for (uint32 RefreshRate : RefreshRates) for (uint32 RefreshRate : RefreshRates)
{ {
RefreshRateComboBox->AddOption(FString::FromInt(RefreshRate)); RefreshRateComboBox->ComboBox->AddOption(FString::FromInt(RefreshRate));
} }
RefreshRateComboBox->AddOption("Unlimited"); RefreshRateComboBox->ComboBox->AddOption("Unlimited");
float FrameRateLimit = GEngine->GameUserSettings->GetFrameRateLimit(); float FrameRateLimit = GEngine->GameUserSettings->GetFrameRateLimit();
if (FrameRateLimit > 0.0f) if (FrameRateLimit > 0.0f)
{ {
RefreshRateComboBox->SetSelectedOption(FString::FromInt(FrameRateLimit)); RefreshRateComboBox->ComboBox->SetSelectedOption(FString::FromInt(FrameRateLimit));
} }
else else
{ {
RefreshRateComboBox->SetSelectedOption("Unlimited"); RefreshRateComboBox->ComboBox->SetSelectedOption("Unlimited");
} }
} }
@ -147,13 +174,18 @@ void UOptionsMenuWidget::GenerateAudioLevelOptions()
{ {
float CurrentVolume = FMath::Clamp(MasterSoundClass->Properties.Volume, 0.0f, 1.0f); float CurrentVolume = FMath::Clamp(MasterSoundClass->Properties.Volume, 0.0f, 1.0f);
MasterAudioSlider->SetValue(CurrentVolume); MasterAudioSlider->SliderBody->SetValue(CurrentVolume);
int AudioLevel = CurrentVolume * 100.0f; int AudioLevel = CurrentVolume * 100.0f;
MasterAudioTextBlock->SetText(FText::FromString(FString::FromInt(AudioLevel) + "%")); MasterAudioTextBlock->SetText(FText::FromString(FString::FromInt(AudioLevel) + "%"));
} }
} }
void UOptionsMenuWidget::OnResolutionFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(ResolutionComboBox);
}
void UOptionsMenuWidget::OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType) void UOptionsMenuWidget::OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
{ {
FString Horizontal; FString Horizontal;
@ -171,6 +203,10 @@ void UOptionsMenuWidget::OnResolutionSelectionChanged(FString SelectedItem, ESel
GEngine->GameUserSettings->ApplySettings(false); GEngine->GameUserSettings->ApplySettings(false);
} }
void UOptionsMenuWidget::OnWindowTypeFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(WindowTypeComboBox);
}
void UOptionsMenuWidget::OnWindowTypeSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType) void UOptionsMenuWidget::OnWindowTypeSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
{ {
@ -209,12 +245,17 @@ void UOptionsMenuWidget::SetWindowModeWindowed()
GEngine->GameViewport->GetViewportSize(Resolution); GEngine->GameViewport->GetViewportSize(Resolution);
FString ResolutionString = FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y); FString ResolutionString = FString::FromInt(Resolution.X) + "x" + FString::FromInt(Resolution.Y);
if (ResolutionComboBox->FindOptionIndex(ResolutionString) == -1) if (ResolutionComboBox->ComboBox->FindOptionIndex(ResolutionString) == -1)
{ {
ResolutionComboBox->AddOption(ResolutionString); ResolutionComboBox->ComboBox->AddOption(ResolutionString);
} }
ResolutionComboBox->SetSelectedOption(ResolutionString); ResolutionComboBox->ComboBox->SetSelectedOption(ResolutionString);
}
void UOptionsMenuWidget::OnDynamicResolutionFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(DynamicResolutionComboBox);
} }
void UOptionsMenuWidget::OnDynamicResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType) void UOptionsMenuWidget::OnDynamicResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
@ -231,6 +272,11 @@ void UOptionsMenuWidget::OnDynamicResolutionSelectionChanged(FString SelectedIte
GEngine->GameUserSettings->ApplySettings(false); GEngine->GameUserSettings->ApplySettings(false);
} }
void UOptionsMenuWidget::OnVsyncFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(VsyncComboBox);
}
void UOptionsMenuWidget::OnVsyncSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType) void UOptionsMenuWidget::OnVsyncSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
{ {
if (SelectedItem == "Enabled") if (SelectedItem == "Enabled")
@ -245,12 +291,22 @@ void UOptionsMenuWidget::OnVsyncSelectionChanged(FString SelectedItem, ESelectIn
GEngine->GameUserSettings->ApplySettings(false); GEngine->GameUserSettings->ApplySettings(false);
} }
void UOptionsMenuWidget::OnRefreshRateFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(RefreshRateComboBox);
}
void UOptionsMenuWidget::OnRefreshRateSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType) void UOptionsMenuWidget::OnRefreshRateSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
{ {
GEngine->GameUserSettings->SetFrameRateLimit(FCString::Atoi(*SelectedItem)); GEngine->GameUserSettings->SetFrameRateLimit(FCString::Atoi(*SelectedItem));
GEngine->GameUserSettings->ApplySettings(false); GEngine->GameUserSettings->ApplySettings(false);
} }
void UOptionsMenuWidget::OnAudioFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(MasterAudioSlider);
}
void UOptionsMenuWidget::OnAudioLeverValueChanged(float Value) void UOptionsMenuWidget::OnAudioLeverValueChanged(float Value)
{ {
if (MasterSoundClass) if (MasterSoundClass)
@ -263,10 +319,13 @@ void UOptionsMenuWidget::OnAudioLeverValueChanged(float Value)
} }
} }
void UOptionsMenuWidget::OnResetToDefaultsFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(ResetToDefaultsButton);
}
void UOptionsMenuWidget::ResetToDefaultsOnClicked() void UOptionsMenuWidget::ResetToDefaultsOnClicked()
{ {
PlayClickedSound();
// Set Resolution to Monitor Res // Set Resolution to Monitor Res
TArray<FIntPoint> Resolutions; TArray<FIntPoint> Resolutions;
UKismetSystemLibrary::GetSupportedFullscreenResolutions(Resolutions); UKismetSystemLibrary::GetSupportedFullscreenResolutions(Resolutions);
@ -276,47 +335,50 @@ void UOptionsMenuWidget::ResetToDefaultsOnClicked()
GEngine->GameUserSettings->SetScreenResolution(Resolutions.Last()); GEngine->GameUserSettings->SetScreenResolution(Resolutions.Last());
FString ResolutionString = FString::FromInt(Resolutions.Last().X) + "x" + FString ResolutionString = FString::FromInt(Resolutions.Last().X) + "x" +
FString::FromInt(Resolutions.Last().Y); FString::FromInt(Resolutions.Last().Y);
ResolutionComboBox->SetSelectedOption(ResolutionString); ResolutionComboBox->ComboBox->SetSelectedOption(ResolutionString);
} }
else else
{ {
// Fallback to 1080p // Fallback to 1080p
GEngine->GameUserSettings->SetScreenResolution({1920, 1080}); GEngine->GameUserSettings->SetScreenResolution({1920, 1080});
FString ResolutionString = FString::FromInt(1920) + "x" + FString::FromInt(1080); FString ResolutionString = FString::FromInt(1920) + "x" + FString::FromInt(1080);
ResolutionComboBox->SetSelectedOption(ResolutionString); ResolutionComboBox->ComboBox->SetSelectedOption(ResolutionString);
} }
// Set Fullscreen // Set Fullscreen
GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Fullscreen); GEngine->GameUserSettings->SetFullscreenMode(EWindowMode::Fullscreen);
WindowTypeComboBox->SetSelectedOption(LexToString(GEngine->GameUserSettings->GetFullscreenMode())); WindowTypeComboBox->ComboBox->SetSelectedOption(LexToString(GEngine->GameUserSettings->GetFullscreenMode()));
// Set Dynamic Resolution on // Set Dynamic Resolution on
GEngine->GameUserSettings->SetDynamicResolutionEnabled(true); GEngine->GameUserSettings->SetDynamicResolutionEnabled(true);
DynamicResolutionComboBox->SetSelectedOption("Enabled"); DynamicResolutionComboBox->ComboBox->SetSelectedOption("Enabled");
// Set VSync Off // Set VSync Off
GEngine->GameUserSettings->SetVSyncEnabled(false); GEngine->GameUserSettings->SetVSyncEnabled(false);
VsyncComboBox->SetSelectedOption("Disabled"); VsyncComboBox->ComboBox->SetSelectedOption("Disabled");
// Set Refresh rate to monitor refresh rate // Set Refresh rate to monitor refresh rate
TArray<uint32> RefreshRates; TArray<uint32> RefreshRates;
GetListOfUniqueRefreshRates(RefreshRates); GetListOfUniqueRefreshRates(RefreshRates);
GEngine->GameUserSettings->SetFrameRateLimit(RefreshRates.Last()); GEngine->GameUserSettings->SetFrameRateLimit(RefreshRates.Last());
RefreshRateComboBox->SetSelectedOption(FString::FromInt(RefreshRates.Last())); RefreshRateComboBox->ComboBox->SetSelectedOption(FString::FromInt(RefreshRates.Last()));
// Set Audio Volume to 50% // Set Audio Volume to 50%
MasterSoundClass->Properties.Volume = 0.5f; MasterSoundClass->Properties.Volume = 0.5f;
MasterAudioTextBlock->SetText(FText::FromString(FString::FromInt(50) + "%")); MasterAudioTextBlock->SetText(FText::FromString(FString::FromInt(50) + "%"));
MasterAudioSlider->SetValue(0.5f); MasterAudioSlider->SliderBody->SetValue(0.5f);
// Save Settings // Save Settings
GEngine->GameUserSettings->ApplySettings(false); GEngine->GameUserSettings->ApplySettings(false);
} }
void UOptionsMenuWidget::OnReturnButtonFocused(FFocusEvent InFocusEvent)
{
SetCurrentFocus(ReturnButton);
}
void UOptionsMenuWidget::ReturnButtonOnClicked() void UOptionsMenuWidget::ReturnButtonOnClicked()
{ {
PlayClickedSound();
if (MainMenuMenuWidget) if (MainMenuMenuWidget)
{ {
RemoveFromParent(); RemoveFromParent();
@ -331,30 +393,6 @@ void UOptionsMenuWidget::ReturnButtonOnClicked()
} }
} }
void UOptionsMenuWidget::ResetToDefaultsButtonOnHovered()
{
PlayHoveredSound();
SetTextBlockHovered(ResetToDefaultsBlock);
}
void UOptionsMenuWidget::ResetToDefaultsButtonOnUnhovered()
{
PlayUnhoveredSound();
SetTextBlockUnhovered(ResetToDefaultsBlock);
}
void UOptionsMenuWidget::ReturnButtonOnHovered()
{
PlayHoveredSound();
SetTextBlockHovered(ReturnBlock);
}
void UOptionsMenuWidget::ReturnButtonOnUnhovered()
{
PlayUnhoveredSound();
SetTextBlockUnhovered(ReturnBlock);
}
void UOptionsMenuWidget::GetListOfUniqueRefreshRates(TArray<uint32>& RefreshRates) void UOptionsMenuWidget::GetListOfUniqueRefreshRates(TArray<uint32>& RefreshRates)
{ {
FScreenResolutionArray ScreenResolutions; FScreenResolutionArray ScreenResolutions;

View File

@ -6,9 +6,13 @@
#include "VampireInteractiveWidget.h" #include "VampireInteractiveWidget.h"
#include "OptionsMenuWidget.generated.h" #include "OptionsMenuWidget.generated.h"
class UCustomSlider;
class UCustomComboBoxString;
class USlider; class USlider;
class UComboBoxString; class UComboBoxString;
class UButton; class UButton;
class UCustomButton;
/** /**
* *
*/ */
@ -18,40 +22,34 @@ class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
GENERATED_BODY() GENERATED_BODY()
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> ResolutionComboBox; TObjectPtr<UCustomComboBoxString> ResolutionComboBox;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UTextBlock> ResolutionTextBlock; TObjectPtr<UTextBlock> ResolutionTextBlock;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> WindowTypeComboBox; TObjectPtr<UCustomComboBoxString> WindowTypeComboBox;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> VsyncComboBox; TObjectPtr<UCustomComboBoxString> VsyncComboBox;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> RefreshRateComboBox; TObjectPtr<UCustomComboBoxString> RefreshRateComboBox;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UComboBoxString> DynamicResolutionComboBox; TObjectPtr<UCustomComboBoxString> DynamicResolutionComboBox;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<USlider> MasterAudioSlider; TObjectPtr<UCustomSlider> MasterAudioSlider;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UTextBlock> MasterAudioTextBlock; TObjectPtr<UTextBlock> MasterAudioTextBlock;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UButton> ReturnButton; TObjectPtr<UCustomButton> ReturnButton;
UPROPERTY(meta = (BindWidget)) UPROPERTY(meta = (BindWidget))
TObjectPtr<UTextBlock> ReturnBlock; TObjectPtr<UCustomButton> ResetToDefaultsButton;
UPROPERTY(meta = (BindWidget))
TObjectPtr<UButton> ResetToDefaultsButton;
UPROPERTY(meta = (BindWidget))
TObjectPtr<UTextBlock> ResetToDefaultsBlock;
UPROPERTY(EditDefaultsOnly, Category = "Widget Settings | New Game") UPROPERTY(EditDefaultsOnly, Category = "Widget Settings | New Game")
TSubclassOf<UUserWidget> MainMenuMenuWidget; TSubclassOf<UUserWidget> MainMenuMenuWidget;
@ -62,6 +60,8 @@ class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
UFUNCTION() UFUNCTION()
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
virtual FReply NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
void GenerateWindowTypeOptions(); void GenerateWindowTypeOptions();
void GenerateResolutionOptions(); void GenerateResolutionOptions();
@ -74,44 +74,56 @@ class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
void GenerateAudioLevelOptions(); void GenerateAudioLevelOptions();
UFUNCTION()
void OnResolutionFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType); void OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
UFUNCTION()
void OnWindowTypeFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void OnWindowTypeSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType); void OnWindowTypeSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
void SetWindowModeFullscreen(); void SetWindowModeFullscreen();
void SetWindowModeWindowedFullscreen(); void SetWindowModeWindowedFullscreen();
void SetWindowModeWindowed(); void SetWindowModeWindowed();
UFUNCTION()
void OnDynamicResolutionFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void OnDynamicResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType); void OnDynamicResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
UFUNCTION()
void OnVsyncFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void OnVsyncSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType); void OnVsyncSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
UFUNCTION()
void OnRefreshRateFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void OnRefreshRateSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType); void OnRefreshRateSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
UFUNCTION()
void OnAudioFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void OnAudioLeverValueChanged(float Value); void OnAudioLeverValueChanged(float Value);
UFUNCTION()
void OnResetToDefaultsFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void ResetToDefaultsOnClicked(); void ResetToDefaultsOnClicked();
UFUNCTION()
void OnReturnButtonFocused(FFocusEvent InFocusEvent);
UFUNCTION() UFUNCTION()
void ReturnButtonOnClicked(); void ReturnButtonOnClicked();
UFUNCTION()
void ResetToDefaultsButtonOnHovered();
UFUNCTION()
void ResetToDefaultsButtonOnUnhovered();
UFUNCTION()
void ReturnButtonOnHovered();
UFUNCTION()
void ReturnButtonOnUnhovered();
void GetListOfUniqueRefreshRates(TArray<uint32>& RefreshRates); void GetListOfUniqueRefreshRates(TArray<uint32>& RefreshRates);
}; };