1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 16:32:59 +08:00

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

@ -0,0 +1,32 @@
using System.Collections.Generic;
using osu.Framework.Input;
using osu.Game.Rulesets.Replays;
using OpenTK;
namespace osu.Game.Rulesets.Osu.Replays
{
public class OsuReplayInputHandler : FramedReplayInputHandler
{
public OsuReplayInputHandler(Replay replay)
: base(replay)
{
}
public override List<InputState> GetPendingStates()
{
List<OsuAction> actions = new List<OsuAction>();
if (CurrentFrame?.MouseLeft ?? false) actions.Add(OsuAction.LeftButton);
if (CurrentFrame?.MouseRight ?? false) actions.Add(OsuAction.RightButton);
return new List<InputState>
{
new ReplayState<OsuAction>
{
Mouse = new ReplayMouseState(ToScreenSpace(Position ?? Vector2.Zero)),
PressedActions = actions
}
};
}
}
}

View File

@ -10,9 +10,11 @@ using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables; using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Osu.Scoring; using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.Replays;
namespace osu.Game.Rulesets.Osu.UI namespace osu.Game.Rulesets.Osu.UI
{ {
@ -49,6 +51,8 @@ namespace osu.Game.Rulesets.Osu.UI
return null; return null;
} }
protected override FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new OsuReplayInputHandler(replay);
protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(0.75f); protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(0.75f);
} }
} }

View File

@ -78,6 +78,7 @@
<Compile Include="OsuDifficulty\Skills\Speed.cs" /> <Compile Include="OsuDifficulty\Skills\Speed.cs" />
<Compile Include="OsuDifficulty\Utils\History.cs" /> <Compile Include="OsuDifficulty\Utils\History.cs" />
<Compile Include="OsuInputManager.cs" /> <Compile Include="OsuInputManager.cs" />
<Compile Include="Replays\OsuReplayInputHandler.cs" />
<Compile Include="UI\Cursor\CursorTrail.cs" /> <Compile Include="UI\Cursor\CursorTrail.cs" />
<Compile Include="UI\Cursor\GameplayCursor.cs" /> <Compile Include="UI\Cursor\GameplayCursor.cs" />
<Compile Include="UI\OsuSettings.cs" /> <Compile Include="UI\OsuSettings.cs" />

View File

@ -4,7 +4,6 @@
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Input; using osu.Framework.Input;
using OpenTK.Input;
namespace osu.Game.Rulesets.Taiko.Replays namespace osu.Game.Rulesets.Taiko.Replays
{ {
@ -17,21 +16,18 @@ namespace osu.Game.Rulesets.Taiko.Replays
public override List<InputState> GetPendingStates() public override List<InputState> GetPendingStates()
{ {
var keys = new List<Key>(); var keys = new List<TaikoAction>();
if (CurrentFrame?.MouseRight1 == true) if (CurrentFrame?.MouseRight1 == true)
keys.Add(Key.F); keys.Add(TaikoAction.LeftCentre);
if (CurrentFrame?.MouseRight2 == true) if (CurrentFrame?.MouseRight2 == true)
keys.Add(Key.J); keys.Add(TaikoAction.RightCentre);
if (CurrentFrame?.MouseLeft1 == true) if (CurrentFrame?.MouseLeft1 == true)
keys.Add(Key.D); keys.Add(TaikoAction.LeftRim);
if (CurrentFrame?.MouseLeft2 == true) if (CurrentFrame?.MouseLeft2 == true)
keys.Add(Key.K); keys.Add(TaikoAction.RightRim);
return new List<InputState> return new List<InputState> { new ReplayState<TaikoAction> { PressedActions = keys } };
{
new InputState { Keyboard = new ReplayKeyboardState(keys) }
};
} }
} }
} }

View File

@ -2,6 +2,8 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using System.Collections.Generic;
using osu.Framework.Input;
using osu.Framework.Input.Handlers; using osu.Framework.Input.Handlers;
using osu.Framework.Platform; using osu.Framework.Platform;
using OpenTK; using OpenTK;
@ -29,5 +31,18 @@ namespace osu.Game.Input.Handlers
public override bool IsActive => true; public override bool IsActive => true;
public override int Priority => 0; 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;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Game.Input.Handlers; 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. /// 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. /// It handles logic of any frames which *must* be executed.
/// </summary> /// </summary>
public class FramedReplayInputHandler : ReplayInputHandler public abstract class FramedReplayInputHandler : ReplayInputHandler
{ {
private readonly Replay replay; 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); 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; this.replay = replay;
} }
@ -51,7 +50,7 @@ namespace osu.Game.Rulesets.Replays
{ {
} }
private Vector2? position protected Vector2? Position
{ {
get get
{ {
@ -62,23 +61,7 @@ namespace osu.Game.Rulesets.Replays
} }
} }
public override List<InputState> GetPendingStates() public override List<InputState> GetPendingStates() => new List<InputState>();
{
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 bool AtLastFrame => currentFrameIndex == Frames.Count - 1; public bool AtLastFrame => currentFrameIndex == Frames.Count - 1;
public bool AtFirstFrame => currentFrameIndex == 0; public bool AtFirstFrame => currentFrameIndex == 0;
@ -133,10 +116,9 @@ namespace osu.Game.Rulesets.Replays
protected class ReplayMouseState : MouseState protected class ReplayMouseState : MouseState
{ {
public ReplayMouseState(Vector2 position, IEnumerable<MouseButton> list) public ReplayMouseState(Vector2 position)
{ {
Position = 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> /// <returns>The input manager.</returns>
public abstract PassThroughInputManager CreateInputManager(); 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; } public Replay Replay { get; private set; }