mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:03:13 +08:00
Add drawable channel caching to new chat overlay
This commit is contained in:
parent
26c8516130
commit
9f5351e5a1
@ -39,8 +39,9 @@ namespace osu.Game.Overlays
|
|||||||
private ChatTextBar textBar = null!;
|
private ChatTextBar textBar = null!;
|
||||||
private Container<ChatOverlayDrawableChannel> currentChannelContainer = null!;
|
private Container<ChatOverlayDrawableChannel> currentChannelContainer = null!;
|
||||||
|
|
||||||
private readonly BindableFloat chatHeight = new BindableFloat();
|
private readonly Dictionary<Channel, ChatOverlayDrawableChannel> loadedChannels = new Dictionary<Channel, ChatOverlayDrawableChannel>();
|
||||||
|
|
||||||
|
private readonly BindableFloat chatHeight = new BindableFloat();
|
||||||
private bool isDraggingTopBar;
|
private bool isDraggingTopBar;
|
||||||
private float dragStartChatHeight;
|
private float dragStartChatHeight;
|
||||||
|
|
||||||
@ -173,7 +174,7 @@ namespace osu.Game.Overlays
|
|||||||
if (currentChannel.Value?.Id != channel.Id)
|
if (currentChannel.Value?.Id != channel.Id)
|
||||||
{
|
{
|
||||||
if (!channel.Joined.Value)
|
if (!channel.Joined.Value)
|
||||||
channel = channelManager.JoinChannel(channel);
|
channel = channelManager.JoinChannel(channel, false);
|
||||||
|
|
||||||
channelManager.CurrentChannel.Value = channel;
|
channelManager.CurrentChannel.Value = channel;
|
||||||
}
|
}
|
||||||
@ -248,13 +249,26 @@ namespace osu.Game.Overlays
|
|||||||
channelListing.State.Value = Visibility.Hidden;
|
channelListing.State.Value = Visibility.Hidden;
|
||||||
textBar.ShowSearch.Value = false;
|
textBar.ShowSearch.Value = false;
|
||||||
|
|
||||||
loading.Show();
|
if (loadedChannels.ContainsKey(newChannel))
|
||||||
LoadComponentAsync(new ChatOverlayDrawableChannel(newChannel), loaded =>
|
|
||||||
{
|
{
|
||||||
currentChannelContainer.Clear();
|
currentChannelContainer.Clear(false);
|
||||||
currentChannelContainer.Add(loaded);
|
currentChannelContainer.Add(loadedChannels[newChannel]);
|
||||||
loading.Hide();
|
}
|
||||||
});
|
else
|
||||||
|
{
|
||||||
|
loading.Show();
|
||||||
|
|
||||||
|
// Ensure the drawable channel is stored before async load to prevent double loading
|
||||||
|
ChatOverlayDrawableChannel drawableChannel = new ChatOverlayDrawableChannel(newChannel);
|
||||||
|
loadedChannels.Add(newChannel, drawableChannel);
|
||||||
|
|
||||||
|
LoadComponentAsync(drawableChannel, loaded =>
|
||||||
|
{
|
||||||
|
currentChannelContainer.Clear(false);
|
||||||
|
currentChannelContainer.Add(loaded);
|
||||||
|
loading.Hide();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,14 +278,21 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
case NotifyCollectionChangedAction.Add:
|
case NotifyCollectionChangedAction.Add:
|
||||||
IEnumerable<Channel> joinedChannels = filterChannels(args.NewItems);
|
IEnumerable<Channel> joinedChannels = filterChannels(args.NewItems);
|
||||||
|
|
||||||
foreach (var channel in joinedChannels)
|
foreach (var channel in joinedChannels)
|
||||||
channelList.AddChannel(channel);
|
channelList.AddChannel(channel);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Remove:
|
case NotifyCollectionChangedAction.Remove:
|
||||||
IEnumerable<Channel> leftChannels = filterChannels(args.OldItems);
|
IEnumerable<Channel> leftChannels = filterChannels(args.OldItems);
|
||||||
|
|
||||||
foreach (var channel in leftChannels)
|
foreach (var channel in leftChannels)
|
||||||
|
{
|
||||||
channelList.RemoveChannel(channel);
|
channelList.RemoveChannel(channel);
|
||||||
|
loadedChannels.Remove(channel);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user