// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics.UserInterface; using osu.Game.Online.Chat; using OpenTK; namespace osu.Game.Overlays.Chat { public class UserChatTabControl : OsuTabControl { protected override TabItem CreateTabItem(UserChat value) => new UserChatTabItem(value) { OnRequestClose = tabCloseRequested }; public Action OnRequestLeave; public UserChatTabControl() { TabContainer.Spacing = new Vector2(-10, 0); TabContainer.Masking = false; } protected override void AddTabItem(TabItem item, bool addToDropdown = true) { base.AddTabItem(item, addToDropdown); if (SelectedTab == null) SelectTab(item); } private void tabCloseRequested(TabItem 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); } public void DeselectAll() { if (SelectedTab != null) SelectedTab.Active.Value = false; SelectedTab = null; } } }