2018-04-12 00:23:09 +08:00
|
|
|
|
using System;
|
2018-04-12 02:01:57 +08:00
|
|
|
|
using System.Linq;
|
2018-04-12 00:23:09 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online.Chat;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Chat
|
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
public class ChatTabControl : Container, IHasCurrentValue<Channel>
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
public readonly ChannelTabControl ChannelTabControl;
|
|
|
|
|
public readonly UserTabControl UserTabControl;
|
2018-04-12 00:23:09 +08:00
|
|
|
|
|
2018-04-12 02:01:57 +08:00
|
|
|
|
public Bindable<Channel> Current { get; } = new Bindable<Channel>();
|
|
|
|
|
public Action<Channel> OnRequestLeave;
|
2018-04-12 00:23:09 +08:00
|
|
|
|
|
|
|
|
|
public ChatTabControl()
|
|
|
|
|
{
|
|
|
|
|
Masking = false;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
ChannelTabControl = new ChannelTabControl
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
|
|
|
|
Width = 0.5f,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-04-12 02:01:57 +08:00
|
|
|
|
OnRequestLeave = channel => OnRequestLeave?.Invoke(channel)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
},
|
2018-04-12 02:01:57 +08:00
|
|
|
|
UserTabControl = new UserTabControl
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
|
|
|
|
Width = 0.5f,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2018-04-12 02:01:57 +08:00
|
|
|
|
OnRequestLeave = channel => OnRequestLeave?.Invoke(channel)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Current.ValueChanged += currentTabChanged;
|
2018-04-12 02:01:57 +08:00
|
|
|
|
ChannelTabControl.Current.ValueChanged += channel =>
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
if (channel != null)
|
|
|
|
|
Current.Value = channel;
|
2018-04-12 00:23:09 +08:00
|
|
|
|
};
|
2018-04-12 02:01:57 +08:00
|
|
|
|
UserTabControl.Current.ValueChanged += channel =>
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
if (channel != null)
|
|
|
|
|
Current.Value = channel;
|
2018-04-12 00:23:09 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-12 02:01:57 +08:00
|
|
|
|
private void currentTabChanged(Channel channel)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
switch (channel.Target)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
case TargetType.User:
|
|
|
|
|
UserTabControl.Current.Value = channel;
|
|
|
|
|
ChannelTabControl.Current.Value = null;
|
2018-04-12 00:23:09 +08:00
|
|
|
|
break;
|
2018-04-12 02:01:57 +08:00
|
|
|
|
case TargetType.Channel:
|
|
|
|
|
ChannelTabControl.Current.Value = channel;
|
|
|
|
|
UserTabControl.Current.Value = null;
|
2018-04-12 00:23:09 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-12 02:01:57 +08:00
|
|
|
|
public void AddItem(Channel channel)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
switch (channel.Target)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
case TargetType.User:
|
|
|
|
|
UserTabControl.AddItem(channel);
|
2018-04-12 00:23:09 +08:00
|
|
|
|
break;
|
2018-04-12 02:01:57 +08:00
|
|
|
|
case TargetType.Channel:
|
|
|
|
|
ChannelTabControl.AddItem(channel);
|
2018-04-12 00:23:09 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-04-12 02:27:33 +08:00
|
|
|
|
|
|
|
|
|
|
2018-04-12 00:23:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-12 02:01:57 +08:00
|
|
|
|
public void RemoveItem(Channel channel)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
Channel nextSelectedChannel = null;
|
|
|
|
|
|
|
|
|
|
switch (channel.Target)
|
2018-04-12 00:23:09 +08:00
|
|
|
|
{
|
2018-04-12 02:01:57 +08:00
|
|
|
|
case TargetType.User:
|
|
|
|
|
UserTabControl.RemoveItem(channel);
|
|
|
|
|
if (Current.Value == channel)
|
|
|
|
|
Current.Value = UserTabControl.Items.FirstOrDefault() ?? ChannelTabControl.Items.FirstOrDefault();
|
2018-04-12 00:23:09 +08:00
|
|
|
|
break;
|
2018-04-12 02:01:57 +08:00
|
|
|
|
case TargetType.Channel:
|
|
|
|
|
ChannelTabControl.RemoveItem(channel);
|
|
|
|
|
if (Current.Value == channel)
|
|
|
|
|
Current.Value = ChannelTabControl.Items.FirstOrDefault() ?? UserTabControl.Items.FirstOrDefault();
|
2018-04-12 00:23:09 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|