mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 14:12:56 +08:00
Allow toggling focus via binding
This commit is contained in:
parent
786beb9759
commit
6d00ea3375
@ -107,6 +107,21 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
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) =>
|
||||
AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == isFocused);
|
||||
|
||||
|
@ -25,6 +25,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
if (allowImmediateFocus) GetContainingInputManager().ChangeFocus(this);
|
||||
}
|
||||
|
||||
public new void KillFocus() => base.KillFocus();
|
||||
|
||||
public bool HoldFocus
|
||||
{
|
||||
get => allowImmediateFocus && focus;
|
||||
|
@ -90,7 +90,7 @@ namespace osu.Game.Input.Bindings
|
||||
new KeyBinding(InputKey.Left, GlobalAction.SeekReplayBackward),
|
||||
new KeyBinding(InputKey.Right, GlobalAction.SeekReplayForward),
|
||||
new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD),
|
||||
new KeyBinding(InputKey.Tab, GlobalAction.FocusChatInput),
|
||||
new KeyBinding(InputKey.Tab, GlobalAction.ToggleChatFocus),
|
||||
};
|
||||
|
||||
public IEnumerable<KeyBinding> SongSelectKeyBindings => new[]
|
||||
@ -282,7 +282,7 @@ namespace osu.Game.Input.Bindings
|
||||
[Description("Seek replay backward")]
|
||||
SeekReplayBackward,
|
||||
|
||||
[Description("Focus chat")]
|
||||
FocusChatInput
|
||||
[Description("Toggle chat focus")]
|
||||
ToggleChatFocus
|
||||
}
|
||||
}
|
||||
|
@ -71,11 +71,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.FocusChatInput:
|
||||
case GlobalAction.ToggleChatFocus:
|
||||
if (Textbox.HasFocus)
|
||||
{
|
||||
Schedule(() => Textbox.KillFocus());
|
||||
}
|
||||
else
|
||||
{
|
||||
expandedFromTextboxFocus.Value = true;
|
||||
|
||||
// schedule required to ensure the textbox has become present from above bindable update.
|
||||
Schedule(() => Textbox.TakeFocus());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user