mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Get key binding container once instead of getting on every touch
This commit is contained in:
parent
327822de5b
commit
58994b790c
@ -13,6 +13,11 @@ namespace osu.Game.Rulesets.Mania
|
||||
: base(ruleset, variant, SimultaneousBindingMode.Unique)
|
||||
{
|
||||
}
|
||||
|
||||
public RulesetKeyBindingContainer GetKeyBindingContainer()
|
||||
{
|
||||
return (RulesetKeyBindingContainer)KeyBindingContainer;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ManiaAction
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user