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