mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 00:33:21 +08:00
Merge pull request #14359 from peppy/multiplayer-chat
Add chat display during multiplayer gameplay
This commit is contained in:
commit
b343f17a52
@ -3,7 +3,6 @@
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
@ -66,7 +65,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
protected class OverlayTestPlayer : TestPlayer
|
||||
{
|
||||
public new OverlayActivation OverlayActivationMode => base.OverlayActivationMode.Value;
|
||||
public new Bindable<bool> LocalUserPlaying => base.LocalUserPlaying;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,131 @@
|
||||
// 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 System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Screens.Play;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneGameplayChatDisplay : MultiplayerTestScene
|
||||
{
|
||||
private GameplayChatDisplay chatDisplay;
|
||||
|
||||
[Cached(typeof(ILocalUserPlayInfo))]
|
||||
private ILocalUserPlayInfo localUserInfo;
|
||||
|
||||
private readonly Bindable<bool> localUserPlaying = new Bindable<bool>();
|
||||
|
||||
private TextBox textBox => chatDisplay.ChildrenOfType<TextBox>().First();
|
||||
|
||||
public TestSceneGameplayChatDisplay()
|
||||
{
|
||||
var mockLocalUserInfo = new Mock<ILocalUserPlayInfo>();
|
||||
mockLocalUserInfo.SetupGet(i => i.IsPlaying).Returns(localUserPlaying);
|
||||
|
||||
localUserInfo = mockLocalUserInfo.Object;
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Width = 0.5f,
|
||||
});
|
||||
|
||||
AddStep("expand", () => chatDisplay.Expanded.Value = true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCantClickWhenPlaying()
|
||||
{
|
||||
setLocalUserPlaying(true);
|
||||
|
||||
AddStep("attempt focus chat", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(textBox);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
assertChatFocused(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusDroppedWhenPlaying()
|
||||
{
|
||||
assertChatFocused(false);
|
||||
|
||||
AddStep("focus chat", () =>
|
||||
{
|
||||
InputManager.MoveMouseTo(textBox);
|
||||
InputManager.Click(MouseButton.Left);
|
||||
});
|
||||
|
||||
setLocalUserPlaying(true);
|
||||
assertChatFocused(false);
|
||||
|
||||
// should still stay non-focused even after entering a new break section.
|
||||
setLocalUserPlaying(false);
|
||||
assertChatFocused(false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusOnTabKeyWhenExpanded()
|
||||
{
|
||||
setLocalUserPlaying(true);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFocusToggleViaAction()
|
||||
{
|
||||
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 tab", () => InputManager.Key(Key.Tab));
|
||||
assertChatFocused(false);
|
||||
AddUntilStep("is not visible", () => !chatDisplay.IsPresent);
|
||||
}
|
||||
|
||||
private void assertChatFocused(bool isFocused) =>
|
||||
AddAssert($"chat {(isFocused ? "focused" : "not focused")}", () => textBox.HasFocus == isFocused);
|
||||
|
||||
private void setLocalUserPlaying(bool playing) =>
|
||||
AddStep($"local user {(playing ? "playing" : "not playing")}", () => localUserPlaying.Value = playing);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
// 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 System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerPlayer : MultiplayerTestScene
|
||||
{
|
||||
private MultiplayerPlayer player;
|
||||
|
||||
[SetUpSteps]
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("set beatmap", () =>
|
||||
{
|
||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||
});
|
||||
|
||||
AddStep("initialise gameplay", () =>
|
||||
{
|
||||
Stack.Push(player = new MultiplayerPlayer(Client.CurrentMatchPlayingItem.Value, Client.Room?.Users.ToArray()));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGameplay()
|
||||
{
|
||||
AddUntilStep("wait for gameplay start", () => player.LocalUserPlaying.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,8 @@ namespace osu.Game.Graphics.UserInterface
|
||||
Scheduler.Add(() => GetContainingInputManager().ChangeFocus(this), false);
|
||||
}
|
||||
|
||||
public new void KillFocus() => base.KillFocus();
|
||||
|
||||
public bool HoldFocus
|
||||
{
|
||||
get => allowImmediateFocus && focus;
|
||||
|
@ -90,6 +90,7 @@ namespace osu.Game.Input.Bindings
|
||||
new KeyBinding(InputKey.Left, GlobalAction.SeekReplayBackward),
|
||||
new KeyBinding(InputKey.Right, GlobalAction.SeekReplayForward),
|
||||
new KeyBinding(InputKey.Control, GlobalAction.HoldForHUD),
|
||||
new KeyBinding(InputKey.Tab, GlobalAction.ToggleChatFocus),
|
||||
};
|
||||
|
||||
public IEnumerable<KeyBinding> SongSelectKeyBindings => new[]
|
||||
@ -280,5 +281,8 @@ namespace osu.Game.Input.Bindings
|
||||
|
||||
[Description("Seek replay backward")]
|
||||
SeekReplayBackward,
|
||||
|
||||
[Description("Toggle chat focus")]
|
||||
ToggleChatFocus
|
||||
}
|
||||
}
|
||||
|
@ -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>();
|
||||
|
||||
private readonly FocusedTextBox textbox;
|
||||
protected readonly ChatTextBox Textbox;
|
||||
|
||||
protected ChannelManager ChannelManager;
|
||||
|
||||
@ -30,6 +31,8 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
private readonly bool postingTextbox;
|
||||
|
||||
protected readonly Box Background;
|
||||
|
||||
private const float textbox_height = 30;
|
||||
|
||||
/// <summary>
|
||||
@ -44,7 +47,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
Background = new Box
|
||||
{
|
||||
Colour = Color4.Black,
|
||||
Alpha = 0.8f,
|
||||
@ -54,7 +57,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
if (postingTextbox)
|
||||
{
|
||||
AddInternal(textbox = new FocusedTextBox
|
||||
AddInternal(Textbox = new ChatTextBox
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = textbox_height,
|
||||
@ -65,7 +68,7 @@ namespace osu.Game.Online.Chat
|
||||
Origin = Anchor.BottomLeft,
|
||||
});
|
||||
|
||||
textbox.OnCommit += postMessage;
|
||||
Textbox.OnCommit += postMessage;
|
||||
}
|
||||
|
||||
Channel.BindValueChanged(channelChanged);
|
||||
@ -82,7 +85,7 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
private void postMessage(TextBox sender, bool newtext)
|
||||
{
|
||||
var text = textbox.Text.Trim();
|
||||
var text = Textbox.Text.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
return;
|
||||
@ -92,7 +95,7 @@ namespace osu.Game.Online.Chat
|
||||
else
|
||||
ChannelManager?.PostMessage(text, target: Channel.Value);
|
||||
|
||||
textbox.Text = string.Empty;
|
||||
Textbox.Text = string.Empty;
|
||||
}
|
||||
|
||||
protected virtual ChatLine CreateMessage(Message message) => new StandAloneMessage(message);
|
||||
@ -110,6 +113,25 @@ namespace osu.Game.Online.Chat
|
||||
AddInternal(drawableChannel);
|
||||
}
|
||||
|
||||
public class ChatTextBox : FocusedTextBox
|
||||
{
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
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
|
||||
{
|
||||
public Func<Message, ChatLine> CreateChatLineAction;
|
||||
|
@ -19,9 +19,12 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
[Resolved(CanBeNull = true)]
|
||||
private ChannelManager channelManager { get; set; }
|
||||
|
||||
public MatchChatDisplay()
|
||||
private readonly bool leaveChannelOnDispose;
|
||||
|
||||
public MatchChatDisplay(bool leaveChannelOnDispose = true)
|
||||
: base(true)
|
||||
{
|
||||
this.leaveChannelOnDispose = leaveChannelOnDispose;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
@ -42,7 +45,9 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
channelManager?.LeaveChannel(Channel.Value);
|
||||
|
||||
if (leaveChannelOnDispose)
|
||||
channelManager?.LeaveChannel(Channel.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
111
osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs
Normal file
111
osu.Game/Screens/OnlinePlay/Multiplayer/GameplayChatDisplay.cs
Normal file
@ -0,0 +1,111 @@
|
||||
// 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;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||
using osu.Game.Screens.Play;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
public class GameplayChatDisplay : MatchChatDisplay, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
[Resolved]
|
||||
private ILocalUserPlayInfo localUserInfo { get; set; }
|
||||
|
||||
private 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()
|
||||
: base(leaveChannelOnDispose: false)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
Background.Alpha = 0.2f;
|
||||
|
||||
Textbox.FocusLost = () => expandedFromTextboxFocus.Value = false;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -68,6 +68,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Direction = FillDirection.Vertical,
|
||||
Spacing = new Vector2(5)
|
||||
});
|
||||
|
||||
// todo: this should be implemented via a custom HUD implementation, and correctly masked to the main content area.
|
||||
@ -78,7 +79,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
((IBindable<bool>)leaderboard.Expanded).BindTo(HUDOverlay.ShowHud);
|
||||
|
||||
leaderboardFlow.Add(l);
|
||||
leaderboardFlow.Insert(0, l);
|
||||
|
||||
if (leaderboard.TeamScores.Count >= 2)
|
||||
{
|
||||
@ -87,10 +88,15 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
Team1Score = { BindTarget = leaderboard.TeamScores.First().Value },
|
||||
Team2Score = { BindTarget = leaderboard.TeamScores.Last().Value },
|
||||
Expanded = { BindTarget = HUDOverlay.ShowHud },
|
||||
}, leaderboardFlow.Add);
|
||||
}, scoreDisplay => leaderboardFlow.Insert(1, scoreDisplay));
|
||||
}
|
||||
});
|
||||
|
||||
LoadComponentAsync(new GameplayChatDisplay
|
||||
{
|
||||
Expanded = { BindTarget = HUDOverlay.ShowHud },
|
||||
}, chat => leaderboardFlow.Insert(2, chat));
|
||||
|
||||
HUDOverlay.Add(loadingDisplay = new LoadingLayer(true) { Depth = float.MaxValue });
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,9 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private readonly Bindable<bool> storyboardReplacesBackground = new Bindable<bool>();
|
||||
|
||||
protected readonly Bindable<bool> LocalUserPlaying = new Bindable<bool>();
|
||||
public IBindable<bool> LocalUserPlaying => localUserPlaying;
|
||||
|
||||
private readonly Bindable<bool> localUserPlaying = new Bindable<bool>();
|
||||
|
||||
public int RestartCount;
|
||||
|
||||
@ -442,7 +444,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
bool inGameplay = !DrawableRuleset.HasReplayLoaded.Value && !DrawableRuleset.IsPaused.Value && !breakTracker.IsBreakTime.Value;
|
||||
OverlayActivationMode.Value = inGameplay ? OverlayActivation.Disabled : OverlayActivation.UserTriggered;
|
||||
LocalUserPlaying.Value = inGameplay;
|
||||
localUserPlaying.Value = inGameplay;
|
||||
}
|
||||
|
||||
private void updateSampleDisabledState()
|
||||
|
Loading…
Reference in New Issue
Block a user