1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 02:52:54 +08:00

Make Room.ChannelId non-bindable

This commit is contained in:
Dan Balasescu 2024-11-13 22:23:33 +09:00
parent 6c84e425f8
commit 80b3e330a6
No known key found for this signature in database
2 changed files with 26 additions and 13 deletions

View File

@ -194,6 +194,15 @@ namespace osu.Game.Online.Rooms
set => SetField(ref currentPlaylistItem, value); 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> /// <summary>
/// The current room status. /// The current room status.
/// </summary> /// </summary>
@ -266,6 +275,9 @@ namespace osu.Game.Online.Rooms
[JsonProperty("current_playlist_item")] [JsonProperty("current_playlist_item")]
private PlaylistItem? currentPlaylistItem; private PlaylistItem? currentPlaylistItem;
[JsonProperty("channel_id")]
private int channelId;
// Not serialised (see: GetRoomsRequest). // Not serialised (see: GetRoomsRequest).
private RoomStatus status = new RoomStatusOpen(); private RoomStatus status = new RoomStatusOpen();
@ -276,10 +288,6 @@ namespace osu.Game.Online.Rooms
[JsonProperty("playlist")] [JsonProperty("playlist")]
public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>(); public readonly BindableList<PlaylistItem> Playlist = new BindableList<PlaylistItem>();
[Cached]
[JsonProperty("channel_id")]
public readonly Bindable<int> ChannelId = new Bindable<int>();
[JsonProperty("playlist_item_stats")] [JsonProperty("playlist_item_stats")]
[Cached] [Cached]
public readonly Bindable<RoomPlaylistItemStats> PlaylistItemStats = new Bindable<RoomPlaylistItemStats>(); 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) if (other.Host != null && Host?.Id != other.Host.Id)
Host = other.Host; Host = other.Host;
ChannelId.Value = other.ChannelId.Value; ChannelId = other.ChannelId;
Status = other.Status; Status = other.Status;
Availability = other.Availability; Availability = other.Availability;
HasPassword = other.HasPassword; HasPassword = other.HasPassword;

View File

@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.ComponentModel;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
@ -10,8 +10,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
{ {
public partial class MatchChatDisplay : StandAloneChatDisplay public partial class MatchChatDisplay : StandAloneChatDisplay
{ {
private readonly IBindable<int> channelId = new Bindable<int>();
[Resolved] [Resolved]
private ChannelManager? channelManager { get; set; } private ChannelManager? channelManager { get; set; }
@ -29,23 +27,30 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
{ {
base.LoadComplete(); base.LoadComplete();
// Required for the time being since this component is created prior to the room being joined. room.PropertyChanged += onRoomPropertyChanged;
channelId.BindTo(room.ChannelId); updateChannel();
channelId.BindValueChanged(_ => updateChannel(), true); }
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.ChannelId))
updateChannel();
} }
private void updateChannel() private void updateChannel()
{ {
if (room.RoomID == null || channelId.Value == 0) if (room.RoomID == null || room.ChannelId == 0)
return; 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) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
if (leaveChannelOnDispose) if (leaveChannelOnDispose)
channelManager?.LeaveChannel(Channel.Value); channelManager?.LeaveChannel(Channel.Value);
} }