From bdb72d7b8210edb08098f8aca3b8c9d225d46fcc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 7 Oct 2016 03:05:26 +0900 Subject: [PATCH] Add basic VolumeControl and saving of volume to config. --- osu.Game/Configuration/OsuConfigManager.cs | 9 +- osu.Game/OsuGame.cs | 11 +++ osu.Game/VolumeControl.cs | 99 ++++++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 4 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 osu.Game/VolumeControl.cs diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 9991394913..e1b3397c42 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -20,6 +20,10 @@ namespace osu.Game.Configuration Set(OsuConfig.Token, string.Empty); Set(OsuConfig.PlayMode, PlayMode.Osu); + + Set(OsuConfig.VolumeGlobal, 0.8, 0, 1); + Set(OsuConfig.VolumeMusic, 1.0, 0, 1); + Set(OsuConfig.VolumeEffect, 1.0, 0, 1); } } @@ -31,6 +35,9 @@ namespace osu.Game.Configuration Username, Password, Token, - PlayMode + PlayMode, + VolumeGlobal, + VolumeEffect, + VolumeMusic } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index de9d3c208f..cd3ddd32fe 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -37,6 +37,11 @@ namespace osu.Game { base.Load(); + //attach out bindables to the audio subsystem. + Audio.Volume.Weld(Config.GetBindable(OsuConfig.VolumeGlobal)); + Audio.VolumeSample.Weld(Config.GetBindable(OsuConfig.VolumeEffect)); + Audio.VolumeTrack.Weld(Config.GetBindable(OsuConfig.VolumeMusic)); + Add(new Drawable[] { intro = new Intro(), Toolbar = new Toolbar @@ -46,6 +51,12 @@ namespace osu.Game OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, Alpha = 0.001f //fixes invalidation fuckup }, + new VolumeControl + { + VolumeGlobal = Audio.Volume, + VolumeSample = Audio.VolumeSample, + VolumeTrack = Audio.VolumeTrack + } }); intro.ModePushed += modeAdded; diff --git a/osu.Game/VolumeControl.cs b/osu.Game/VolumeControl.cs new file mode 100644 index 0000000000..ea899e6ea5 --- /dev/null +++ b/osu.Game/VolumeControl.cs @@ -0,0 +1,99 @@ +using System; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Drawables; +using osu.Framework.Input; +using osu.Framework.Graphics.Transformations; + +namespace osu.Game +{ + internal class VolumeControl : Container + { + private Box meterFill; + private Container meterContainer; + + public BindableDouble VolumeGlobal { get; set; } + public BindableDouble VolumeSample { get; set; } + public BindableDouble VolumeTrack { get; set; } + + public VolumeControl() + { + RelativeSizeAxes = Axes.Both; + } + + public override void Load() + { + base.Load(); + Children = new Drawable[] + { + meterContainer = new Container { + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight, + Position = new Vector2(10, 10), + Size = new Vector2(40, 180), + Children = new Drawable[] + { + new Box + { + Colour = Color4.Black, + RelativeSizeAxes = Axes.Both, + }, + new Container + { + RelativeSizeAxes = Axes.Both, + Size = new Vector2(0.5f, 0.9f), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Children = new Drawable[] + { + new Box + { + Colour = Color4.DarkGray, + RelativeSizeAxes = Axes.Both, + }, + meterFill = new Box + { + Colour = Color4.White, + RelativeSizeAxes = Axes.Both, + Origin = Anchor.BottomCentre, + Anchor = Anchor.BottomCentre + }, + } + } + } + } + }; + } + + protected override bool OnWheelDown(InputState state) + { + appear(); + + VolumeGlobal.Value -= 0.05f; + meterFill.ScaleTo(new Vector2(1, (float)VolumeGlobal.Value), 300, EasingTypes.OutQuint); + + return base.OnWheelDown(state); + } + + protected override bool OnWheelUp(InputState state) + { + appear(); + + VolumeGlobal.Value += 0.05f; + meterFill.ScaleTo(new Vector2(1, (float)VolumeGlobal.Value), 300, EasingTypes.OutQuint); + + return base.OnWheelUp(state); + } + + private void appear() + { + meterContainer.ClearTransformations(); + meterContainer.FadeIn(100); + meterContainer.Delay(1000); + meterContainer.FadeOut(100); + } + } +} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 7a4195cc3e..e9fa92d984 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -131,6 +131,7 @@ +