diff --git a/osu.Game/VolumeControl.cs b/osu.Game/VolumeControl.cs index ff74a767bd..bc67513fb4 100644 --- a/osu.Game/VolumeControl.cs +++ b/osu.Game/VolumeControl.cs @@ -1,21 +1,16 @@ -using System; -using OpenTK; -using OpenTK.Graphics; +using osu.Framework; 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; -using osu.Framework; +using OpenTK; namespace osu.Game { internal class VolumeControl : Container { - private Box meterFill; - private Container meterContainer; - + private FlowContainer volumeMetersContainer; + private VolumeMeter volumeMeterMaster; public BindableDouble VolumeGlobal { get; set; } public BindableDouble VolumeSample { get; set; } public BindableDouble VolumeTrack { get; set; } @@ -25,84 +20,63 @@ namespace osu.Game RelativeSizeAxes = Axes.Both; } + private void volumeChanged(object sender, System.EventArgs e) + { + appear(); + } + public override void Load(BaseGame game) { base.Load(game); + VolumeGlobal.ValueChanged += volumeChanged; + VolumeSample.ValueChanged += volumeChanged; + VolumeTrack.ValueChanged += volumeChanged; + Children = new Drawable[] { - meterContainer = new Container { + volumeMetersContainer = new FlowContainer + { Anchor = Anchor.BottomRight, Origin = Anchor.BottomRight, - Position = new Vector2(10, 10), - Size = new Vector2(40, 180), + Position = new Vector2(10, 30), + Spacing = new Vector2(15,0), Alpha = 0, 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 - }, - } - } + volumeMeterMaster = new VolumeMeter("Master", VolumeGlobal), + new VolumeMeter("Effects", VolumeSample), + new VolumeMeter("Music", VolumeTrack) } } }; + } - updateFill(); + protected override void Dispose(bool isDisposing) + { + VolumeGlobal.ValueChanged -= volumeChanged; + VolumeSample.ValueChanged -= volumeChanged; + VolumeTrack.ValueChanged -= volumeChanged; + base.Dispose(isDisposing); } protected override bool OnWheelDown(InputState state) { - appear(); - - VolumeGlobal.Value -= 0.05f; - updateFill(); - - return base.OnWheelDown(state); + volumeMeterMaster.TriggerWheelDown(state); + return true; } protected override bool OnWheelUp(InputState state) { - appear(); - - VolumeGlobal.Value += 0.05f; - updateFill(); - - return base.OnWheelUp(state); - } - - private void updateFill() - { - meterFill.ScaleTo(new Vector2(1, (float)VolumeGlobal.Value), 300, EasingTypes.OutQuint); + volumeMeterMaster.TriggerWheelUp(state); + return true; } private void appear() { - meterContainer.ClearTransformations(); - meterContainer.FadeIn(100); - meterContainer.Delay(1000); - meterContainer.FadeOut(100); + volumeMetersContainer.ClearTransformations(); + volumeMetersContainer.FadeIn(100); + volumeMetersContainer.Delay(1000); + volumeMetersContainer.FadeOut(100); } } } \ No newline at end of file diff --git a/osu.Game/VolumeMeter.cs b/osu.Game/VolumeMeter.cs new file mode 100644 index 0000000000..121059a380 --- /dev/null +++ b/osu.Game/VolumeMeter.cs @@ -0,0 +1,84 @@ +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Drawables; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using osu.Framework.Input; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game +{ + internal class VolumeMeter : Container + { + private Box meterFill; + private BindableDouble volume; + + public VolumeMeter(string meterName, BindableDouble volume) + { + this.volume = volume; + 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 + } + } + }, + new SpriteText + { + Text = meterName, + Anchor = Anchor.BottomCentre, + Origin = Anchor.TopCentre + } + }; + } + + public double Volume + { + get { return volume.Value; } + private set + { + volume.Value = value; + updateFill(); + } + } + + protected override bool OnWheelUp(InputState state) + { + Volume += 0.05f; + return true; + } + + protected override bool OnWheelDown(InputState state) + { + Volume -= 0.05f; + return true; + } + + private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, EasingTypes.OutQuint); + } +} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index f1d8334eba..f9201e8a32 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -171,6 +171,7 @@ +