1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 22:22:54 +08:00

Merge pull request #14560 from Joehuu/privatise-toolbar-offset

Fix overlays closing when clicking any empty area of the toolbar
This commit is contained in:
Dean Herbert 2021-09-01 15:20:54 +09:00 committed by GitHub
commit bee79abe8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 53 deletions

View File

@ -323,6 +323,71 @@ namespace osu.Game.Tests.Visual.Navigation
AddWaitStep("wait two frames", 2);
}
[Test]
public void TestOverlayClosing()
{
// use now playing overlay for "overlay -> background" drag case
// since most overlays use a scroll container that absorbs on mouse down
NowPlayingOverlay nowPlayingOverlay = null;
AddStep("enter menu", () => InputManager.Key(Key.Enter));
AddStep("get and press now playing hotkey", () =>
{
nowPlayingOverlay = Game.ChildrenOfType<NowPlayingOverlay>().Single();
InputManager.Key(Key.F6);
});
// drag tests
// background -> toolbar
AddStep("move cursor to background", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.BottomRight));
AddStep("press left mouse button", () => InputManager.PressButton(MouseButton.Left));
AddStep("move cursor to toolbar", () => InputManager.MoveMouseTo(Game.Toolbar.ScreenSpaceDrawQuad.Centre));
AddStep("release left mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("now playing is hidden", () => nowPlayingOverlay.State.Value == Visibility.Hidden);
AddStep("press now playing hotkey", () => InputManager.Key(Key.F6));
// toolbar -> background
AddStep("press left mouse button", () => InputManager.PressButton(MouseButton.Left));
AddStep("move cursor to background", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.BottomRight));
AddStep("release left mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("now playing is still visible", () => nowPlayingOverlay.State.Value == Visibility.Visible);
// background -> overlay
AddStep("press left mouse button", () => InputManager.PressButton(MouseButton.Left));
AddStep("move cursor to now playing overlay", () => InputManager.MoveMouseTo(nowPlayingOverlay.ScreenSpaceDrawQuad.Centre));
AddStep("release left mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("now playing is still visible", () => nowPlayingOverlay.State.Value == Visibility.Visible);
// overlay -> background
AddStep("press left mouse button", () => InputManager.PressButton(MouseButton.Left));
AddStep("move cursor to background", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.BottomRight));
AddStep("release left mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("now playing is still visible", () => nowPlayingOverlay.State.Value == Visibility.Visible);
// background -> background
AddStep("press left mouse button", () => InputManager.PressButton(MouseButton.Left));
AddStep("move cursor to left", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.BottomLeft));
AddStep("release left mouse button", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("now playing is hidden", () => nowPlayingOverlay.State.Value == Visibility.Hidden);
AddStep("press now playing hotkey", () => InputManager.Key(Key.F6));
// click tests
// toolbar
AddStep("move cursor to toolbar", () => InputManager.MoveMouseTo(Game.Toolbar.ScreenSpaceDrawQuad.Centre));
AddStep("click left mouse button", () => InputManager.Click(MouseButton.Left));
AddAssert("now playing is still visible", () => nowPlayingOverlay.State.Value == Visibility.Visible);
// background
AddStep("move cursor to background", () => InputManager.MoveMouseTo(Game.ScreenSpaceDrawQuad.BottomRight));
AddStep("click left mouse button", () => InputManager.Click(MouseButton.Left));
AddAssert("now playing is hidden", () => nowPlayingOverlay.State.Value == Visibility.Hidden);
}
private void pushEscape() =>
AddStep("Press escape", () => InputManager.Key(Key.Escape));

View File

@ -104,6 +104,8 @@ namespace osu.Game
protected Container ScreenOffsetContainer { get; private set; }
private Container overlayOffsetContainer;
[Resolved]
private FrameworkConfigManager frameworkConfig { get; set; }
@ -120,7 +122,7 @@ namespace osu.Game
public virtual StableStorage GetStorageForStableInstall() => null;
public float ToolbarOffset => (Toolbar?.Position.Y ?? 0) + (Toolbar?.DrawHeight ?? 0);
private float toolbarOffset => (Toolbar?.Position.Y ?? 0) + (Toolbar?.DrawHeight ?? 0);
private IdleTracker idleTracker;
@ -158,7 +160,7 @@ namespace osu.Game
private readonly string[] args;
private readonly List<OverlayContainer> overlays = new List<OverlayContainer>();
private readonly List<OsuFocusedOverlayContainer> focusedOverlays = new List<OsuFocusedOverlayContainer>();
private readonly List<OverlayContainer> visibleBlockingOverlays = new List<OverlayContainer>();
@ -193,7 +195,7 @@ namespace osu.Game
/// <param name="hideToolbar">Whether the toolbar should also be hidden.</param>
public void CloseAllOverlays(bool hideToolbar = true)
{
foreach (var overlay in overlays)
foreach (var overlay in focusedOverlays)
overlay.Hide();
if (hideToolbar) Toolbar.Hide();
@ -692,9 +694,16 @@ namespace osu.Game
},
}
},
overlayContent = new Container { RelativeSizeAxes = Axes.Both },
rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
overlayOffsetContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
overlayContent = new Container { RelativeSizeAxes = Axes.Both },
rightFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
leftFloatingOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
}
},
topMostOverlayContent = new Container { RelativeSizeAxes = Axes.Both },
idleTracker,
new ConfineMouseTracker()
@ -731,7 +740,6 @@ namespace osu.Game
loadComponentSingleFile(Notifications.With(d =>
{
d.GetToolbarHeight = () => ToolbarOffset;
d.Anchor = Anchor.TopRight;
d.Origin = Anchor.TopRight;
}), rightFloatingOverlayContent.Add, true);
@ -757,7 +765,7 @@ namespace osu.Game
loadComponentSingleFile(channelManager = new ChannelManager(), AddInternal, true);
loadComponentSingleFile(chatOverlay = new ChatOverlay(), overlayContent.Add, true);
loadComponentSingleFile(new MessageNotifier(), AddInternal, true);
loadComponentSingleFile(Settings = new SettingsOverlay { GetToolbarHeight = () => ToolbarOffset }, leftFloatingOverlayContent.Add, true);
loadComponentSingleFile(Settings = new SettingsOverlay(), leftFloatingOverlayContent.Add, true);
var changelogOverlay = loadComponentSingleFile(new ChangelogOverlay(), overlayContent.Add, true);
loadComponentSingleFile(userProfile = new UserProfileOverlay(), overlayContent.Add, true);
loadComponentSingleFile(beatmapSetOverlay = new BeatmapSetOverlay(), overlayContent.Add, true);
@ -766,14 +774,12 @@ namespace osu.Game
loadComponentSingleFile(new LoginOverlay
{
GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}, rightFloatingOverlayContent.Add, true);
loadComponentSingleFile(new NowPlayingOverlay
{
GetToolbarHeight = () => ToolbarOffset,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}, rightFloatingOverlayContent.Add, true);
@ -904,8 +910,8 @@ namespace osu.Game
if (cache)
dependencies.CacheAs(component);
if (component is OverlayContainer overlay)
overlays.Add(overlay);
if (component is OsuFocusedOverlayContainer overlay)
focusedOverlays.Add(overlay);
// schedule is here to ensure that all component loads are done after LoadComplete is run (and thus all dependencies are cached).
// with some better organisation of LoadComplete to do construction and dependency caching in one step, followed by calls to loadComponentSingleFile,
@ -1013,8 +1019,8 @@ namespace osu.Game
{
base.UpdateAfterChildren();
ScreenOffsetContainer.Padding = new MarginPadding { Top = ToolbarOffset };
overlayContent.Padding = new MarginPadding { Top = ToolbarOffset };
ScreenOffsetContainer.Padding = new MarginPadding { Top = toolbarOffset };
overlayOffsetContainer.Padding = new MarginPadding { Top = toolbarOffset };
var horizontalOffset = 0f;

View File

@ -10,7 +10,6 @@ using osuTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using System;
namespace osu.Game.Overlays
{
@ -20,11 +19,6 @@ namespace osu.Game.Overlays
private const float transition_time = 400;
/// <summary>
/// Provide a source for the toolbar height.
/// </summary>
public Func<float> GetToolbarHeight;
public LoginOverlay()
{
AutoSizeAxes = Axes.Both;
@ -94,12 +88,5 @@ namespace osu.Game.Overlays
settingsSection.Bounding = false;
this.FadeOut(transition_time);
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
}
}
}

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Overlays.Notifications;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Localisation;
@ -30,11 +29,6 @@ namespace osu.Game.Overlays
private FlowContainer<NotificationSection> sections;
/// <summary>
/// Provide a source for the toolbar height.
/// </summary>
public Func<float> GetToolbarHeight;
[BackgroundDependencyLoader]
private void load()
{
@ -168,12 +162,5 @@ namespace osu.Game.Overlays
updateCounts();
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
}
}
}

