mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +08:00
Merge branch 'master' into fix-mania-input
This commit is contained in:
commit
13c3ef65a8
@ -1 +1 @@
|
|||||||
Subproject commit 3edf65857759f32d5a6d07ed523a2892b09c3c6a
|
Subproject commit 14a33d110e2ed32e3a875bc2acd2bade244ba045
|
@ -16,15 +16,16 @@ using osu.Game.Online.Chat;
|
|||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Chat
|
namespace osu.Game.Overlays.Chat
|
||||||
{
|
{
|
||||||
public class ChatTabControl : OsuTabControl<Channel>
|
public class ChatTabControl : OsuTabControl<Channel>
|
||||||
{
|
{
|
||||||
protected override TabItem<Channel> CreateTabItem(Channel value) => new ChannelTabItem(value);
|
|
||||||
|
|
||||||
private const float shear_width = 10;
|
private const float shear_width = 10;
|
||||||
|
|
||||||
|
public Action<Channel> OnRequestLeave;
|
||||||
|
|
||||||
public readonly Bindable<bool> ChannelSelectorActive = new Bindable<bool>();
|
public readonly Bindable<bool> ChannelSelectorActive = new Bindable<bool>();
|
||||||
|
|
||||||
private readonly ChannelTabItem.ChannelSelectorTabItem selectorTab;
|
private readonly ChannelTabItem.ChannelSelectorTabItem selectorTab;
|
||||||
@ -49,6 +50,20 @@ namespace osu.Game.Overlays.Chat
|
|||||||
ChannelSelectorActive.BindTo(selectorTab.Active);
|
ChannelSelectorActive.BindTo(selectorTab.Active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void AddTabItem(TabItem<Channel> item, bool addToDropdown = true)
|
||||||
|
{
|
||||||
|
if (selectorTab.Depth < float.MaxValue)
|
||||||
|
// performTabSort might've made selectorTab's position wonky, fix it
|
||||||
|
TabContainer.ChangeChildDepth(selectorTab, float.MaxValue);
|
||||||
|
|
||||||
|
base.AddTabItem(item, addToDropdown);
|
||||||
|
|
||||||
|
if (SelectedTab == null)
|
||||||
|
SelectTab(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override TabItem<Channel> CreateTabItem(Channel value) => new ChannelTabItem(value) { OnRequestClose = tabCloseRequested };
|
||||||
|
|
||||||
protected override void SelectTab(TabItem<Channel> tab)
|
protected override void SelectTab(TabItem<Channel> tab)
|
||||||
{
|
{
|
||||||
if (tab is ChannelTabItem.ChannelSelectorTabItem)
|
if (tab is ChannelTabItem.ChannelSelectorTabItem)
|
||||||
@ -62,18 +77,38 @@ namespace osu.Game.Overlays.Chat
|
|||||||
base.SelectTab(tab);
|
base.SelectTab(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void tabCloseRequested(TabItem<Channel> tab)
|
||||||
|
{
|
||||||
|
int totalTabs = TabContainer.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[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 class ChannelTabItem : TabItem<Channel>
|
||||||
{
|
{
|
||||||
private Color4 backgroundInactive;
|
private Color4 backgroundInactive;
|
||||||
private Color4 backgroundHover;
|
private Color4 backgroundHover;
|
||||||
private Color4 backgroundActive;
|
private Color4 backgroundActive;
|
||||||
|
|
||||||
|
public override bool IsRemovable => !Pinned;
|
||||||
|
|
||||||
private readonly SpriteText text;
|
private readonly SpriteText text;
|
||||||
private readonly SpriteText textBold;
|
private readonly SpriteText textBold;
|
||||||
|
private readonly ClickableContainer closeButton;
|
||||||
private readonly Box box;
|
private readonly Box box;
|
||||||
private readonly Box highlightBox;
|
private readonly Box highlightBox;
|
||||||
private readonly SpriteIcon icon;
|
private readonly SpriteIcon icon;
|
||||||
|
|
||||||
|
public Action<ChannelTabItem> OnRequestClose;
|
||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
{
|
{
|
||||||
if (Active)
|
if (Active)
|
||||||
@ -108,6 +143,9 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
protected override bool OnHover(InputState state)
|
protected override bool OnHover(InputState state)
|
||||||
{
|
{
|
||||||
|
if (IsRemovable)
|
||||||
|
closeButton.FadeIn(200, Easing.OutQuint);
|
||||||
|
|
||||||
if (!Active)
|
if (!Active)
|
||||||
box.FadeColour(backgroundHover, transition_length, Easing.OutQuint);
|
box.FadeColour(backgroundHover, transition_length, Easing.OutQuint);
|
||||||
return true;
|
return true;
|
||||||
@ -115,6 +153,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
|
|
||||||
protected override void OnHoverLost(InputState state)
|
protected override void OnHoverLost(InputState state)
|
||||||
{
|
{
|
||||||
|
closeButton.FadeOut(200, Easing.OutQuint);
|
||||||
updateState();
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,13 +243,69 @@ namespace osu.Game.Overlays.Chat
|
|||||||
Font = @"Exo2.0-Bold",
|
Font = @"Exo2.0-Bold",
|
||||||
TextSize = 18,
|
TextSize = 18,
|
||||||
},
|
},
|
||||||
}
|
closeButton = new CloseButton
|
||||||
}
|
{
|
||||||
|
Alpha = 0,
|
||||||
|
Margin = new MarginPadding { Right = 20 },
|
||||||
|
Origin = Anchor.CentreRight,
|
||||||
|
Anchor = Anchor.CentreRight,
|
||||||
|
Action = delegate
|
||||||
|
{
|
||||||
|
if (IsRemovable) OnRequestClose?.Invoke(this);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CloseButton : ClickableContainer
|
||||||
|
{
|
||||||
|
private readonly SpriteIcon icon;
|
||||||
|
|
||||||
|
public CloseButton()
|
||||||
|
{
|
||||||
|
Size = new Vector2(20);
|
||||||
|
|
||||||
|
Child = icon = new SpriteIcon
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Scale = new Vector2(0.75f),
|
||||||
|
Icon = FontAwesome.fa_close,
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
||||||
|
{
|
||||||
|
icon.ScaleTo(0.5f, 1000, Easing.OutQuint);
|
||||||
|
return base.OnMouseDown(state, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
|
||||||
|
{
|
||||||
|
icon.ScaleTo(0.75f, 1000, Easing.OutElastic);
|
||||||
|
return base.OnMouseUp(state, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnHover(InputState state)
|
||||||
|
{
|
||||||
|
icon.FadeColour(Color4.Red, 200, Easing.OutQuint);
|
||||||
|
return base.OnHover(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(InputState state)
|
||||||
|
{
|
||||||
|
icon.FadeColour(Color4.White, 200, Easing.OutQuint);
|
||||||
|
base.OnHoverLost(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class ChannelSelectorTabItem : ChannelTabItem
|
public class ChannelSelectorTabItem : ChannelTabItem
|
||||||
{
|
{
|
||||||
|
public override bool IsRemovable => false;
|
||||||
|
|
||||||
public ChannelSelectorTabItem(Channel value) : base(value)
|
public ChannelSelectorTabItem(Channel value) : base(value)
|
||||||
{
|
{
|
||||||
Depth = float.MaxValue;
|
Depth = float.MaxValue;
|
||||||
|
@ -160,6 +160,7 @@ namespace osu.Game.Overlays
|
|||||||
channelTabs = new ChatTabControl
|
channelTabs = new ChatTabControl
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
OnRequestLeave = removeChannel,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -305,6 +306,7 @@ namespace osu.Game.Overlays
|
|||||||
addChannel(channels.Find(c => c.Name == @"#lobby"));
|
addChannel(channels.Find(c => c.Name == @"#lobby"));
|
||||||
|
|
||||||
channelSelection.OnRequestJoin = addChannel;
|
channelSelection.OnRequestJoin = addChannel;
|
||||||
|
channelSelection.OnRequestLeave = removeChannel;
|
||||||
channelSelection.Sections = new[]
|
channelSelection.Sections = new[]
|
||||||
{
|
{
|
||||||
new ChannelSection
|
new ChannelSection
|
||||||
@ -332,7 +334,15 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (currentChannel == value || value == null) return;
|
if (currentChannel == value) return;
|
||||||
|
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
currentChannel = null;
|
||||||
|
textbox.Current.Disabled = true;
|
||||||
|
currentChannelContainer.Clear(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
currentChannel = value;
|
currentChannel = value;
|
||||||
|
|
||||||
@ -391,6 +401,19 @@ namespace osu.Game.Overlays
|
|||||||
channel.Joined.Value = true;
|
channel.Joined.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeChannel(Channel channel)
|
||||||
|
{
|
||||||
|
if (channel == null) return;
|
||||||
|
|
||||||
|
if (channel == CurrentChannel) CurrentChannel = null;
|
||||||
|
|
||||||
|
careChannels.Remove(channel);
|
||||||
|
loadedChannels.Remove(loadedChannels.Find(c => c.Channel == channel));
|
||||||
|
channelTabs.RemoveItem(channel);
|
||||||
|
|
||||||
|
channel.Joined.Value = false;
|
||||||
|
}
|
||||||
|
|
||||||
private void fetchInitialMessages(Channel channel)
|
private void fetchInitialMessages(Channel channel)
|
||||||
{
|
{
|
||||||
var req = new GetMessagesRequest(new List<Channel> { channel }, null);
|
var req = new GetMessagesRequest(new List<Channel> { channel }, null);
|
||||||
|
Loading…
Reference in New Issue
Block a user