mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Allow expanding chat using key binding even when it is hidden
This commit is contained in:
@ -83,13 +83,28 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestFocusOnTabKey()
|
public void TestFocusOnTabKeyWhenExpanded()
|
||||||
{
|
{
|
||||||
assertChatFocused(false);
|
assertChatFocused(false);
|
||||||
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
AddStep("press tab", () => InputManager.Key(Key.Tab));
|
||||||
assertChatFocused(true);
|
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) =>
|
private void assertChatFocused(bool isFocused) =>
|
||||||
AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == 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.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Overlays.Chat;
|
using osu.Game.Overlays.Chat;
|
||||||
@ -22,7 +23,7 @@ namespace osu.Game.Online.Chat
|
|||||||
{
|
{
|
||||||
public readonly Bindable<Channel> Channel = new Bindable<Channel>();
|
public readonly Bindable<Channel> Channel = new Bindable<Channel>();
|
||||||
|
|
||||||
protected readonly FocusedTextBox Textbox;
|
protected readonly ChatTextBox Textbox;
|
||||||
|
|
||||||
protected ChannelManager ChannelManager;
|
protected ChannelManager ChannelManager;
|
||||||
|
|
||||||
@ -121,6 +122,14 @@ namespace osu.Game.Online.Chat
|
|||||||
BackgroundUnfocused = new Color4(10, 10, 10, 10);
|
BackgroundUnfocused = new Color4(10, 10, 10, 10);
|
||||||
BackgroundFocused = new Color4(10, 10, 10, 255);
|
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
|
public class StandAloneDrawableChannel : DrawableChannel
|
||||||
|
@ -22,28 +22,20 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
|
|
||||||
public Bindable<bool> Expanded = new Bindable<bool>();
|
public Bindable<bool> Expanded = new Bindable<bool>();
|
||||||
|
|
||||||
|
private readonly Bindable<bool> expandedFromTextboxFocus = new Bindable<bool>();
|
||||||
|
|
||||||
private const float height = 100;
|
private const float height = 100;
|
||||||
|
|
||||||
|
public override bool PropagateNonPositionalInputSubTree => true;
|
||||||
|
|
||||||
public GameplayChatDisplay()
|
public GameplayChatDisplay()
|
||||||
: base(leaveChannelOnDispose: false)
|
: base(leaveChannelOnDispose: false)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
|
|
||||||
Background.Alpha = 0.2f;
|
Background.Alpha = 0.2f;
|
||||||
}
|
|
||||||
|
|
||||||
private void expandedChanged(ValueChangedEvent<bool> expanded)
|
Textbox.FocusLost = () => expandedFromTextboxFocus.Value = false;
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
@ -61,7 +53,18 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
Textbox.ReleaseFocusOnCommit = playing.NewValue;
|
Textbox.ReleaseFocusOnCommit = playing.NewValue;
|
||||||
}, true);
|
}, 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)
|
public bool OnPressed(GlobalAction action)
|
||||||
@ -69,7 +72,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case GlobalAction.FocusChatInput:
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,5 +85,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
public void OnReleased(GlobalAction action)
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user