mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Merge branch 'update-framework-event-handling' into update-framework
This commit is contained in:
commit
ae4c371bec
@ -4,7 +4,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Input.States;
|
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osu.Game.Rulesets.Osu.Objects;
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
@ -77,7 +76,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
wasLeft = !wasLeft;
|
wasLeft = !wasLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
osuInputManager.HandleCustomInput(new InputState(), state);
|
state.Apply(osuInputManager.CurrentState, osuInputManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ApplyToRulesetContainer(RulesetContainer<OsuHitObject> rulesetContainer)
|
public void ApplyToRulesetContainer(RulesetContainer<OsuHitObject> rulesetContainer)
|
||||||
|
@ -8,14 +8,14 @@ using System.Linq;
|
|||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input.EventArgs;
|
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
[Description("player pause/fail screens")]
|
[Description("player pause/fail screens")]
|
||||||
public class TestCaseGameplayMenuOverlay : OsuTestCase
|
public class TestCaseGameplayMenuOverlay : ManualInputManagerTestCase
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(FailOverlay), typeof(PauseContainer) };
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(FailOverlay), typeof(PauseContainer) };
|
||||||
|
|
||||||
@ -73,12 +73,18 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
AddStep("Show overlay", () => failOverlay.Show());
|
AddStep("Show overlay", () => failOverlay.Show());
|
||||||
|
|
||||||
AddStep("Hover first button", () => failOverlay.Buttons.First().TriggerOnMouseMove(null));
|
AddStep("Hover first button", () => InputManager.MoveMouseTo(failOverlay.Buttons.First()));
|
||||||
AddStep("Hide overlay", () => failOverlay.Hide());
|
AddStep("Hide overlay", () => failOverlay.Hide());
|
||||||
|
|
||||||
AddAssert("Overlay state is reset", () => !failOverlay.Buttons.Any(b => b.Selected));
|
AddAssert("Overlay state is reset", () => !failOverlay.Buttons.Any(b => b.Selected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void press(Key key)
|
||||||
|
{
|
||||||
|
InputManager.PressKey(key);
|
||||||
|
InputManager.ReleaseKey(key);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests that pressing enter after an overlay shows doesn't trigger an event because a selection hasn't occurred.
|
/// Tests that pressing enter after an overlay shows doesn't trigger an event because a selection hasn't occurred.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -86,7 +92,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
AddStep("Show overlay", () => pauseOverlay.Show());
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
||||||
|
|
||||||
AddStep("Press enter", () => pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Enter }));
|
AddStep("Press enter", () => press(Key.Enter));
|
||||||
AddAssert("Overlay still open", () => pauseOverlay.State == Visibility.Visible);
|
AddAssert("Overlay still open", () => pauseOverlay.State == Visibility.Visible);
|
||||||
|
|
||||||
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
||||||
@ -99,7 +105,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
AddStep("Show overlay", () => pauseOverlay.Show());
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
||||||
|
|
||||||
AddStep("Up arrow", () => pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Up }));
|
AddStep("Up arrow", () => press(Key.Up));
|
||||||
AddAssert("Last button selected", () => pauseOverlay.Buttons.Last().Selected);
|
AddAssert("Last button selected", () => pauseOverlay.Buttons.Last().Selected);
|
||||||
|
|
||||||
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
||||||
@ -112,7 +118,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
AddStep("Show overlay", () => pauseOverlay.Show());
|
AddStep("Show overlay", () => pauseOverlay.Show());
|
||||||
|
|
||||||
AddStep("Down arrow", () => pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down }));
|
AddStep("Down arrow", () => press(Key.Down));
|
||||||
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected);
|
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected);
|
||||||
|
|
||||||
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
||||||
@ -125,11 +131,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
AddStep("Show overlay", () => failOverlay.Show());
|
AddStep("Show overlay", () => failOverlay.Show());
|
||||||
|
|
||||||
AddStep("Up arrow", () => failOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Up }));
|
AddStep("Up arrow", () => press(Key.Up));
|
||||||
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected);
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected);
|
||||||
AddStep("Up arrow", () => failOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Up }));
|
AddStep("Up arrow", () => press(Key.Up));
|
||||||
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected);
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected);
|
||||||
AddStep("Up arrow", () => failOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Up }));
|
AddStep("Up arrow", () => press(Key.Up));
|
||||||
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected);
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected);
|
||||||
|
|
||||||
AddStep("Hide overlay", () => failOverlay.Hide());
|
AddStep("Hide overlay", () => failOverlay.Hide());
|
||||||
@ -142,11 +148,11 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
AddStep("Show overlay", () => failOverlay.Show());
|
AddStep("Show overlay", () => failOverlay.Show());
|
||||||
|
|
||||||
AddStep("Down arrow", () => failOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down }));
|
AddStep("Down arrow", () => press(Key.Down));
|
||||||
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected);
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected);
|
||||||
AddStep("Down arrow", () => failOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down }));
|
AddStep("Down arrow", () => press(Key.Down));
|
||||||
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected);
|
AddAssert("Last button selected", () => failOverlay.Buttons.Last().Selected);
|
||||||
AddStep("Down arrow", () => failOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down }));
|
AddStep("Down arrow", () => press(Key.Down));
|
||||||
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected);
|
AddAssert("First button selected", () => failOverlay.Buttons.First().Selected);
|
||||||
|
|
||||||
AddStep("Hide overlay", () => failOverlay.Hide());
|
AddStep("Hide overlay", () => failOverlay.Hide());
|
||||||
@ -161,8 +167,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
||||||
|
|
||||||
AddStep("Down arrow", () => pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down }));
|
AddStep("Down arrow", () => press(Key.Down));
|
||||||
AddStep("Hover second button", () => secondButton.TriggerOnMouseMove(null));
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(secondButton));
|
||||||
AddAssert("First button not selected", () => !pauseOverlay.Buttons.First().Selected);
|
AddAssert("First button not selected", () => !pauseOverlay.Buttons.First().Selected);
|
||||||
AddAssert("Second button selected", () => secondButton.Selected);
|
AddAssert("Second button selected", () => secondButton.Selected);
|
||||||
|
|
||||||
@ -174,12 +180,16 @@ namespace osu.Game.Tests.Visual
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void testKeySelectionAfterMouseSelection()
|
private void testKeySelectionAfterMouseSelection()
|
||||||
{
|
{
|
||||||
AddStep("Show overlay", () => pauseOverlay.Show());
|
AddStep("Show overlay", () =>
|
||||||
|
{
|
||||||
|
pauseOverlay.Show();
|
||||||
|
InputManager.MoveMouseTo(Vector2.Zero);
|
||||||
|
});
|
||||||
|
|
||||||
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
||||||
|
|
||||||
AddStep("Hover second button", () => secondButton.TriggerOnMouseMove(null));
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(secondButton));
|
||||||
AddStep("Up arrow", () => pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Up }));
|
AddStep("Up arrow", () => press(Key.Up));
|
||||||
AddAssert("Second button not selected", () => !secondButton.Selected);
|
AddAssert("Second button not selected", () => !secondButton.Selected);
|
||||||
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected);
|
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected);
|
||||||
|
|
||||||
@ -195,9 +205,9 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
var secondButton = pauseOverlay.Buttons.Skip(1).First();
|
||||||
|
|
||||||
AddStep("Hover second button", () => secondButton.TriggerOnMouseMove(null));
|
AddStep("Hover second button", () => InputManager.MoveMouseTo(secondButton));
|
||||||
AddStep("Unhover second button", () => secondButton.TriggerOnHoverLost(null));
|
AddStep("Unhover second button", () => InputManager.MoveMouseTo(Vector2.Zero));
|
||||||
AddStep("Down arrow", () => pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down }));
|
AddStep("Down arrow", () => press(Key.Down));
|
||||||
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected); // Initial state condition
|
AddAssert("First button selected", () => pauseOverlay.Buttons.First().Selected); // Initial state condition
|
||||||
|
|
||||||
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
AddStep("Hide overlay", () => pauseOverlay.Hide());
|
||||||
@ -218,7 +228,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
var lastAction = pauseOverlay.OnRetry;
|
var lastAction = pauseOverlay.OnRetry;
|
||||||
pauseOverlay.OnRetry = () => triggered = true;
|
pauseOverlay.OnRetry = () => triggered = true;
|
||||||
|
|
||||||
retryButton.TriggerOnClick();
|
retryButton.Click();
|
||||||
pauseOverlay.OnRetry = lastAction;
|
pauseOverlay.OnRetry = lastAction;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -235,23 +245,28 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
AddStep("Select second button", () =>
|
AddStep("Select second button", () =>
|
||||||
{
|
{
|
||||||
pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down });
|
press(Key.Down);
|
||||||
pauseOverlay.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Down });
|
press(Key.Down);
|
||||||
});
|
});
|
||||||
|
|
||||||
var retryButton = pauseOverlay.Buttons.Skip(1).First();
|
|
||||||
|
|
||||||
bool triggered = false;
|
bool triggered = false;
|
||||||
|
Action lastAction = null;
|
||||||
AddStep("Press enter", () =>
|
AddStep("Press enter", () =>
|
||||||
{
|
{
|
||||||
var lastAction = pauseOverlay.OnRetry;
|
lastAction = pauseOverlay.OnRetry;
|
||||||
pauseOverlay.OnRetry = () => triggered = true;
|
pauseOverlay.OnRetry = () => triggered = true;
|
||||||
|
press(Key.Enter);
|
||||||
retryButton.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = Key.Enter });
|
|
||||||
pauseOverlay.OnRetry = lastAction;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("Action was triggered", () => triggered);
|
AddAssert("Action was triggered", () =>
|
||||||
|
{
|
||||||
|
if (lastAction != null)
|
||||||
|
{
|
||||||
|
pauseOverlay.OnRetry = lastAction;
|
||||||
|
lastAction = null;
|
||||||
|
}
|
||||||
|
return triggered;
|
||||||
|
});
|
||||||
AddAssert("Overlay is closed", () => pauseOverlay.State == Visibility.Hidden);
|
AddAssert("Overlay is closed", () => pauseOverlay.State == Visibility.Hidden);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Input.EventArgs;
|
|
||||||
using osu.Framework.MathUtils;
|
using osu.Framework.MathUtils;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
@ -15,7 +14,7 @@ using OpenTK.Input;
|
|||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestCaseKeyCounter : OsuTestCase
|
public class TestCaseKeyCounter : ManualInputManagerTestCase
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
@ -53,16 +52,16 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
AddStep($"Press {testKey} key", () =>
|
AddStep($"Press {testKey} key", () =>
|
||||||
{
|
{
|
||||||
rewindTestKeyCounterKeyboard.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = testKey, Repeat = false });
|
InputManager.PressKey(testKey);
|
||||||
rewindTestKeyCounterKeyboard.TriggerOnKeyUp(null, new KeyUpEventArgs { Key = testKey });
|
InputManager.ReleaseKey(testKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert($"Check {testKey} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == 1);
|
AddAssert($"Check {testKey} counter after keypress", () => rewindTestKeyCounterKeyboard.CountPresses == 1);
|
||||||
|
|
||||||
AddStep($"Press {testKey} key", () =>
|
AddStep($"Press {testKey} key", () =>
|
||||||
{
|
{
|
||||||
rewindTestKeyCounterKeyboard.TriggerOnKeyDown(null, new KeyDownEventArgs { Key = testKey, Repeat = false });
|
InputManager.PressKey(testKey);
|
||||||
rewindTestKeyCounterKeyboard.TriggerOnKeyUp(null, new KeyUpEventArgs { Key = testKey });
|
InputManager.ReleaseKey(testKey);
|
||||||
time1 = Clock.CurrentTime;
|
time1 = Clock.CurrentTime;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,10 +3,13 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Input.Handlers;
|
using osu.Framework.Input.Handlers;
|
||||||
using osu.Framework.Input.StateChanges;
|
using osu.Framework.Input.StateChanges;
|
||||||
|
using osu.Framework.Input.StateChanges.Events;
|
||||||
using osu.Framework.Input.States;
|
using osu.Framework.Input.States;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Input.Handlers
|
namespace osu.Game.Input.Handlers
|
||||||
@ -40,7 +43,29 @@ namespace osu.Game.Input.Handlers
|
|||||||
|
|
||||||
public void Apply(InputState state, IInputStateChangeHandler handler)
|
public void Apply(InputState state, IInputStateChangeHandler handler)
|
||||||
{
|
{
|
||||||
handler.HandleCustomInput(state, this);
|
if (!(state is RulesetInputManagerInputState<T> inputState))
|
||||||
|
throw new InvalidOperationException($"{nameof(ReplayState<T>)} should only be applied to a {nameof(RulesetInputManagerInputState<T>)}");
|
||||||
|
|
||||||
|
var lastPressed = inputState.LastReplayState?.PressedActions ?? new List<T>();
|
||||||
|
var released = lastPressed.Except(PressedActions).ToArray();
|
||||||
|
var pressed = PressedActions.Except(lastPressed).ToArray();
|
||||||
|
|
||||||
|
inputState.LastReplayState = this;
|
||||||
|
|
||||||
|
handler.HandleInputStateChange(new ReplayStateChangeEvent<T>(state, this, released, pressed));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ReplayStateChangeEvent<T> : InputStateChangeEvent
|
||||||
|
{
|
||||||
|
public readonly T[] ReleasedActions;
|
||||||
|
public readonly T[] PressedActions;
|
||||||
|
|
||||||
|
public ReplayStateChangeEvent(InputState state, IInput input, T[] releasedActions, T[] pressedActions)
|
||||||
|
: base(state, input)
|
||||||
|
{
|
||||||
|
ReleasedActions = releasedActions;
|
||||||
|
PressedActions = pressedActions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Action = () => playButton.TriggerOnClick();
|
Action = () => playButton.Click();
|
||||||
Playing.ValueChanged += newValue => progress.FadeTo(newValue ? 1 : 0, 100);
|
Playing.ValueChanged += newValue => progress.FadeTo(newValue ? 1 : 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case GlobalAction.Select:
|
case GlobalAction.Select:
|
||||||
Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.TriggerOnClick();
|
Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.Click();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
if (!actionInvoked)
|
if (!actionInvoked)
|
||||||
// In the case a user did not choose an action before a hide was triggered, press the last button.
|
// In the case a user did not choose an action before a hide was triggered, press the last button.
|
||||||
// This is presumed to always be a sane default "cancel" action.
|
// This is presumed to always be a sane default "cancel" action.
|
||||||
buttonsContainer.Last().TriggerOnClick();
|
buttonsContainer.Last().Click();
|
||||||
|
|
||||||
base.PopOut();
|
base.PopOut();
|
||||||
content.FadeOut(EXIT_DURATION, Easing.InSine);
|
content.FadeOut(EXIT_DURATION, Easing.InSine);
|
||||||
@ -261,7 +261,7 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
private void pressButtonAtIndex(int index)
|
private void pressButtonAtIndex(int index)
|
||||||
{
|
{
|
||||||
if (index < Buttons.Count())
|
if (index < Buttons.Count())
|
||||||
Buttons.Skip(index).First().TriggerOnClick();
|
Buttons.Skip(index).First().Click();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ namespace osu.Game.Overlays
|
|||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case GlobalAction.Back:
|
case GlobalAction.Back:
|
||||||
TriggerOnClick();
|
Click();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// 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.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
@ -10,7 +9,7 @@ using osu.Framework.Graphics.Containers;
|
|||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.EventArgs;
|
using osu.Framework.Input.EventArgs;
|
||||||
using osu.Framework.Input.StateChanges;
|
using osu.Framework.Input.StateChanges.Events;
|
||||||
using osu.Framework.Input.States;
|
using osu.Framework.Input.States;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
@ -56,33 +55,20 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
#region Action mapping (for replays)
|
#region Action mapping (for replays)
|
||||||
|
|
||||||
private List<T> lastPressedActions = new List<T>();
|
public override void HandleInputStateChange(InputStateChangeEvent inputStateChange)
|
||||||
|
|
||||||
public override void HandleCustomInput(InputState state, IInput input)
|
|
||||||
{
|
{
|
||||||
if (!(input is ReplayState<T> replayState))
|
if (inputStateChange is ReplayStateChangeEvent<T> replayStateChanged)
|
||||||
{
|
{
|
||||||
base.HandleCustomInput(state, input);
|
foreach (var action in replayStateChanged.ReleasedActions)
|
||||||
return;
|
KeyBindingContainer.TriggerReleased(action);
|
||||||
}
|
|
||||||
|
|
||||||
if (state is RulesetInputManagerInputState<T> inputState)
|
foreach (var action in replayStateChanged.PressedActions)
|
||||||
|
KeyBindingContainer.TriggerPressed(action);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
inputState.LastReplayState = replayState;
|
base.HandleInputStateChange(inputStateChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here we handle states specifically coming from a replay source.
|
|
||||||
// These have extra action information rather than keyboard keys or mouse buttons.
|
|
||||||
|
|
||||||
List<T> newActions = replayState.PressedActions;
|
|
||||||
|
|
||||||
foreach (var released in lastPressedActions.Except(newActions))
|
|
||||||
KeyBindingContainer.TriggerReleased(released);
|
|
||||||
|
|
||||||
foreach (var pressed in newActions.Except(lastPressedActions))
|
|
||||||
KeyBindingContainer.TriggerPressed(pressed);
|
|
||||||
|
|
||||||
lastPressedActions = newActions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -115,7 +115,7 @@ namespace osu.Game.Screens.Menu
|
|||||||
case GlobalAction.Back:
|
case GlobalAction.Back:
|
||||||
return goBack();
|
return goBack();
|
||||||
case GlobalAction.Select:
|
case GlobalAction.Select:
|
||||||
logo?.TriggerOnClick();
|
logo?.Click();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -133,7 +133,7 @@ namespace osu.Game.Screens.Menu
|
|||||||
sampleBack?.Play();
|
sampleBack?.Play();
|
||||||
return true;
|
return true;
|
||||||
case ButtonSystemState.Play:
|
case ButtonSystemState.Play:
|
||||||
backButton.TriggerOnClick();
|
backButton.Click();
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -150,10 +150,10 @@ namespace osu.Game.Screens.Menu
|
|||||||
State = ButtonSystemState.TopLevel;
|
State = ButtonSystemState.TopLevel;
|
||||||
return true;
|
return true;
|
||||||
case ButtonSystemState.TopLevel:
|
case ButtonSystemState.TopLevel:
|
||||||
buttonsTopLevel.First().TriggerOnClick();
|
buttonsTopLevel.First().Click();
|
||||||
return false;
|
return false;
|
||||||
case ButtonSystemState.Play:
|
case ButtonSystemState.Play:
|
||||||
buttonsPlay.First().TriggerOnClick();
|
buttonsPlay.First().Click();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ namespace osu.Game.Screens.Play
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
|
/// Action that is invoked when <see cref="GlobalAction.Back"/> is triggered.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual Action BackAction => () => InternalButtons.Children.Last().TriggerOnClick();
|
protected virtual Action BackAction => () => InternalButtons.Children.Last().Click();
|
||||||
|
|
||||||
public abstract string Header { get; }
|
public abstract string Header { get; }
|
||||||
public abstract string Description { get; }
|
public abstract string Description { get; }
|
||||||
|
@ -7,8 +7,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input.EventArgs;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Input.States;
|
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
@ -152,13 +151,18 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => true;
|
||||||
|
|
||||||
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) => Target.Children.Any(c => c.TriggerOnKeyDown(state, args));
|
protected override bool Handle(UIEvent e)
|
||||||
|
{
|
||||||
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) => Target.Children.Any(c => c.TriggerOnKeyUp(state, args));
|
switch (e)
|
||||||
|
{
|
||||||
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => Target.Children.Any(c => c.TriggerOnMouseDown(state, args));
|
case KeyDownEvent _:
|
||||||
|
case KeyUpEvent _:
|
||||||
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args) => Target.Children.Any(c => c.TriggerOnMouseUp(state, args));
|
case MouseDownEvent _:
|
||||||
|
case MouseUpEvent _:
|
||||||
|
return Target.Children.Any(c => c.TriggerEvent(e));
|
||||||
|
}
|
||||||
|
return base.Handle(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ namespace osu.Game.Screens.Play
|
|||||||
public override string Header => "paused";
|
public override string Header => "paused";
|
||||||
public override string Description => "you're not going to do what i think you're going to do, are ya?";
|
public override string Description => "you're not going to do what i think you're going to do, are ya?";
|
||||||
|
|
||||||
protected override Action BackAction => () => InternalButtons.Children.First().TriggerOnClick();
|
protected override Action BackAction => () => InternalButtons.Children.First().Click();
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
|
@ -141,7 +141,7 @@ namespace osu.Game.Screens.Play
|
|||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case GlobalAction.SkipCutscene:
|
case GlobalAction.SkipCutscene:
|
||||||
button.TriggerOnClick();
|
button.Click();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user