Skip to content

Commit

Permalink
Add new settings, and bind to FrameworkConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnoyingRain5 committed Dec 1, 2023
1 parent 313ad00 commit 16e6fde
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 35 deletions.
1 change: 0 additions & 1 deletion CrankItUp.Game/src/CrankItUpGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private void load(Storage store)
// Read the stream as a string, and write the string to the console.
var settings = JObject.Parse(sr.ReadToEnd());
Settings.inputmode = (Settings.InputMode)settings.GetValue<int>("inputMode");
Settings.volume.Value = settings.GetValue<double>("volume");
}
catch
{
Expand Down
134 changes: 104 additions & 30 deletions CrankItUp.Game/src/Screens/SettingsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
using osu.Framework.Audio;
using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Framework.Configuration;
using Newtonsoft.Json.Linq;
using System.IO;
using NuGet.Protocol;
using osu.Framework.Platform;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;

namespace CrankItUp.Game
{
Expand All @@ -25,66 +27,119 @@ public enum InputMode
Linear
}

// init vars
public static BindableDouble volume = new BindableDouble
{
Default = 0.5,
Value = 0.5,
MinValue = 0,
MaxValue = 1
};
public static InputMode inputmode = InputMode.Rotational;
}

public partial class SettingsScreen : Screen
{
CIUButton inputModeButton;
CIUButton windowModeButton;
CIUButton backButton;
CIUButton setupButton;
SpriteText volumeText;
BasicSliderBar<double> volumeSlider;
SpriteText globalVolumeText;
BasicSliderBar<double> globalVolumeSlider;
SpriteText musicVolumeText;
private BasicSliderBar<double> musicVolumeSlider;
private SpriteText effectsVolumeText;
private BasicSliderBar<double> effectsVolumeSlider;
Storage storage;
Bindable<WindowMode> windowModeBindable;

[BackgroundDependencyLoader]
private void load(AudioManager audio, TextureStore textures, Storage store)
private void load(
AudioManager audio,
TextureStore textures,
Storage store,
FrameworkConfigManager frameworkConfig
)
{
storage = store;
audio.AddAdjustment(AdjustableProperty.Volume, Settings.volume);
volumeText = new SpriteText
globalVolumeText = new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, -170),
Text = "Global Volume",
Colour = Color4.White,
};
globalVolumeSlider = new BasicSliderBar<double>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, -140),
Size = new Vector2(200, 20),
RangePadding = 20,
BackgroundColour = Color4.White,
SelectionColour = Color4.Blue,
KeyboardStep = 0.1f,
Current = frameworkConfig.GetBindable<double>(FrameworkSetting.VolumeUniversal)
};
musicVolumeText = new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, -110),
Text = "Music Volume",
Colour = Color4.White,
};
musicVolumeSlider = new BasicSliderBar<double>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, -80),
Size = new Vector2(200, 20),
RangePadding = 20,
BackgroundColour = Color4.White,
SelectionColour = Color4.Blue,
KeyboardStep = 0.1f,
Current = frameworkConfig.GetBindable<double>(FrameworkSetting.VolumeMusic)
};
effectsVolumeText = new SpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, -30),
Text = "Volume",
Position = new Vector2(0, -50),
Text = "Effects Volume",
Colour = Color4.White,
};
volumeSlider = new BasicSliderBar<double>
effectsVolumeSlider = new BasicSliderBar<double>
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, -10),
Position = new Vector2(0, -20),
Size = new Vector2(200, 20),
RangePadding = 20,
BackgroundColour = Color4.White,
SelectionColour = Color4.Blue,
KeyboardStep = 1,
Current = Settings.volume
KeyboardStep = 0.1f,
Current = frameworkConfig.GetBindable<double>(FrameworkSetting.VolumeEffect)
};
inputModeButton = new CIUButton(textures)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 30),
Text = "Input Mode: " + Settings.inputmode.ToString(),
Text = "Input mode: " + Settings.inputmode.ToString(),
Size = new Vector2(200, 40),
Margin = new MarginPadding(10),
Action = () => changeInputMode(),
};
setupButton = new CIUButton(textures)
windowModeButton = new CIUButton(textures)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 80),
Text =
"Window type: " + frameworkConfig.Get<WindowMode>(FrameworkSetting.WindowMode),
Size = new Vector2(200, 40),
Margin = new MarginPadding(10),
Action = () => changeWindowMode(frameworkConfig),
};
setupButton = new CIUButton(textures)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 130),
Text = "Restart initial setup",
Size = new Vector2(200, 40),
Margin = new MarginPadding(10),
Expand All @@ -94,7 +149,7 @@ private void load(AudioManager audio, TextureStore textures, Storage store)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 130),
Position = new Vector2(0, 180),
Text = "Back to menu",
Size = new Vector2(200, 40),
Margin = new MarginPadding(10),
Expand All @@ -106,8 +161,13 @@ private void load(AudioManager audio, TextureStore textures, Storage store)
new DrawSizePreservingFillContainer
{
inputModeButton,
volumeText,
volumeSlider,
windowModeButton,
globalVolumeText,
globalVolumeSlider,
effectsVolumeText,
effectsVolumeSlider,
musicVolumeText,
musicVolumeSlider,
setupButton,
backButton,
new SpriteText
Expand All @@ -120,6 +180,24 @@ private void load(AudioManager audio, TextureStore textures, Storage store)
},
}
};
// set up bindables and events
windowModeBindable = frameworkConfig.GetBindable<WindowMode>(
FrameworkSetting.WindowMode
);
windowModeBindable.ValueChanged += onWindowModeChange;
}

private void onWindowModeChange(ValueChangedEvent<WindowMode> @event)
{
Logger.Log(@event.NewValue.ToString());
windowModeButton.Text = "Window mode: " + @event.NewValue.ToString();
}

private void changeWindowMode(FrameworkConfigManager frameworkConfig)
{
// this function only changes the window mode, it doesn't change the text, as that is handled by the event
WindowMode currentvalue = frameworkConfig.Get<WindowMode>(FrameworkSetting.WindowMode);
frameworkConfig.SetValue(FrameworkSetting.WindowMode, currentvalue + 1);
}

public void changeInputMode()
Expand All @@ -134,7 +212,7 @@ public void changeInputMode()
Settings.inputmode = Settings.InputMode.Rotational;
}
// update button text
inputModeButton.Text = "Input Mode: " + Settings.inputmode.ToString();
inputModeButton.Text = "Input mode: " + Settings.inputmode.ToString();
}

protected override bool OnKeyDown(KeyDownEvent e)
Expand All @@ -149,11 +227,7 @@ protected override bool OnKeyDown(KeyDownEvent e)
public void pushMenu()
{
// save settings to disk
JObject settings = new JObject
{
{ "inputMode", (int)Settings.inputmode },
{ "volume", Settings.volume.Value }
};
JObject settings = new JObject { { "inputMode", (int)Settings.inputmode }, };
StreamWriter settingswriter = new StreamWriter(
storage.CreateFileSafely("settings.json")
);
Expand Down
4 changes: 0 additions & 4 deletions CrankItUp.Game/src/Screens/TitleScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public partial class TitleScreen : Screen
private void load(AudioManager audio, TextureStore textures)
{
track = audio.GetTrackStore().Get("Body F10ating in the Zero Gravity Space.mp3");
audio.AddAdjustment(
AdjustableProperty.Volume,
new BindableDouble(Settings.volume.Value)
);
track.Start();
track.Looping = true;

Expand Down

0 comments on commit 16e6fde

Please sign in to comment.