1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Allow toggling focus via binding

This commit is contained in:
Dean Herbert 2021-08-19 14:19:59 +09:00
parent 786beb9759
commit 6d00ea3375
4 changed files with 32 additions and 7 deletions

View File

@ -107,6 +107,21 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("is not visible", () => !chatDisplay.IsPresent); AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
} }
[Test]
public void TestFocusToggleViaAction()
{
AddStep("set not expanded", () => chatDisplay.Expanded.Value = false);
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
AddStep("press tab", () => InputManager.Key(Key.Tab));
assertChatFocused(true);
AddUntilStep("is visible", () => chatDisplay.IsPresent);
AddStep("press tab", () => InputManager.Key(Key.Tab));
assertChatFocused(false);
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
}
private void assertChatFocused(bool isFocused) => private void assertChatFocused(bool isFocused) =>
AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == isFocused); AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == isFocused);

View File

@ -25,6 +25,8 @@ namespace osu.Game.Graphics.UserInterface
if (allowImmediateFocus) GetContainingInputManager().ChangeFocus(this); if (allowImmediateFocus) GetContainingInputManager().ChangeFocus(this);
} }
public new void KillFocus() => base.KillFocus();
public bool HoldFocus public bool HoldFocus
{ {
get => allowImmediateFocus && focus; get => allowImmediateFocus && focus;

View File

@ -90,7 +90,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.Left, GlobalAction.SeekReplayBackward), new KeyBinding(InputKey.Left, GlobalAction.SeekReplayBackward),
new KeyBinding(InputKey.Right, GlobalAction.SeekReplayForward), new KeyBinding(InputKey.Right, GlobalAction.SeekReplayForward),
new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD), new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD),
new KeyBinding(InputKey.Tab, GlobalAction.FocusChatInput), new KeyBinding(InputKey.Tab, GlobalAction.ToggleChatFocus),
}; };
public IEnumerable<KeyBinding> SongSelectKeyBindings => new[] public IEnumerable<KeyBinding> SongSelectKeyBindings => new[]
@ -282,7 +282,7 @@ namespace osu.Game.Input.Bindings
[Description("Seek replay backward")] [Description("Seek replay backward")]
SeekReplayBackward, SeekReplayBackward,
[Description("Focus chat")] [Description("Toggle chat focus")]
FocusChatInput ToggleChatFocus
} }
} }

View File

@ -71,11 +71,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
{ {
switch (action) switch (action)
{ {
case GlobalAction.FocusChatInput: case GlobalAction.ToggleChatFocus:
if (Textbox.HasFocus)
{
Schedule(() => Textbox.KillFocus());
}
else
{
expandedFromTextboxFocus.Value = true; expandedFromTextboxFocus.Value = true;
// schedule required to ensure the textbox has become present from above bindable update. // schedule required to ensure the textbox has become present from above bindable update.
Schedule(() => Textbox.TakeFocus()); Schedule(() => Textbox.TakeFocus());
}
return true; return true;
} }