mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Remove chatTabControl and transfer the logic into ChannelTabControl.
This commit is contained in:
@ -14,24 +14,22 @@ using osu.Framework.MathUtils;
|
|||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
using osu.Game.Overlays.Chat;
|
|
||||||
using osu.Game.Overlays.Chat.Tabs;
|
using osu.Game.Overlays.Chat.Tabs;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
public class TestCaseChatTabControl : OsuTestCase
|
public class TestCaseChannelTabControl : OsuTestCase
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
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;
|
SpriteText currentText;
|
||||||
Add(new Container
|
Add(new Container
|
||||||
@ -41,7 +39,7 @@ namespace osu.Game.Tests.Visual
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
chatTabControl = new ChatTabControl
|
channelTabControl = new ChannelTabControl
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
@ -68,13 +66,13 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
currentText = new SpriteText
|
currentText = new SpriteText
|
||||||
{
|
{
|
||||||
Text = "Currently selected chat: "
|
Text = "Currently selected channel:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chatTabControl.OnRequestLeave += chat => chatTabControl.RemoveItem(chat);
|
channelTabControl.OnRequestLeave += channel => channelTabControl.RemoveChannel(channel);
|
||||||
chatTabControl.Current.ValueChanged += chat => currentText.Text = "Currently selected chat: " + chat.ToString();
|
channelTabControl.Current.ValueChanged += channel => currentText.Text = "Currently selected channel: " + channel.ToString();
|
||||||
|
|
||||||
AddStep("Add random user", addRandomUser);
|
AddStep("Add random user", addRandomUser);
|
||||||
AddRepeatStep("Add 3 random users", addRandomUser, 3);
|
AddRepeatStep("Add 3 random users", addRandomUser, 3);
|
||||||
@ -88,12 +86,12 @@ namespace osu.Game.Tests.Visual
|
|||||||
if (users == null || users.Count == 0)
|
if (users == null || users.Count == 0)
|
||||||
return;
|
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)
|
private void addChannel(string name)
|
||||||
{
|
{
|
||||||
chatTabControl.AddItem(new Channel
|
channelTabControl.AddChannel(new Channel
|
||||||
{
|
{
|
||||||
Name = name
|
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 OpenTK;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Chat.Tabs
|
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)
|
protected override void SelectTab(TabItem<Channel> tab)
|
||||||
{
|
{
|
||||||
if (tab is ChannelSelectorTabItem)
|
if (tab is ChannelSelectorTabItem)
|
||||||
|
@ -20,6 +20,7 @@ using osu.Game.Graphics.UserInterface;
|
|||||||
using osu.Game.Online.Chat;
|
using osu.Game.Online.Chat;
|
||||||
using osu.Game.Overlays.Chat;
|
using osu.Game.Overlays.Chat;
|
||||||
using osu.Game.Overlays.Chat.Selection;
|
using osu.Game.Overlays.Chat.Selection;
|
||||||
|
using osu.Game.Overlays.Chat.Tabs;
|
||||||
|
|
||||||
namespace osu.Game.Overlays
|
namespace osu.Game.Overlays
|
||||||
{
|
{
|
||||||
@ -43,7 +44,7 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
public const float TAB_AREA_HEIGHT = 50;
|
public const float TAB_AREA_HEIGHT = 50;
|
||||||
|
|
||||||
private readonly ChatTabControl chatTabControl;
|
private readonly ChannelTabControl channelTabControl;
|
||||||
|
|
||||||
private readonly Container chatContainer;
|
private readonly Container chatContainer;
|
||||||
private readonly Container tabsArea;
|
private readonly Container tabsArea;
|
||||||
@ -152,22 +153,24 @@ namespace osu.Game.Overlays
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = Color4.Black,
|
Colour = Color4.Black,
|
||||||
},
|
},
|
||||||
chatTabControl = new ChatTabControl
|
channelTabControl = new ChannelTabControl
|
||||||
{
|
{
|
||||||
|
Anchor = Anchor.BottomLeft,
|
||||||
|
Origin = Anchor.BottomLeft,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
OnRequestLeave = channel => channelManager.JoinedChannels.Remove(channel)
|
OnRequestLeave = channel => channelManager.JoinedChannels.Remove(channel)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
chatTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat;
|
channelTabControl.Current.ValueChanged += chat => channelManager.CurrentChannel.Value = chat;
|
||||||
chatTabControl.ChannelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden;
|
channelTabControl.ChannelSelectorActive.ValueChanged += value => channelSelection.State = value ? Visibility.Visible : Visibility.Hidden;
|
||||||
channelSelection.StateChanged += state =>
|
channelSelection.StateChanged += state =>
|
||||||
{
|
{
|
||||||
chatTabControl.ChannelTabControl.ChannelSelectorActive.Value = state == Visibility.Visible;
|
channelTabControl.ChannelSelectorActive.Value = state == Visibility.Visible;
|
||||||
|
|
||||||
if (state == Visibility.Visible)
|
if (state == Visibility.Visible)
|
||||||
{
|
{
|
||||||
@ -193,14 +196,16 @@ namespace osu.Game.Overlays
|
|||||||
case NotifyCollectionChangedAction.Add:
|
case NotifyCollectionChangedAction.Add:
|
||||||
foreach (Channel newChannel in args.NewItems)
|
foreach (Channel newChannel in args.NewItems)
|
||||||
{
|
{
|
||||||
chatTabControl.AddItem(newChannel);
|
channelTabControl.AddChannel(newChannel);
|
||||||
|
|
||||||
newChannel.Joined.Value = true;
|
newChannel.Joined.Value = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NotifyCollectionChangedAction.Remove:
|
case NotifyCollectionChangedAction.Remove:
|
||||||
foreach (Channel removedChannel in args.OldItems)
|
foreach (Channel removedChannel in args.OldItems)
|
||||||
{
|
{
|
||||||
chatTabControl.RemoveItem(removedChannel);
|
channelTabControl.RemoveChannel(removedChannel);
|
||||||
|
|
||||||
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == removedChannel ));
|
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == removedChannel ));
|
||||||
removedChannel.Joined.Value = false;
|
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)
|
if (channel == null)
|
||||||
{
|
{
|
||||||
textbox.Current.Disabled = true;
|
textbox.Current.Disabled = true;
|
||||||
currentChannelContainer.Clear(false);
|
currentChannelContainer.Clear(false);
|
||||||
chatTabControl.Current.Value = null;
|
channelTabControl.Current.Value = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
textbox.Current.Disabled = channel.ReadOnly;
|
textbox.Current.Disabled = channel.ReadOnly;
|
||||||
|
|
||||||
if (chatTabControl.Current.Value != channel)
|
if (channelTabControl.Current.Value != channel)
|
||||||
Scheduler.Add(() => chatTabControl.Current.Value = channel);
|
Scheduler.Add(() => channelTabControl.Current.Value = channel);
|
||||||
|
|
||||||
var loaded = loadedChannels.Find(d => d.Channel == channel);
|
var loaded = loadedChannels.Find(d => d.Channel == channel);
|
||||||
if (loaded == null)
|
if (loaded == null)
|
||||||
@ -329,7 +334,7 @@ namespace osu.Game.Overlays
|
|||||||
loading.Show();
|
loading.Show();
|
||||||
|
|
||||||
this.channelManager = channelManager;
|
this.channelManager = channelManager;
|
||||||
channelManager.CurrentChannel.ValueChanged += currentChatChanged;
|
channelManager.CurrentChannel.ValueChanged += currentChannelChanged;
|
||||||
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
|
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
|
||||||
channelManager.AvailableChannels.CollectionChanged += (sender, args) => channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
|
channelManager.AvailableChannels.CollectionChanged += (sender, args) => channelSelection.UpdateAvailableChannels(channelManager.AvailableChannels);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user