From 442a649c6362416c03755e763034f5dfec43f741 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 30 Dec 2017 20:45:41 +0900 Subject: [PATCH] Make all FocusedOverlays hide on clicks outside of themselves Also allows wheel events to pass through around them. --- .../Containers/OsuFocusedOverlayContainer.cs | 42 +++++++++++++++++++ osu.Game/Overlays/MusicController.cs | 2 - osu.Game/Overlays/SettingsOverlay.cs | 3 -- osu.Game/Overlays/UserProfileOverlay.cs | 10 ----- .../Select/Options/BeatmapOptionsOverlay.cs | 2 + 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/osu.Game/Graphics/Containers/OsuFocusedOverlayContainer.cs b/osu.Game/Graphics/Containers/OsuFocusedOverlayContainer.cs index c788df3066..a6d1414676 100644 --- a/osu.Game/Graphics/Containers/OsuFocusedOverlayContainer.cs +++ b/osu.Game/Graphics/Containers/OsuFocusedOverlayContainer.cs @@ -5,6 +5,8 @@ using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using OpenTK; namespace osu.Game.Graphics.Containers { @@ -22,6 +24,46 @@ namespace osu.Game.Graphics.Containers StateChanged += onStateChanged; } + /// + /// Whether mouse input should be blocked screen-wide while this overlay is visible. + /// Performing mouse actions outside of the valid extents will hide the overlay but pass the events through. + /// + public virtual bool BlockScreenWideMouse => BlockPassThroughMouse; + + // receive input outside our bounds so we can trigger a close event on ourselves. + public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => BlockScreenWideMouse || base.ReceiveMouseInputAt(screenSpacePos); + + protected override bool OnWheel(InputState state) + { + // always allow wheel to pass through to stuff outside our DrawRectangle. + if (!base.ReceiveMouseInputAt(state.Mouse.NativeState.Position)) + return false; + + return BlockPassThroughMouse; + } + + protected override bool OnClick(InputState state) + { + if (!base.ReceiveMouseInputAt(state.Mouse.NativeState.Position)) + { + State = Visibility.Hidden; + return true; + } + + return base.OnClick(state); + } + + protected override bool OnDragStart(InputState state) + { + if (!base.ReceiveMouseInputAt(state.Mouse.NativeState.Position)) + { + State = Visibility.Hidden; + return true; + } + + return base.OnDragStart(state); + } + private void onStateChanged(Visibility visibility) { switch (visibility) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index b8f33c9a60..b19eab47a0 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -65,8 +65,6 @@ namespace osu.Game.Overlays AlwaysPresent = true; } - protected override bool OnDragStart(InputState state) => true; - protected override bool OnDrag(InputState state) { Trace.Assert(state.Mouse.PositionMouseDown != null, "state.Mouse.PositionMouseDown != null"); diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index a80f6d4da8..ea406e88d7 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -54,7 +54,6 @@ namespace osu.Game.Overlays { this.showSidebar = showSidebar; RelativeSizeAxes = Axes.Y; - AutoSizeAxes = Axes.X; } protected virtual IEnumerable CreateSections() => null; @@ -177,8 +176,6 @@ namespace osu.Game.Overlays public override bool AcceptsFocus => true; - protected override bool OnClick(InputState state) => true; - protected override void OnFocus(InputState state) { GetContainingInputManager().ChangeFocus(searchTextBox); diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 9aa660147a..c2e7fc5b44 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -10,7 +10,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; -using osu.Framework.Input; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; @@ -34,15 +33,6 @@ namespace osu.Game.Overlays public const float CONTENT_X_MARGIN = 50; - // receive input outside our bounds so we can trigger a close event on ourselves. - public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true; - - protected override bool OnClick(InputState state) - { - State = Visibility.Hidden; - return true; - } - public UserProfileOverlay() { FirstWaveColour = OsuColour.Gray(0.4f); diff --git a/osu.Game/Screens/Select/Options/BeatmapOptionsOverlay.cs b/osu.Game/Screens/Select/Options/BeatmapOptionsOverlay.cs index c66cc7beff..789064a5f1 100644 --- a/osu.Game/Screens/Select/Options/BeatmapOptionsOverlay.cs +++ b/osu.Game/Screens/Select/Options/BeatmapOptionsOverlay.cs @@ -25,6 +25,8 @@ namespace osu.Game.Screens.Select.Options private readonly Box holder; private readonly FillFlowContainer buttonsContainer; + public override bool BlockScreenWideMouse => false; + protected override void PopIn() { base.PopIn();