1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-01 04:12:55 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Match/Components/MatchChatDisplay.cs

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

59 lines
1.7 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.
2018-12-21 13:01:06 +08:00
2024-11-13 21:23:33 +08:00
using System.ComponentModel;
2018-12-21 13:01:06 +08:00
using osu.Framework.Allocation;
using osu.Game.Online.Chat;
2020-12-25 12:38:11 +08:00
using osu.Game.Online.Rooms;
2018-12-21 13:01:06 +08:00
namespace osu.Game.Screens.OnlinePlay.Match.Components
2018-12-21 13:01:06 +08:00
{
public partial class MatchChatDisplay : StandAloneChatDisplay
{
[Resolved]
2018-12-21 13:01:06 +08:00
private ChannelManager? channelManager { get; set; }
private readonly Room room;
private readonly bool leaveChannelOnDispose;
public MatchChatDisplay(Room room, bool leaveChannelOnDispose = true)
2018-12-21 13:01:06 +08:00
: base(true)
{
this.room = room;
this.leaveChannelOnDispose = leaveChannelOnDispose;
2018-12-21 13:01:06 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
2024-11-13 21:23:33 +08:00
room.PropertyChanged += onRoomPropertyChanged;
updateChannel();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.ChannelId))
updateChannel();
2018-12-21 13:37:05 +08:00
}
private void updateChannel()
{
2024-11-13 21:23:33 +08:00
if (room.RoomID == null || room.ChannelId == 0)
return;
2024-11-13 21:23:33 +08:00
Channel.Value = channelManager?.JoinChannel(new Channel { Id = room.ChannelId, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
2018-12-21 13:01:06 +08:00
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
2024-11-13 21:23:33 +08:00
room.PropertyChanged -= onRoomPropertyChanged;
if (leaveChannelOnDispose)
channelManager?.LeaveChannel(Channel.Value);
}
2018-12-21 13:01:06 +08:00
}
}