mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Use new InputStateChangeEvent for RulesetInputManager
This commit is contained in:
@ -3,10 +3,13 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Input.Handlers;
|
||||
using osu.Framework.Input.StateChanges;
|
||||
using osu.Framework.Input.StateChanges.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Input.Handlers
|
||||
@ -40,7 +43,29 @@ namespace osu.Game.Input.Handlers
|
||||
|
||||
public void Apply(InputState state, IInputStateChangeHandler handler)
|
||||
{
|
||||
handler.HandleCustomInput(state, this);
|
||||
if (!(state is RulesetInputManagerInputState<T> inputState))
|
||||
throw new InvalidOperationException($"{nameof(ReplayState<T>)} should only be applied to a {nameof(RulesetInputManagerInputState<T>)}");
|
||||
|
||||
var lastPressed = inputState.LastReplayState?.PressedActions ?? new List<T>();
|
||||
var released = lastPressed.Except(PressedActions).ToArray();
|
||||
var pressed = PressedActions.Except(lastPressed).ToArray();
|
||||
|
||||
inputState.LastReplayState = this;
|
||||
|
||||
handler.HandleInputStateChange(new ReplayStateChangeEvent<T>(state, this, released, pressed));
|
||||
}
|
||||
}
|
||||
|
||||
public class ReplayStateChangeEvent<T> : InputStateChangeEvent
|
||||
{
|
||||
public readonly T[] ReleasedActions;
|
||||
public readonly T[] PressedActions;
|
||||
|
||||
public ReplayStateChangeEvent(InputState state, IInput input, T[] releasedActions, T[] pressedActions)
|
||||
: base(state, input)
|
||||
{
|
||||
ReleasedActions = releasedActions;
|
||||
PressedActions = pressedActions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user