From 4597a765b842bcdd98934f38eb7674ad512a5370 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 31 Jan 2017 19:00:54 -0500 Subject: [PATCH] Fix escape key to exit PlaySongSelect This is less than ideal but is the least disruptive solution. The InputManager itself holds Escape keypresses from getting to anything else if something is focused. --- osu.Game/Screens/Select/FilterControl.cs | 7 +++---- osu.Game/Screens/Select/PlaySongSelect.cs | 1 + osu.Game/Screens/Select/SearchTextBox.cs | 17 ++++++++++------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Select/FilterControl.cs b/osu.Game/Screens/Select/FilterControl.cs index 9bcf3ad9a2..fa2aac6fae 100644 --- a/osu.Game/Screens/Select/FilterControl.cs +++ b/osu.Game/Screens/Select/FilterControl.cs @@ -18,6 +18,7 @@ namespace osu.Game.Screens.Select public string Search => searchTextBox.Text; public SortMode Sort { get; private set; } = SortMode.Title; + public Action Exit; private SearchTextBox searchTextBox; @@ -50,10 +51,8 @@ namespace osu.Game.Screens.Select } }; - searchTextBox.OnChange += (sender, text) => - { - FilterChanged?.Invoke(); - }; + searchTextBox.OnChange += (sender, text) => FilterChanged?.Invoke(); + searchTextBox.Exit = () => Exit?.Invoke(); } public void Deactivate() diff --git a/osu.Game/Screens/Select/PlaySongSelect.cs b/osu.Game/Screens/Select/PlaySongSelect.cs index 5570af73af..27d37e7028 100644 --- a/osu.Game/Screens/Select/PlaySongSelect.cs +++ b/osu.Game/Screens/Select/PlaySongSelect.cs @@ -146,6 +146,7 @@ namespace osu.Game.Screens.Select Position = wedged_container_start_position, RelativeSizeAxes = Axes.X, FilterChanged = filterChanged, + Exit = () => Exit(), }, beatmapInfoWedge = new BeatmapInfoWedge { diff --git a/osu.Game/Screens/Select/SearchTextBox.cs b/osu.Game/Screens/Select/SearchTextBox.cs index 8b95d74fb5..9428fe7f32 100644 --- a/osu.Game/Screens/Select/SearchTextBox.cs +++ b/osu.Game/Screens/Select/SearchTextBox.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using OpenTK; using OpenTK.Graphics; using OpenTK.Input; @@ -15,6 +16,7 @@ namespace osu.Game.Screens.Select { protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255); protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255); + public Action Exit; public bool GrabFocus = false; private SpriteText placeholder; @@ -60,11 +62,6 @@ namespace osu.Game.Screens.Select }); } - protected override void LoadComplete() - { - base.LoadComplete(); - } - protected override void Update() { if (GrabFocus && !HasFocus && IsVisible) @@ -72,10 +69,16 @@ namespace osu.Game.Screens.Select base.Update(); } + protected override void OnFocusLost(InputState state) + { + if (state.Keyboard.Keys.Any(key => key == Key.Escape)) + Exit?.Invoke(); + base.OnFocusLost(state); + } + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (args.Key == Key.Left || args.Key == Key.Right - || args.Key == Key.Enter || args.Key == Key.Escape) + if (args.Key == Key.Left || args.Key == Key.Right || args.Key == Key.Enter) return false; return base.OnKeyDown(state, args); }