2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 17:56:20 +08:00
|
|
|
|
|
2016-10-26 17:45:48 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-10-10 22:19:05 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-10-10 01:45:34 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-01-31 17:53:52 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2016-10-10 01:45:34 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-08-22 13:44:13 +08:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Game.Input.Bindings;
|
2016-10-10 01:45:34 +08:00
|
|
|
|
|
2016-10-26 17:45:48 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface.Volume
|
2016-10-10 01:45:34 +08:00
|
|
|
|
{
|
2017-08-22 13:44:13 +08:00
|
|
|
|
internal class VolumeMeter : Container, IKeyBindingHandler<GlobalAction>
|
2016-10-10 01:45:34 +08:00
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Box meterFill;
|
2017-03-07 09:59:19 +08:00
|
|
|
|
public BindableDouble Bindable { get; } = new BindableDouble();
|
2016-10-10 22:19:05 +08:00
|
|
|
|
|
2016-11-23 15:12:21 +08:00
|
|
|
|
public VolumeMeter(string meterName)
|
2016-10-10 01:45:34 +08:00
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(40, 180);
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.Black,
|
2016-10-12 22:36:42 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both
|
2016-10-10 01:45:34 +08:00
|
|
|
|
},
|
|
|
|
|
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,
|
2016-10-12 22:36:42 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both
|
2016-10-10 01:45:34 +08:00
|
|
|
|
},
|
2016-10-12 22:36:42 +08:00
|
|
|
|
meterFill = new Box
|
2016-10-10 01:45:34 +08:00
|
|
|
|
{
|
|
|
|
|
Colour = Color4.White,
|
2016-11-29 17:35:59 +08:00
|
|
|
|
Scale = new Vector2(1, 0),
|
2016-10-10 01:45:34 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.BottomCentre
|
2016-10-12 22:36:42 +08:00
|
|
|
|
}
|
2016-10-10 01:45:34 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2017-01-31 17:53:52 +08:00
|
|
|
|
new OsuSpriteText
|
2016-10-14 00:11:51 +08:00
|
|
|
|
{
|
|
|
|
|
Text = meterName,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2016-10-14 14:46:40 +08:00
|
|
|
|
Origin = Anchor.TopCentre
|
2016-10-14 00:11:51 +08:00
|
|
|
|
}
|
2016-10-10 01:45:34 +08:00
|
|
|
|
};
|
2016-11-29 17:35:59 +08:00
|
|
|
|
|
|
|
|
|
Bindable.ValueChanged += delegate { updateFill(); };
|
2016-10-10 01:45:34 +08:00
|
|
|
|
}
|
2016-10-10 22:19:05 +08:00
|
|
|
|
|
2016-11-06 18:13:52 +08:00
|
|
|
|
protected override void LoadComplete()
|
2016-10-22 20:33:43 +08:00
|
|
|
|
{
|
2016-11-06 18:13:52 +08:00
|
|
|
|
base.LoadComplete();
|
2016-10-22 20:33:43 +08:00
|
|
|
|
updateFill();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-13 03:17:53 +08:00
|
|
|
|
public double Volume
|
2016-10-10 22:19:05 +08:00
|
|
|
|
{
|
2016-11-23 15:12:21 +08:00
|
|
|
|
get { return Bindable.Value; }
|
2016-10-13 03:17:53 +08:00
|
|
|
|
private set
|
|
|
|
|
{
|
2016-11-23 15:12:21 +08:00
|
|
|
|
Bindable.Value = value;
|
2016-10-13 03:17:53 +08:00
|
|
|
|
}
|
2016-10-10 22:19:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 13:44:13 +08:00
|
|
|
|
public void Increase()
|
2016-10-10 22:19:05 +08:00
|
|
|
|
{
|
2017-08-22 13:44:13 +08:00
|
|
|
|
Volume += 0.05f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Decrease()
|
|
|
|
|
{
|
|
|
|
|
Volume -= 0.05f;
|
2016-10-10 22:19:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, Easing.OutQuint);
|
2017-08-22 13:44:13 +08:00
|
|
|
|
|
|
|
|
|
public bool OnPressed(GlobalAction action)
|
|
|
|
|
{
|
|
|
|
|
if (!IsHovered) return false;
|
|
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.DecreaseVolume:
|
|
|
|
|
Decrease();
|
|
|
|
|
return true;
|
|
|
|
|
case GlobalAction.IncreaseVolume:
|
|
|
|
|
Increase();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool OnReleased(GlobalAction action) => false;
|
2016-10-10 01:45:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|