mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 20:22:55 +08:00
Add proper screen space - gamefield mapping
This commit is contained in:
parent
6d48068061
commit
14a85a84bf
@ -58,6 +58,8 @@ namespace osu.Game.Rulesets.Osu.UI
|
||||
|
||||
protected override ReplayInputHandler CreateReplayInputHandler(Replay replay) => new OsuFramedReplayInputHandler(replay);
|
||||
|
||||
protected override ReplayRecorder CreateReplayRecorder(Replay replay) => new OsuReplayRecorder(replay);
|
||||
|
||||
public override double GameplayStartTime
|
||||
{
|
||||
get
|
||||
|
@ -8,7 +8,6 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.StateChanges;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets;
|
||||
@ -25,6 +24,8 @@ namespace osu.Game.Tests.Gameplay
|
||||
{
|
||||
private readonly TestRulesetInputManager playbackManager;
|
||||
|
||||
private readonly TestRulesetInputManager recordingManager;
|
||||
|
||||
public TestSceneReplayRecording()
|
||||
{
|
||||
Replay replay = new Replay();
|
||||
@ -36,9 +37,12 @@ namespace osu.Game.Tests.Gameplay
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
|
||||
recordingManager = new TestRulesetInputManager(new TestSceneModSettings.TestRulesetInfo(), 0, SimultaneousBindingMode.Unique)
|
||||
{
|
||||
Recorder = new TestReplayRecorder(replay),
|
||||
Recorder = new TestReplayRecorder(replay)
|
||||
{
|
||||
ScreenSpaceToGamefield = pos => recordingManager.ToLocalSpace(pos)
|
||||
},
|
||||
Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -211,7 +215,7 @@ namespace osu.Game.Tests.Gameplay
|
||||
{
|
||||
}
|
||||
|
||||
protected override ReplayFrame HandleFrame(InputState state, List<TestAction> pressedActions, ReplayFrame previousFrame) =>
|
||||
new TestReplayFrame(Time.Current, ToLocalSpace(state.Mouse.Position), pressedActions.ToArray());
|
||||
protected override ReplayFrame HandleFrame(Vector2 position, List<TestAction> actions, ReplayFrame previousFrame) =>
|
||||
new TestReplayFrame(Time.Current, position, actions.ToArray());
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ namespace osu.Game.Rulesets.UI
|
||||
/// </summary>
|
||||
public Func<Vector2, Vector2> GamefieldToScreenSpace => HitObjectContainer.ToScreenSpace;
|
||||
|
||||
/// <summary>
|
||||
/// A function that converts screen space coordinates to gamefield.
|
||||
/// </summary>
|
||||
public Func<Vector2, Vector2> ScreenSpaceToGamefield => HitObjectContainer.ToLocalSpace;
|
||||
|
||||
/// <summary>
|
||||
/// All the <see cref="DrawableHitObject"/>s contained in this <see cref="Playfield"/> and all <see cref="NestedPlayfields"/>.
|
||||
/// </summary>
|
||||
|
@ -1,15 +1,16 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Replays;
|
||||
using osu.Game.Rulesets.Replays;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Rulesets.UI
|
||||
{
|
||||
@ -66,16 +67,19 @@ namespace osu.Game.Rulesets.UI
|
||||
if (!important && last != null && Time.Current - last.Time < (1000d / RecordFrameRate))
|
||||
return;
|
||||
|
||||
var frame = HandleFrame(inputManager.CurrentState, pressedActions, last);
|
||||
var position = ScreenSpaceToGamefield?.Invoke(inputManager.CurrentState.Mouse.Position) ?? inputManager.CurrentState.Mouse.Position;
|
||||
|
||||
var frame = HandleFrame(position, pressedActions, last);
|
||||
|
||||
if (frame != null)
|
||||
target.Frames.Add(frame);
|
||||
}
|
||||
|
||||
protected abstract ReplayFrame HandleFrame(InputState state, List<T> testActions, ReplayFrame previousFrame);
|
||||
protected abstract ReplayFrame HandleFrame(Vector2 position, List<T> actions, ReplayFrame previousFrame);
|
||||
}
|
||||
|
||||
public abstract class ReplayRecorder : Component
|
||||
{
|
||||
public Func<Vector2, Vector2> ScreenSpaceToGamefield;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user