2021-08-17 05:57:48 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2022-02-25 07:12:25 +00:00
|
|
|
using JetBrains.Annotations;
|
2021-08-17 05:57:48 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2021-08-17 06:05:36 +00:00
|
|
|
using osu.Framework.Input.Bindings;
|
2021-08-21 05:44:54 +00:00
|
|
|
using osu.Framework.Input.Events;
|
2021-08-17 06:05:36 +00:00
|
|
|
using osu.Game.Input.Bindings;
|
2024-08-04 16:32:08 +00:00
|
|
|
using osu.Game.Localisation;
|
2021-08-24 04:22:06 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2021-08-17 05:57:48 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|
|
|
{
|
2021-08-17 06:05:36 +00:00
|
|
|
public partial class GameplayChatDisplay : MatchChatDisplay, IKeyBindingHandler<GlobalAction>
|
2021-08-17 05:57:48 +00:00
|
|
|
{
|
2022-02-25 07:12:25 +00:00
|
|
|
[Resolved(CanBeNull = true)]
|
|
|
|
[CanBeNull]
|
2021-08-17 05:57:48 +00:00
|
|
|
private ILocalUserPlayInfo localUserInfo { get; set; }
|
|
|
|
|
2024-10-01 10:55:46 +00:00
|
|
|
private readonly IBindable<LocalUserPlayingState> localUserPlaying = new Bindable<LocalUserPlayingState>();
|
2021-08-17 05:57:48 +00:00
|
|
|
|
2024-10-01 10:55:46 +00:00
|
|
|
public override bool PropagatePositionalInputSubTree => localUserPlaying.Value != LocalUserPlayingState.Playing;
|
2021-08-18 08:30:50 +00:00
|
|
|
|
2021-08-17 05:57:48 +00:00
|
|
|
public Bindable<bool> Expanded = new Bindable<bool>();
|
|
|
|
|
2021-12-10 05:15:00 +00:00
|
|
|
private readonly Bindable<bool> expandedFromTextBoxFocus = new Bindable<bool>();
|
2021-08-18 09:25:21 +00:00
|
|
|
|
2021-08-17 05:57:48 +00:00
|
|
|
private const float height = 100;
|
|
|
|
|
2021-08-18 09:25:21 +00:00
|
|
|
public override bool PropagateNonPositionalInputSubTree => true;
|
|
|
|
|
2021-08-24 04:22:06 +00:00
|
|
|
public GameplayChatDisplay(Room room)
|
|
|
|
: base(room, leaveChannelOnDispose: false)
|
2021-08-17 05:57:48 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
|
|
|
Background.Alpha = 0.2f;
|
|
|
|
|
2024-08-05 03:29:56 +00:00
|
|
|
TextBox.PlaceholderText = ChatStrings.InGameInputPlaceholder;
|
2024-08-07 11:47:35 +00:00
|
|
|
TextBox.Focus = () => TextBox.PlaceholderText = Resources.Localisation.Web.ChatStrings.InputPlaceholder;
|
|
|
|
TextBox.FocusLost = () =>
|
|
|
|
{
|
|
|
|
TextBox.PlaceholderText = ChatStrings.InGameInputPlaceholder;
|
|
|
|
expandedFromTextBoxFocus.Value = false;
|
|
|
|
};
|
2021-08-17 05:57:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-21 05:44:54 +00:00
|
|
|
protected override bool OnHover(HoverEvent e) => true; // use UI mouse cursor.
|
|
|
|
|
2021-08-17 05:57:48 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-02-25 07:12:25 +00:00
|
|
|
if (localUserInfo != null)
|
2024-10-01 08:00:32 +00:00
|
|
|
localUserPlaying.BindTo(localUserInfo.PlayingState);
|
2022-02-25 07:12:25 +00:00
|
|
|
|
2021-08-17 05:57:48 +00:00
|
|
|
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.
|
2021-12-10 05:15:00 +00:00
|
|
|
TextBox.HoldFocus = false;
|
2021-08-17 05:57:48 +00:00
|
|
|
|
|
|
|
// only hold focus (after sending a message) during breaks
|
2024-10-01 10:55:46 +00:00
|
|
|
TextBox.ReleaseFocusOnCommit = playing.NewValue == LocalUserPlayingState.Playing;
|
2021-08-17 05:57:48 +00:00
|
|
|
}, true);
|
|
|
|
|
2021-08-18 09:25:21 +00:00
|
|
|
Expanded.BindValueChanged(_ => updateExpandedState(), true);
|
2021-12-10 05:15:00 +00:00
|
|
|
expandedFromTextBoxFocus.BindValueChanged(focus =>
|
2021-08-18 09:25:21 +00:00
|
|
|
{
|
|
|
|
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 05:57:48 +00:00
|
|
|
}
|
2021-08-17 06:05:36 +00:00
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2021-08-17 06:05:36 +00:00
|
|
|
{
|
2021-09-16 09:26:12 +00:00
|
|
|
switch (e.Action)
|
2021-08-17 06:05:36 +00:00
|
|
|
{
|
2021-10-26 04:55:02 +00:00
|
|
|
case GlobalAction.Back:
|
2021-12-10 05:15:00 +00:00
|
|
|
if (TextBox.HasFocus)
|
2021-10-26 04:55:02 +00:00
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
Schedule(() => TextBox.KillFocus());
|
2021-10-26 04:55:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-08-19 05:19:59 +00:00
|
|
|
case GlobalAction.ToggleChatFocus:
|
2021-12-10 05:15:00 +00:00
|
|
|
if (TextBox.HasFocus)
|
2021-08-19 05:19:59 +00:00
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
Schedule(() => TextBox.KillFocus());
|
2021-08-19 05:19:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
expandedFromTextBoxFocus.Value = true;
|
2021-08-19 05:19:59 +00:00
|
|
|
|
|
|
|
// schedule required to ensure the textbox has become present from above bindable update.
|
2021-12-10 05:15:00 +00:00
|
|
|
Schedule(() => TextBox.TakeFocus());
|
2021-08-19 05:19:59 +00:00
|
|
|
}
|
2021-08-18 09:25:21 +00:00
|
|
|
|
2021-08-17 06:05:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2021-08-17 06:05:36 +00:00
|
|
|
{
|
|
|
|
}
|
2021-08-18 09:25:21 +00:00
|
|
|
|
|
|
|
private void updateExpandedState()
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
if (Expanded.Value || expandedFromTextBoxFocus.Value)
|
2021-08-18 09:25:21 +00:00
|
|
|
{
|
|
|
|
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 05:57:48 +00:00
|
|
|
}
|
|
|
|
}
|