2019-01-24 17:43:03 +09: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 18:19:50 +09:00
|
|
|
|
|
2024-08-08 12:56:03 +09:00
|
|
|
|
using System.Linq;
|
2018-03-03 19:49:38 +01:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-03-03 19:08:35 +01:00
|
|
|
|
using osu.Framework.Audio;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-03-03 19:08:35 +01:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2016-10-07 03:05:26 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
2018-03-03 19:08:35 +01:00
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2016-10-07 03:05:26 +09:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-03-03 19:08:35 +01:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-02 12:02:47 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2016-10-26 18:45:48 +09:00
|
|
|
|
using osu.Framework.Threading;
|
2018-03-03 19:08:35 +01:00
|
|
|
|
using osu.Game.Graphics;
|
2021-07-05 19:22:55 +02:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-08-22 14:44:13 +09:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2018-03-03 19:08:35 +01:00
|
|
|
|
using osu.Game.Overlays.Volume;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-03-03 19:08:35 +01:00
|
|
|
|
namespace osu.Game.Overlays
|
2016-10-07 03:05:26 +09:00
|
|
|
|
{
|
2024-08-08 12:56:03 +09:00
|
|
|
|
[Cached]
|
2019-10-14 16:27:59 -07:00
|
|
|
|
public partial class VolumeOverlay : VisibilityContainer
|
2016-10-07 03:05:26 +09:00
|
|
|
|
{
|
2024-08-08 12:56:03 +09:00
|
|
|
|
public Bindable<bool> IsMuted { get; } = new Bindable<bool>();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-03-03 19:08:35 +01:00
|
|
|
|
private const float offset = 10;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2024-07-11 14:29:56 +03:00
|
|
|
|
private VolumeMeter volumeMeterMaster = null!;
|
|
|
|
|
private VolumeMeter volumeMeterEffect = null!;
|
|
|
|
|
private VolumeMeter volumeMeterMusic = null!;
|
2019-09-15 16:31:57 +02:00
|
|
|
|
|
2024-07-11 14:29:56 +03:00
|
|
|
|
private SelectionCycleFillFlowContainer<VolumeMeter> volumeMeters = null!;
|
2021-07-04 14:47:07 +02:00
|
|
|
|
|
2018-03-03 19:08:35 +01:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
2016-10-22 17:50:42 +09:00
|
|
|
|
{
|
2018-03-03 19:25:34 +01:00
|
|
|
|
AutoSizeAxes = Axes.X;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-03-03 19:08:35 +01:00
|
|
|
|
AddRange(new Drawable[]
|
2016-11-12 18:34:36 +01:00
|
|
|
|
{
|
2018-03-03 19:08:35 +01:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Width = 300,
|
2018-03-07 14:07:04 +09:00
|
|
|
|
Colour = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0.75f), Color4.Black.Opacity(0))
|
2018-03-03 19:08:35 +01:00
|
|
|
|
},
|
2024-08-08 12:56:03 +09:00
|
|
|
|
new FillFlowContainer
|
2016-11-23 16:12:21 +09:00
|
|
|
|
{
|
2018-03-03 19:08:35 +01:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2016-11-23 16:12:21 +09:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2018-03-03 19:08:35 +01:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Spacing = new Vector2(0, offset),
|
|
|
|
|
Margin = new MarginPadding { Left = offset },
|
2024-08-08 12:56:03 +09:00
|
|
|
|
Children = new Drawable[]
|
2016-11-23 16:12:21 +09:00
|
|
|
|
{
|
2024-08-08 12:56:03 +09:00
|
|
|
|
volumeMeters = new SelectionCycleFillFlowContainer<VolumeMeter>
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Spacing = new Vector2(0, offset),
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
volumeMeterEffect = new VolumeMeter("EFFECTS", 125, colours.BlueDarker),
|
|
|
|
|
volumeMeterMaster = new MasterVolumeMeter("MASTER", 150, colours.PinkDarker) { IsMuted = { BindTarget = IsMuted }, },
|
|
|
|
|
volumeMeterMusic = new VolumeMeter("MUSIC", 125, colours.BlueDarker),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-03-03 19:08:35 +01:00
|
|
|
|
});
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-03-03 19:08:35 +01:00
|
|
|
|
volumeMeterMaster.Bindable.BindTo(audio.Volume);
|
|
|
|
|
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
|
|
|
|
|
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);
|
2016-10-22 17:50:42 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2016-11-12 18:34:36 +01:00
|
|
|
|
protected override void LoadComplete()
|
2016-10-07 03:05:26 +09:00
|
|
|
|
{
|
2016-11-12 18:34:36 +01:00
|
|
|
|
base.LoadComplete();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-07-05 19:22:55 +02:00
|
|
|
|
foreach (var volumeMeter in volumeMeters)
|
|
|
|
|
volumeMeter.Bindable.ValueChanged += _ => Show();
|
2016-10-13 17:52:49 +03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-06-27 18:43:29 +09:00
|
|
|
|
public bool Adjust(GlobalAction action, float amount = 1, bool isPrecise = false)
|
2016-10-07 03:05:26 +09:00
|
|
|
|
{
|
2018-05-11 22:57:36 +09:00
|
|
|
|
if (!IsLoaded) return false;
|
|
|
|
|
|
2017-08-22 14:44:13 +09:00
|
|
|
|
switch (action)
|
2016-11-15 15:22:14 +09:00
|
|
|
|
{
|
2017-08-22 14:44:13 +09:00
|
|
|
|
case GlobalAction.DecreaseVolume:
|
2019-06-11 14:28:52 +09:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
2017-08-22 14:44:13 +09:00
|
|
|
|
Show();
|
|
|
|
|
else
|
2021-07-05 19:22:55 +02:00
|
|
|
|
volumeMeters.Selected?.Decrease(amount, isPrecise);
|
2017-08-22 14:44:13 +09:00
|
|
|
|
return true;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2017-08-22 14:44:13 +09:00
|
|
|
|
case GlobalAction.IncreaseVolume:
|
2019-06-11 14:28:52 +09:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
2017-08-22 14:44:13 +09:00
|
|
|
|
Show();
|
|
|
|
|
else
|
2021-07-05 19:22:55 +02:00
|
|
|
|
volumeMeters.Selected?.Increase(amount, isPrecise);
|
2017-08-22 14:44:13 +09:00
|
|
|
|
return true;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2021-07-04 14:47:07 +02:00
|
|
|
|
case GlobalAction.NextVolumeMeter:
|
2024-07-07 21:33:27 +02:00
|
|
|
|
if (State.Value != Visibility.Visible)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
volumeMeters.SelectNext();
|
2021-07-05 19:22:55 +02:00
|
|
|
|
Show();
|
2021-07-04 14:47:07 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case GlobalAction.PreviousVolumeMeter:
|
2024-07-07 21:33:27 +02:00
|
|
|
|
if (State.Value != Visibility.Visible)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
volumeMeters.SelectPrevious();
|
2021-07-05 19:22:55 +02:00
|
|
|
|
Show();
|
2021-07-04 14:47:07 +02:00
|
|
|
|
return true;
|
|
|
|
|
|
2018-01-16 17:46:54 +01:00
|
|
|
|
case GlobalAction.ToggleMute:
|
2018-01-20 11:45:04 +01:00
|
|
|
|
Show();
|
2024-08-08 12:56:03 +09:00
|
|
|
|
volumeMeters.OfType<MasterVolumeMeter>().First().ToggleMute();
|
2018-01-16 17:46:54 +01:00
|
|
|
|
return true;
|
2016-11-15 15:22:14 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-08-22 14:44:13 +09:00
|
|
|
|
return false;
|
2016-10-07 03:05:26 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2022-06-15 15:41:38 +09:00
|
|
|
|
public void FocusMasterVolume()
|
|
|
|
|
{
|
|
|
|
|
volumeMeters.Select(volumeMeterMaster);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-13 16:47:10 +09:00
|
|
|
|
public override void Show()
|
|
|
|
|
{
|
2021-07-04 15:31:43 +02:00
|
|
|
|
// Focus on the master meter as a default if previously hidden
|
2021-07-04 14:47:07 +02:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
2022-06-15 15:41:38 +09:00
|
|
|
|
FocusMasterVolume();
|
2021-07-04 14:47:07 +02:00
|
|
|
|
|
2019-06-11 14:28:52 +09:00
|
|
|
|
if (State.Value == Visibility.Visible)
|
2018-06-13 16:47:10 +09:00
|
|
|
|
schedulePopOut();
|
|
|
|
|
|
|
|
|
|
base.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 18:45:48 +09:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2017-02-25 13:12:39 +01:00
|
|
|
|
ClearTransforms();
|
2017-07-14 19:18:12 +03:00
|
|
|
|
this.FadeIn(100);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2016-10-26 18:45:48 +09:00
|
|
|
|
schedulePopOut();
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2016-10-26 18:45:48 +09:00
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-07-14 19:18:12 +03:00
|
|
|
|
this.FadeOut(100);
|
2016-10-26 18:45:48 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override bool OnMouseMove(MouseMoveEvent e)
|
2018-06-07 01:14:43 +09:00
|
|
|
|
{
|
|
|
|
|
// keep the scheduled event correctly timed as long as we have movement.
|
|
|
|
|
schedulePopOut();
|
2018-10-02 12:02:47 +09:00
|
|
|
|
return base.OnMouseMove(e);
|
2018-06-07 01:14:43 +09:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-06-13 16:46:48 +09:00
|
|
|
|
{
|
2018-06-22 13:32:00 +09:00
|
|
|
|
schedulePopOut();
|
2018-06-13 16:46:48 +09:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-06-22 13:32:19 +09:00
|
|
|
|
{
|
|
|
|
|
schedulePopOut();
|
2018-10-02 12:02:47 +09:00
|
|
|
|
base.OnHoverLost(e);
|
2018-06-22 13:32:19 +09:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 14:29:56 +03:00
|
|
|
|
private ScheduledDelegate? popOutDelegate;
|
|
|
|
|
|
2016-10-26 18:45:48 +09:00
|
|
|
|
private void schedulePopOut()
|
2016-10-07 03:05:26 +09:00
|
|
|
|
{
|
2016-10-26 18:45:48 +09:00
|
|
|
|
popOutDelegate?.Cancel();
|
2018-06-07 01:14:43 +09:00
|
|
|
|
this.Delay(1000).Schedule(() =>
|
|
|
|
|
{
|
2018-06-13 16:46:48 +09:00
|
|
|
|
if (!IsHovered)
|
2018-06-07 01:14:43 +09:00
|
|
|
|
Hide();
|
|
|
|
|
}, out popOutDelegate);
|
2016-10-07 03:05:26 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-21 11:49:42 +09:00
|
|
|
|
}
|