1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:07:25 +08:00

Get key binding container once instead of getting on every touch

This commit is contained in:
pikokr 2021-12-27 21:20:52 +09:00
parent 327822de5b
commit 58994b790c
3 changed files with 12 additions and 15 deletions

View File

@ -13,6 +13,11 @@ namespace osu.Game.Rulesets.Mania
: base(ruleset, variant, SimultaneousBindingMode.Unique)
{
}
public RulesetKeyBindingContainer GetKeyBindingContainer()
{
return (RulesetKeyBindingContainer)KeyBindingContainer;
}
}
public enum ManiaAction

View File

@ -136,31 +136,22 @@ namespace osu.Game.Rulesets.Mania.UI
{
}
// https://github.com/ppy/osu-framework/blob/49c954321c3686628b2c223670363438f88a0341/osu.Framework/Graphics/Drawable.cs#L1513-L1524
private T findClosestParent<T>() where T : class, IDrawable
private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; }
private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingManager()
{
Drawable cursor = this;
while ((cursor = cursor.Parent) != null)
{
if (cursor is T match)
return match;
}
return default;
return keyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer();
}
private ManiaInputManager.RulesetKeyBindingContainer keyBindingManager => findClosestParent<ManiaInputManager.RulesetKeyBindingContainer>();
protected override bool OnTouchDown(TouchDownEvent e)
{
keyBindingManager.TriggerPressed(Action.Value);
getKeyBindingManager().TriggerPressed(Action.Value);
return base.OnTouchDown(e);
}
protected override void OnTouchUp(TouchUpEvent e)
{
keyBindingManager.TriggerReleased(Action.Value);
getKeyBindingManager().TriggerReleased(Action.Value);
}
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos)

View File

@ -50,6 +50,7 @@ namespace osu.Game.Rulesets.UI
/// <summary>
/// The key conversion input manager for this DrawableRuleset.
/// </summary>
[Cached]
public PassThroughInputManager KeyBindingInputManager;
public override double GameplayStartTime => Objects.FirstOrDefault()?.StartTime - 2000 ?? 0;