1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-24 19:17:20 +08:00

Move "global" scroll-adjusts-volume to a per-screen component-based implementation

This commit is contained in:
Dean Herbert 2024-12-16 15:18:39 +09:00
parent d72a0b04b8
commit bdd417c1a1
No known key found for this signature in database
9 changed files with 92 additions and 76 deletions

View File

@ -6,6 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Volume;
@ -59,13 +60,12 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test]
public void TestAltScrollNotBlocked()
{
bool scrollReceived = false;
TestGlobalScrollAdjustsVolume volumeAdjust = null!;
AddStep("add volume control receptor", () => Add(new VolumeControlReceptor
AddStep("add volume control receptor", () => Add(volumeAdjust = new TestGlobalScrollAdjustsVolume
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue,
ScrollActionRequested = (_, _, _) => scrollReceived = true,
}));
AddStep("hold alt", () => InputManager.PressKey(Key.AltLeft));
@ -75,10 +75,21 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.ScrollVerticalBy(10);
});
AddAssert("receptor received scroll input", () => scrollReceived);
AddAssert("receptor received scroll input", () => volumeAdjust.ScrollReceived);
AddStep("release alt", () => InputManager.ReleaseKey(Key.AltLeft));
}
public partial class TestGlobalScrollAdjustsVolume : GlobalScrollAdjustsVolume
{
public bool ScrollReceived { get; private set; }
protected override bool OnScroll(ScrollEvent e)
{
ScrollReceived = true;
return base.OnScroll(e);
}
}
private partial class TestOverlay : OsuFocusedOverlayContainer
{
[BackgroundDependencyLoader]

View File

@ -1,8 +1,7 @@
// 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.
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Volume;
@ -11,7 +10,14 @@ namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneVolumeOverlay : OsuTestScene
{
private VolumeOverlay volume;
private VolumeOverlay volume = null!;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs(volume = new VolumeOverlay());
return dependencies;
}
protected override void LoadComplete()
{
@ -19,12 +25,10 @@ namespace osu.Game.Tests.Visual.UserInterface
AddRange(new Drawable[]
{
volume = new VolumeOverlay(),
new VolumeControlReceptor
volume,
new GlobalScrollAdjustsVolume
{
RelativeSizeAxes = Axes.Both,
ActionRequested = action => volume.Adjust(action),
ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise),
},
});

View File

@ -57,7 +57,6 @@ using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.OSD;
using osu.Game.Overlays.SkinEditor;
using osu.Game.Overlays.Toolbar;
using osu.Game.Overlays.Volume;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens;
@ -980,12 +979,6 @@ namespace osu.Game
AddRange(new Drawable[]
{
new VolumeControlReceptor
{
RelativeSizeAxes = Axes.Both,
ActionRequested = action => volume.Adjust(action),
ScrollActionRequested = (action, amount, isPrecise) => volume.Adjust(action, amount, isPrecise),
},
ScreenOffsetContainer = new Container
{
RelativeSizeAxes = Axes.Both,
@ -1432,6 +1425,19 @@ namespace osu.Game
switch (e.Action)
{
case GlobalAction.DecreaseVolume:
case GlobalAction.IncreaseVolume:
return volume.Adjust(e.Action);
case GlobalAction.ToggleMute:
case GlobalAction.NextVolumeMeter:
case GlobalAction.PreviousVolumeMeter:
if (!e.Repeat)
return true;
return volume.Adjust(e.Action);
case GlobalAction.ToggleFPSDisplay:
fpsCounter.ToggleVisibility();
return true;

View File

@ -0,0 +1,40 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
namespace osu.Game.Overlays.Volume
{
/// <summary>
/// Add to a container or screen to make scrolling anywhere in the container cause the global game volume to be adjusted.
/// </summary>
/// <remarks>
/// This is generally expected behaviour in many locations in osu!stable.
/// </remarks>
public partial class GlobalScrollAdjustsVolume : Container
{
[Resolved]
private VolumeOverlay? volumeOverlay { get; set; }
public GlobalScrollAdjustsVolume()
{
RelativeSizeAxes = Axes.Both;
}
protected override bool OnScroll(ScrollEvent e)
{
if (e.ScrollDelta.Y == 0)
return false;
// forward any unhandled mouse scroll events to the volume control.
return volumeOverlay?.Adjust(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise) ?? false;
}
public bool OnScroll(KeyBindingScrollEvent<GlobalAction> e) =>
volumeOverlay?.Adjust(e.Action, e.ScrollAmount, e.IsPrecise) ?? false;
}
}

View File

@ -1,57 +0,0 @@
// 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.
#nullable disable
using System;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
namespace osu.Game.Overlays.Volume
{
public partial class VolumeControlReceptor : Container, IScrollBindingHandler<GlobalAction>, IHandleGlobalKeyboardInput
{
public Func<GlobalAction, bool> ActionRequested;
public Func<GlobalAction, float, bool, bool> ScrollActionRequested;
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (e.Action)
{
case GlobalAction.DecreaseVolume:
case GlobalAction.IncreaseVolume:
return ActionRequested?.Invoke(e.Action) == true;
case GlobalAction.ToggleMute:
case GlobalAction.NextVolumeMeter:
case GlobalAction.PreviousVolumeMeter:
if (!e.Repeat)
return ActionRequested?.Invoke(e.Action) == true;
return false;
}
return false;
}
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
protected override bool OnScroll(ScrollEvent e)
{
if (e.ScrollDelta.Y == 0)
return false;
// forward any unhandled mouse scroll events to the volume control.
ScrollActionRequested?.Invoke(GlobalAction.IncreaseVolume, e.ScrollDelta.Y, e.IsPrecise);
return true;
}
public bool OnScroll(KeyBindingScrollEvent<GlobalAction> e) =>
ScrollActionRequested?.Invoke(e.Action, e.ScrollAmount, e.IsPrecise) ?? false;
}
}

View File

@ -28,6 +28,7 @@ using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Overlays.Dialog;
using osu.Game.Overlays.SkinEditor;
using osu.Game.Overlays.Volume;
using osu.Game.Rulesets;
using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Edit;
@ -124,6 +125,7 @@ namespace osu.Game.Screens.Menu
AddRangeInternal(new[]
{
new GlobalScrollAdjustsVolume(),
buttonsContainer = new ParallaxContainer
{
ParallaxAmount = 0.01f,

View File

@ -28,6 +28,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.IO.Archives;
using osu.Game.Online.API;
using osu.Game.Overlays;
using osu.Game.Overlays.Volume;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
@ -251,7 +252,11 @@ namespace osu.Game.Screens.Play
dependencies.CacheAs(HealthProcessor);
InternalChild = GameplayClockContainer = CreateGameplayClockContainer(Beatmap.Value, DrawableRuleset.GameplayStartTime);
InternalChildren = new Drawable[]
{
new GlobalScrollAdjustsVolume(),
GameplayClockContainer = CreateGameplayClockContainer(Beatmap.Value, DrawableRuleset.GameplayStartTime),
};
AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer));

View File

@ -27,6 +27,7 @@ using osu.Game.Input;
using osu.Game.Localisation;
using osu.Game.Overlays;
using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Volume;
using osu.Game.Performance;
using osu.Game.Scoring;
using osu.Game.Screens.Menu;
@ -190,6 +191,7 @@ namespace osu.Game.Screens.Play
InternalChildren = new Drawable[]
{
new GlobalScrollAdjustsVolume(),
(content = new LogoTrackingContainer
{
Anchor = Anchor.Centre,

View File

@ -31,6 +31,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Overlays.Volume;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Backgrounds;
@ -169,10 +170,12 @@ namespace osu.Game.Screens.Select
AddRangeInternal(new Drawable[]
{
new GlobalScrollAdjustsVolume(),
new VerticalMaskingContainer
{
Children = new Drawable[]
{
new GlobalScrollAdjustsVolume(),
new GridContainer // used for max width implementation
{
RelativeSizeAxes = Axes.Both,