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

Merge pull request #7831 from peppy/improve-relax-key-down-up

Add a key up delay for relax mod presses
This commit is contained in:
Dean Herbert 2020-02-15 11:42:53 +09:00 committed by GitHub
commit 4379466b1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 33 deletions

View File

@ -9,6 +9,7 @@ using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.UI;
using static osu.Game.Input.Handlers.ReplayInputHandler;
@ -24,6 +25,21 @@ namespace osu.Game.Rulesets.Osu.Mods
/// </summary>
private const float relax_leniency = 3;
private bool isDownState;
private bool wasLeft;
private OsuInputManager osuInputManager;
private ReplayState<OsuAction> state;
private double lastStateChangeTime;
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
// grab the input manager for future use.
osuInputManager = (OsuInputManager)drawableRuleset.KeyBindingInputManager;
osuInputManager.AllowUserPresses = false;
}
public void Update(Playfield playfield)
{
bool requiresHold = false;
@ -63,11 +79,14 @@ namespace osu.Game.Rulesets.Osu.Mods
if (requiresHit)
{
addAction(false);
addAction(true);
changeState(false);
changeState(true);
}
addAction(requiresHold);
if (requiresHold)
changeState(true);
else if (isDownState && time - lastStateChangeTime > AutoGenerator.KEY_UP_DELAY)
changeState(false);
void handleHitCircle(DrawableHitCircle circle)
{
@ -77,39 +96,28 @@ namespace osu.Game.Rulesets.Osu.Mods
Debug.Assert(circle.HitObject.HitWindows != null);
requiresHit |= circle.HitObject.HitWindows.CanBeHit(time - circle.HitObject.StartTime);
}
}
private bool wasHit;
private bool wasLeft;
private OsuInputManager osuInputManager;
private void addAction(bool hitting)
{
if (wasHit == hitting)
return;
wasHit = hitting;
var state = new ReplayState<OsuAction>
void changeState(bool down)
{
PressedActions = new List<OsuAction>()
};
if (isDownState == down)
return;
if (hitting)
{
state.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
wasLeft = !wasLeft;
isDownState = down;
lastStateChangeTime = time;
state = new ReplayState<OsuAction>
{
PressedActions = new List<OsuAction>()
};
if (down)
{
state.PressedActions.Add(wasLeft ? OsuAction.LeftButton : OsuAction.RightButton);
wasLeft = !wasLeft;
}
state?.Apply(osuInputManager.CurrentState, osuInputManager);
}
state.Apply(osuInputManager.CurrentState, osuInputManager);
}
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
{
// grab the input manager for future use.
osuInputManager = (OsuInputManager)drawableRuleset.KeyBindingInputManager;
osuInputManager.AllowUserPresses = false;
}
}
}

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Replays
#region Constants
// Shared amongst all modes
protected const double KEY_UP_DELAY = 50;
public const double KEY_UP_DELAY = 50;
#endregion