View File

@ -55,11 +55,6 @@ namespace osu.Game.Overlays
protected override string PopInSampleName => "UI/now-playing-pop-in";
protected override string PopOutSampleName => "UI/now-playing-pop-out";
/// <summary>
/// Provide a source for the toolbar height.
/// </summary>
public Func<float> GetToolbarHeight;
[Resolved]
private MusicController musicController { get; set; }
@ -246,7 +241,6 @@ namespace osu.Game.Overlays
base.UpdateAfterChildren();
Height = dragContainer.Height;
dragContainer.Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
}
protected override void Update()

View File

@ -54,11 +54,6 @@ namespace osu.Game.Overlays
protected override string PopInSampleName => "UI/settings-pop-in";
/// <summary>
/// Provide a source for the toolbar height.
/// </summary>
public Func<float> GetToolbarHeight;
private readonly bool showSidebar;
private LoadingLayer loading;
@ -193,7 +188,6 @@ namespace osu.Game.Overlays
base.UpdateAfterChildren();
ContentContainer.Margin = new MarginPadding { Left = Sidebar?.DrawWidth ?? 0 };
Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
}
private const double fade_in_duration = 1000;

View File

@ -18,7 +18,7 @@ using osu.Game.Input.Bindings;
namespace osu.Game.Overlays.Toolbar
{
public class Toolbar : VisibilityContainer, IKeyBindingHandler<GlobalAction>
public class Toolbar : OverlayContainer, IKeyBindingHandler<GlobalAction>
{
public const float HEIGHT = 40;
public const float TOOLTIP_HEIGHT = 30;
@ -41,6 +41,8 @@ namespace osu.Game.Overlays.Toolbar
// Toolbar and its components need keyboard input even when hidden.
public override bool PropagateNonPositionalInputSubTree => true;
protected override bool BlockScrollInput => false;
public Toolbar()
{
RelativeSizeAxes = Axes.X;