// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System.Linq; using osu.Framework.Input.Bindings; using osu.Game.Input.Bindings; using osu.Game.Screens.Play; namespace osu.Game.Rulesets.UI { public abstract class RulesetInputManager : DatabasedKeyBindingInputManager, ICanAttachKeyCounter where T : struct { protected RulesetInputManager(RulesetInfo ruleset, int variant, SimultaneousBindingMode unique) : base(ruleset, variant, unique) { } public void Attach(KeyCounterCollection keyCounter) { var receptor = new ActionReceptor(keyCounter); Add(receptor); keyCounter.SetReceptor(receptor); keyCounter.AddRange(DefaultKeyBindings.Select(b => b.GetAction()).Distinct().Select(b => new KeyCounterAction(b))); } public class ActionReceptor : KeyCounterCollection.Receptor, IKeyBindingHandler { public ActionReceptor(KeyCounterCollection target) : base(target) { } public bool OnPressed(T action) => Target.Children.OfType>().Any(c => c.OnPressed(action)); public bool OnReleased(T action) => Target.Children.OfType>().Any(c => c.OnReleased(action)); } } public interface ICanAttachKeyCounter { void Attach(KeyCounterCollection keyCounter); } }