Preserve current channel if ChatOverlay is being loaded in

This commit is contained in:
Craftplacer
2020-01-18 15:27:55 +01:00
parent f55cf03bd0
commit bc6f71fe97
2 changed files with 11 additions and 4 deletions

View File

@ -59,15 +59,16 @@ namespace osu.Game.Overlays.Chat.Tabs
/// <summary>
/// Adds a channel to the ChannelTabControl.
/// The first channel added will automaticly selected.
/// The first channel added will automaticly selected if <paramref name="setChannel"/> is true.
/// </summary>
/// <param name="channel">The channel that is going to be added.</param>
public void AddChannel(Channel channel)
/// <param name="setChannel">If the current channel should be changed if none was selected before</param>
public void AddChannel(Channel channel, bool setChannel = true)
{
if (!Items.Contains(channel))
AddItem(channel);
if (Current.Value == null)
if (Current.Value == null && setChannel)
Current.Value = channel;
}

View File

@ -221,8 +221,14 @@ namespace osu.Game.Overlays
// TODO: consider scheduling bindable callbacks to not perform when overlay is not present.
channelManager.JoinedChannels.ItemsAdded += onChannelAddedToJoinedChannels;
channelManager.JoinedChannels.ItemsRemoved += onChannelRemovedFromJoinedChannels;
bool channelSelected = channelManager.CurrentChannel.Value != null;
foreach (Channel channel in channelManager.JoinedChannels)
ChannelTabControl.AddChannel(channel);
ChannelTabControl.AddChannel(channel, !channelSelected);
if (channelSelected)
ChannelTabControl.Current.Value = channelManager.CurrentChannel.Value;
channelManager.AvailableChannels.ItemsAdded += availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;