1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 14:52:57 +08:00

Add volume control support via toolbar music button

This commit is contained in:
Salman Ahmed 2022-06-14 20:35:09 +03:00
parent 6fe5cacd3c
commit 7f23677972
2 changed files with 47 additions and 1 deletions

View File

@ -30,6 +30,21 @@ namespace osu.Game.Tests.Visual.Menus
[Resolved]
private IRulesetStore rulesets { get; set; }
[Cached]
private readonly NowPlayingOverlay nowPlayingOverlay = new NowPlayingOverlay
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Y = Toolbar.HEIGHT,
};
[Cached]
private readonly VolumeOverlay volumeOverlay = new VolumeOverlay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
};
private readonly Mock<TestNotificationOverlay> notifications = new Mock<TestNotificationOverlay>();
private readonly BindableInt unreadNotificationCount = new BindableInt();
@ -44,7 +59,15 @@ namespace osu.Game.Tests.Visual.Menus
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = toolbar = new TestToolbar { State = { Value = Visibility.Visible } };
Remove(nowPlayingOverlay);
Remove(volumeOverlay);
Children = new Drawable[]
{
nowPlayingOverlay,
volumeOverlay,
toolbar = new TestToolbar { State = { Value = Visibility.Visible } },
};
});
[Test]
@ -124,6 +147,19 @@ namespace osu.Game.Tests.Visual.Menus
AddAssert("not scrolled", () => scroll.Current == 0);
}
[Test]
public void TestVolumeControlViaMusicButton()
{
AddStep("hover toolbar music button", () => InputManager.MoveMouseTo(this.ChildrenOfType<ToolbarMusicButton>().Single()));
AddStep("reset volume", () => Audio.Volume.Value = 1);
AddRepeatStep("scroll down", () => InputManager.ScrollVerticalBy(-10), 5);
AddAssert("volume lowered down", () => Audio.Volume.Value < 1);
AddRepeatStep("scroll up", () => InputManager.ScrollVerticalBy(10), 5);
AddAssert("volume raised up", () => Audio.Volume.Value == 1);
}
public class TestToolbar : Toolbar
{
public new Bindable<OverlayActivation> OverlayActivationMode => base.OverlayActivationMode as Bindable<OverlayActivation>;

View File

@ -3,6 +3,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
namespace osu.Game.Overlays.Toolbar
@ -21,5 +22,14 @@ namespace osu.Game.Overlays.Toolbar
{
StateContainer = music;
}
[Resolved(canBeNull: true)]
private VolumeOverlay volume { get; set; }
protected override bool OnScroll(ScrollEvent e)
{
volume?.Adjust(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise);
return true;
}
}
}