mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 12:32:56 +08:00
Remove chatTabControl and transfer the logic into ChannelTabControl.
This commit is contained in:
parent
7b653fab17
commit
95cb21299a
@ -14,24 +14,22 @@ using osu.Framework.MathUtils;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Overlays.Chat;
|
||||
using osu.Game.Overlays.Chat.Tabs;
|
||||
using osu.Game.Users;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual
|
||||
{
|
||||
public class TestCaseChatTabControl : OsuTestCase
|
||||
public class TestCaseChannelTabControl : OsuTestCase
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(ChatTabControl),
|
||||
typeof(ChannelTabControl)
|
||||
typeof(ChannelTabControl),
|
||||
};
|
||||
|
||||
private readonly ChatTabControl chatTabControl;
|
||||
private readonly ChannelTabControl channelTabControl;
|
||||
|
||||
public TestCaseChatTabControl()
|
||||
public TestCaseChannelTabControl()
|
||||
{
|
||||
SpriteText currentText;
|
||||
Add(new Container
|
||||
@ -41,7 +39,7 @@ namespace osu.Game.Tests.Visual
|
||||
Anchor = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
chatTabControl = new ChatTabControl
|
||||
channelTabControl = new ChannelTabControl
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Origin = Anchor.Centre,
|
||||
@ -68,13 +66,13 @@ namespace osu.Game.Tests.Visual
|
||||
{
|
||||
currentText = new SpriteText
|
||||
{
|
||||
Text = "Currently selected chat: "
|
||||
Text = "Currently selected channel:"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
chatTabControl.OnRequestLeave += chat => chatTabControl.RemoveItem(chat);
|
||||
chatTabControl.Current.ValueChanged += chat => currentText.Text = "Currently selected chat: " + chat.ToString();
|
||||
channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel);
|
||||
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString();
|
||||
|
||||
AddStep("Add random user", addRandomUser);
|
||||
AddRepeatStep("Add 3 random users", addRandomUser, 3);
|
||||
@ -88,12 +86,12 @@ namespace osu.Game.Tests.Visual
|
||||
if (users == null || users.Count == 0)
|
||||
return;
|
||||
|
||||
chatTabControl.AddItem(new PrivateChannel { User = users[RNG.Next(0, users.Count - 1)] });
|
||||
channelTabControl.AddChannel(new PrivateChannel { User = users[RNG.Next(0, users.Count - 1)] });
|
||||
}
|
||||
|
||||
private void addChannel(string name)
|
||||
{
|
||||
chatTabControl.AddItem(new Channel
|
||||
channelTabControl.AddChannel(new Channel
|
||||
{
|
||||
Name = name
|
||||
});
|
@ -1,76 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Overlays.Chat.Tabs;
|
||||
|
||||
namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
public class ChatTabControl : Container, IHasCurrentValue<Channel>
|
||||
{
|
||||
public readonly ChannelTabControl ChannelTabControl;
|
||||
|
||||
public Bindable<Channel> Current { get; } = new Bindable<Channel>();
|
||||
public Action<Channel> OnRequestLeave;
|
||||
|
||||
public ChatTabControl()
|
||||
{
|
||||
Masking = false;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
ChannelTabControl = new ChannelTabControl
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
OnRequestLeave = channel => OnRequestLeave?.Invoke(channel)
|
||||
},
|
||||
};
|
||||
|
||||
Current.ValueChanged += currentTabChanged;
|
||||
ChannelTabControl.Current.ValueChanged += channel =>
|
||||
{
|
||||
if (channel != null)
|
||||
Current.Value = channel;
|
||||
};
|
||||
}
|
||||
|
||||
private void currentTabChanged(Channel channel)
|
||||
{
|
||||
ChannelTabControl.Current.Value = channel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a channel to the ChatTabControl.
|
||||
/// The first channel added will automaticly selected.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel that is going to be added.</param>
|
||||
public void AddItem(Channel channel)
|
||||
{
|
||||
if (!ChannelTabControl.Items.Contains(channel))
|
||||
ChannelTabControl.AddItem(channel);
|
||||
|
||||
if (Current.Value == null)
|
||||
Current.Value = channel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a channel from the ChatTabControl.
|
||||
/// If the selected channel is the one that is beeing removed, the next available channel will be selected.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel that is going to be removed.</param>
|
||||
public void RemoveItem(Channel channel)
|
||||
{
|
||||
ChannelTabControl.RemoveItem(channel);
|
||||
if (Current.Value == channel)
|
||||
Current.Value = ChannelTabControl.Items.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ using osu.Game.Online.Chat;
|
||||
using OpenTK;
|
||||
using osu.Framework.Configuration;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Overlays.Chat.Tabs
|
||||
{
|
||||
@ -64,6 +65,33 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a channel to the ChannelTabControl.
|
||||
/// The first channel added will automaticly selected.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel that is going to be added.</param>
|
||||
public void AddChannel(Channel channel)
|
||||
{
|
||||
if (!Items.Contains(channel))
|
||||
AddItem(channel);
|
||||
|
||||
if (Current.Value == null)
|
||||
Current.Value = channel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a channel from the ChannelTabControl.
|
||||
/// If the selected channel is the one that is beeing removed, the next available channel will be selected.
|
||||
/// </summary>
|
||||
/// <param name="channel">The channel that is going to be removed.</param>
|
||||
public void RemoveChannel(Channel channel)
|
||||
{
|
||||
RemoveItem(channel);
|
||||
|
||||
if (Current.Value == channel)
|
||||
Current.Value = Items.FirstOrDefault();
|
||||
}
|
||||
|
||||
protected override void SelectTab(TabItem<Channel> tab)
|
||||
{
|
||||
if (tab is ChannelSelectorTabItem)
|
||||
|
@ -20,6 +20,7 @@ using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Overlays.Chat;
|
||||
using osu.Game.Overlays.Chat.Selection;
|
||||
using osu.Game.Overlays.Chat.Tabs;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
@ -43,7 +44,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
public const float TAB_AREA_HEIGHT = 50;
|
||||
|
||||
private readonly ChatTabControl chatTabControl;
|
||||
private readonly ChannelTabControl channelTabControl;
|
||||
|
||||
private readonly Container chatContainer;
|
||||
private readonly Container tabsArea;
|
||||
@ -152,22 +153,24 @@ namespace osu.Game.Overlays
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Color4.Black,
|
||||
},
|
||||
chatTabControl = new ChatTabControl
|
||||
channelTabControl = new ChannelTabControl
|
||||
{
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Origin = Anchor.BottomLeft,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
OnRequestLeave = channel => channelManager.JoinedChannels.Remove(channel)
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
chatTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat;
|
||||
chatTabControl.ChannelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden;
|
||||
channelTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat;
|
||||
channelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden;
|
||||
channelSelection.StateChanged += state =>
|
||||
{
|
||||
chatTabControl.ChannelTabControl.ChannelSelectorActive.Value = state == Visibility.Visible;
|
||||
channelTabControl.ChannelSelectorActive.Value = state == Visibility.Visible;
|
||||
|
||||
if (state == Visibility.Visible)
|
||||
{
|
||||
@ -193,14 +196,16 @@ namespace osu.Game.Overlays
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
foreach (Channel newChannel in args.NewItems)
|
||||
{
|
||||
chatTabControl.AddItem(newChannel);
|
||||
channelTabControl.AddChannel(newChannel);
|
||||
|
||||
newChannel.Joined.Value = true;
|
||||
}
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
foreach (Channel removedChannel in args.OldItems)
|
||||
{
|
||||
chatTabControl.RemoveItem(removedChannel);
|
||||
channelTabControl.RemoveChannel(removedChannel);
|
||||
|
||||
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == removedChannel ));
|
||||
removedChannel.Joined.Value = false;
|
||||
}
|
||||
@ -208,20 +213,20 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
}
|
||||
|
||||
private void currentChatChanged(Channel channel)
|
||||
private void currentChannelChanged(Channel channel)
|
||||
{
|
||||
if (channel == null)
|
||||
{
|
||||
textbox.Current.Disabled = true;
|
||||
currentChannelContainer.Clear(false);
|
||||
chatTabControl.Current.Value = null;
|
||||
channelTabControl.Current.Value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
textbox.Current.Disabled = channel.ReadOnly;
|
||||
|
||||
if (chatTabControl.Current.Value != channel)
|
||||
Scheduler.Add(() => chatTabControl.Current.Value = channel);
|
||||
if (channelTabControl.Current.Value != channel)
|
||||
Scheduler.Add(() => channelTabControl.Current.Value = channel);
|
||||
|
||||
var loaded = loadedChannels.Find(d => d.Channel == channel);
|
||||
if (loaded == null)
|
||||
@ -329,7 +334,7 @@ namespace osu.Game.Overlays
|
||||
loading.Show();
|
||||
|
||||
this.channelManager = channelManager;
|
||||
channelManager.CurrentChannel.ValueChanged += currentChatChanged;
|
||||
channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
|
||||
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
|
||||
channelManager.AvailableChannels.CollectionChanged += (sender, args) => channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user