mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 21:07:18 +09:00
Merge pull request #9633 from Joehuu/fix-keybind-clearing
This commit is contained in:
commit
dd2f677aa4
@ -64,5 +64,77 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
}, 0, true);
|
}, 0, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestClearButtonOnBindings()
|
||||||
|
{
|
||||||
|
KeyBindingRow backBindingRow = null;
|
||||||
|
|
||||||
|
AddStep("click back binding row", () =>
|
||||||
|
{
|
||||||
|
backBindingRow = panel.ChildrenOfType<KeyBindingRow>().ElementAt(10);
|
||||||
|
InputManager.MoveMouseTo(backBindingRow);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
clickClearButton();
|
||||||
|
|
||||||
|
AddAssert("first binding cleared", () => string.IsNullOrEmpty(backBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().Text.Text));
|
||||||
|
|
||||||
|
AddStep("click second binding", () =>
|
||||||
|
{
|
||||||
|
var target = backBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1);
|
||||||
|
|
||||||
|
InputManager.MoveMouseTo(target);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
clickClearButton();
|
||||||
|
|
||||||
|
AddAssert("second binding cleared", () => string.IsNullOrEmpty(backBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1).Text.Text));
|
||||||
|
|
||||||
|
void clickClearButton()
|
||||||
|
{
|
||||||
|
AddStep("click clear button", () =>
|
||||||
|
{
|
||||||
|
var clearButton = backBindingRow.ChildrenOfType<KeyBindingRow.ClearButton>().Single();
|
||||||
|
|
||||||
|
InputManager.MoveMouseTo(clearButton);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestClickRowSelectsFirstBinding()
|
||||||
|
{
|
||||||
|
KeyBindingRow backBindingRow = null;
|
||||||
|
|
||||||
|
AddStep("click back binding row", () =>
|
||||||
|
{
|
||||||
|
backBindingRow = panel.ChildrenOfType<KeyBindingRow>().ElementAt(10);
|
||||||
|
InputManager.MoveMouseTo(backBindingRow);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("first binding selected", () => backBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
|
||||||
|
|
||||||
|
AddStep("click second binding", () =>
|
||||||
|
{
|
||||||
|
var target = backBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1);
|
||||||
|
|
||||||
|
InputManager.MoveMouseTo(target);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddStep("click back binding row", () =>
|
||||||
|
{
|
||||||
|
backBindingRow = panel.ChildrenOfType<KeyBindingRow>().ElementAt(10);
|
||||||
|
InputManager.MoveMouseTo(backBindingRow);
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddAssert("first binding selected", () => backBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().First().IsBinding);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
public bool FilteringActive { get; set; }
|
public bool FilteringActive { get; set; }
|
||||||
|
|
||||||
private OsuSpriteText text;
|
private OsuSpriteText text;
|
||||||
private Drawable pressAKey;
|
private FillFlowContainer cancelAndClearButtons;
|
||||||
|
|
||||||
private FillFlowContainer<KeyButton> buttons;
|
private FillFlowContainer<KeyButton> buttons;
|
||||||
|
|
||||||
public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend((string)text.Text);
|
public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend((string)text.Text);
|
||||||
@ -80,7 +79,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
Hollow = true,
|
Hollow = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
Children = new[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
@ -99,7 +98,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = Anchor.TopRight
|
Origin = Anchor.TopRight
|
||||||
},
|
},
|
||||||
pressAKey = new FillFlowContainer
|
cancelAndClearButtons = new FillFlowContainer
|
||||||
{
|
{
|
||||||
AutoSizeAxes = Axes.Both,
|
AutoSizeAxes = Axes.Both,
|
||||||
Padding = new MarginPadding(padding) { Top = height + padding * 2 },
|
Padding = new MarginPadding(padding) { Top = height + padding * 2 },
|
||||||
@ -187,7 +186,8 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
|
|
||||||
if (bindTarget.IsHovered)
|
if (bindTarget.IsHovered)
|
||||||
finalise();
|
finalise();
|
||||||
else
|
// prevent updating bind target before clear button's action
|
||||||
|
else if (!cancelAndClearButtons.Any(b => b.IsHovered))
|
||||||
updateBindTarget();
|
updateBindTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,8 +298,8 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
if (HasFocus)
|
if (HasFocus)
|
||||||
GetContainingInputManager().ChangeFocus(null);
|
GetContainingInputManager().ChangeFocus(null);
|
||||||
|
|
||||||
pressAKey.FadeOut(300, Easing.OutQuint);
|
cancelAndClearButtons.FadeOut(300, Easing.OutQuint);
|
||||||
pressAKey.BypassAutoSizeAxes |= Axes.Y;
|
cancelAndClearButtons.BypassAutoSizeAxes |= Axes.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnFocus(FocusEvent e)
|
protected override void OnFocus(FocusEvent e)
|
||||||
@ -307,8 +307,8 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
AutoSizeDuration = 500;
|
AutoSizeDuration = 500;
|
||||||
AutoSizeEasing = Easing.OutQuint;
|
AutoSizeEasing = Easing.OutQuint;
|
||||||
|
|
||||||
pressAKey.FadeIn(300, Easing.OutQuint);
|
cancelAndClearButtons.FadeIn(300, Easing.OutQuint);
|
||||||
pressAKey.BypassAutoSizeAxes &= ~Axes.Y;
|
cancelAndClearButtons.BypassAutoSizeAxes &= ~Axes.Y;
|
||||||
|
|
||||||
updateBindTarget();
|
updateBindTarget();
|
||||||
base.OnFocus(e);
|
base.OnFocus(e);
|
||||||
@ -320,6 +320,9 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
base.OnFocusLost(e);
|
base.OnFocusLost(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the bind target to the currently hovered key button or the first if clicked anywhere else.
|
||||||
|
/// </summary>
|
||||||
private void updateBindTarget()
|
private void updateBindTarget()
|
||||||
{
|
{
|
||||||
if (bindTarget != null) bindTarget.IsBinding = false;
|
if (bindTarget != null) bindTarget.IsBinding = false;
|
||||||
@ -354,7 +357,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KeyButton : Container
|
public class KeyButton : Container
|
||||||
{
|
{
|
||||||
public readonly Framework.Input.Bindings.KeyBinding KeyBinding;
|
public readonly Framework.Input.Bindings.KeyBinding KeyBinding;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user