1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Merge pull request #2858 from ekrctb/use-new-input-manager

Update osu!-side code in line with input handling changes
This commit is contained in:
Dean Herbert 2018-06-22 18:31:49 +09:00 committed by GitHub
commit 9cec769191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 57 additions and 29 deletions

View File

@ -73,7 +73,7 @@ namespace osu.Desktop
} }
public StableStorage() public StableStorage()
: base(string.Empty) : base(string.Empty, null)
{ {
} }
} }

View File

@ -28,9 +28,9 @@ namespace osu.Game.Rulesets.Catch.Replays
} }
} }
public override List<InputState> GetPendingStates() public override List<IInput> GetPendingInputs()
{ {
if (!Position.HasValue) return new List<InputState>(); if (!Position.HasValue) return new List<IInput>();
var actions = new List<CatchAction>(); var actions = new List<CatchAction>();
@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Catch.Replays
else if (Position.Value < CurrentFrame.Position) else if (Position.Value < CurrentFrame.Position)
actions.Add(CatchAction.MoveLeft); actions.Add(CatchAction.MoveLeft);
return new List<InputState> return new List<IInput>
{ {
new CatchReplayState new CatchReplayState
{ {

View File

@ -16,6 +16,7 @@ using osu.Game.Rulesets.Catch.Objects.Drawable;
using osu.Game.Rulesets.Catch.Replays; using osu.Game.Rulesets.Catch.Replays;
using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
@ -93,7 +94,7 @@ namespace osu.Game.Rulesets.Catch.UI
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
var state = GetContainingInputManager().CurrentState as CatchFramedReplayInputHandler.CatchReplayState; var state = (GetContainingInputManager().CurrentState as RulesetInputManagerInputState<CatchAction>)?.LastReplayState as CatchFramedReplayInputHandler.CatchReplayState;
if (state?.CatcherX != null) if (state?.CatcherX != null)
MovableCatcher.X = state.CatcherX.Value; MovableCatcher.X = state.CatcherX.Value;

View File

@ -17,6 +17,6 @@ namespace osu.Game.Rulesets.Mania.Replays
protected override bool IsImportant(ManiaReplayFrame frame) => frame.Actions.Any(); protected override bool IsImportant(ManiaReplayFrame frame) => frame.Actions.Any();
public override List<InputState> GetPendingStates() => new List<InputState> { new ReplayState<ManiaAction> { PressedActions = CurrentFrame.Actions } }; public override List<IInput> GetPendingInputs() => new List<IInput> { new ReplayState<ManiaAction> { PressedActions = CurrentFrame.Actions } };
} }
} }

View File

@ -30,13 +30,16 @@ namespace osu.Game.Rulesets.Osu.Replays
} }
} }
public override List<InputState> GetPendingStates() public override List<IInput> GetPendingInputs()
{ {
return new List<InputState> return new List<IInput>
{ {
new MousePositionAbsoluteInput
{
Position = GamefieldToScreenSpace(Position ?? Vector2.Zero)
},
new ReplayState<OsuAction> new ReplayState<OsuAction>
{ {
Mouse = new ReplayMouseState(GamefieldToScreenSpace(Position ?? Vector2.Zero)),
PressedActions = CurrentFrame.Actions PressedActions = CurrentFrame.Actions
} }
}; };

View File

@ -17,6 +17,6 @@ namespace osu.Game.Rulesets.Taiko.Replays
protected override bool IsImportant(TaikoReplayFrame frame) => frame.Actions.Any(); protected override bool IsImportant(TaikoReplayFrame frame) => frame.Actions.Any();
public override List<InputState> GetPendingStates() => new List<InputState> { new ReplayState<TaikoAction> { PressedActions = CurrentFrame.Actions } }; public override List<IInput> GetPendingInputs() => new List<IInput> { new ReplayState<TaikoAction> { PressedActions = CurrentFrame.Actions } };
} }
} }

View File

@ -32,16 +32,14 @@ namespace osu.Game.Input.Handlers
public override int Priority => 0; public override int Priority => 0;
public class ReplayState<T> : InputState public class ReplayState<T> : IInput
where T : struct where T : struct
{ {
public List<T> PressedActions; public List<T> PressedActions;
public override InputState Clone() public void Apply(InputState state, IInputStateChangeHandler handler)
{ {
var clone = (ReplayState<T>)base.Clone(); handler.HandleCustomInput(state, this);
clone.PressedActions = new List<T>(PressedActions);
return clone;
} }
} }
} }

View File

@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.Replays
return true; return true;
} }
public override List<InputState> GetPendingStates() => new List<InputState>(); public override List<IInput> GetPendingInputs() => new List<IInput>();
public bool AtLastFrame => currentFrameIndex == Frames.Count - 1; public bool AtLastFrame => currentFrameIndex == Frames.Count - 1;
public bool AtFirstFrame => currentFrameIndex == 0; public bool AtFirstFrame => currentFrameIndex == 0;
@ -119,7 +119,8 @@ namespace osu.Game.Rulesets.Replays
{ {
public ReplayKeyboardState(List<Key> keys) public ReplayKeyboardState(List<Key> keys)
{ {
Keys = keys; foreach (var key in keys)
Keys.Add(key);
} }
} }
} }

