2019-03-04 04:24:19 +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.
|
2018-11-16 05:22:42 +00:00
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-02 04:40:43 +00:00
|
|
|
using osu.Framework.Bindables;
|
2019-06-14 07:57:29 +00:00
|
|
|
using osu.Framework.Graphics;
|
2022-06-08 09:54:23 +00:00
|
|
|
using osu.Game.Online.API;
|
2018-11-16 05:22:42 +00:00
|
|
|
using osu.Game.Online.Chat;
|
2019-02-02 09:29:20 +00:00
|
|
|
using osu.Game.Overlays.Chat;
|
2018-11-16 10:43:54 +00:00
|
|
|
using osu.Game.Tournament.IPC;
|
2019-06-18 05:51:48 +00:00
|
|
|
using osu.Game.Tournament.Models;
|
2018-11-16 05:22:42 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Components
|
|
|
|
{
|
2019-06-18 04:44:38 +00:00
|
|
|
public partial class TournamentMatchChatDisplay : StandAloneChatDisplay
|
2018-11-16 05:22:42 +00:00
|
|
|
{
|
2018-11-16 10:43:54 +00:00
|
|
|
private readonly Bindable<string> chatChannel = new Bindable<string>();
|
|
|
|
|
2023-06-25 11:46:58 +00:00
|
|
|
private ChannelManager? manager;
|
2018-11-16 10:43:54 +00:00
|
|
|
|
2023-06-12 12:56:37 +00:00
|
|
|
[Resolved]
|
2023-06-25 11:46:58 +00:00
|
|
|
private LadderInfo ladderInfo { get; set; } = null!;
|
2023-06-12 12:56:37 +00:00
|
|
|
|
2019-06-18 04:44:38 +00:00
|
|
|
public TournamentMatchChatDisplay()
|
2019-06-14 07:57:29 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2020-03-08 05:46:09 +00:00
|
|
|
Height = 144;
|
2020-03-07 06:28:19 +00:00
|
|
|
Anchor = Anchor.BottomLeft;
|
|
|
|
Origin = Anchor.BottomLeft;
|
|
|
|
|
|
|
|
CornerRadius = 0;
|
2019-06-14 07:57:29 +00:00
|
|
|
}
|
|
|
|
|
2023-06-25 15:39:15 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2023-06-25 11:46:58 +00:00
|
|
|
private void load(MatchIPCInfo? ipc, IAPIProvider api)
|
2018-11-16 10:43:54 +00:00
|
|
|
{
|
|
|
|
if (ipc != null)
|
|
|
|
{
|
|
|
|
chatChannel.BindTo(ipc.ChatChannel);
|
2019-03-02 04:40:43 +00:00
|
|
|
chatChannel.BindValueChanged(c =>
|
2018-11-16 10:43:54 +00:00
|
|
|
{
|
2019-03-02 04:40:43 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(c.NewValue))
|
2018-11-16 10:43:54 +00:00
|
|
|
return;
|
|
|
|
|
2019-03-02 04:40:43 +00:00
|
|
|
int id = int.Parse(c.NewValue);
|
2018-11-16 10:43:54 +00:00
|
|
|
|
2018-11-17 01:40:44 +00:00
|
|
|
if (id <= 0) return;
|
|
|
|
|
|
|
|
if (manager == null)
|
|
|
|
{
|
2022-11-04 09:51:00 +00:00
|
|
|
AddInternal(manager = new ChannelManager(api));
|
2018-11-17 01:40:44 +00:00
|
|
|
Channel.BindTo(manager.CurrentChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var ch in manager.JoinedChannels.ToList())
|
|
|
|
manager.LeaveChannel(ch);
|
|
|
|
|
|
|
|
var channel = new Channel
|
2018-11-16 10:43:54 +00:00
|
|
|
{
|
|
|
|
Id = id,
|
|
|
|
Type = ChannelType.Public
|
|
|
|
};
|
|
|
|
|
|
|
|
manager.JoinChannel(channel);
|
|
|
|
manager.CurrentChannel.Value = channel;
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-08 09:11:57 +00:00
|
|
|
public void Expand() => this.FadeIn(300);
|
|
|
|
|
|
|
|
public void Contract() => this.FadeOut(200);
|
|
|
|
|
2023-06-12 12:56:37 +00:00
|
|
|
protected override ChatLine CreateMessage(Message message) => new MatchMessage(message, ladderInfo);
|
2019-06-13 08:04:57 +00:00
|
|
|
|
2020-03-23 03:03:33 +00:00
|
|
|
protected override StandAloneDrawableChannel CreateDrawableChannel(Channel channel) => new MatchChannel(channel);
|
|
|
|
|
|
|
|
public partial class MatchChannel : StandAloneDrawableChannel
|
|
|
|
{
|
|
|
|
public MatchChannel(Channel channel)
|
|
|
|
: base(channel)
|
|
|
|
{
|
|
|
|
ScrollbarVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 07:50:38 +00:00
|
|
|
protected partial class MatchMessage : StandAloneMessage
|
2018-11-16 05:22:42 +00:00
|
|
|
{
|
2023-06-12 12:56:37 +00:00
|
|
|
public MatchMessage(Message message, LadderInfo info)
|
2018-12-20 07:50:38 +00:00
|
|
|
: base(message)
|
2018-11-16 05:22:42 +00:00
|
|
|
{
|
2023-06-25 15:36:44 +00:00
|
|
|
if (info.CurrentMatch.Value is TournamentMatch match)
|
|
|
|
{
|
2023-07-25 11:50:55 +00:00
|
|
|
if (match.Team1.Value?.Players.Any(u => u.OnlineID == Message.Sender.OnlineID) == true)
|
2023-06-25 15:36:44 +00:00
|
|
|
UsernameColour = TournamentGame.COLOUR_RED;
|
2023-07-25 11:50:55 +00:00
|
|
|
else if (match.Team2.Value?.Players.Any(u => u.OnlineID == Message.Sender.OnlineID) == true)
|
2023-06-25 15:36:44 +00:00
|
|
|
UsernameColour = TournamentGame.COLOUR_BLUE;
|
|
|
|
}
|
2018-11-16 05:22:42 +00:00
|
|
|
}
|
2018-11-17 12:27:02 +00:00
|
|
|
}
|
2018-11-16 05:22:42 +00:00
|
|
|
}
|
|
|
|
}
|