This repository has been archived on 2024-07-09. You can view files and clone it, but cannot push or open issues or pull requests.
everellia/SheKnowsWhatYouAreToHerGame/Assets/Scripts/OptionsMenu.cs

90 lines
3 KiB
C#
Raw Permalink Normal View History

2024-07-03 18:36:39 +00:00
/*
* author: mark joshwel
* date: 30/5/2024
* description: options menu script for handling credits menu button functions
*/
using UnityEngine.UIElements;
/// <summary>
2024-07-03 20:37:15 +00:00
/// class managing the credits menu and button function invocations
2024-07-03 18:36:39 +00:00
/// </summary>
public class OptionsMenu : CommonMenu
{
/// <summary>
/// button to return to the main menu
2024-07-03 18:36:39 +00:00
/// </summary>
public Button ButtonReturn;
/// <summary>
2024-07-03 20:37:15 +00:00
/// slider for music volume
2024-07-03 18:36:39 +00:00
/// </summary>
public Slider SliderAudioMusic;
/// <summary>
2024-07-03 20:37:15 +00:00
/// slider for sfx volume
2024-07-03 18:36:39 +00:00
/// </summary>
public Slider SliderAudioSfx;
/// <summary>
2024-07-03 20:37:15 +00:00
/// function to associate a display state with the menu,
/// and subscribe button events to their respective functions
2024-07-03 18:36:39 +00:00
/// </summary>
public override void OnEnable()
{
2024-07-03 20:50:59 +00:00
// set the associated state and call the base OnEnable
2024-07-03 18:36:39 +00:00
associatedState = GameManager.DisplayState.ScreenOptionsMenu;
base.OnEnable();
// get the start button from the ui root and subscribe appropriate functions
ButtonReturn = UI.Q<Button>("ButtonReturn");
ButtonReturn.clicked += PlayClick;
ButtonReturn.clicked += OptionReturnToMainMenu;
// get the music slider from the ui root
SliderAudioMusic = UI.Q<Slider>("Music");
// and set the initial value to the current music volume
SliderAudioMusic.value = Audio.GetMusicVolume() * 100;
// and subscribe appropriate functions
SliderAudioMusic.RegisterCallback<ChangeEvent<float>>(OptionSetMusicVolume);
// get the sfx slider from the ui root
SliderAudioSfx = UI.Q<Slider>("SFX");
// and set the initial value to the current sfx volume
SliderAudioSfx.value = Audio.GetSfxVolume() * 100;
// and subscribe appropriate functions
SliderAudioSfx.RegisterCallback<ChangeEvent<float>>(OptionSetSfxVolume);
}
/// <summary>
/// handles return to the main menu button press,
2024-07-03 20:37:15 +00:00
/// signals the game manager appropriately
2024-07-03 18:36:39 +00:00
/// </summary>
private void OptionReturnToMainMenu()
{
// return to the main menu
2024-07-03 18:36:39 +00:00
Game.SetDisplayState(GameManager.DisplayState.ScreenMainMenu);
}
/// <summary>
2024-07-03 20:37:15 +00:00
/// handle music volume slider change,
/// sets the music channel volume in the audio manager appropriately
2024-07-03 18:36:39 +00:00
/// </summary>
/// <param name="evt"></param>
private void OptionSetMusicVolume(ChangeEvent<float> evt)
{
// slider is from 0 to 100, convert to 0 to 1, and set
Audio.SetMusicVolume(evt.newValue / 100);
}
/// <summary>
2024-07-03 20:37:15 +00:00
/// handle sfx volume slider change,
/// sets the sfx channel volume in the audio manager appropriately
2024-07-03 18:36:39 +00:00
/// </summary>
/// <param name="evt"></param>
private void OptionSetSfxVolume(ChangeEvent<float> evt)
{
// slider is from 0 to 100, convert to 0 to 1, and set
Audio.SetSfxVolume(evt.newValue / 100);
}
}