mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 21:43:04 +08:00
Improve UX & input handling when customisation panel is open
This commit is contained in:
parent
167ffac218
commit
86b8357b8b
@ -30,6 +30,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
Width = 400f,
|
||||
State = { Value = Visibility.Visible },
|
||||
SelectedMods = { BindTarget = SelectedMods },
|
||||
}
|
||||
};
|
||||
|
@ -10,16 +10,18 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Effects;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
{
|
||||
public partial class ModCustomisationPanel : VisibilityContainer
|
||||
public partial class ModCustomisationPanel : OverlayContainer, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
private const float header_height = 42f;
|
||||
private const float content_vertical_padding = 20f;
|
||||
@ -35,6 +37,12 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
public Bindable<IReadOnlyList<Mod>> SelectedMods { get; } = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||
|
||||
public override bool HandlePositionalInput => Expanded.Value;
|
||||
|
||||
public override bool HandleNonPositionalInput => Expanded.Value;
|
||||
|
||||
protected override bool BlockPositionalInput => true;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
@ -63,6 +71,7 @@ namespace osu.Game.Overlays.Mods
|
||||
Radius = 20f,
|
||||
Roundness = 5f,
|
||||
},
|
||||
Expanded = { BindTarget = Expanded },
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -110,12 +119,30 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (Expanded.Value && !content.ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
|
||||
Expanded.Value = false;
|
||||
Expanded.Value = false;
|
||||
return base.OnClick(e);
|
||||
}
|
||||
|
||||
return base.OnMouseDown(e);
|
||||
protected override bool OnKeyDown(KeyDownEvent e) => true;
|
||||
|
||||
protected override bool OnScroll(ScrollEvent e) => true;
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case GlobalAction.Back:
|
||||
Expanded.Value = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
||||
{
|
||||
}
|
||||
|
||||
private void updateDisplay()
|
||||
@ -162,8 +189,10 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
private partial class FocusGrabbingContainer : InputBlockingContainer
|
||||
{
|
||||
public override bool RequestsFocus => true;
|
||||
public override bool AcceptsFocus => true;
|
||||
public IBindable<bool> Expanded { get; } = new BindableBool();
|
||||
|
||||
public override bool RequestsFocus => Expanded.Value;
|
||||
public override bool AcceptsFocus => Expanded.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ using osu.Game.Localisation;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Utils;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Overlays.Mods
|
||||
@ -215,7 +216,6 @@ namespace osu.Game.Overlays.Mods
|
||||
},
|
||||
customisationPanel = new ModCustomisationPanel
|
||||
{
|
||||
Alpha = 0f,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Width = 400,
|
||||
@ -508,9 +508,17 @@ namespace osu.Game.Overlays.Mods
|
||||
private void updateCustomisationVisualState()
|
||||
{
|
||||
if (customisationPanel.Expanded.Value)
|
||||
{
|
||||
columnScroll.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
||||
SearchTextBox.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
||||
SearchTextBox.KillFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
columnScroll.FadeColour(Color4.White, 400, Easing.OutQuint);
|
||||
SearchTextBox.FadeColour(Color4.White, 400, Easing.OutQuint);
|
||||
setTextBoxFocus(textSearchStartsActive.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -678,16 +686,12 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
switch (e.Action)
|
||||
{
|
||||
// If the customisation panel is expanded, the back action will be handled by it first.
|
||||
case GlobalAction.Back:
|
||||
// Pressing the back binding should only go back one step at a time.
|
||||
hideOverlay(false);
|
||||
return true;
|
||||
|
||||
// This is handled locally here because this overlay is being registered at the game level
|
||||
// and therefore takes away keyboard focus from the screen stack.
|
||||
case GlobalAction.ToggleModSelection:
|
||||
// Pressing toggle should completely hide the overlay in one shot.
|
||||
hideOverlay(true);
|
||||
hideOverlay();
|
||||
return true;
|
||||
|
||||
// This is handled locally here due to conflicts in input handling between the search text box and the deselect all mods button.
|
||||
@ -710,7 +714,7 @@ namespace osu.Game.Overlays.Mods
|
||||
// If there is no search in progress, it should exit the dialog (a bit weird, but this is the expectation from stable).
|
||||
if (string.IsNullOrEmpty(SearchTerm))
|
||||
{
|
||||
hideOverlay(true);
|
||||
hideOverlay();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -728,18 +732,7 @@ namespace osu.Game.Overlays.Mods
|
||||
|
||||
return base.OnPressed(e);
|
||||
|
||||
void hideOverlay(bool immediate)
|
||||
{
|
||||
if (customisationPanel.Expanded.Value)
|
||||
{
|
||||
customisationPanel.Expanded.Value = false;
|
||||
|
||||
if (!immediate)
|
||||
return;
|
||||
}
|
||||
|
||||
BackButton.TriggerClick();
|
||||
}
|
||||
void hideOverlay() => BackButton.TriggerClick();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IKeyBindingHandler{PlatformAction}"/>
|
||||
|
Loading…
Reference in New Issue
Block a user