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

Merge branch 'master' into multiplayer-room-settings

This commit is contained in:
Dan Balasescu 2018-11-26 16:46:27 +09:00 committed by GitHub
commit 38ef1d1f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 39 deletions

View File

@ -16,6 +16,7 @@ using NUnit.Framework;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Framework.Configuration;
namespace osu.Game.Tests.Visual namespace osu.Game.Tests.Visual
{ {
@ -54,8 +55,9 @@ namespace osu.Game.Tests.Visual
linkColour = colours.Blue; linkColour = colours.Blue;
var chatManager = new ChannelManager(); var chatManager = new ChannelManager();
chatManager.AvailableChannels.Add(new Channel { Name = "#english"}); BindableCollection<Channel> availableChannels = (BindableCollection<Channel>)chatManager.AvailableChannels;
chatManager.AvailableChannels.Add(new Channel { Name = "#japanese" }); availableChannels.Add(new Channel { Name = "#english"});
availableChannels.Add(new Channel { Name = "#japanese" });
Dependencies.Cache(chatManager); Dependencies.Cache(chatManager);
Dependencies.Cache(new ChatOverlay()); Dependencies.Cache(new ChatOverlay());

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
@ -31,6 +30,9 @@ namespace osu.Game.Online.Chat
@"#lobby" @"#lobby"
}; };
private readonly BindableCollection<Channel> availableChannels = new BindableCollection<Channel>();
private readonly BindableCollection<Channel> joinedChannels = new BindableCollection<Channel>();
/// <summary> /// <summary>
/// The currently opened channel /// The currently opened channel
/// </summary> /// </summary>
@ -39,12 +41,12 @@ namespace osu.Game.Online.Chat
/// <summary> /// <summary>
/// The Channels the player has joined /// The Channels the player has joined
/// </summary> /// </summary>
public ObservableCollection<Channel> JoinedChannels { get; } = new ObservableCollection<Channel>(); //todo: should be publicly readonly public IBindableCollection<Channel> JoinedChannels => joinedChannels;
/// <summary> /// <summary>
/// The channels available for the player to join /// The channels available for the player to join
/// </summary> /// </summary>
public ObservableCollection<Channel> AvailableChannels { get; } = new ObservableCollection<Channel>(); //todo: should be publicly readonly public IBindableCollection<Channel> AvailableChannels => availableChannels;
private IAPIProvider api; private IAPIProvider api;
private ScheduledDelegate fetchMessagesScheduleder; private ScheduledDelegate fetchMessagesScheduleder;
@ -293,8 +295,8 @@ namespace osu.Game.Online.Chat
found.Users.Remove(foundSelf); found.Users.Remove(foundSelf);
} }
if (joined == null && addToJoined) JoinedChannels.Add(found); if (joined == null && addToJoined) joinedChannels.Add(found);
if (available == null && addToAvailable) AvailableChannels.Add(found); if (available == null && addToAvailable) availableChannels.Add(found);
return found; return found;
} }
@ -346,9 +348,10 @@ namespace osu.Game.Online.Chat
{ {
if (channel == null) return; if (channel == null) return;
if (channel == CurrentChannel.Value) CurrentChannel.Value = null; if (channel == CurrentChannel.Value)
CurrentChannel.Value = null;
JoinedChannels.Remove(channel); joinedChannels.Remove(channel);
if (channel.Joined.Value) if (channel.Joined.Value)
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -181,28 +180,6 @@ namespace osu.Game.Overlays
channelSelection.OnRequestLeave = channel => channelManager.LeaveChannel(channel); channelSelection.OnRequestLeave = channel => channelManager.LeaveChannel(channel);
} }
private void joinedChannelsChanged(object sender, NotifyCollectionChangedEventArgs args)
{
switch (args.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (Channel newChannel in args.NewItems)
{
channelTabControl.AddChannel(newChannel);
}
break;
case NotifyCollectionChangedAction.Remove:
foreach (Channel removedChannel in args.OldItems)
{
channelTabControl.RemoveChannel(removedChannel);
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == removedChannel));
}
break;
}
}
private void currentChannelChanged(Channel channel) private void currentChannelChanged(Channel channel)
{ {
if (channel == null) if (channel == null)
@ -322,19 +299,35 @@ namespace osu.Game.Overlays
this.channelManager = channelManager; this.channelManager = channelManager;
channelManager.CurrentChannel.ValueChanged += currentChannelChanged; channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged; channelManager.JoinedChannels.ItemsAdded += onChannelAddedToJoinedChannels;
channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged; channelManager.JoinedChannels.ItemsRemoved += onChannelRemovedFromJoinedChannels;
channelManager.AvailableChannels.ItemsAdded += availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved += availableChannelsChanged;
//for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged. //for the case that channelmanager was faster at fetching the channels than our attachment to CollectionChanged.
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels); channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
joinedChannelsChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, channelManager.JoinedChannels)); foreach (Channel channel in channelManager.JoinedChannels)
channelTabControl.AddChannel(channel);
} }
private void availableChannelsChanged(object sender, NotifyCollectionChangedEventArgs e) private void onChannelAddedToJoinedChannels(IEnumerable<Channel> channels)
{ {
channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels); foreach (Channel channel in channels)
channelTabControl.AddChannel(channel);
} }
private void onChannelRemovedFromJoinedChannels(IEnumerable<Channel> channels)
{
foreach (Channel channel in channels)
{
channelTabControl.RemoveChannel(channel);
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == channel));
}
}
private void availableChannelsChanged(IEnumerable<Channel> channels)
=> channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);
@ -342,8 +335,10 @@ namespace osu.Game.Overlays
if (channelManager != null) if (channelManager != null)
{ {
channelManager.CurrentChannel.ValueChanged -= currentChannelChanged; channelManager.CurrentChannel.ValueChanged -= currentChannelChanged;
channelManager.JoinedChannels.CollectionChanged -= joinedChannelsChanged; channelManager.JoinedChannels.ItemsAdded -= onChannelAddedToJoinedChannels;
channelManager.AvailableChannels.CollectionChanged -= availableChannelsChanged; channelManager.JoinedChannels.ItemsRemoved -= onChannelRemovedFromJoinedChannels;
channelManager.AvailableChannels.ItemsAdded -= availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved -= availableChannelsChanged;
} }
} }