Add next tab selection logic in game, make IsRemovable public.

- Don't clear DrawableChannel when unjoined
This commit is contained in:
naoey 2017-08-05 10:22:06 +05:30
parent 3b6ffadcc7
commit 8dbbc623c7
2 changed files with 18 additions and 10 deletions

View File

@ -53,7 +53,7 @@ namespace osu.Game.Overlays.Chat
protected override TabItem<Channel> CreateTabItem(Channel value)
{
ChannelTabItem tab = new ChannelTabItem(value);
tab.OnRequestClose = () => OnRequestLeave?.Invoke(value);
tab.OnRequestClose = () => onTabClose(tab);
return tab;
}
@ -71,13 +71,28 @@ namespace osu.Game.Overlays.Chat
base.SelectTab(tab);
}
private void onTabClose(TabItem<Channel> tab)
{
int totalTabs = TabContainer.Children.Count - 1; // account for selectorTab
int currentIndex = MathHelper.Clamp(TabContainer.IndexOf(tab), 1, totalTabs);
if (tab == SelectedTab && totalTabs > 1)
// Select the tab after tab-to-be-removed's index, or the tab before if current == last
SelectTab(TabContainer.Children[currentIndex == totalTabs ? currentIndex - 1 : currentIndex + 1]);
else if (totalTabs == 1 && !selectorTab.Active)
// Open channel selection overlay if all channel tabs will be closed after removing this tab
SelectTab(selectorTab);
OnRequestLeave?.Invoke(tab.Value);
}
private class ChannelTabItem : TabItem<Channel>
{
private Color4 backgroundInactive;
private Color4 backgroundHover;
private Color4 backgroundActive;
protected override bool IsRemovable => !Pinned;
public override bool IsRemovable => !Pinned;
private readonly SpriteText text;
private readonly SpriteText textBold;
@ -246,7 +261,7 @@ namespace osu.Game.Overlays.Chat
public class ChannelSelectorTabItem : ChannelTabItem
{
protected override bool IsRemovable => false;
public override bool IsRemovable => false;
public ChannelSelectorTabItem(Channel value) : base(value)
{

View File

@ -46,7 +46,6 @@ namespace osu.Game.Overlays.Chat
};
channel.NewMessagesArrived += newMessagesArrived;
channel.Joined.ValueChanged += channelJoinStatusChanged;
}
[BackgroundDependencyLoader]
@ -65,7 +64,6 @@ namespace osu.Game.Overlays.Chat
{
base.Dispose(isDisposing);
Channel.NewMessagesArrived -= newMessagesArrived;
Channel.Joined.ValueChanged -= channelJoinStatusChanged;
}
private void newMessagesArrived(IEnumerable<Message> newMessages)
@ -92,11 +90,6 @@ namespace osu.Game.Overlays.Chat
}
}
private void channelJoinStatusChanged(bool joined)
{
if (!joined) flow.Clear();
}
private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd());
}
}