Merge pull request #2769 from Aergwyn/allow-back-in-player

Standardise handling of "Back" key binding
This commit is contained in:
Dan Balasescu 2018-07-02 15:01:23 +09:00 committed by GitHub
commit 154e30fe64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 98 additions and 89 deletions

View File

@ -8,12 +8,14 @@
using osu.Framework.Input;
using OpenTK;
using osu.Framework.Configuration;
using osu.Framework.Input.Bindings;
using osu.Game.Audio;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
namespace osu.Game.Graphics.Containers
{
public class OsuFocusedOverlayContainer : FocusedOverlayContainer, IPreviewTrackOwner
public class OsuFocusedOverlayContainer : FocusedOverlayContainer, IPreviewTrackOwner, IKeyBindingHandler<GlobalAction>
{
private SampleChannel samplePopIn;
private SampleChannel samplePopOut;
@ -65,6 +67,19 @@ protected override bool OnClick(InputState state)
return base.OnClick(state);
}
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
State = Visibility.Hidden;
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => false;
private void onStateChanged(Visibility visibility)
{
switch (visibility)

View File

@ -2,9 +2,10 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using OpenTK.Input;
using osu.Framework.Input;
using System;
using osu.Game.Input.Bindings;
using OpenTK.Input;
namespace osu.Game.Graphics.UserInterface
{
@ -19,6 +20,7 @@ public class FocusedTextBox : OsuTextBox
public Action Exit;
private bool focus;
public bool HoldFocus
{
get { return focus; }
@ -26,7 +28,7 @@ public bool HoldFocus
{
focus = value;
if (!focus && HasFocus)
GetContainingInputManager().ChangeFocus(null);
base.KillFocus();
}
}
@ -41,18 +43,34 @@ protected override void OnFocus(InputState state)
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!args.Repeat && args.Key == Key.Escape)
{
if (Text.Length > 0)
Text = string.Empty;
else
Exit?.Invoke();
return true;
}
if (!HasFocus) return false;
if (args.Key == Key.Escape)
return false; // disable the framework-level handling of escape key for confority (we use GlobalAction.Back).
return base.OnKeyDown(state, args);
}
public override bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
if (Text.Length > 0)
{
Text = string.Empty;
return true;
}
}
return base.OnPressed(action);
}
protected override void KillFocus()
{
base.KillFocus();
Exit?.Invoke();
}
public override bool RequestsFocus => HoldFocus;
}
}

View File

@ -18,7 +18,7 @@ public class OsuPasswordTextBox : OsuTextBox
{
protected override Drawable GetDrawableCharacter(char c) => new PasswordMaskChar(CalculatedTextSize);
public override bool AllowClipboardExport => false;
protected override bool AllowClipboardExport => false;
private readonly CapsWarning warning;

View File

@ -9,10 +9,12 @@
using osu.Game.Graphics.Sprites;
using OpenTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
namespace osu.Game.Graphics.UserInterface
{
public class OsuTextBox : TextBox
public class OsuTextBox : TextBox, IKeyBindingHandler<GlobalAction>
{
protected override Color4 BackgroundUnfocused => Color4.Black.Opacity(0.5f);
protected override Color4 BackgroundFocused => OsuColour.Gray(0.3f).Opacity(0.8f);
@ -33,10 +35,7 @@ public OsuTextBox()
TextContainer.Height = 0.5f;
CornerRadius = 5;
Current.DisabledChanged += disabled =>
{
Alpha = disabled ? 0.3f : 1;
};
Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; };
}
[BackgroundDependencyLoader]
@ -59,5 +58,18 @@ protected override void OnFocusLost(InputState state)
}
protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), TextSize = CalculatedTextSize };
public virtual bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
KillFocus();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => false;
}
}

View File

