Add Audio Volume slider to Options menu
This commit is contained in:
parent
b369bed850
commit
7932d9ba34
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,12 +3,16 @@
|
||||
|
||||
#include "OptionsMenuWidget.h"
|
||||
|
||||
#include "AudioMixerDevice.h"
|
||||
#include "Components/Button.h"
|
||||
#include "Components/ComboBoxString.h"
|
||||
#include "GameFramework/GameUserSettings.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "RHI.h"
|
||||
#include "Components/Slider.h"
|
||||
#include "Components/TextBlock.h"
|
||||
#include "Sound/SoundClass.h"
|
||||
|
||||
void UOptionsMenuWidget::NativeConstruct()
|
||||
{
|
||||
@ -30,6 +34,9 @@ void UOptionsMenuWidget::NativeConstruct()
|
||||
GenerateRefreshRateOptions();
|
||||
RefreshRateComboBox->OnSelectionChanged.AddDynamic(this, &UOptionsMenuWidget::OnRefreshRateSelectionChanged);
|
||||
|
||||
GenerateAudioLevelOptions();
|
||||
MasterAudioSlider->OnValueChanged.AddDynamic(this, &UOptionsMenuWidget::OnAudioLeverValueChanged);
|
||||
|
||||
if (ReturnButton)
|
||||
{
|
||||
ReturnButton->OnClicked.AddUniqueDynamic(this, &UOptionsMenuWidget::ReturnButtonOnClicked);
|
||||
@ -138,6 +145,19 @@ void UOptionsMenuWidget::GenerateRefreshRateOptions()
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::GenerateAudioLevelOptions()
|
||||
{
|
||||
if (MasterSoundClass)
|
||||
{
|
||||
float CurrentVolume = FMath::Clamp(MasterSoundClass->Properties.Volume, 0.0f, 1.0f);
|
||||
|
||||
MasterAudioSlider->SetValue(CurrentVolume);
|
||||
|
||||
int AudioLevel = CurrentVolume * 100.0f;
|
||||
MasterAudioTextBlock->SetText(FText::FromString(FString::FromInt(AudioLevel) + "%"));
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
|
||||
{
|
||||
FString Horizontal;
|
||||
@ -235,6 +255,18 @@ void UOptionsMenuWidget::OnRefreshRateSelectionChanged(FString SelectedItem, ESe
|
||||
GEngine->GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::OnAudioLeverValueChanged(float Value)
|
||||
{
|
||||
if (MasterSoundClass)
|
||||
{
|
||||
MasterSoundClass->Properties.Volume = FMath::Clamp(Value, 0.0f, 1.0f);
|
||||
|
||||
int AudioLevel = FMath::Clamp(Value, 0.0f, 1.0f) * 100.0f;
|
||||
|
||||
MasterAudioTextBlock->SetText(FText::FromString(FString::FromInt(AudioLevel) + "%"));
|
||||
}
|
||||
}
|
||||
|
||||
void UOptionsMenuWidget::ReturnButtonOnClicked()
|
||||
{
|
||||
if (MainMenuMenuWidget)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "VampireInteractiveWidget.h"
|
||||
#include "OptionsMenuWidget.generated.h"
|
||||
|
||||
class USlider;
|
||||
class UComboBoxString;
|
||||
class UButton;
|
||||
/**
|
||||
@ -33,6 +34,12 @@ class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UComboBoxString> DynamicResolutionComboBox;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<USlider> MasterAudioSlider;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UTextBlock> MasterAudioTextBlock;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
TObjectPtr<UButton> ReturnButton;
|
||||
@ -49,7 +56,11 @@ class VAMPIRES_API UOptionsMenuWidget : public UVampireInteractiveWidget
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Widget Settings | New Game")
|
||||
TSubclassOf<UUserWidget> MainMenuMenuWidget;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Widget Settings | Sound Settings")
|
||||
TObjectPtr<USoundClass> MasterSoundClass = nullptr;
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
@ -63,6 +74,8 @@ private:
|
||||
|
||||
void GenerateRefreshRateOptions();
|
||||
|
||||
void GenerateAudioLevelOptions();
|
||||
|
||||
UFUNCTION()
|
||||
void OnResolutionSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
|
||||
|
||||
@ -81,6 +94,9 @@ private:
|
||||
UFUNCTION()
|
||||
void OnRefreshRateSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
|
||||
|
||||
UFUNCTION()
|
||||
void OnAudioLeverValueChanged(float Value);
|
||||
|
||||
UFUNCTION()
|
||||
void ReturnButtonOnClicked();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user