From d5496321e2cf8dfaf0c254460786d25d0bacac8b Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 14 Feb 2020 20:31:55 +0900 Subject: [PATCH] Implement leaderboard chat display --- .../TestSceneMatchLeaderboardChatDisplay.cs | 39 +++++++ .../Components/LeaderboardChatDisplay.cs | 100 ++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboardChatDisplay.cs create mode 100644 osu.Game/Screens/Multi/Match/Components/LeaderboardChatDisplay.cs diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboardChatDisplay.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboardChatDisplay.cs new file mode 100644 index 0000000000..e46386b263 --- /dev/null +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMatchLeaderboardChatDisplay.cs @@ -0,0 +1,39 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Screens.Multi.Match.Components; +using osuTK; + +namespace osu.Game.Tests.Visual.Multiplayer +{ + public class TestSceneMatchLeaderboardChatDisplay : MultiplayerTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(LeaderboardChatDisplay) + }; + + protected override bool UseOnlineAPI => true; + + public TestSceneMatchLeaderboardChatDisplay() + { + Room.RoomID.Value = 7; + + Add(new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(500), + Child = new LeaderboardChatDisplay + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }); + } + } +} diff --git a/osu.Game/Screens/Multi/Match/Components/LeaderboardChatDisplay.cs b/osu.Game/Screens/Multi/Match/Components/LeaderboardChatDisplay.cs new file mode 100644 index 0000000000..de02b7f605 --- /dev/null +++ b/osu.Game/Screens/Multi/Match/Components/LeaderboardChatDisplay.cs @@ -0,0 +1,100 @@ +// Copyright (c) ppy Pty Ltd . 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.Graphics.Containers; +using osu.Framework.Graphics.UserInterface; +using osu.Game.Graphics; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Screens.Multi.Match.Components +{ + public class LeaderboardChatDisplay : MultiplayerComposite + { + private const double fade_duration = 100; + + private readonly OsuTabControl tabControl; + private readonly MatchLeaderboard leaderboard; + private readonly MatchChatDisplay chat; + + public LeaderboardChatDisplay() + { + RelativeSizeAxes = Axes.Both; + + InternalChild = new GridContainer + { + RelativeSizeAxes = Axes.Both, + Content = new[] + { + new Drawable[] + { + tabControl = new DisplayModeTabControl + { + RelativeSizeAxes = Axes.X, + Height = 24, + } + }, + new Drawable[] + { + new Container + { + RelativeSizeAxes = Axes.Both, + Padding = new MarginPadding { Top = 10 }, + Children = new Drawable[] + { + leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, + chat = new MatchChatDisplay + { + RelativeSizeAxes = Axes.Both, + Alpha = 0 + } + } + } + }, + }, + RowDimensions = new[] + { + new Dimension(GridSizeMode.AutoSize), + } + }; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + tabControl.AccentColour = colours.Yellow; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + tabControl.Current.BindValueChanged(changeTab); + } + + public void RefreshScores() => leaderboard.RefreshScores(); + + private void changeTab(ValueChangedEvent mode) + { + chat.FadeTo(mode.NewValue == DisplayMode.Chat ? 1 : 0, fade_duration); + leaderboard.FadeTo(mode.NewValue == DisplayMode.Leaderboard ? 1 : 0, fade_duration); + } + + private class DisplayModeTabControl : OsuTabControl + { + protected override TabItem CreateTabItem(DisplayMode value) => base.CreateTabItem(value).With(d => + { + d.Anchor = Anchor.Centre; + d.Origin = Anchor.Centre; + }); + } + + private enum DisplayMode + { + Leaderboard, + Chat, + } + } +}