2021-08-17 13:57:48 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2021-08-17 14:05:36 +08:00
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
using osu.Game.Input.Bindings;
|
2021-08-17 13:57:48 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|
|
|
{
|
2021-08-17 14:05:36 +08:00
|
|
|
public class GameplayChatDisplay : MatchChatDisplay, IKeyBindingHandler<GlobalAction>
|
2021-08-17 13:57:48 +08:00
|
|
|
{
|
|
|
|
[Resolved]
|
|
|
|
private ILocalUserPlayInfo localUserInfo { get; set; }
|
|
|
|
|
|
|
|
private IBindable<bool> localUserPlaying = new Bindable<bool>();
|
|
|
|
|
2021-08-18 16:30:50 +08:00
|
|
|
public override bool PropagatePositionalInputSubTree => !localUserPlaying.Value;
|
|
|
|
|
2021-08-17 13:57:48 +08:00
|
|
|
public Bindable<bool> Expanded = new Bindable<bool>();
|
|
|
|
|
2021-08-18 17:25:21 +08:00
|
|
|
private readonly Bindable<bool> expandedFromTextboxFocus = new Bindable<bool>();
|
|
|
|
|
2021-08-17 13:57:48 +08:00
|
|
|
private const float height = 100;
|
|
|
|
|
2021-08-18 17:25:21 +08:00
|
|
|
public override bool PropagateNonPositionalInputSubTree => true;
|
|
|
|
|
2021-08-17 13:57:48 +08:00
|
|
|
public GameplayChatDisplay()
|
2021-08-18 17:24:19 +08:00
|
|
|
: base(leaveChannelOnDispose: false)
|
2021-08-17 13:57:48 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
Background.Alpha = 0.2f;
|
|
|
|
|
2021-08-18 17:25:21 +08:00
|
|
|
Textbox.FocusLost = () => expandedFromTextboxFocus.Value = false;
|
2021-08-17 13:57:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
localUserPlaying = localUserInfo.IsPlaying.GetBoundCopy();
|
|
|
|
localUserPlaying.BindValueChanged(playing =>
|
|
|
|
{
|
|
|
|
// for now let's never hold focus. this avoid misdirected gameplay keys entering chat.
|
|
|
|
// note that this is done within this callback as it triggers an un-focus as well.
|
|
|
|
Textbox.HoldFocus = false;
|
|
|
|
|
|
|
|
// only hold focus (after sending a message) during breaks
|
|
|
|
Textbox.ReleaseFocusOnCommit = playing.NewValue;
|
|
|
|
}, true);
|
|
|
|
|
2021-08-18 17:25:21 +08:00
|
|
|
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);
|
2021-08-17 13:57:48 +08:00
|
|
|
}
|
2021-08-17 14:05:36 +08:00
|
|
|
|
|
|
|
public bool OnPressed(GlobalAction action)
|
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
2021-08-19 13:19:59 +08:00
|
|
|
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());
|
|
|
|
}
|
2021-08-18 17:25:21 +08:00
|
|
|
|
2021-08-17 14:05:36 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnReleased(GlobalAction action)
|
|
|
|
{
|
|
|
|
}
|
2021-08-18 17:25:21 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2021-08-17 13:57:48 +08:00
|
|
|
}
|
|
|
|
}
|