2019-01-24 17:43:03 +09: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-12-21 14:01:06 +09:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 19:04:31 +09:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-21 14:01:06 +09:00
|
|
|
using osu.Game.Online.Chat;
|
2020-12-25 13:38:11 +09:00
|
|
|
using osu.Game.Online.Rooms;
|
2018-12-21 14:01:06 +09:00
|
|
|
|
2020-12-25 16:50:00 +01:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Match.Components
|
2018-12-21 14:01:06 +09:00
|
|
|
{
|
|
|
|
public class MatchChatDisplay : StandAloneChatDisplay
|
|
|
|
{
|
2021-08-24 13:22:06 +09:00
|
|
|
private readonly IBindable<int> channelId = new Bindable<int>();
|
2018-12-21 14:01:06 +09:00
|
|
|
|
2018-12-22 14:38:46 +09:00
|
|
|
[Resolved(CanBeNull = true)]
|
2018-12-21 14:01:06 +09:00
|
|
|
private ChannelManager channelManager { get; set; }
|
|
|
|
|
2021-08-24 14:25:29 +09:00
|
|
|
private readonly Room room;
|
2021-08-18 18:24:19 +09:00
|
|
|
private readonly bool leaveChannelOnDispose;
|
|
|
|
|
2021-08-24 13:22:06 +09:00
|
|
|
public MatchChatDisplay(Room room, bool leaveChannelOnDispose = true)
|
2018-12-21 14:01:06 +09:00
|
|
|
: base(true)
|
|
|
|
{
|
2021-08-24 14:25:29 +09:00
|
|
|
this.room = room;
|
2021-08-18 18:24:19 +09:00
|
|
|
this.leaveChannelOnDispose = leaveChannelOnDispose;
|
2018-12-21 14:01:06 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2021-08-24 14:25:29 +09:00
|
|
|
// Required for the time being since this component is created prior to the room being joined.
|
|
|
|
channelId.BindTo(room.ChannelId);
|
2019-03-07 15:35:57 +09:00
|
|
|
channelId.BindValueChanged(_ => updateChannel(), true);
|
2018-12-21 14:37:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateChannel()
|
|
|
|
{
|
2021-08-24 14:25:29 +09:00
|
|
|
if (room.RoomID.Value == null || channelId.Value == 0)
|
2019-03-07 15:35:57 +09:00
|
|
|
return;
|
|
|
|
|
2021-08-24 14:25:29 +09:00
|
|
|
Channel.Value = channelManager?.JoinChannel(new Channel { Id = channelId.Value, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
|
2018-12-21 14:01:06 +09:00
|
|
|
}
|
2021-01-21 15:42:23 +09:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
2021-08-18 18:24:19 +09:00
|
|
|
|
|
|
|
if (leaveChannelOnDispose)
|
|
|
|
channelManager?.LeaveChannel(Channel.Value);
|
2021-01-21 15:42:23 +09:00
|
|
|
}
|
2018-12-21 14:01:06 +09:00
|
|
|
}
|
|
|
|
}
|