1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 22:52:57 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

131 lines
4.2 KiB
C#
Raw Normal View History

// 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 15:37:17 +08:00
#nullable disable
2022-02-25 15:12:25 +08:00
using JetBrains.Annotations;
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.Framework.Input.Events;
2021-08-17 14:05:36 +08:00
using osu.Game.Input.Bindings;
using osu.Game.Online.Rooms;
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 partial class GameplayChatDisplay : MatchChatDisplay, IKeyBindingHandler<GlobalAction>
{
2022-02-25 15:12:25 +08:00
[Resolved(CanBeNull = true)]
[CanBeNull]
private ILocalUserPlayInfo localUserInfo { get; set; }
2022-02-25 15:12:25 +08:00
private readonly IBindable<bool> localUserPlaying = new Bindable<bool>();
public override bool PropagatePositionalInputSubTree => !localUserPlaying.Value;
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(Room room)
: base(room, leaveChannelOnDispose: false)
{
RelativeSizeAxes = Axes.X;
Background.Alpha = 0.2f;
TextBox.FocusLost = () => expandedFromTextBoxFocus.Value = false;
}
protected override bool OnHover(HoverEvent e) => true; // use UI mouse cursor.
protected override void LoadComplete()
{
base.LoadComplete();
2022-02-25 15:12:25 +08:00
if (localUserInfo != null)
localUserPlaying.BindTo(localUserInfo.IsPlaying);
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);
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 14:05:36 +08:00
2021-09-16 17:26:12 +08:00
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
2021-08-17 14:05:36 +08:00
{
2021-09-16 17:26:12 +08:00
switch (e.Action)
2021-08-17 14:05:36 +08:00
{
case GlobalAction.Back:
if (TextBox.HasFocus)
{
Schedule(() => TextBox.KillFocus());
return true;
}
break;
2021-08-19 13:19:59 +08:00
case GlobalAction.ToggleChatFocus:
if (TextBox.HasFocus)
2021-08-19 13:19:59 +08:00
{
Schedule(() => TextBox.KillFocus());
2021-08-19 13:19:59 +08:00
}
else
{
expandedFromTextBoxFocus.Value = true;
2021-08-19 13:19:59 +08:00
// schedule required to ensure the textbox has become present from above bindable update.
Schedule(() => TextBox.TakeFocus());
2021-08-19 13:19:59 +08:00
}
2021-08-17 14:05:36 +08:00
return true;
}
return false;
}
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
2021-08-17 14:05:36 +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);
}
}
}
}