mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 17:07:38 +08:00
Add volume UI to toolbar music button
This commit is contained in:
parent
7f23677972
commit
1f31e3fb51
@ -2,30 +2,79 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Toolbar
|
namespace osu.Game.Overlays.Toolbar
|
||||||
{
|
{
|
||||||
public class ToolbarMusicButton : ToolbarOverlayToggleButton
|
public class ToolbarMusicButton : ToolbarOverlayToggleButton
|
||||||
{
|
{
|
||||||
|
private Circle volumeBar;
|
||||||
|
|
||||||
protected override Anchor TooltipAnchor => Anchor.TopRight;
|
protected override Anchor TooltipAnchor => Anchor.TopRight;
|
||||||
|
|
||||||
public ToolbarMusicButton()
|
public ToolbarMusicButton()
|
||||||
{
|
{
|
||||||
Hotkey = GlobalAction.ToggleNowPlaying;
|
Hotkey = GlobalAction.ToggleNowPlaying;
|
||||||
|
AutoSizeAxes = Axes.X;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(NowPlayingOverlay music)
|
private void load(NowPlayingOverlay music)
|
||||||
{
|
{
|
||||||
StateContainer = music;
|
StateContainer = music;
|
||||||
|
|
||||||
|
Flow.Padding = new MarginPadding { Horizontal = Toolbar.HEIGHT / 4 };
|
||||||
|
Flow.Add(new Container
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private AudioManager audio { get; set; }
|
||||||
|
|
||||||
[Resolved(canBeNull: true)]
|
[Resolved(canBeNull: true)]
|
||||||
private VolumeOverlay volume { get; set; }
|
private VolumeOverlay volume { get; set; }
|
||||||
|
|
||||||
|
private IBindable<double> globalVolume;
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
globalVolume = audio.Volume.GetBoundCopy();
|
||||||
|
globalVolume.BindValueChanged(v => volumeBar.Height = (float)v.NewValue, true);
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnScroll(ScrollEvent e)
|
protected override bool OnScroll(ScrollEvent e)
|
||||||
{
|
{
|
||||||
volume?.Adjust(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise);
|
volume?.Adjust(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise);
|
||||||
|
Loading…
Reference in New Issue
Block a user