mirror of
https://github.com/ppy/osu.git
synced 2025-01-18 20:22:58 +08:00
Make Room.ChannelId
non-bindable
This commit is contained in:
parent
6c84e425f8
commit
80b3e330a6
@ -194,6 +194,15 @@ namespace osu.Game.Online.Rooms
|
||||
set => SetField(ref currentPlaylistItem, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The chat channel id for the room. Will be <c>0</c> while the room has not yet been created.
|
||||
/// </summary>
|
||||
public int ChannelId
|
||||
{
|
||||
get => channelId;
|
||||
private set => SetField(ref channelId, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The current room status.
|
||||
/// </summary>
|
||||
@ -266,6 +275,9 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("current_playlist_item")]
|
||||
private PlaylistItem? currentPlaylistItem;
|
||||
|
||||
[JsonProperty("channel_id")]
|
||||
private int channelId;
|
||||
|
||||
// Not serialised (see: GetRoomsRequest).
|
||||
private RoomStatus status = new RoomStatusOpen();
|
||||
|
||||
@ -276,10 +288,6 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("playlist")]
|
||||
public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>();
|
||||
|
||||
[Cached]
|
||||
[JsonProperty("channel_id")]
|
||||
public readonly Bindable<int> ChannelId = new Bindable<int>();
|
||||
|
||||
[JsonProperty("playlist_item_stats")]
|
||||
[Cached]
|
||||
public readonly Bindable<RoomPlaylistItemStats> PlaylistItemStats = new Bindable<RoomPlaylistItemStats>();
|
||||
@ -313,7 +321,7 @@ namespace osu.Game.Online.Rooms
|
||||
if (other.Host != null && Host?.Id != other.Host.Id)
|
||||
Host = other.Host;
|
||||
|
||||
ChannelId.Value = other.ChannelId.Value;
|
||||
ChannelId = other.ChannelId;
|
||||
Status = other.Status;
|
||||
Availability = other.Availability;
|
||||
HasPassword = other.HasPassword;
|
||||
|
@ -1,8 +1,8 @@
|
||||
// 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.ComponentModel;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
@ -10,8 +10,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
{
|
||||
public partial class MatchChatDisplay : StandAloneChatDisplay
|
||||
{
|
||||
private readonly IBindable<int> channelId = new Bindable<int>();
|
||||
|
||||
[Resolved]
|
||||
private ChannelManager? channelManager { get; set; }
|
||||
|
||||
@ -29,23 +27,30 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
// Required for the time being since this component is created prior to the room being joined.
|
||||
channelId.BindTo(room.ChannelId);
|
||||
channelId.BindValueChanged(_ => updateChannel(), true);
|
||||
room.PropertyChanged += onRoomPropertyChanged;
|
||||
updateChannel();
|
||||
}
|
||||
|
||||
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Room.ChannelId))
|
||||
updateChannel();
|
||||
}
|
||||
|
||||
private void updateChannel()
|
||||
{
|
||||
if (room.RoomID == null || channelId.Value == 0)
|
||||
if (room.RoomID == null || room.ChannelId == 0)
|
||||
return;
|
||||
|
||||
Channel.Value = channelManager?.JoinChannel(new Channel { Id = channelId.Value, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
|
||||
Channel.Value = channelManager?.JoinChannel(new Channel { Id = room.ChannelId, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
room.PropertyChanged -= onRoomPropertyChanged;
|
||||
|
||||
if (leaveChannelOnDispose)
|
||||
channelManager?.LeaveChannel(Channel.Value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user