Compare commits

...

2 Commits

Author SHA1 Message Date
baz
7932d9ba34 Add Audio Volume slider to Options menu 2025-08-12 00:42:03 +01:00
baz
b369bed850 Assign Sounds to Sound Class 2025-08-12 00:41:44 +01:00
12 changed files with 69 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/Sounds/SC_GameMaster.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

View File

@ -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)

View File

@ -6,6 +6,7 @@
#include "VampireInteractiveWidget.h"
#include "OptionsMenuWidget.generated.h"
class USlider;
class UComboBoxString;
class UButton;
/**
@ -34,6 +35,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();