mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 16:12:57 +08:00
Merge pull request #1807 from peppy/focused-overlay-improvements
QoL improvements to focused overlays
This commit is contained in:
commit
1a67a8a061
@ -5,6 +5,8 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Input;
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Containers
|
namespace osu.Game.Graphics.Containers
|
||||||
{
|
{
|
||||||
@ -22,6 +24,48 @@ namespace osu.Game.Graphics.Containers
|
|||||||
StateChanged += onStateChanged;
|
StateChanged += onStateChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnDrag(InputState state) => State == Visibility.Hidden;
|
||||||
|
|
||||||
private void onStateChanged(Visibility visibility)
|
private void onStateChanged(Visibility visibility)
|
||||||
{
|
{
|
||||||
switch (visibility)
|
switch (visibility)
|
||||||
|
@ -27,6 +27,7 @@ using osu.Game.Overlays.Notifications;
|
|||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
|
using OpenTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game
|
namespace osu.Game
|
||||||
{
|
{
|
||||||
@ -284,10 +285,10 @@ namespace osu.Game
|
|||||||
|
|
||||||
notifications.Enabled.BindTo(ShowOverlays);
|
notifications.Enabled.BindTo(ShowOverlays);
|
||||||
|
|
||||||
ShowOverlays.ValueChanged += visible =>
|
ShowOverlays.ValueChanged += show =>
|
||||||
{
|
{
|
||||||
//central game screen change logic.
|
//central game screen change logic.
|
||||||
if (!visible)
|
if (!show)
|
||||||
{
|
{
|
||||||
hideAllOverlays();
|
hideAllOverlays();
|
||||||
musicController.State = Visibility.Hidden;
|
musicController.State = Visibility.Hidden;
|
||||||
@ -331,10 +332,21 @@ namespace osu.Game
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Task asyncLoadStream;
|
private Task asyncLoadStream;
|
||||||
|
private int visibleOverlayCount;
|
||||||
|
|
||||||
private void loadComponentSingleFile<T>(T d, Action<T> add)
|
private void loadComponentSingleFile<T>(T d, Action<T> add)
|
||||||
where T : Drawable
|
where T : Drawable
|
||||||
{
|
{
|
||||||
|
var focused = d as FocusedOverlayContainer;
|
||||||
|
if (focused != null)
|
||||||
|
{
|
||||||
|
focused.StateChanged += s =>
|
||||||
|
{
|
||||||
|
visibleOverlayCount += s == Visibility.Visible ? 1 : -1;
|
||||||
|
screenStack.FadeColour(visibleOverlayCount > 0 ? OsuColour.Gray(0.5f) : Color4.White, 500, Easing.OutQuint);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// schedule is here to ensure that all component loads are done after LoadComplete is run (and thus all dependencies are cached).
|
// 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,
|
// with some better organisation of LoadComplete to do construction and dependency caching in one step, followed by calls to loadComponentSingleFile,
|
||||||
// we could avoid the need for scheduling altogether.
|
// we could avoid the need for scheduling altogether.
|
||||||
|
@ -240,8 +240,6 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public override bool AcceptsFocus => true;
|
public override bool AcceptsFocus => true;
|
||||||
|
|
||||||
protected override bool OnClick(InputState state) => true;
|
|
||||||
|
|
||||||
protected override void OnFocus(InputState state)
|
protected override void OnFocus(InputState state)
|
||||||
{
|
{
|
||||||
//this is necessary as textbox is masked away and therefore can't get focus :(
|
//this is necessary as textbox is masked away and therefore can't get focus :(
|
||||||
|
@ -65,10 +65,10 @@ namespace osu.Game.Overlays
|
|||||||
AlwaysPresent = true;
|
AlwaysPresent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnDragStart(InputState state) => true;
|
|
||||||
|
|
||||||
protected override bool OnDrag(InputState state)
|
protected override bool OnDrag(InputState state)
|
||||||
{
|
{
|
||||||
|
if (base.OnDrag(state)) return true;
|
||||||
|
|
||||||
Trace.Assert(state.Mouse.PositionMouseDown != null, "state.Mouse.PositionMouseDown != null");
|
Trace.Assert(state.Mouse.PositionMouseDown != null, "state.Mouse.PositionMouseDown != null");
|
||||||
|
|
||||||
Vector2 change = state.Mouse.Position - state.Mouse.PositionMouseDown.Value;
|
Vector2 change = state.Mouse.Position - state.Mouse.PositionMouseDown.Value;
|
||||||
@ -77,7 +77,7 @@ namespace osu.Game.Overlays
|
|||||||
change *= change.Length <= 0 ? 0 : (float)Math.Pow(change.Length, 0.7f) / change.Length;
|
change *= change.Length <= 0 ? 0 : (float)Math.Pow(change.Length, 0.7f) / change.Length;
|
||||||
|
|
||||||
dragContainer.MoveTo(change);
|
dragContainer.MoveTo(change);
|
||||||
return base.OnDrag(state);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnDragEnd(InputState state)
|
protected override bool OnDragEnd(InputState state)
|
||||||
|
@ -177,8 +177,6 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public override bool AcceptsFocus => true;
|
public override bool AcceptsFocus => true;
|
||||||
|
|
||||||
protected override bool OnClick(InputState state) => true;
|
|
||||||
|
|
||||||
protected override void OnFocus(InputState state)
|
protected override void OnFocus(InputState state)
|
||||||
{
|
{
|
||||||
GetContainingInputManager().ChangeFocus(searchTextBox);
|
GetContainingInputManager().ChangeFocus(searchTextBox);
|
||||||
|
@ -10,7 +10,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
@ -34,15 +33,6 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public const float CONTENT_X_MARGIN = 50;
|
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()
|
public UserProfileOverlay()
|
||||||
{
|
{
|
||||||
FirstWaveColour = OsuColour.Gray(0.4f);
|
FirstWaveColour = OsuColour.Gray(0.4f);
|
||||||
|
@ -25,6 +25,8 @@ namespace osu.Game.Screens.Select.Options
|
|||||||
private readonly Box holder;
|
private readonly Box holder;
|
||||||
private readonly FillFlowContainer<BeatmapOptionsButton> buttonsContainer;
|
private readonly FillFlowContainer<BeatmapOptionsButton> buttonsContainer;
|
||||||
|
|
||||||
|
public override bool BlockScreenWideMouse => false;
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
base.PopIn();
|
base.PopIn();
|
||||||
|
Loading…
Reference in New Issue
Block a user