// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Collections.Generic; using System.Linq; using osu.Game.Rulesets.Mods; using osuTK.Input; namespace osu.Game.Overlays.Mods.Input { /// /// This implementation of receives a sequence of s, /// and maps the sequence of keys onto the items it is provided in . /// In this case, particular mods are not bound to particular keys, the hotkeys are a byproduct of mod ordering. /// public class SequentialModHotkeyHandler : IModHotkeyHandler { public static SequentialModHotkeyHandler Create(ModType modType) { switch (modType) { case ModType.DifficultyReduction: return new SequentialModHotkeyHandler(new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P }); case ModType.DifficultyIncrease: return new SequentialModHotkeyHandler(new[] { Key.A, Key.S, Key.D, Key.F, Key.G, Key.H, Key.J, Key.K, Key.L }); case ModType.Automation: return new SequentialModHotkeyHandler(new[] { Key.Z, Key.X, Key.C, Key.V, Key.B, Key.N, Key.M }); default: throw new ArgumentOutOfRangeException(nameof(modType), modType, $"Cannot create {nameof(SequentialModHotkeyHandler)} for provided mod type"); } } private readonly Key[] toggleKeys; private SequentialModHotkeyHandler(Key[] keys) { toggleKeys = keys; } public bool HandleHotkeyPressed(Key hotkey, IEnumerable availableMods) { int index = Array.IndexOf(toggleKeys, hotkey); if (index < 0) return false; var modState = availableMods.ElementAtOrDefault(index); if (modState == null || modState.Filtered.Value) return false; modState.Active.Toggle(); return true; } } }