@ -34,8 +34,6 @@ public SearchTextBox()
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (HandlePendingText(state)) return true;
if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed)
{
switch (args.Key)

View File

@ -202,9 +202,6 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
switch (args.Key)
{
case Key.Escape:
finalise();
return true;
case Key.Delete:
{
if (state.Keyboard.ShiftPressed)

View File

@ -148,8 +148,6 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
case Key.Space:
logo?.TriggerOnClick(state);
return true;
case Key.Escape:
return goBack();
}
return false;
@ -181,16 +179,7 @@ private bool goBack()
}
}
public bool OnReleased(GlobalAction action)
{
switch (action)
{
case GlobalAction.Back:
return true;
default:
return false;
}
}
public bool OnReleased(GlobalAction action) => false;
private void onPlay()
{

View File

@ -1,34 +1,34 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using OpenTK.Input;
namespace osu.Game.Screens.Menu
{
public class ExitConfirmOverlay : HoldToConfirmOverlay
public class ExitConfirmOverlay : HoldToConfirmOverlay, IKeyBindingHandler<GlobalAction>
{
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
public bool OnPressed(GlobalAction action)
{
if (args.Key == Key.Escape && !args.Repeat)
if (action == GlobalAction.Back)
{
BeginConfirm();
return true;
}
return base.OnKeyDown(state, args);
return false;
}
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
public bool OnReleased(GlobalAction action)
{
if (args.Key == Key.Escape)
if (action == GlobalAction.Back)
{
AbortConfirm();
return true;
}
return base.OnKeyUp(state, args);
return false;
}
}
}

View File

@ -8,7 +8,6 @@
using osu.Framework.Audio.Sample;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
@ -17,7 +16,6 @@
using osu.Game.Rulesets;
using osu.Game.Screens.Menu;
using OpenTK;
using OpenTK.Input;
using osu.Game.Overlays;
using osu.Framework.Graphics.Containers;
@ -108,6 +106,8 @@ private void load(BindableBeatmap beatmap, OsuGame osu, AudioManager audio, Bind
public bool OnPressed(GlobalAction action)
{
if (!IsCurrentScreen) return false;
if (action == GlobalAction.Back && AllowBackButton)
{
Exit();
@ -119,20 +119,6 @@ public bool OnPressed(GlobalAction action)
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back && AllowBackButton;
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Repeat || !IsCurrentScreen) return false;
switch (args.Key)
{
case Key.Escape:
Exit();
return true;
}
return base.OnKeyDown(state, args);
}
protected override void OnResuming(Screen last)
{
sampleExit?.Play();

View File

@ -1,12 +1,9 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input;
using OpenTK.Input;
using osu.Game.Graphics;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using System.Linq;
namespace osu.Game.Screens.Play
{
@ -21,16 +18,5 @@ private void load(OsuColour colours)
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!args.Repeat && args.Key == Key.Escape)
{
InternalButtons.Children.Last().TriggerOnClick();
return true;
}
return base.OnKeyDown(state, args);
}
}
}

View File

@ -15,10 +15,13 @@
using osu.Framework.Graphics.Shapes;
using OpenTK.Input;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
namespace osu.Game.Screens.Play
{
public abstract class GameplayMenuOverlay : OverlayContainer
public abstract class GameplayMenuOverlay : OverlayContainer, IKeyBindingHandler<GlobalAction>
{
private const int transition_duration = 200;
private const int button_height = 70;
@ -31,6 +34,11 @@ public abstract class GameplayMenuOverlay : OverlayContainer
public Action OnRetry;
public Action OnQuit;
/// <summary>
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
/// </summary>
protected virtual Action BackAction => () => InternalButtons.Children.Last().TriggerOnClick();
public abstract string Header { get; }
public abstract string Description { get; }
@ -219,6 +227,19 @@ protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
return base.OnKeyDown(state, args);
}
public bool OnPressed(GlobalAction action)
{
if (action == GlobalAction.Back)
{
BackAction.Invoke();
return true;
}
return false;
}
public bool OnReleased(GlobalAction action) => action == GlobalAction.Back;
private void buttonSelectionChanged(DialogButton button, bool isSelected)
{
if (!isSelected)

View File

@ -6,11 +6,9 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Timing;
using osu.Game.Graphics;
using OpenTK.Graphics;
using OpenTK.Input;
namespace osu.Game.Screens.Play
{
@ -138,16 +136,7 @@ public class PauseOverlay : GameplayMenuOverlay
public override string Header => "paused";
public override string Description => "you're not going to do what i think you're going to do, are ya?";
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (!args.Repeat && args.Key == Key.Escape)
{
InternalButtons.Children.First().TriggerOnClick();
return true;
}
return base.OnKeyDown(state, args);
}
protected override Action BackAction => () => InternalButtons.Children.First().TriggerOnClick();
[BackgroundDependencyLoader]
private void load(OsuColour colours)

View File

@ -49,8 +49,6 @@ public class Player : ScreenWithBeatmapBackground, IProvideCursor
public bool AllowLeadIn { get; set; } = true;
public bool AllowResults { get; set; } = true;
protected override bool AllowBackButton => false;
private Bindable<bool> mouseWheelDisabled;
private Bindable<double> userAudioOffset;

View File

@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="ppy.osu.Framework" Version="2018.626.0" />
<PackageReference Include="ppy.osu.Framework" Version="2018.629.0" />
<PackageReference Include="SharpCompress" Version="0.17.1" />
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />