Add InputTarget to capture input from columns before hit objects.

This commit is contained in:
smoogipooo
2017-05-22 15:25:37 +09:00
parent 409464381c
commit c972335297

View File

@ -95,6 +95,12 @@ namespace osu.Game.Rulesets.Mania.UI
Name = "Hit objects", Name = "Hit objects",
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
// For column lighting, we need to capture input events before the notes
new InputTarget
{
KeyDown = onKeyDown,
KeyUp = onKeyUp
}
} }
}, },
new Container new Container
@ -178,12 +184,9 @@ namespace osu.Game.Rulesets.Mania.UI
} }
} }
public void Add(DrawableHitObject<ManiaHitObject, ManiaJudgement> hitObject) public void Add(DrawableHitObject<ManiaHitObject, ManiaJudgement> hitObject) => ControlPointContainer.Add(hitObject);
{
ControlPointContainer.Add(hitObject);
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) private bool onKeyDown(InputState state, KeyDownEventArgs args)
{ {
if (args.Repeat) if (args.Repeat)
return false; return false;
@ -197,7 +200,7 @@ namespace osu.Game.Rulesets.Mania.UI
return false; return false;
} }
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) private bool onKeyUp(InputState state, KeyUpEventArgs args)
{ {
if (args.Key == Key) if (args.Key == Key)
{ {
@ -207,5 +210,24 @@ namespace osu.Game.Rulesets.Mania.UI
return false; return false;
} }
/// <summary>
/// This is a simple container which delegates various input events that have to be captured before the notes.
/// </summary>
private class InputTarget : Container
{
public Func<InputState, KeyDownEventArgs, bool> KeyDown;
public Func<InputState, KeyUpEventArgs, bool> 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;
}
} }
} }