1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 02:52:54 +08:00

Clear pressed keys and last replay frame when detaching replay from ruleset input manager

This commit is contained in:
Bartłomiej Dach 2024-07-03 10:18:45 +02:00
parent 7f1d113454
commit 294aa09c41
No known key found for this signature in database

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Input.StateChanges;
using osu.Framework.Input.StateChanges.Events;
using osu.Framework.Input.States;
using osu.Game.Configuration;
@ -108,7 +109,11 @@ namespace osu.Game.Rulesets.UI
get => replayInputHandler;
set
{
if (replayInputHandler != null) RemoveHandler(replayInputHandler);
if (replayInputHandler != null)
{
RemoveHandler(replayInputHandler);
new ReplayStateReset().Apply(CurrentState, this);
}
replayInputHandler = value;
UseParentInput = replayInputHandler == null;
@ -220,6 +225,19 @@ namespace osu.Game.Rulesets.UI
RealmKeyBindingStore.ClearDuplicateBindings(KeyBindings);
}
}
private class ReplayStateReset : IInput
{
public void Apply(InputState state, IInputStateChangeHandler handler)
{
if (!(state is RulesetInputManagerInputState<T> inputState))
throw new InvalidOperationException($"{nameof(ReplayState<T>)} should only be applied to a {nameof(RulesetInputManagerInputState<T>)}");
inputState.LastReplayState = null;
handler.HandleInputStateChange(new ReplayStateChangeEvent<T>(state, this, inputState.LastReplayState?.PressedActions.ToArray() ?? [], []));
}
}
}
public class RulesetInputManagerInputState<T> : InputState