Skip to content

Commit

Permalink
Improve hold input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LumpBloom7 committed Mar 18, 2024
1 parent 1d06b48 commit cd74a45
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions osu.Game.Rulesets.Sentakki/Objects/Drawables/DrawableHold.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -71,7 +71,6 @@ protected override void OnFree()
base.OnFree();
HoldStartTime = null;
TotalHoldTime = 0;
pressedCount = 0;
}

protected override void UpdateInitialTransforms()
Expand Down Expand Up @@ -218,8 +217,24 @@ private void endHold()
HoldStartTime = null;
}

// Tracks how many inputs are pressing on this HitObject currently
private int pressedCount = 0;
private SentakkiInputManager sentakkiActionInputManager = null!;
internal SentakkiInputManager SentakkiActionInputManager => sentakkiActionInputManager ??= (SentakkiInputManager)GetContainingInputManager();

private int pressedCount
{
get
{
int count = 0;
foreach (var pressedAction in sentakkiActionInputManager.PressedActions)
{
if (pressedAction == SentakkiAction.Key1 + HitObject.Lane)
++count;
}

return count;
}
}

public bool OnPressed(KeyBindingPressEvent<SentakkiAction> e)
{
if (AllJudged)
Expand All @@ -228,8 +243,6 @@ public bool OnPressed(KeyBindingPressEvent<SentakkiAction> e)
if (e.Action != SentakkiAction.Key1 + HitObject.Lane)
return false;

pressedCount++;

if (beginHoldAt(Time.Current - Head.HitObject.StartTime))
{
Head.UpdateResult();
Expand All @@ -250,7 +263,8 @@ public void OnReleased(KeyBindingReleaseEvent<SentakkiAction> e)
return;

// We only release the hold once ALL inputs are released
if (--pressedCount != 0)
// We check for 1 here as drawables receive the event before the counter decrements
if (pressedCount > 1)
return;

endHold();
Expand Down

0 comments on commit cd74a45

Please sign in to comment.