View File

@ -15,6 +15,7 @@ using osu.Game.Input.Bindings;
using osu.Game.Input.Handlers; using osu.Game.Input.Handlers;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using OpenTK.Input; using OpenTK.Input;
using static osu.Game.Input.Handlers.ReplayInputHandler;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
@ -29,6 +30,18 @@ namespace osu.Game.Rulesets.UI
} }
} }
protected override InputState CreateInitialState()
{
var state = base.CreateInitialState();
return new RulesetInputManagerInputState<T>
{
Mouse = state.Mouse,
Keyboard = state.Keyboard,
Joystick = state.Joystick,
LastReplayState = null
};
}
protected readonly KeyBindingContainer<T> KeyBindingContainer; protected readonly KeyBindingContainer<T> KeyBindingContainer;
protected override Container<Drawable> Content => KeyBindingContainer; protected override Container<Drawable> Content => KeyBindingContainer;
@ -42,13 +55,18 @@ namespace osu.Game.Rulesets.UI
private List<T> lastPressedActions = new List<T>(); private List<T> lastPressedActions = new List<T>();
protected override void HandleNewState(InputState state) public override void HandleCustomInput(InputState state, IInput input)
{ {
base.HandleNewState(state); if (!(input is ReplayState<T> replayState))
{
base.HandleCustomInput(state, input);
return;
}
var replayState = state as ReplayInputHandler.ReplayState<T>; if (state is RulesetInputManagerInputState<T> inputState)
{
if (replayState == null) return; inputState.LastReplayState = replayState;
}
// Here we handle states specifically coming from a replay source. // Here we handle states specifically coming from a replay source.
// These have extra action information rather than keyboard keys or mouse buttons. // These have extra action information rather than keyboard keys or mouse buttons.
@ -80,7 +98,7 @@ namespace osu.Game.Rulesets.UI
if (replayInputHandler != null) RemoveHandler(replayInputHandler); if (replayInputHandler != null) RemoveHandler(replayInputHandler);
replayInputHandler = value; replayInputHandler = value;
UseParentState = replayInputHandler == null; UseParentInput = replayInputHandler == null;
if (replayInputHandler != null) if (replayInputHandler != null)
AddHandler(replayInputHandler); AddHandler(replayInputHandler);
@ -123,7 +141,7 @@ namespace osu.Game.Rulesets.UI
protected override bool RequiresChildrenUpdate => base.RequiresChildrenUpdate && validState; protected override bool RequiresChildrenUpdate => base.RequiresChildrenUpdate && validState;
private bool isAttached => replayInputHandler != null && !UseParentState; private bool isAttached => replayInputHandler != null && !UseParentInput;
private const int max_catch_up_updates_per_frame = 50; private const int max_catch_up_updates_per_frame = 50;
@ -267,4 +285,10 @@ namespace osu.Game.Rulesets.UI
{ {
void Attach(KeyCounterCollection keyCounter); void Attach(KeyCounterCollection keyCounter);
} }
public class RulesetInputManagerInputState<T> : InputState
where T : struct
{
public ReplayState<T> LastReplayState;
}
} }

View File

@ -2,6 +2,7 @@
// 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.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -182,14 +183,14 @@ namespace osu.Game.Screens.Play.HUD
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{ {
if (!pendingAnimation && state.Mouse.Buttons.Count == 1) if (!pendingAnimation && state.Mouse.Buttons.Count() == 1)
BeginConfirm(); BeginConfirm();
return true; return true;
} }
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{ {
if (state.Mouse.Buttons.Count == 0) if (!state.Mouse.Buttons.Any())
AbortConfirm(); AbortConfirm();
return true; return true;
} }

View File

@ -7,7 +7,7 @@ namespace osu.Game.Tests.Platform
{ {
public class TestStorage : DesktopStorage public class TestStorage : DesktopStorage
{ {
public TestStorage(string baseName) : base(baseName) public TestStorage(string baseName) : base(baseName, null)
{ {
} }

View File

@ -23,7 +23,7 @@ namespace osu.Game.Tests.Visual
/// </summary> /// </summary>
protected void ReturnUserInput() protected void ReturnUserInput()
{ {
AddStep("Return user input", () => InputManager.UseParentState = true); AddStep("Return user input", () => InputManager.UseParentInput = true);
} }
} }
} }

View File

@ -18,7 +18,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="ppy.osu.Framework" Version="2018.619.0" /> <PackageReference Include="ppy.osu.Framework" Version="2018.622.0" />
<PackageReference Include="SharpCompress" Version="0.18.1" /> <PackageReference Include="SharpCompress" Version="0.18.1" />
<PackageReference Include="NUnit" Version="3.10.1" /> <PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />