1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 02:32:56 +08:00
osu-lazer/osu.Game/Overlays/Chat/ChatTabControl.cs

107 lines
3.6 KiB
C#
Raw Normal View History

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