mirror of
https://github.com/osukey/osukey.git
synced 2025-05-08 15:17:24 +09:00
Merge pull request #9213 from smoogipoo/fix-keybinding-crash
Fix crash when double-clicking clear binding button
This commit is contained in:
commit
2ec7059ac4
@ -1,13 +1,19 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.KeyBinding;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Settings
|
namespace osu.Game.Tests.Visual.Settings
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneKeyBindingPanel : OsuTestScene
|
public class TestSceneKeyBindingPanel : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private readonly KeyBindingPanel panel;
|
private readonly KeyBindingPanel panel;
|
||||||
|
|
||||||
@ -21,5 +27,42 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
panel.Show();
|
panel.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestClickTwiceOnClearButton()
|
||||||
|
{
|
||||||
|
KeyBindingRow firstRow = null;
|
||||||
|
|
||||||
|
AddStep("click first row", () =>
|
||||||
|
{
|
||||||
|
firstRow = panel.ChildrenOfType<KeyBindingRow>().First();
|
||||||
|
InputManager.MoveMouseTo(firstRow);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("schedule button clicks", () =>
|
||||||
|
{
|
||||||
|
var clearButton = firstRow.ChildrenOfType<KeyBindingRow.ClearButton>().Single();
|
||||||
|
|
||||||
|
InputManager.MoveMouseTo(clearButton);
|
||||||
|
|
||||||
|
int buttonClicks = 0;
|
||||||
|
ScheduledDelegate clickDelegate = null;
|
||||||
|
|
||||||
|
clickDelegate = Scheduler.AddDelayed(() =>
|
||||||
|
{
|
||||||
|
InputManager.PressButton(MouseButton.Left);
|
||||||
|
InputManager.ReleaseButton(MouseButton.Left);
|
||||||
|
|
||||||
|
if (++buttonClicks == 2)
|
||||||
|
{
|
||||||
|
// ReSharper disable once AccessToModifiedClosure
|
||||||
|
Debug.Assert(clickDelegate != null);
|
||||||
|
// ReSharper disable once AccessToModifiedClosure
|
||||||
|
clickDelegate.Cancel();
|
||||||
|
}
|
||||||
|
}, 0, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,6 +274,9 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
|
|
||||||
private void clear()
|
private void clear()
|
||||||
{
|
{
|
||||||
|
if (bindTarget == null)
|
||||||
|
return;
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(InputKey.None);
|
bindTarget.UpdateKeyCombination(InputKey.None);
|
||||||
finalise();
|
finalise();
|
||||||
}
|
}
|
||||||
@ -333,7 +336,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClearButton : TriangleButton
|
public class ClearButton : TriangleButton
|
||||||
{
|
{
|
||||||
public ClearButton()
|
public ClearButton()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user