From f6c168be27568d460ff39d57bb76480faf06ef3c Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Mon, 8 Jan 2018 18:21:18 +0100 Subject: [PATCH] add skip cutscene as "in game" keybinding --- .../Bindings/GlobalKeyBindingInputManager.cs | 13 +++++++++++- .../KeyBinding/GlobalKeyBindingsSection.cs | 20 +++++++++++++++---- osu.Game/Screens/Play/SkipButton.cs | 17 ++++++++-------- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs index bf492af776..f5e54775fb 100644 --- a/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs +++ b/osu.Game/Input/Bindings/GlobalKeyBindingInputManager.cs @@ -20,7 +20,9 @@ namespace osu.Game.Input.Bindings handler = game; } - public override IEnumerable DefaultKeyBindings => new[] + public override IEnumerable DefaultKeyBindings => GlobalKeyBindings.Concat(InGameKeyBindings); + + public IEnumerable GlobalKeyBindings => new[] { new KeyBinding(InputKey.F8, GlobalAction.ToggleChat), new KeyBinding(InputKey.F9, GlobalAction.ToggleSocial), @@ -33,6 +35,11 @@ namespace osu.Game.Input.Bindings new KeyBinding(new[] { InputKey.MouseWheelDown }, GlobalAction.DecreaseVolume), }; + public IEnumerable InGameKeyBindings => new[] + { + new KeyBinding(InputKey.Space, GlobalAction.SkipCutscene) + }; + protected override IEnumerable KeyBindingInputQueue => handler == null ? base.KeyBindingInputQueue : new[] { handler }.Concat(base.KeyBindingInputQueue); } @@ -55,5 +62,9 @@ namespace osu.Game.Input.Bindings IncreaseVolume, [Description("Decrease Volume")] DecreaseVolume, + + // In-Game Keybindings + [Description("Skip Cutscene")] + SkipCutscene } } diff --git a/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs b/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs index 8ec0a44d9b..f5b3096404 100644 --- a/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs @@ -1,8 +1,8 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Input.Bindings; using osu.Game.Graphics; +using osu.Game.Input.Bindings; using osu.Game.Overlays.Settings; namespace osu.Game.Overlays.KeyBinding @@ -12,19 +12,31 @@ namespace osu.Game.Overlays.KeyBinding public override FontAwesome Icon => FontAwesome.fa_osu_hot; public override string Header => "Global"; - public GlobalKeyBindingsSection(KeyBindingContainer manager) + public GlobalKeyBindingsSection(GlobalKeyBindingInputManager manager) { Add(new DefaultBindingsSubsection(manager)); + Add(new InGameKeyBindingsSubsection(manager)); } + private class DefaultBindingsSubsection : KeyBindingsSubsection { protected override string Header => string.Empty; - public DefaultBindingsSubsection(KeyBindingContainer manager) + public DefaultBindingsSubsection(GlobalKeyBindingInputManager manager) : base(null) { - Defaults = manager.DefaultKeyBindings; + Defaults = manager.GlobalKeyBindings; + } + } + + private class InGameKeyBindingsSubsection : KeyBindingsSubsection + { + protected override string Header => "In Game"; + + public InGameKeyBindingsSubsection(GlobalKeyBindingInputManager manager) : base(null) + { + Defaults = manager.InGameKeyBindings; } } } diff --git a/osu.Game/Screens/Play/SkipButton.cs b/osu.Game/Screens/Play/SkipButton.cs index 0001aa0e76..55b2e21c53 100644 --- a/osu.Game/Screens/Play/SkipButton.cs +++ b/osu.Game/Screens/Play/SkipButton.cs @@ -14,13 +14,14 @@ using osu.Game.Graphics.Sprites; using osu.Game.Screens.Ranking; using OpenTK; using OpenTK.Graphics; -using OpenTK.Input; using osu.Framework.Graphics.Shapes; using osu.Game.Graphics.Containers; +using osu.Framework.Input.Bindings; +using osu.Game.Input.Bindings; namespace osu.Game.Screens.Play { - public class SkipButton : Container + public class SkipButton : Container, IKeyBindingHandler { private readonly double startTime; public IAdjustableClock AudioClock; @@ -117,20 +118,20 @@ namespace osu.Game.Screens.Play remainingTimeBox.ResizeWidthTo((float)Math.Max(0, 1 - (Time.Current - displayTime) / (beginFadeTime - displayTime)), 120, Easing.OutQuint); } - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + public bool OnPressed(GlobalAction action) { - if (args.Repeat) return false; - - switch (args.Key) + switch (action) { - case Key.Space: + case GlobalAction.SkipCutscene: button.TriggerOnClick(); return true; } - return base.OnKeyDown(state, args); + return false; } + public bool OnReleased(GlobalAction action) => false; + private class FadeContainer : Container, IStateful { public event Action StateChanged;