mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:57:52 +08:00
Use new InputStateChangeEvent for RulesetInputManager
This commit is contained in:
parent
492b5edb02
commit
c8e9d9375f
@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Input.Handlers;
|
using osu.Framework.Input.Handlers;
|
||||||
using osu.Framework.Input.StateChanges;
|
using osu.Framework.Input.StateChanges;
|
||||||
|
using osu.Framework.Input.StateChanges.Events;
|
||||||
using osu.Framework.Input.States;
|
using osu.Framework.Input.States;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Input.Handlers
|
namespace osu.Game.Input.Handlers
|
||||||
@ -40,7 +43,29 @@ namespace osu.Game.Input.Handlers
|
|||||||
|
|
||||||
public void Apply(InputState state, IInputStateChangeHandler handler)
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,9 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.EventArgs;
|
using osu.Framework.Input.EventArgs;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Input.StateChanges;
|
using osu.Framework.Input.StateChanges;
|
||||||
|
using osu.Framework.Input.StateChanges.Events;
|
||||||
using osu.Framework.Input.States;
|
using osu.Framework.Input.States;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -56,33 +58,20 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
#region Action mapping (for replays)
|
#region Action mapping (for replays)
|
||||||
|
|
||||||
private List<T> lastPressedActions = new List<T>();
|
public override void HandleInputStateChange(InputStateChangeEvent inputStateChange)
|
||||||
|
{
|
||||||
|
if (inputStateChange is ReplayStateChangeEvent<T> replayStateChanged)
|
||||||
|
{
|
||||||
|
foreach (var action in replayStateChanged.ReleasedActions)
|
||||||
|
KeyBindingContainer.TriggerReleased(action);
|
||||||
|
|
||||||
public override void HandleCustomInput(InputState state, IInput input)
|
foreach (var action in replayStateChanged.PressedActions)
|
||||||
{
|
KeyBindingContainer.TriggerPressed(action);
|
||||||
if (!(input is ReplayState<T> replayState))
|
|
||||||
{
|
|
||||||
base.HandleCustomInput(state, input);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (state is RulesetInputManagerInputState<T> inputState)
|
|
||||||
{
|
{
|
||||||
inputState.LastReplayState = replayState;
|
base.HandleInputStateChange(inputStateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we handle states specifically coming from a replay source.
|
|
||||||
// These have extra action information rather than keyboard keys or mouse buttons.
|
|
||||||
|
|
||||||
List<T> newActions = replayState.PressedActions;
|
|
||||||
|
|
||||||
foreach (var released in lastPressedActions.Except(newActions))
|
|
||||||
KeyBindingContainer.TriggerReleased(released);
|
|
||||||
|
|
||||||
foreach (var pressed in newActions.Except(lastPressedActions))
|
|
||||||
KeyBindingContainer.TriggerPressed(pressed);
|
|
||||||
|
|
||||||
lastPressedActions = newActions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user