Update autoplay and replay handling to result in actions, not keys

This commit is contained in:
Dean Herbert
2017-08-24 15:36:42 +09:00
parent 189988236b
commit a7a7e0323f
7 changed files with 64 additions and 34 deletions

View File

@ -2,6 +2,8 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.Input;
using osu.Framework.Input.Handlers;
using osu.Framework.Platform;
using OpenTK;
@ -29,5 +31,18 @@ namespace osu.Game.Input.Handlers
public override bool IsActive => true;
public override int Priority => 0;
public class ReplayState<T> : InputState
where T : struct
{
public List<T> PressedActions;
public override InputState Clone()
{
var clone = (ReplayState<T>)base.Clone();
clone.PressedActions = new List<T>(PressedActions);
return clone;
}
}
}
}

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Input;
using osu.Framework.MathUtils;
using osu.Game.Input.Handlers;
@ -18,7 +17,7 @@ namespace osu.Game.Rulesets.Replays
/// The ReplayHandler will take a replay and handle the propagation of updates to the input stack.
/// It handles logic of any frames which *must* be executed.
/// </summary>
public class FramedReplayInputHandler : ReplayInputHandler
public abstract class FramedReplayInputHandler : ReplayInputHandler
{
private readonly Replay replay;
@ -31,7 +30,7 @@ namespace osu.Game.Rulesets.Replays
private int nextFrameIndex => MathHelper.Clamp(currentFrameIndex + (currentDirection > 0 ? 1 : -1), 0, Frames.Count - 1);
public FramedReplayInputHandler(Replay replay)
protected FramedReplayInputHandler(Replay replay)
{
this.replay = replay;
}
@ -51,7 +50,7 @@ namespace osu.Game.Rulesets.Replays
{
}
private Vector2? position
protected Vector2? Position
{
get
{
@ -62,23 +61,7 @@ namespace osu.Game.Rulesets.Replays
}
}
public override List<InputState> GetPendingStates()
{
var buttons = new HashSet<MouseButton>();
if (CurrentFrame?.MouseLeft ?? false)
buttons.Add(MouseButton.Left);
if (CurrentFrame?.MouseRight ?? false)
buttons.Add(MouseButton.Right);
return new List<InputState>
{
new InputState
{
Mouse = new ReplayMouseState(ToScreenSpace(position ?? Vector2.Zero), buttons),
Keyboard = new ReplayKeyboardState(new List<Key>())
}
};
}
public override List<InputState> GetPendingStates() => new List<InputState>();
public bool AtLastFrame => currentFrameIndex == Frames.Count - 1;
public bool AtFirstFrame => currentFrameIndex == 0;
@ -133,10 +116,9 @@ namespace osu.Game.Rulesets.Replays
protected class ReplayMouseState : MouseState
{
public ReplayMouseState(Vector2 position, IEnumerable<MouseButton> list)
public ReplayMouseState(Vector2 position)
{
Position = position;
list.ForEach(b => SetPressed(b, true));
}
}

View File

@ -97,7 +97,7 @@ namespace osu.Game.Rulesets.UI
/// <returns>The input manager.</returns>
public abstract PassThroughInputManager CreateInputManager();
protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay);
protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => null;
public Replay Replay { get; private set; }