2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-01-16 11:40:52 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using System.Linq;
|
2017-02-28 19:14:48 +08:00
|
|
|
|
using osu.Framework.Timing;
|
|
|
|
|
using osu.Game.Input.Handlers;
|
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
using KeyboardState = osu.Framework.Input.KeyboardState;
|
|
|
|
|
using MouseState = osu.Framework.Input.MouseState;
|
2017-01-16 11:40:52 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2017-02-28 19:14:48 +08:00
|
|
|
|
public class PlayerInputManager : PassThroughInputManager
|
2017-01-16 11:40:52 +08:00
|
|
|
|
{
|
2017-02-28 19:14:48 +08:00
|
|
|
|
private bool leftViaKeyboard;
|
|
|
|
|
private bool rightViaKeyboard;
|
|
|
|
|
private Bindable<bool> mouseDisabled;
|
|
|
|
|
|
|
|
|
|
private ManualClock clock = new ManualClock();
|
|
|
|
|
private IFrameBasedClock parentClock;
|
|
|
|
|
|
2017-03-04 14:29:15 +08:00
|
|
|
|
private ReplayInputHandler replayInputHandler;
|
|
|
|
|
public ReplayInputHandler ReplayInputHandler
|
2017-01-16 11:40:52 +08:00
|
|
|
|
{
|
2017-02-28 19:14:48 +08:00
|
|
|
|
get { return replayInputHandler; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (replayInputHandler != null) RemoveHandler(replayInputHandler);
|
|
|
|
|
|
|
|
|
|
replayInputHandler = value;
|
|
|
|
|
UseParentState = replayInputHandler == null;
|
|
|
|
|
|
|
|
|
|
if (replayInputHandler != null)
|
|
|
|
|
AddHandler(replayInputHandler);
|
|
|
|
|
}
|
2017-01-16 11:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 19:14:48 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
parentClock = Clock;
|
|
|
|
|
Clock = new FramedClock(clock);
|
|
|
|
|
}
|
2017-01-16 11:40:52 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
|
{
|
2017-02-28 19:14:48 +08:00
|
|
|
|
mouseDisabled = config.GetBindable<bool>(OsuConfig.MouseDisableButtons);
|
2017-01-16 11:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void TransformState(InputState state)
|
|
|
|
|
{
|
|
|
|
|
base.TransformState(state);
|
|
|
|
|
|
2017-02-28 19:14:48 +08:00
|
|
|
|
var mouse = state.Mouse as MouseState;
|
|
|
|
|
var keyboard = state.Keyboard as KeyboardState;
|
|
|
|
|
|
|
|
|
|
if (keyboard != null)
|
2017-01-16 11:40:52 +08:00
|
|
|
|
{
|
2017-02-28 19:14:48 +08:00
|
|
|
|
leftViaKeyboard = keyboard.Keys.Contains(Key.Z);
|
|
|
|
|
rightViaKeyboard = keyboard.Keys.Contains(Key.X);
|
2017-01-16 11:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 19:14:48 +08:00
|
|
|
|
if (mouse != null)
|
2017-01-16 11:40:52 +08:00
|
|
|
|
{
|
|
|
|
|
if (mouseDisabled.Value)
|
|
|
|
|
{
|
2017-03-13 18:11:57 +08:00
|
|
|
|
mouse.PressedButtons.Remove(MouseButton.Left);
|
|
|
|
|
mouse.PressedButtons.Remove(MouseButton.Right);
|
2017-01-16 11:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (leftViaKeyboard)
|
2017-03-13 18:11:57 +08:00
|
|
|
|
mouse.PressedButtons.Add(MouseButton.Left);
|
2017-01-16 11:40:52 +08:00
|
|
|
|
if (rightViaKeyboard)
|
2017-03-13 18:11:57 +08:00
|
|
|
|
mouse.PressedButtons.Add(MouseButton.Right);
|
2017-01-16 11:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-28 19:14:48 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
if (parentClock == null) return;
|
|
|
|
|
|
|
|
|
|
clock.Rate = parentClock.Rate;
|
|
|
|
|
clock.IsRunning = parentClock.IsRunning;
|
|
|
|
|
|
|
|
|
|
//if a replayHandler is not attached, we should just pass-through.
|
|
|
|
|
if (UseParentState || replayInputHandler == null)
|
|
|
|
|
{
|
|
|
|
|
clock.CurrentTime = parentClock.CurrentTime;
|
|
|
|
|
base.Update();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
double? newTime = replayInputHandler.SetFrameFromTime(parentClock.CurrentTime);
|
|
|
|
|
|
|
|
|
|
if (newTime == null)
|
|
|
|
|
//we shouldn't execute for this time value
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (clock.CurrentTime == parentClock.CurrentTime)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
clock.CurrentTime = newTime.Value;
|
|
|
|
|
base.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-16 11:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|