2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2022-06-15 03:13:26 +08:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2020-08-06 16:20:03 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2022-06-15 03:13:26 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-06-15 14:56:59 +08:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
2022-06-15 01:35:09 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2022-06-15 14:56:59 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2020-08-06 16:17:24 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2022-06-15 03:13:26 +08:00
|
|
|
|
using osuTK.Graphics;
|
2022-06-15 14:57:09 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class ToolbarMusicButton : ToolbarOverlayToggleButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2022-06-15 03:13:26 +08:00
|
|
|
|
private Circle volumeBar;
|
|
|
|
|
|
2020-08-06 16:20:03 +08:00
|
|
|
|
protected override Anchor TooltipAnchor => Anchor.TopRight;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public ToolbarMusicButton()
|
|
|
|
|
{
|
2020-08-06 16:17:24 +08:00
|
|
|
|
Hotkey = GlobalAction.ToggleNowPlaying;
|
2022-06-15 03:13:26 +08:00
|
|
|
|
AutoSizeAxes = Axes.X;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2019-08-13 13:29:58 +08:00
|
|
|
|
private void load(NowPlayingOverlay music)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
StateContainer = music;
|
2022-06-15 03:13:26 +08:00
|
|
|
|
|
|
|
|
|
Flow.Padding = new MarginPadding { Horizontal = Toolbar.HEIGHT / 4 };
|
2022-06-15 14:56:59 +08:00
|
|
|
|
Flow.Add(volumeDisplay = new Container
|
2022-06-15 03:13:26 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Width = 3f,
|
|
|
|
|
Height = IconContainer.Height,
|
|
|
|
|
Margin = new MarginPadding { Horizontal = 2.5f },
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Circle
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.White.Opacity(0.25f),
|
|
|
|
|
},
|
|
|
|
|
volumeBar = new Circle
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 0f,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2022-06-15 01:35:09 +08:00
|
|
|
|
|
2022-06-15 03:13:26 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private AudioManager audio { get; set; }
|
|
|
|
|
|
2022-06-15 01:35:09 +08:00
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private VolumeOverlay volume { get; set; }
|
|
|
|
|
|
2022-06-15 03:13:26 +08:00
|
|
|
|
private IBindable<double> globalVolume;
|
2022-06-15 14:56:59 +08:00
|
|
|
|
private Container volumeDisplay;
|
2022-06-15 03:13:26 +08:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
globalVolume = audio.Volume.GetBoundCopy();
|
2022-06-15 14:56:59 +08:00
|
|
|
|
globalVolume.BindValueChanged(v => volumeBar.ResizeHeightTo((float)v.NewValue, 200, Easing.OutQuint), true);
|
2022-06-15 03:13:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:57:09 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
2022-06-17 01:22:25 +08:00
|
|
|
|
if (!IsHovered)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-06-15 14:57:09 +08:00
|
|
|
|
switch (e.Key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Up:
|
|
|
|
|
focusForAdjustment();
|
|
|
|
|
volume?.Adjust(GlobalAction.IncreaseVolume);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
case Key.Down:
|
|
|
|
|
focusForAdjustment();
|
2022-06-15 15:21:27 +08:00
|
|
|
|
volume?.Adjust(GlobalAction.DecreaseVolume);
|
2022-06-15 14:57:09 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 01:35:09 +08:00
|
|
|
|
protected override bool OnScroll(ScrollEvent e)
|
|
|
|
|
{
|
2022-06-15 14:56:59 +08:00
|
|
|
|
focusForAdjustment();
|
2022-06-15 01:35:09 +08:00
|
|
|
|
volume?.Adjust(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2022-06-15 14:56:59 +08:00
|
|
|
|
|
|
|
|
|
private void focusForAdjustment()
|
|
|
|
|
{
|
|
|
|
|
volume?.FocusMasterVolume();
|
|
|
|
|
expandVolumeBarTemporarily();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TransformSequence<Container> expandTransform;
|
|
|
|
|
private ScheduledDelegate contractTransform;
|
|
|
|
|
|
|
|
|
|
private void expandVolumeBarTemporarily()
|
|
|
|
|
{
|
|
|
|
|
// avoid starting a new transform if one is already active.
|
|
|
|
|
if (expandTransform == null)
|
|
|
|
|
{
|
|
|
|
|
expandTransform = volumeDisplay.ResizeWidthTo(6, 500, Easing.OutQuint);
|
|
|
|
|
expandTransform.Finally(_ => expandTransform = null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contractTransform?.Cancel();
|
|
|
|
|
contractTransform = Scheduler.AddDelayed(() =>
|
|
|
|
|
{
|
|
|
|
|
volumeDisplay.ResizeWidthTo(3f, 500, Easing.OutQuint);
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|