mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 03:25:11 +08:00
Tidy up escape handling
This commit is contained in:
parent
8cf1553fd5
commit
6a80a21078
@ -2,7 +2,6 @@
|
||||
// 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;
|
||||
|
||||
@ -26,6 +25,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
focus = value;
|
||||
if (!focus && HasFocus)
|
||||
//todo: replace with KillInput after ppy/osu-framework#1656 is merged.
|
||||
GetContainingInputManager().ChangeFocus(null);
|
||||
}
|
||||
}
|
||||
@ -39,18 +39,10 @@ namespace osu.Game.Graphics.UserInterface
|
||||
BorderThickness = 0;
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
protected override void KillFocus()
|
||||
{
|
||||
if (!args.Repeat && args.Key == Key.Escape)
|
||||
{
|
||||
if (Text.Length > 0)
|
||||
Text = string.Empty;
|
||||
else
|
||||
Exit?.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.OnKeyDown(state, args);
|
||||
base.KillFocus();
|
||||
Exit?.Invoke();
|
||||
}
|
||||
|
||||
public override bool RequestsFocus => HoldFocus;
|
||||
|
@ -9,10 +9,12 @@ using osu.Framework.Input;
|
||||
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 @@ namespace osu.Game.Graphics.UserInterface
|
||||
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,21 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
|
||||
protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), TextSize = CalculatedTextSize };
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (action == GlobalAction.Back)
|
||||
{
|
||||
if (Text.Length > 0)
|
||||
Text = string.Empty;
|
||||
else
|
||||
KillFocus();
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool OnReleased(GlobalAction action) => false;
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace osu.Game.Graphics.UserInterface
|
||||
|
||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
||||
{
|
||||
if (HandlePendingText(state)) return true;
|
||||
if (HandlePendingText(state)) return false;
|
||||
|
||||
if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed)
|
||||
{
|
||||
|
@ -202,9 +202,6 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
|
||||
switch (args.Key)
|
||||
{
|
||||
case Key.Escape:
|
||||
finalise();
|
||||
return true;
|
||||
case Key.Delete:
|
||||
{
|
||||
if (state.Keyboard.ShiftPressed)
|
||||
|
@ -148,8 +148,6 @@ namespace osu.Game.Screens.Menu
|
||||
case Key.Space:
|
||||
logo?.TriggerOnClick(state);
|
||||
return true;
|
||||
case Key.Escape:
|
||||
return goBack();
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -181,16 +179,7 @@ namespace osu.Game.Screens.Menu
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnReleased(GlobalAction action)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.Back:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool OnReleased(GlobalAction action) => false;
|
||||
|
||||
private void onPlay()
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ using osu.Framework.Audio;
|
||||
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.Input.Bindings;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.Menu;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
||||
@ -106,6 +104,8 @@ namespace osu.Game.Screens
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (!IsCurrentScreen) return false;
|
||||
|
||||
if (action == GlobalAction.Back && AllowBackButton)
|
||||
{
|
||||
Exit();
|
||||
@ -117,20 +117,6 @@ namespace osu.Game.Screens
|
||||
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user