From 7e21ddb5eb5ab0fbdc466fe1209bad805fe999b9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 19:17:29 +0900 Subject: [PATCH 01/12] Remove usage of HideOnEscape --- osu.Desktop/Overlays/VersionManager.cs | 2 -- osu.Game/Graphics/UserInterface/FocusedTextBox.cs | 9 +++++---- osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs | 2 -- osu.Game/Overlays/Toolbar/Toolbar.cs | 2 -- osu.Game/Screens/Play/MenuOverlay.cs | 5 ++--- osu.Game/Screens/Play/SongProgress.cs | 2 -- osu.Game/Screens/Select/BeatmapInfoWedge.cs | 2 -- 7 files changed, 7 insertions(+), 17 deletions(-) diff --git a/osu.Desktop/Overlays/VersionManager.cs b/osu.Desktop/Overlays/VersionManager.cs index 18fa43ab5c..b445340f50 100644 --- a/osu.Desktop/Overlays/VersionManager.cs +++ b/osu.Desktop/Overlays/VersionManager.cs @@ -27,8 +27,6 @@ namespace osu.Desktop.Overlays private UpdateManager updateManager; private NotificationOverlay notificationOverlay; - protected override bool HideOnEscape => false; - public override bool HandleInput => false; [BackgroundDependencyLoader] diff --git a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs index dbbb069f7c..fe060f70f0 100644 --- a/osu.Game/Graphics/UserInterface/FocusedTextBox.cs +++ b/osu.Game/Graphics/UserInterface/FocusedTextBox.cs @@ -5,7 +5,6 @@ using OpenTK.Graphics; using OpenTK.Input; using osu.Framework.Input; using System; -using System.Linq; namespace osu.Game.Graphics.UserInterface { @@ -37,16 +36,18 @@ namespace osu.Game.Graphics.UserInterface BorderThickness = 0; } - protected override void OnFocusLost(InputState state) + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (state.Keyboard.Keys.Any(key => key == Key.Escape)) + if (args.Key == Key.Escape) { if (Text.Length > 0) Text = string.Empty; else Exit?.Invoke(); + return true; } - base.OnFocusLost(state); + + return base.OnKeyDown(state, args); } public override bool RequestsFocus => HoldFocus; diff --git a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs index fa192b0825..cd77fb9f5b 100644 --- a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs +++ b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs @@ -15,8 +15,6 @@ namespace osu.Game.Graphics.UserInterface.Volume { private readonly VolumeMeter volumeMeterMaster; - protected override bool HideOnEscape => false; - private void volumeChanged(double newVolume) { Show(); diff --git a/osu.Game/Overlays/Toolbar/Toolbar.cs b/osu.Game/Overlays/Toolbar/Toolbar.cs index 1ecfe90aa1..f9821782a7 100644 --- a/osu.Game/Overlays/Toolbar/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar/Toolbar.cs @@ -22,8 +22,6 @@ namespace osu.Game.Overlays.Toolbar private readonly ToolbarUserArea userArea; - protected override bool HideOnEscape => false; - protected override bool BlockPassThroughMouse => false; private const double transition_time = 500; diff --git a/osu.Game/Screens/Play/MenuOverlay.cs b/osu.Game/Screens/Play/MenuOverlay.cs index a0f867d248..0a8e172e57 100644 --- a/osu.Game/Screens/Play/MenuOverlay.cs +++ b/osu.Game/Screens/Play/MenuOverlay.cs @@ -22,8 +22,6 @@ namespace osu.Game.Screens.Play private const int button_height = 70; private const float background_alpha = 0.75f; - protected override bool HideOnEscape => false; - protected override bool BlockPassThroughKeyboard => true; public Action OnRetry; @@ -95,7 +93,8 @@ namespace osu.Game.Screens.Play Origin = Anchor.TopCentre, Anchor = Anchor.TopCentre, Height = button_height, - Action = delegate { + Action = delegate + { action?.Invoke(); Hide(); } diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index c513daf3d9..68f0cb3661 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -18,8 +18,6 @@ namespace osu.Game.Screens.Play { private const int bottom_bar_height = 5; - protected override bool HideOnEscape => false; - private static readonly Vector2 handle_size = new Vector2(14, 25); private const float transition_duration = 200; diff --git a/osu.Game/Screens/Select/BeatmapInfoWedge.cs b/osu.Game/Screens/Select/BeatmapInfoWedge.cs index 1fb9c707f0..872f7483b6 100644 --- a/osu.Game/Screens/Select/BeatmapInfoWedge.cs +++ b/osu.Game/Screens/Select/BeatmapInfoWedge.cs @@ -50,8 +50,6 @@ namespace osu.Game.Screens.Select AlwaysPresent = true; } - protected override bool HideOnEscape => false; - protected override bool BlockPassThroughMouse => false; protected override void PopIn() From 5ebec53970a8e6a3b24ec401a65a9028ba928eab Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 19:17:42 +0900 Subject: [PATCH 02/12] Integrate key binding config with main settings --- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 75 ++++++++++++------- osu.Game/Overlays/MainSettings.cs | 51 ++++++++++++- .../Sections/Input/KeyboardSettings.cs | 5 +- .../Settings/Sections/InputSection.cs | 4 +- osu.Game/Overlays/SettingsOverlay.cs | 69 +++++++++-------- 5 files changed, 139 insertions(+), 65 deletions(-) diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 082e1c0eec..3415c22972 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input; -using osu.Framework.Input.Bindings; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Input; @@ -106,12 +105,6 @@ namespace osu.Game.Overlays.KeyBinding } }; - reloadBindings(); - } - - private void reloadBindings() - { - buttons.Clear(); foreach (var b in bindings) buttons.Add(new KeyButton(b)); } @@ -149,23 +142,46 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (HasFocus && !isModifier(args.Key)) + if (args.Key == Key.Delete) { - bindTarget.KeyBinding.KeyCombination = args.Key == Key.Delete ? Key.Unknown : new KeyCombination(state.Keyboard.Keys); - + bindTarget.UpdateKeyCombination(Key.Unknown); store.Update(bindTarget.KeyBinding); GetContainingInputManager().ChangeFocus(null); return true; } + if (HasFocus) + { + bindTarget.UpdateKeyCombination(state.Keyboard.Keys.ToArray()); + if (!isModifier(args.Key)) + finalise(); + return true; + } + return base.OnKeyDown(state, args); } + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + { + if (HasFocus) + { + finalise(); + return true; + } + + return base.OnKeyUp(state, args); + } + + private void finalise() + { + store.Update(bindTarget.KeyBinding); + GetContainingInputManager().ChangeFocus(null); + } + protected override void OnFocusLost(InputState state) { bindTarget.IsBinding = false; bindTarget = null; - reloadBindings(); pressAKey.FadeOut(300, Easing.OutQuint); pressAKey.Padding = new MarginPadding { Bottom = -pressAKey.DrawHeight }; @@ -197,19 +213,16 @@ namespace osu.Game.Overlays.KeyBinding get { return isBinding; } set { + if (value == isBinding) return; isBinding = value; - if (value) + if (isBinding) { box.FadeColour(Color4.White, transition_time, Easing.OutQuint); Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - } else - { - box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); - } + updateHoverState(); } } @@ -261,25 +274,29 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnHover(InputState state) { - if (isBinding) - return false; - - box.FadeColour(hoverColour, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - + if (!isBinding) + updateHoverState(); return base.OnHover(state); } protected override void OnHoverLost(InputState state) { - if (isBinding) - return; - - box.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.White, transition_time, Easing.OutQuint); - + if (!isBinding) + updateHoverState(); base.OnHoverLost(state); } + + private void updateHoverState() + { + box.FadeColour(IsHovered ? hoverColour : Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint); + } + + public void UpdateKeyCombination(params Key[] newCombination) + { + KeyBinding.KeyCombination = newCombination; + Text.Text = KeyBinding.KeyCombination.ReadableString(); + } } } } \ No newline at end of file diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs index 44c4d4ccdb..b040f5043b 100644 --- a/osu.Game/Overlays/MainSettings.cs +++ b/osu.Game/Overlays/MainSettings.cs @@ -2,7 +2,9 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; +using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings.Sections; @@ -10,6 +12,8 @@ namespace osu.Game.Overlays { public class MainSettings : SettingsOverlay { + private readonly KeyBindingOverlay keyBindingOverlay; + protected override IEnumerable CreateSections() => new SettingsSection[] { new GeneralSection(), @@ -17,7 +21,7 @@ namespace osu.Game.Overlays new GameplaySection(), new AudioSection(), new SkinSection(), - new InputSection(), + new InputSection(keyBindingOverlay), new OnlineSection(), new MaintenanceSection(), new DebugSection(), @@ -26,8 +30,51 @@ namespace osu.Game.Overlays protected override Drawable CreateHeader() => new SettingsHeader("settings", "Change the way osu! behaves"); protected override Drawable CreateFooter() => new SettingsFooter(); - public MainSettings() : base(true) + public MainSettings() + : base(true) { + keyBindingOverlay = new KeyBindingOverlay { Depth = 1 }; + keyBindingOverlay.StateChanged += keyBindingOverlay_StateChanged; + } + + public override bool AcceptsFocus => keyBindingOverlay.State != Visibility.Visible; + + private void keyBindingOverlay_StateChanged(VisibilityContainer container, Visibility visibility) + { + const float hidden_width = 120; + + switch (visibility) + { + case Visibility.Visible: + Background.FadeTo(0.9f, 500, Easing.OutQuint); + SectionsContainer.FadeOut(100); + ContentContainer.MoveToX(hidden_width - ContentContainer.DrawWidth, 500, Easing.OutQuint); + break; + case Visibility.Hidden: + Background.FadeTo(0.6f, 500, Easing.OutQuint); + SectionsContainer.FadeIn(500, Easing.OutQuint); + ContentContainer.MoveToX(0, 500, Easing.OutQuint); + break; + } + } + + protected override void PopOut() + { + base.PopOut(); + keyBindingOverlay.State = Visibility.Hidden; + } + + [BackgroundDependencyLoader] + private void load() + { + AddInternal(keyBindingOverlay); + } + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + keyBindingOverlay.Margin = new MarginPadding { Left = ContentContainer.Margin.Left + ContentContainer.DrawWidth + ContentContainer.X }; } } } \ No newline at end of file diff --git a/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs b/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs index 9ead4ca7a4..01e73d0168 100644 --- a/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Input/KeyboardSettings.cs @@ -10,14 +10,15 @@ namespace osu.Game.Overlays.Settings.Sections.Input { protected override string Header => "Keyboard"; - public KeyboardSettings() + public KeyboardSettings(KeyBindingOverlay keyConfig) { Children = new Drawable[] { new OsuButton { RelativeSizeAxes = Axes.X, - Text = "Key Configuration" + Text = "Key Configuration", + Action = () => keyConfig.ToggleVisibility() }, }; } diff --git a/osu.Game/Overlays/Settings/Sections/InputSection.cs b/osu.Game/Overlays/Settings/Sections/InputSection.cs index 65df3746b3..5ece8aad77 100644 --- a/osu.Game/Overlays/Settings/Sections/InputSection.cs +++ b/osu.Game/Overlays/Settings/Sections/InputSection.cs @@ -12,12 +12,12 @@ namespace osu.Game.Overlays.Settings.Sections public override string Header => "Input"; public override FontAwesome Icon => FontAwesome.fa_keyboard_o; - public InputSection() + public InputSection(KeyBindingOverlay keyConfig) { Children = new Drawable[] { new MouseSettings(), - new KeyboardSettings(), + new KeyboardSettings(keyConfig), }; } } diff --git a/osu.Game/Overlays/SettingsOverlay.cs b/osu.Game/Overlays/SettingsOverlay.cs index 76f9ef3326..f62087ee71 100644 --- a/osu.Game/Overlays/SettingsOverlay.cs +++ b/osu.Game/Overlays/SettingsOverlay.cs @@ -29,6 +29,10 @@ namespace osu.Game.Overlays private const float sidebar_padding = 10; + protected Container ContentContainer; + + protected override Container Content => ContentContainer; + private Sidebar sidebar; private SidebarButton selectedSidebarButton; @@ -40,6 +44,8 @@ namespace osu.Game.Overlays private readonly bool showSidebar; + protected Box Background; + protected SettingsOverlay(bool showSidebar) { this.showSidebar = showSidebar; @@ -52,40 +58,43 @@ namespace osu.Game.Overlays [BackgroundDependencyLoader(permitNulls: true)] private void load(OsuGame game) { - Children = new Drawable[] + InternalChild = ContentContainer = new Container { - new Box + Width = width, + RelativeSizeAxes = Axes.Y, + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - Alpha = 0.6f, - }, - SectionsContainer = new SettingsSectionsContainer - { - RelativeSizeAxes = Axes.Y, - Width = width, - Margin = new MarginPadding { Left = SIDEBAR_WIDTH }, - ExpandableHeader = CreateHeader(), - FixedHeader = searchTextBox = new SearchTextBox + Background = new Box { - RelativeSizeAxes = Axes.X, - Origin = Anchor.TopCentre, - Anchor = Anchor.TopCentre, - Width = 0.95f, - Margin = new MarginPadding - { - Top = 20, - Bottom = 20 - }, - Exit = Hide, + RelativeSizeAxes = Axes.Both, + Colour = Color4.Black, + Alpha = 0.6f, }, - Footer = CreateFooter() - }, + SectionsContainer = new SettingsSectionsContainer + { + RelativeSizeAxes = Axes.Both, + ExpandableHeader = CreateHeader(), + FixedHeader = searchTextBox = new SearchTextBox + { + RelativeSizeAxes = Axes.X, + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre, + Width = 0.95f, + Margin = new MarginPadding + { + Top = 20, + Bottom = 20 + }, + Exit = Hide, + }, + Footer = CreateFooter() + }, + } }; if (showSidebar) { - Add(sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); + AddInternal(sidebar = new Sidebar { Width = SIDEBAR_WIDTH }); SectionsContainer.SelectedSection.ValueChanged += section => { @@ -136,7 +145,7 @@ namespace osu.Game.Overlays { base.PopIn(); - SectionsContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); + ContentContainer.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(0, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(1, TRANSITION_LENGTH / 2); @@ -147,7 +156,7 @@ namespace osu.Game.Overlays { base.PopOut(); - SectionsContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); + ContentContainer.MoveToX(-width, TRANSITION_LENGTH, Easing.OutQuint); sidebar?.MoveToX(-SIDEBAR_WIDTH, TRANSITION_LENGTH, Easing.OutQuint); this.FadeTo(0, TRANSITION_LENGTH / 2); @@ -170,8 +179,8 @@ namespace osu.Game.Overlays { base.UpdateAfterChildren(); - SectionsContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; - SectionsContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; + ContentContainer.Margin = new MarginPadding { Left = sidebar?.DrawWidth ?? 0 }; + ContentContainer.Padding = new MarginPadding { Top = getToolbarHeight() }; } protected class SettingsSectionsContainer : SectionsContainer From 71f83dbdfa606541b163d9cc17130bffb884560e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 20:16:40 +0900 Subject: [PATCH 03/12] Add null check for safety --- .../Settings/Sections/Audio/AudioDevicesSettings.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs index 47f7abf571..9b1c5e5e49 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/AudioDevicesSettings.cs @@ -26,8 +26,11 @@ namespace osu.Game.Overlays.Settings.Sections.Audio { base.Dispose(isDisposing); - audio.OnNewDevice -= onDeviceChanged; - audio.OnLostDevice -= onDeviceChanged; + if (audio != null) + { + audio.OnNewDevice -= onDeviceChanged; + audio.OnLostDevice -= onDeviceChanged; + } } private void updateItems() From c41ba7b7042eee8ac1d66839bbb5c6f0c6393451 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 22:55:13 +0900 Subject: [PATCH 04/12] Update with latest framework changes --- .../Bindings/GlobalKeyBindingInputManager.cs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index 4dff25d509..e9eab49c32 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using osu.Framework.Graphics; -using osu.Framework.Input; using osu.Framework.Input.Bindings; namespace osu.Game.Input.Bindings @@ -31,23 +30,7 @@ namespace osu.Game.Input.Bindings new KeyBinding(new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect), }; - protected override bool PropagateKeyDown(IEnumerable drawables, InputState state, KeyDownEventArgs args) - { - if (handler != null) - drawables = new[] { handler }.Concat(drawables); - - // always handle ourselves before all children. - return base.PropagateKeyDown(drawables, state, args); - } - - protected override bool PropagateKeyUp(IEnumerable drawables, InputState state, KeyUpEventArgs args) - { - if (handler != null) - drawables = new[] { handler }.Concat(drawables); - - // always handle ourselves before all children. - return base.PropagateKeyUp(drawables, state, args); - } + protected override IEnumerable GetKeyboardInputQueue() => new[] { handler }.Concat(base.GetKeyboardInputQueue()); } public enum GlobalAction From e64f455ff74d14fcf31f417d8406cc0f86e24241 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:01:10 +0900 Subject: [PATCH 05/12] Escape to cancel, again --- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 3415c22972..274619991c 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -142,12 +142,16 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - if (args.Key == Key.Delete) + switch (args.Key) { - bindTarget.UpdateKeyCombination(Key.Unknown); - store.Update(bindTarget.KeyBinding); - GetContainingInputManager().ChangeFocus(null); - return true; + case Key.Escape: + GetContainingInputManager().ChangeFocus(null); + return true; + case Key.Delete: + bindTarget.UpdateKeyCombination(Key.Unknown); + store.Update(bindTarget.KeyBinding); + GetContainingInputManager().ChangeFocus(null); + return true; } if (HasFocus) From 09089a31260122e1385aa58acbdcbc6bb781731d Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:20:08 +0900 Subject: [PATCH 06/12] Fix potential nullref --- osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index e9eab49c32..31be2e6adc 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -30,7 +30,8 @@ namespace osu.Game.Input.Bindings new KeyBinding(new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect), }; - protected override IEnumerable GetKeyboardInputQueue() => new[] { handler }.Concat(base.GetKeyboardInputQueue()); + protected override IEnumerable GetKeyboardInputQueue() => + handler == null ? base.GetKeyboardInputQueue() : new[] { handler }.Concat(base.GetKeyboardInputQueue()); } public enum GlobalAction From 0c19202b9aff2371e5daef1f7d3d3e6236902b8f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:20:18 +0900 Subject: [PATCH 07/12] Add basic back button --- osu.Game/Overlays/MainSettings.cs | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/osu.Game/Overlays/MainSettings.cs b/osu.Game/Overlays/MainSettings.cs index b040f5043b..6302c56018 100644 --- a/osu.Game/Overlays/MainSettings.cs +++ b/osu.Game/Overlays/MainSettings.cs @@ -5,14 +5,21 @@ using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Settings; using osu.Game.Overlays.Settings.Sections; +using osu.Game.Screens.Ranking; +using OpenTK; namespace osu.Game.Overlays { public class MainSettings : SettingsOverlay { private readonly KeyBindingOverlay keyBindingOverlay; + private BackButton backButton; protected override IEnumerable CreateSections() => new SettingsSection[] { @@ -49,11 +56,15 @@ namespace osu.Game.Overlays Background.FadeTo(0.9f, 500, Easing.OutQuint); SectionsContainer.FadeOut(100); ContentContainer.MoveToX(hidden_width - ContentContainer.DrawWidth, 500, Easing.OutQuint); + + backButton.Delay(100).FadeIn(100); break; case Visibility.Hidden: Background.FadeTo(0.6f, 500, Easing.OutQuint); SectionsContainer.FadeIn(500, Easing.OutQuint); ContentContainer.MoveToX(0, 500, Easing.OutQuint); + + backButton.FadeOut(100); break; } } @@ -68,6 +79,14 @@ namespace osu.Game.Overlays private void load() { AddInternal(keyBindingOverlay); + AddInternal(backButton = new BackButton + { + Alpha = 0, + Height = 150, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Action = () => keyBindingOverlay.Hide() + }); } protected override void UpdateAfterChildren() @@ -75,6 +94,81 @@ namespace osu.Game.Overlays base.UpdateAfterChildren(); keyBindingOverlay.Margin = new MarginPadding { Left = ContentContainer.Margin.Left + ContentContainer.DrawWidth + ContentContainer.X }; + + backButton.Margin = new MarginPadding { Left = ContentContainer.Margin.Left }; + backButton.Width = ContentContainer.DrawWidth + ContentContainer.X; + } + + private class BackButton : OsuClickableContainer + { + private FillFlowContainer flow; + private AspectContainer aspect; + + [BackgroundDependencyLoader] + private void load() + { + Children = new Drawable[] + { + aspect = new AspectContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + RelativeSizeAxes = Axes.Y, + Children = new Drawable[] + { + flow = new FillFlowContainer + { + Anchor = Anchor.TopCentre, + RelativePositionAxes = Axes.Y, + Y = 0.4f, + AutoSizeAxes = Axes.Both, + Origin = Anchor.Centre, + Direction = FillDirection.Horizontal, + Children = new[] + { + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, + new SpriteIcon { Size = new Vector2(15), Shadow = true, Icon = FontAwesome.fa_chevron_left }, + } + }, + new OsuSpriteText + { + Anchor = Anchor.TopCentre, + RelativePositionAxes = Axes.Y, + Y = 0.7f, + TextSize = 12, + Font = @"Exo2.0-Bold", + Origin = Anchor.Centre, + Text = @"back", + }, + } + } + }; + } + + protected override bool OnHover(InputState state) + { + flow.TransformSpacingTo(new Vector2(5), 500, Easing.OutQuint); + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + flow.TransformSpacingTo(new Vector2(0), 500, Easing.OutQuint); + base.OnHoverLost(state); + } + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + aspect.ScaleTo(0.75f, 2000, Easing.OutQuint); + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) + { + aspect.ScaleTo(1, 1000, Easing.OutElastic); + return base.OnMouseUp(state, args); + } } } } \ No newline at end of file From c6c9c5431fe19c4638d24877bb3c7cbced88b7c8 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 23:22:12 +0900 Subject: [PATCH 08/12] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index acb9bfb084..68e461df82 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit acb9bfb084b5607ff31c6269cb7942fa02624b75 +Subproject commit 68e461df82a608d5748e758101f99f9d3081f8b6 From 8c05a40fbfd5decac27b45ecea116d6ce4c23dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 16 Aug 2017 01:10:09 +0900 Subject: [PATCH 09/12] Use SliderStep instead of TestCaseSliderBar This greatly simplifies TestCaseKeyCounter and TestCaseHitObject and allows more future automation. --- .../Visual/TestCaseHitObjects.cs | 27 ++----------------- .../Visual/TestCaseKeyCounter.cs | 27 +++---------------- 2 files changed, 5 insertions(+), 49 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs index df5f9f65b8..8dfaa7ea3d 100644 --- a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs @@ -27,35 +27,13 @@ namespace osu.Desktop.Tests.Visual { var rateAdjustClock = new StopwatchClock(true); framedClock = new FramedClock(rateAdjustClock); - playbackSpeed.ValueChanged += delegate { rateAdjustClock.Rate = playbackSpeed.Value; }; - - playbackSpeed.TriggerChange(); AddStep(@"circles", () => loadHitobjects(HitObjectType.Circle)); AddStep(@"slider", () => loadHitobjects(HitObjectType.Slider)); AddStep(@"spinner", () => loadHitobjects(HitObjectType.Spinner)); - AddToggleStep(@"auto", state => { auto = state; loadHitobjects(mode); }); - - BasicSliderBar sliderBar; - Add(new Container - { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - new SpriteText { Text = "Playback Speed" }, - sliderBar = new BasicSliderBar - { - Width = 150, - Height = 10, - SelectionColor = Color4.Orange, - } - } - }); - - sliderBar.Current.BindTo(playbackSpeed); + AddToggleStep("Auto", state => { auto = state; loadHitobjects(mode); }); + AddSliderStep("Playback speed", 0.0, 2.0, 0.5, v => rateAdjustClock.Rate = v); framedClock.ProcessFrame(); @@ -75,7 +53,6 @@ namespace osu.Desktop.Tests.Visual private HitObjectType mode = HitObjectType.Slider; - private readonly BindableNumber playbackSpeed = new BindableDouble(0.5) { MinValue = 0, MaxValue = 1 }; private readonly Container playfieldContainer; private readonly Container approachContainer; diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs index efb662d3b9..f0c77659eb 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs @@ -34,34 +34,13 @@ namespace osu.Desktop.Tests.Visual new KeyCounterMouse(MouseButton.Right), }, }; - BindableInt bindable = new BindableInt { MinValue = 0, MaxValue = 200, Default = 50 }; - bindable.ValueChanged += delegate { kc.FadeTime = bindable.Value; }; - AddStep("Add Random", () => + + AddStep("Add random", () => { Key key = (Key)((int)Key.A + RNG.Next(26)); kc.Add(new KeyCounterKeyboard(key)); }); - - TestSliderBar sliderBar; - - Add(new Container - { - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - AutoSizeAxes = Axes.Both, - Children = new Drawable[] - { - new SpriteText { Text = "FadeTime" }, - sliderBar = new TestSliderBar - { - Width = 150, - Height = 10, - SelectionColor = Color4.Orange, - } - } - }); - - sliderBar.Current.BindTo(bindable); + AddSliderStep("Fade time", 0, 200, 50, v => kc.FadeTime = v); Add(kc); } From 55b159b976208e72c422d5353639ae8f7fb3628a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Wed, 16 Aug 2017 13:02:11 +0900 Subject: [PATCH 10/12] Remove unnecessary usings --- osu.Desktop.Tests/Visual/TestCaseHitObjects.cs | 4 ---- osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs | 3 --- 2 files changed, 7 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs index 8dfaa7ea3d..75e1a656de 100644 --- a/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs +++ b/osu.Desktop.Tests/Visual/TestCaseHitObjects.cs @@ -2,18 +2,14 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Collections.Generic; -using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Framework.Graphics.UserInterface; using osu.Framework.Timing; using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects.Drawables; using OpenTK; -using OpenTK.Graphics; namespace osu.Desktop.Tests.Visual { diff --git a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs index f0c77659eb..1861a77a3a 100644 --- a/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs +++ b/osu.Desktop.Tests/Visual/TestCaseKeyCounter.cs @@ -1,11 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Configuration; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; -using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Framework.MathUtils; using osu.Game.Screens.Play; From 118d0f09704483c7d8ba03735d1085891d1c3e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 17 Aug 2017 07:28:07 +0900 Subject: [PATCH 11/12] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index acb9bfb084..5c22092e59 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit acb9bfb084b5607ff31c6269cb7942fa02624b75 +Subproject commit 5c22092e590d589927962b8d0173dae5f9b1405c From 4ef1be308037af1d4775b9c0d8a491d5ab2aae00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 17 Aug 2017 08:43:45 +0900 Subject: [PATCH 12/12] More localised key binding hover colour logic --- osu.Game/Overlays/KeyBinding/KeyBindingRow.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 274619991c..44aee0e666 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -220,13 +220,7 @@ namespace osu.Game.Overlays.KeyBinding if (value == isBinding) return; isBinding = value; - if (isBinding) - { - box.FadeColour(Color4.White, transition_time, Easing.OutQuint); - Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); - } - else - updateHoverState(); + updateHoverState(); } } @@ -278,22 +272,28 @@ namespace osu.Game.Overlays.KeyBinding protected override bool OnHover(InputState state) { - if (!isBinding) - updateHoverState(); + updateHoverState(); return base.OnHover(state); } protected override void OnHoverLost(InputState state) { - if (!isBinding) - updateHoverState(); + updateHoverState(); base.OnHoverLost(state); } private void updateHoverState() { - box.FadeColour(IsHovered ? hoverColour : Color4.Black, transition_time, Easing.OutQuint); - Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint); + if (isBinding) + { + box.FadeColour(Color4.White, transition_time, Easing.OutQuint); + Text.FadeColour(Color4.Black, transition_time, Easing.OutQuint); + } + else + { + box.FadeColour(IsHovered ? hoverColour : Color4.Black, transition_time, Easing.OutQuint); + Text.FadeColour(IsHovered ? Color4.Black : Color4.White, transition_time, Easing.OutQuint); + } } public void UpdateKeyCombination(params Key[] newCombination)