1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Merge branch 'fix_idle_tracker' of https://github.com/UselessToucan/osu into fix_idle_tracker

This commit is contained in:
Dean Herbert 2018-11-26 17:41:22 +09:00
commit 77090500e8
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.Sprites;
using osu.Game.Overlays;
using osu.Framework.Configuration;
namespace osu.Game.Tests.Visual
{
@ -54,8 +55,9 @@ namespace osu.Game.Tests.Visual
linkColour = colours.Blue;
var chatManager = new ChannelManager();
chatManager.AvailableChannels.Add(new Channel { Name = "#english"});
chatManager.AvailableChannels.Add(new Channel { Name = "#japanese" });
BindableCollection<Channel> availableChannels = (BindableCollection<Channel>)chatManager.AvailableChannels;
availableChannels.Add(new Channel { Name = "#english"});
availableChannels.Add(new Channel { Name = "#japanese" });
Dependencies.Cache(chatManager);
Dependencies.Cache(new ChatOverlay());

View File

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

View File

@ -2,7 +2,6 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using System.Collections.Specialized;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
@ -181,28 +180,6 @@ namespace osu.Game.Overlays
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)
{
if (channel == null)
@ -322,19 +299,35 @@ namespace osu.Game.Overlays
this.channelManager = channelManager;
channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
channelManager.JoinedChannels.ItemsAdded += onChannelAddedToJoinedChannels;
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.
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)
{
base.Dispose(isDisposing);
@ -342,8 +335,10 @@ namespace osu.Game.Overlays
if (channelManager != null)
{
channelManager.CurrentChannel.ValueChanged -= currentChannelChanged;
channelManager.JoinedChannels.CollectionChanged -= joinedChannelsChanged;
channelManager.AvailableChannels.CollectionChanged -= availableChannelsChanged;
channelManager.JoinedChannels.ItemsAdded -= onChannelAddedToJoinedChannels;
channelManager.JoinedChannels.ItemsRemoved -= onChannelRemovedFromJoinedChannels;
channelManager.AvailableChannels.ItemsAdded -= availableChannelsChanged;
channelManager.AvailableChannels.ItemsRemoved -= availableChannelsChanged;
}
}