From c9723352977ecf57fbe8cfb579d8497482dd42a8 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 22 May 2017 15:25:37 +0900 Subject: [PATCH] Add InputTarget to capture input from columns before hit objects. --- osu.Game.Rulesets.Mania/UI/Column.cs | 34 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index dea00433e6..e1a925937d 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -95,6 +95,12 @@ namespace osu.Game.Rulesets.Mania.UI Name = "Hit objects", RelativeSizeAxes = Axes.Both, }, + // For column lighting, we need to capture input events before the notes + new InputTarget + { + KeyDown = onKeyDown, + KeyUp = onKeyUp + } } }, new Container @@ -178,12 +184,9 @@ namespace osu.Game.Rulesets.Mania.UI } } - public void Add(DrawableHitObject hitObject) - { - ControlPointContainer.Add(hitObject); - } + public void Add(DrawableHitObject hitObject) => ControlPointContainer.Add(hitObject); - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + private bool onKeyDown(InputState state, KeyDownEventArgs args) { if (args.Repeat) return false; @@ -197,7 +200,7 @@ namespace osu.Game.Rulesets.Mania.UI return false; } - protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + private bool onKeyUp(InputState state, KeyUpEventArgs args) { if (args.Key == Key) { @@ -207,5 +210,24 @@ namespace osu.Game.Rulesets.Mania.UI return false; } + + /// + /// This is a simple container which delegates various input events that have to be captured before the notes. + /// + private class InputTarget : Container + { + public Func KeyDown; + public Func KeyUp; + + public InputTarget() + { + RelativeSizeAxes = Axes.Both; + AlwaysPresent = true; + Alpha = 0; + } + + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) => KeyDown?.Invoke(state, args) ?? false; + protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) => KeyUp?.Invoke(state, args) ?? false; + } } }