game(ui,scripts): interim options menu

This commit is contained in:
sippy-thinks 2024-08-11 14:52:08 +08:00
parent b9141cf5ee
commit 43399cf933
2 changed files with 33 additions and 9 deletions

View file

@ -16,6 +16,11 @@ public class ScreenOptionsMenu : CommonMenu
/// </summary> /// </summary>
public Button ButtonReturn; public Button ButtonReturn;
/// <summary>
/// slider for master (music + sfx) volume
/// </summary>
public Slider SliderAudioMaster;
/// <summary> /// <summary>
/// slider for music volume /// slider for music volume
/// </summary> /// </summary>
@ -25,7 +30,7 @@ public class ScreenOptionsMenu : CommonMenu
/// slider for sfx volume /// slider for sfx volume
/// </summary> /// </summary>
public Slider SliderAudioSfx; public Slider SliderAudioSfx;
/// <summary> /// <summary>
/// function to associate a display state with the menu, /// function to associate a display state with the menu,
/// and subscribe button events to their respective functions /// and subscribe button events to their respective functions
@ -42,14 +47,21 @@ public override void OnEnable()
ButtonReturn.clicked += OptionReturnToMainMenu; ButtonReturn.clicked += OptionReturnToMainMenu;
// get the music slider from the ui root // get the music slider from the ui root
SliderAudioMusic = UI.Q<Slider>("Music"); SliderAudioMaster = UI.Q<Slider>("MasterSlider");
// TODO: and set the initial value to the current music volume
// SliderAudioMusic.value = Audio.GetMusicVolume() * 100;
// and subscribe appropriate functions
SliderAudioMaster.RegisterCallback<ChangeEvent<float>>(OptionSetMasterVolume);
// get the music slider from the ui root
SliderAudioMusic = UI.Q<Slider>("MusicSlider");
// TODO: and set the initial value to the current music volume // TODO: and set the initial value to the current music volume
// SliderAudioMusic.value = Audio.GetMusicVolume() * 100; // SliderAudioMusic.value = Audio.GetMusicVolume() * 100;
// and subscribe appropriate functions // and subscribe appropriate functions
SliderAudioMusic.RegisterCallback<ChangeEvent<float>>(OptionSetMusicVolume); SliderAudioMusic.RegisterCallback<ChangeEvent<float>>(OptionSetMusicVolume);
// get the sfx slider from the ui root // get the sfx slider from the ui root
SliderAudioSfx = UI.Q<Slider>("SFX"); SliderAudioSfx = UI.Q<Slider>("SFXSlider");
// TODO: and set the initial value to the current sfx volume // TODO: and set the initial value to the current sfx volume
// SliderAudioSfx.value = Audio.GetSfxVolume() * 100; // SliderAudioSfx.value = Audio.GetSfxVolume() * 100;
// and subscribe appropriate functions // and subscribe appropriate functions
@ -65,12 +77,23 @@ private void OptionReturnToMainMenu()
// return to the main menu // return to the main menu
Game.SetDisplayState(GameManager.DisplayState.ScreenMainMenu); Game.SetDisplayState(GameManager.DisplayState.ScreenMainMenu);
} }
/// <summary> /// <summary>
/// handle music volume slider change, /// handle music volume slider change,
/// sets the music channel volume in the audio manager appropriately /// sets the music channel volume in the audio manager appropriately
/// </summary> /// </summary>
/// <param name="evt"></param> /// <param name="evt">change event</param>
private void OptionSetMasterVolume(ChangeEvent<float> evt)
{
// TODO: slider is from 0 to 100, convert to 0 to 1, and set
// Audio.SetMusicVolume(evt.newValue / 100);
}
/// <summary>
/// handle music volume slider change,
/// sets the music channel volume in the audio manager appropriately
/// </summary>
/// <param name="evt">change event</param>
private void OptionSetMusicVolume(ChangeEvent<float> evt) private void OptionSetMusicVolume(ChangeEvent<float> evt)
{ {
// TODO: slider is from 0 to 100, convert to 0 to 1, and set // TODO: slider is from 0 to 100, convert to 0 to 1, and set
@ -81,7 +104,7 @@ private void OptionSetMusicVolume(ChangeEvent<float> evt)
/// handle sfx volume slider change, /// handle sfx volume slider change,
/// sets the sfx channel volume in the audio manager appropriately /// sets the sfx channel volume in the audio manager appropriately
/// </summary> /// </summary>
/// <param name="evt"></param> /// <param name="evt">change event</param>
private void OptionSetSfxVolume(ChangeEvent<float> evt) private void OptionSetSfxVolume(ChangeEvent<float> evt)
{ {
// TODO: slider is from 0 to 100, convert to 0 to 1, and set // TODO: slider is from 0 to 100, convert to 0 to 1, and set

View file

@ -4,8 +4,9 @@
<ui:VisualElement name="HoriHolder" style="flex-grow: 1; flex-direction: column; max-height: 60%; margin-left: 10%; margin-right: 10%;"> <ui:VisualElement name="HoriHolder" style="flex-grow: 1; flex-direction: column; max-height: 60%; margin-left: 10%; margin-right: 10%;">
<ui:VisualElement name="Logospace" style="flex-grow: 1; width: auto; flex-direction: row; padding-bottom: 6%; height: 50%; min-height: 50%;" /> <ui:VisualElement name="Logospace" style="flex-grow: 1; width: auto; flex-direction: row; padding-bottom: 6%; height: 50%; min-height: 50%;" />
<ui:VisualElement name="Buttonspace" style="flex-grow: 1; width: 50%; min-width: 50%; height: 50%; min-height: 50%; align-items: center; justify-content: flex-end; align-self: center;"> <ui:VisualElement name="Buttonspace" style="flex-grow: 1; width: 50%; min-width: 50%; height: 50%; min-height: 50%; align-items: center; justify-content: flex-end; align-self: center;">
<ui:Slider label="Music" high-value="100" name="Music" style="justify-content: space-around; align-items: stretch; align-self: stretch;" /> <ui:Slider label="Master" high-value="100" name="MasterSlider" style="justify-content: space-around; align-items: stretch; align-self: stretch;" />
<ui:Slider label="Effects" high-value="100" name="SFX" style="align-self: stretch; padding-bottom: 0; margin-bottom: 10%; justify-content: space-around;" /> <ui:Slider label="Music" high-value="100" name="MusicSlider" style="justify-content: space-around; align-items: stretch; align-self: stretch;" />
<ui:Slider label="Effects" high-value="100" name="SFXSlider" style="align-self: stretch; padding-bottom: 0; margin-bottom: 10%; justify-content: space-around;" />
<ui:Button text="Return" parse-escape-sequences="true" display-tooltip-when-elided="true" name="ButtonReturn" /> <ui:Button text="Return" parse-escape-sequences="true" display-tooltip-when-elided="true" name="ButtonReturn" />
</ui:VisualElement> </ui:VisualElement>
</ui:VisualElement> </ui:VisualElement>