From 5ebec53970a8e6a3b24ec401a65a9028ba928eab Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Aug 2017 19:17:42 +0900 Subject: [PATCH] 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