mirror of
https://github.com/ppy/osu
synced 2025-02-17 02:47:19 +00:00
Allow expanding chat using key binding even when it is hidden
This commit is contained in:
parent
365c1bccc6
commit
1faf789f0e
@ -83,13 +83,28 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusOnTabKey()
|
||||
public void TestFocusOnTabKeyWhenExpanded()
|
||||
{
|
||||
assertChatFocused(false);
|
||||
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
||||
assertChatFocused(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusOnTabKeyWhenNotExpanded()
|
||||
{
|
||||
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 enter", () => InputManager.Key(Key.Enter));
|
||||
assertChatFocused(false);
|
||||
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
||||
}
|
||||
|
||||
private void assertChatFocused(bool isFocused) =>
|
||||
AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == isFocused);
|
||||
|
||||
|
@ -8,6 +8,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Chat;
|
||||
@ -22,7 +23,7 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
public readonly Bindable<Channel> Channel = new Bindable<Channel>();
|
||||
|
||||
protected readonly FocusedTextBox Textbox;
|
||||
protected readonly ChatTextBox Textbox;
|
||||
|
||||
protected ChannelManager ChannelManager;
|
||||
|
||||
@ -121,6 +122,14 @@ namespace osu.Game.Online.Chat
|
||||
BackgroundUnfocused = new Color4(10, 10, 10, 10);
|
||||
BackgroundFocused = new Color4(10, 10, 10, 255);
|
||||
}
|
||||
|
||||
protected override void OnFocusLost(FocusLostEvent e)
|
||||
{
|
||||
base.OnFocusLost(e);
|
||||
FocusLost?.Invoke();
|
||||
}
|
||||
|
||||
public Action FocusLost;
|
||||
}
|
||||
|
||||
public class StandAloneDrawableChannel : DrawableChannel
|
||||
|
@ -22,28 +22,20 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
public Bindable<bool> Expanded = new Bindable<bool>();
|
||||
|
||||
private readonly Bindable<bool> expandedFromTextboxFocus = new Bindable<bool>();
|
||||
|
||||
private const float height = 100;
|
||||
|
||||
public override bool PropagateNonPositionalInputSubTree => true;
|
||||
|
||||
public GameplayChatDisplay()
|
||||
: base(leaveChannelOnDispose: false)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
Background.Alpha = 0.2f;
|
||||
}
|
||||
|
||||
private void expandedChanged(ValueChangedEvent<bool> expanded)
|
||||
{
|
||||
if (expanded.NewValue)
|
||||
{
|
||||
this.FadeIn(300, Easing.OutQuint);
|
||||
this.ResizeHeightTo(height, 500, Easing.OutQuint);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.FadeOut(300, Easing.OutQuint);
|
||||
this.ResizeHeightTo(0, 500, Easing.OutQuint);
|
||||
}
|
||||
Textbox.FocusLost = () => expandedFromTextboxFocus.Value = false;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -61,7 +53,18 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
Textbox.ReleaseFocusOnCommit = playing.NewValue;
|
||||
}, true);
|
||||
|
||||
Expanded.BindValueChanged(expandedChanged, true);
|
||||
Expanded.BindValueChanged(_ => updateExpandedState(), true);
|
||||
expandedFromTextboxFocus.BindValueChanged(focus =>
|
||||
{
|
||||
if (focus.NewValue)
|
||||
updateExpandedState();
|
||||
else
|
||||
{
|
||||
// on finishing typing a message there should be a brief delay before hiding.
|
||||
using (BeginDelayedSequence(600))
|
||||
updateExpandedState();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
@ -69,7 +72,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.FocusChatInput:
|
||||
Textbox.TakeFocus();
|
||||
expandedFromTextboxFocus.Value = true;
|
||||
|
||||
// schedule required to ensure the textbox has become present from above bindable update.
|
||||
Schedule(() => Textbox.TakeFocus());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -79,5 +85,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
public void OnReleased(GlobalAction action)
|
||||
{
|
||||
}
|
||||
|
||||
private void updateExpandedState()
|
||||
{
|
||||
if (Expanded.Value || expandedFromTextboxFocus.Value)
|
||||
{
|
||||
this.FadeIn(300, Easing.OutQuint);
|
||||
this.ResizeHeightTo(height, 500, Easing.OutQuint);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.FadeOut(300, Easing.OutQuint);
|
||||
this.ResizeHeightTo(0, 500, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user