2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Threading;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
|
using osu.Game.Overlays.Volume;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2019-10-14 23:27:59 +00:00
|
|
|
|
public class VolumeOverlay : VisibilityContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
private const float offset = 10;
|
|
|
|
|
|
|
|
|
|
private VolumeMeter volumeMeterMaster;
|
|
|
|
|
private VolumeMeter volumeMeterEffect;
|
|
|
|
|
private VolumeMeter volumeMeterMusic;
|
|
|
|
|
private MuteButton muteButton;
|
|
|
|
|
|
|
|
|
|
private readonly BindableDouble muteAdjustment = new BindableDouble();
|
|
|
|
|
|
2019-11-12 09:45:42 +00:00
|
|
|
|
public Bindable<bool> IsMuted { get; } = new Bindable<bool>();
|
2019-09-15 14:31:57 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Width = 300,
|
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.75f), Color4.Black.Opacity(0))
|
|
|
|
|
},
|
2020-05-15 03:21:02 +00:00
|
|
|
|
muteButton = new MuteButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
|
Current = { BindTarget = IsMuted }
|
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Spacing = new Vector2(0, offset),
|
|
|
|
|
Margin = new MarginPadding { Left = offset },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-05-15 03:21:02 +00:00
|
|
|
|
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
volumeMeterMaster = new VolumeMeter("MASTER", 150, colours.PinkDarker),
|
|
|
|
|
volumeMeterMusic = new VolumeMeter("MUSIC", 125, colours.BlueDarker),
|
|
|
|
|
}
|
2020-05-15 03:21:02 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
volumeMeterMaster.Bindable.BindTo(audio.Volume);
|
|
|
|
|
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
|
|
|
|
|
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);
|
|
|
|
|
|
2019-11-12 09:45:42 +00:00
|
|
|
|
IsMuted.BindValueChanged(muted =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-02-22 08:51:39 +00:00
|
|
|
|
if (muted.NewValue)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
audio.AddAdjustment(AdjustableProperty.Volume, muteAdjustment);
|
|
|
|
|
else
|
|
|
|
|
audio.RemoveAdjustment(AdjustableProperty.Volume, muteAdjustment);
|
2019-10-03 10:11:50 +00:00
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2018-06-06 16:14:43 +00:00
|
|
|
|
volumeMeterMaster.Bindable.ValueChanged += _ => Show();
|
|
|
|
|
volumeMeterEffect.Bindable.ValueChanged += _ => Show();
|
|
|
|
|
volumeMeterMusic.Bindable.ValueChanged += _ => Show();
|
|
|
|
|
muteButton.Current.ValueChanged += _ => Show();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-27 09:43:29 +00:00
|
|
|
|
public bool Adjust(GlobalAction action, float amount = 1, bool isPrecise = false)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-05-11 13:57:36 +00:00
|
|
|
|
if (!IsLoaded) return false;
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.DecreaseVolume:
|
2019-06-11 05:28:52 +00:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Show();
|
2019-06-24 05:53:02 +00:00
|
|
|
|
else if (volumeMeterMusic.IsHovered)
|
|
|
|
|
volumeMeterMusic.Decrease(amount, isPrecise);
|
|
|
|
|
else if (volumeMeterEffect.IsHovered)
|
|
|
|
|
volumeMeterEffect.Decrease(amount, isPrecise);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
else
|
2018-06-27 09:43:29 +00:00
|
|
|
|
volumeMeterMaster.Decrease(amount, isPrecise);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return true;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case GlobalAction.IncreaseVolume:
|
2019-06-11 05:28:52 +00:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Show();
|
2019-06-24 05:53:02 +00:00
|
|
|
|
else if (volumeMeterMusic.IsHovered)
|
|
|
|
|
volumeMeterMusic.Increase(amount, isPrecise);
|
|
|
|
|
else if (volumeMeterEffect.IsHovered)
|
|
|
|
|
volumeMeterEffect.Increase(amount, isPrecise);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
else
|
2018-06-27 09:43:29 +00:00
|
|
|
|
volumeMeterMaster.Increase(amount, isPrecise);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return true;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case GlobalAction.ToggleMute:
|
|
|
|
|
Show();
|
2019-02-21 09:56:34 +00:00
|
|
|
|
muteButton.Current.Value = !muteButton.Current.Value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScheduledDelegate popOutDelegate;
|
|
|
|
|
|
2018-06-13 07:47:10 +00:00
|
|
|
|
public override void Show()
|
|
|
|
|
{
|
2019-06-11 05:28:52 +00:00
|
|
|
|
if (State.Value == Visibility.Visible)
|
2018-06-13 07:47:10 +00:00
|
|
|
|
schedulePopOut();
|
|
|
|
|
|
|
|
|
|
base.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
ClearTransforms();
|
|
|
|
|
this.FadeIn(100);
|
|
|
|
|
|
|
|
|
|
schedulePopOut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
this.FadeOut(100);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
2018-06-06 16:14:43 +00:00
|
|
|
|
{
|
|
|
|
|
// keep the scheduled event correctly timed as long as we have movement.
|
|
|
|
|
schedulePopOut();
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnMouseMove(e);
|
2018-06-06 16:14:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-06-13 07:46:48 +00:00
|
|
|
|
{
|
2018-06-22 04:32:00 +00:00
|
|
|
|
schedulePopOut();
|
2018-06-13 07:46:48 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-06-22 04:32:19 +00:00
|
|
|
|
{
|
|
|
|
|
schedulePopOut();
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnHoverLost(e);
|
2018-06-22 04:32:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private void schedulePopOut()
|
|
|
|
|
{
|
|
|
|
|
popOutDelegate?.Cancel();
|
2018-06-06 16:14:43 +00:00
|
|
|
|
this.Delay(1000).Schedule(() =>
|
|
|
|
|
{
|
2018-06-13 07:46:48 +00:00
|
|
|
|
if (!IsHovered)
|
2018-06-06 16:14:43 +00:00
|
|
|
|
Hide();
|
|
|
|
|
}, out popOutDelegate);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|