mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 06:52:56 +08:00
Only use one tabControl (channeltabcontrol). Fix that the Channel messages did not refresh.
This commit is contained in:
parent
142e1b8587
commit
29e8c70ed7
@ -21,8 +21,7 @@ namespace osu.Game.Tests.Visual
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(ChatTabControl),
|
||||
typeof(ChannelTabControl),
|
||||
typeof(UserTabControl)
|
||||
typeof(ChannelTabControl)
|
||||
};
|
||||
|
||||
private readonly ChatTabControl chatTabControl;
|
||||
|
@ -47,8 +47,7 @@ namespace osu.Game.Online.Chat
|
||||
/// </summary>
|
||||
public ObservableCollection<Channel> AvailableChannels { get; } = new ObservableCollection<Channel>();
|
||||
|
||||
private APIAccess api;
|
||||
private readonly Scheduler scheduler;
|
||||
private IAPIProvider api;
|
||||
private ScheduledDelegate fetchMessagesScheduleder;
|
||||
private GetMessagesRequest fetchMsgReq;
|
||||
private GetPrivateMessagesRequest fetchPrivateMsgReq;
|
||||
@ -282,7 +281,7 @@ namespace osu.Game.Online.Chat
|
||||
case APIState.Online:
|
||||
if (JoinedChannels.Count == 0)
|
||||
initializeDefaultChannels();
|
||||
fetchMessagesScheduleder = scheduler.AddDelayed(fetchNewMessages, 1000, true);
|
||||
fetchMessagesScheduleder = Scheduler.AddDelayed(fetchNewMessages, 1000, true);
|
||||
break;
|
||||
default:
|
||||
fetchMsgReq?.Cancel();
|
||||
@ -295,7 +294,7 @@ namespace osu.Game.Online.Chat
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IAPIProvider api)
|
||||
{
|
||||
this.api = this.api;
|
||||
this.api = api;
|
||||
api.Register(this);
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,9 @@ namespace osu.Game
|
||||
dependencies.Cache(api);
|
||||
dependencies.CacheAs<IAPIProvider>(api);
|
||||
|
||||
dependencies.Cache(new ChannelManager());
|
||||
var channelManager = new ChannelManager();
|
||||
dependencies.Inject(channelManager);
|
||||
dependencies.Cache(channelManager);
|
||||
|
||||
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory));
|
||||
dependencies.Cache(FileStore = new FileStore(contextFactory, Host.Storage));
|
||||
|
@ -60,7 +60,18 @@ namespace osu.Game.Overlays.Chat
|
||||
base.AddTabItem(item, addToDropdown);
|
||||
}
|
||||
|
||||
protected override TabItem<Channel> CreateTabItem(Channel value) => new ChannelTabItem(value) { OnRequestClose = tabCloseRequested };
|
||||
protected override TabItem<Channel> CreateTabItem(Channel value)
|
||||
{
|
||||
switch (value.Target)
|
||||
{
|
||||
case TargetType.Channel:
|
||||
return new ChannelTabItem(value) { OnRequestClose = tabCloseRequested };
|
||||
case TargetType.User:
|
||||
return new UserTabItem(value) { OnRequestClose = tabCloseRequested };
|
||||
default:
|
||||
throw new InvalidOperationException("Only TargetType User and Channel are supported.");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SelectTab(TabItem<Channel> tab)
|
||||
{
|
||||
|
@ -14,7 +14,6 @@ namespace osu.Game.Overlays.Chat
|
||||
public class ChatTabControl : Container, IHasCurrentValue<Channel>
|
||||
{
|
||||
public readonly ChannelTabControl ChannelTabControl;
|
||||
public readonly UserTabControl UserTabControl;
|
||||
|
||||
public Bindable<Channel> Current { get; } = new Bindable<Channel>();
|
||||
public Action<Channel> OnRequestLeave;
|
||||
@ -27,20 +26,11 @@ namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
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;
|
||||
@ -49,58 +39,25 @@ namespace osu.Game.Overlays.Chat
|
||||
if (channel != null)
|
||||
Current.Value = channel;
|
||||
};
|
||||
UserTabControl.Current.ValueChanged += channel =>
|
||||
{
|
||||
if (channel != null)
|
||||
Current.Value = channel;
|
||||
};
|
||||
}
|
||||
|
||||
private void currentTabChanged(Channel channel)
|
||||
{
|
||||
switch (channel.Target)
|
||||
{
|
||||
case TargetType.User:
|
||||
UserTabControl.Current.Value = channel;
|
||||
ChannelTabControl.Current.Value = null;
|
||||
break;
|
||||
case TargetType.Channel:
|
||||
ChannelTabControl.Current.Value = channel;
|
||||
UserTabControl.Current.Value = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddItem(Channel channel)
|
||||
{
|
||||
switch (channel.Target)
|
||||
{
|
||||
case TargetType.User:
|
||||
UserTabControl.AddItem(channel);
|
||||
break;
|
||||
case TargetType.Channel:
|
||||
ChannelTabControl.AddItem(channel);
|
||||
break;
|
||||
}
|
||||
if (Current.Value == null)
|
||||
Current.Value = channel;
|
||||
}
|
||||
|
||||
public void RemoveItem(Channel channel)
|
||||
{
|
||||
Channel nextSelectedChannel = null;
|
||||
|
||||
switch (channel.Target)
|
||||
{
|
||||
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;
|
||||
}
|
||||
Current.Value = ChannelTabControl.Items.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ namespace osu.Game.Overlays.Chat
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Scheduler.Add(() => newMessagesArrived(Chat.Messages));
|
||||
newMessagesArrived(Chat.Messages);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
|
@ -1,46 +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 osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Chat;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Overlays.Chat
|
||||
{
|
||||
public class UserTabControl : OsuTabControl<Channel>
|
||||
{
|
||||
protected override TabItem<Channel> CreateTabItem(Channel value)
|
||||
{
|
||||
if (value.Target != TargetType.User)
|
||||
throw new ArgumentException("Argument value needs to have the targettype user.");
|
||||
return new UserTabItem(value) { OnRequestClose = tabCloseRequested };
|
||||
}
|
||||
|
||||
public Action<Channel> OnRequestLeave;
|
||||
|
||||
public UserTabControl()
|
||||
{
|
||||
TabContainer.Spacing = new Vector2(-10, 0);
|
||||
TabContainer.Masking = false;
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Right = 10
|
||||
};
|
||||
}
|
||||
|
||||
private void tabCloseRequested(TabItem<Channel> priv)
|
||||
{
|
||||
int totalTabs = TabContainer.Count -1; // account for selectorTab
|
||||
int currentIndex = MathHelper.Clamp(TabContainer.IndexOf(priv), 1, totalTabs);
|
||||
|
||||
if (priv == SelectedTab && totalTabs > 1)
|
||||
// Select the tab after tab-to-be-removed's index, or the tab before if current == last
|
||||
SelectTab(TabContainer[currentIndex == totalTabs ? currentIndex - 1 : currentIndex + 1]);
|
||||
|
||||
OnRequestLeave?.Invoke(priv.Value);
|
||||
}
|
||||
}
|
||||
}
|
@ -39,8 +39,8 @@ namespace osu.Game.Overlays.Chat
|
||||
|
||||
AutoSizeAxes = Axes.X;
|
||||
Height = 50;
|
||||
Origin = Anchor.BottomRight;
|
||||
Anchor = Anchor.BottomRight;
|
||||
Origin = Anchor.BottomLeft;
|
||||
Anchor = Anchor.BottomLeft;
|
||||
EdgeEffect = activateEdgeEffect;
|
||||
Masking = true;
|
||||
Shear = shear;
|
||||
|
@ -345,6 +345,7 @@ namespace osu.Game.Overlays
|
||||
channelManager.CurrentChannel.ValueChanged += currentChatChanged;
|
||||
channelManager.JoinedChannels.CollectionChanged += joinedChannelsChanged;
|
||||
channelManager.AvailableChannels.CollectionChanged += availableChannelsChanged;
|
||||
Add(channelManager);
|
||||
}
|
||||
|
||||
private void postMessage(TextBox textbox, bool newText)
|
||||
|
Loading…
Reference in New Issue
Block a user