1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 17:35:10 +08:00

Merge pull request #18290 from jai-x/new-chat-remove-selector-item

Use dummy channel to show selector and remove `ChannelListSelector`
This commit is contained in:
Dean Herbert 2022-05-23 15:49:00 +09:00 committed by GitHub
commit 7d93778355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 101 additions and 148 deletions

View File

@ -13,6 +13,7 @@ using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Chat.ChannelList; using osu.Game.Overlays.Chat.ChannelList;
using osu.Game.Overlays.Chat.Listing;
namespace osu.Game.Tests.Visual.Online namespace osu.Game.Tests.Visual.Online
{ {
@ -118,35 +119,37 @@ namespace osu.Game.Tests.Visual.Online
{ {
AddStep("Unread Selected", () => AddStep("Unread Selected", () =>
{ {
if (selected.Value != null) if (validItem)
channelList.GetItem(selected.Value).Unread.Value = true; channelList.GetItem(selected.Value).Unread.Value = true;
}); });
AddStep("Read Selected", () => AddStep("Read Selected", () =>
{ {
if (selected.Value != null) if (validItem)
channelList.GetItem(selected.Value).Unread.Value = false; channelList.GetItem(selected.Value).Unread.Value = false;
}); });
AddStep("Add Mention Selected", () => AddStep("Add Mention Selected", () =>
{ {
if (selected.Value != null) if (validItem)
channelList.GetItem(selected.Value).Mentions.Value++; channelList.GetItem(selected.Value).Mentions.Value++;
}); });
AddStep("Add 98 Mentions Selected", () => AddStep("Add 98 Mentions Selected", () =>
{ {
if (selected.Value != null) if (validItem)
channelList.GetItem(selected.Value).Mentions.Value += 98; channelList.GetItem(selected.Value).Mentions.Value += 98;
}); });
AddStep("Clear Mentions Selected", () => AddStep("Clear Mentions Selected", () =>
{ {
if (selected.Value != null) if (validItem)
channelList.GetItem(selected.Value).Mentions.Value = 0; channelList.GetItem(selected.Value).Mentions.Value = 0;
}); });
} }
private bool validItem => selected.Value != null && !(selected.Value is ChannelListing.ChannelListingChannel);
private Channel createRandomPublicChannel() private Channel createRandomPublicChannel()
{ {
int id = RNG.Next(0, 10000); int id = RNG.Next(0, 10000);

View File

@ -376,7 +376,7 @@ namespace osu.Game.Tests.Visual.Online
AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox); AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox);
AddStep("Click drawable channel", () => clickDrawable(currentDrawableChannel)); AddStep("Click drawable channel", () => clickDrawable(currentDrawableChannel));
AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox); AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox);
AddStep("Click selector", () => clickDrawable(chatOverlay.ChildrenOfType<ChannelListSelector>().Single())); AddStep("Click selector", () => clickDrawable(channelSelectorButton));
AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox); AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox);
AddStep("Click listing", () => clickDrawable(chatOverlay.ChildrenOfType<ChannelListing>().Single())); AddStep("Click listing", () => clickDrawable(chatOverlay.ChildrenOfType<ChannelListing>().Single()));
AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox); AddAssert("TextBox is focused", () => InputManager.FocusedDrawable == chatOverlayTextBox);
@ -397,6 +397,7 @@ namespace osu.Game.Tests.Visual.Online
chatOverlay.SlowLoading = true; chatOverlay.SlowLoading = true;
}); });
AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1)); AddStep("Join channel 1", () => channelManager.JoinChannel(testChannel1));
AddStep("Select channel 1", () => clickDrawable(getChannelListItem(testChannel1)));
AddAssert("Channel 1 loading", () => !channelIsVisible && chatOverlay.GetSlowLoadingChannel(testChannel1).LoadState == LoadState.Loading); AddAssert("Channel 1 loading", () => !channelIsVisible && chatOverlay.GetSlowLoadingChannel(testChannel1).LoadState == LoadState.Loading);
AddStep("Join channel 2", () => channelManager.JoinChannel(testChannel2)); AddStep("Join channel 2", () => channelManager.JoinChannel(testChannel2));
@ -437,6 +438,9 @@ namespace osu.Game.Tests.Visual.Online
private ChatOverlayTopBar chatOverlayTopBar => private ChatOverlayTopBar chatOverlayTopBar =>
chatOverlay.ChildrenOfType<ChatOverlayTopBar>().Single(); chatOverlay.ChildrenOfType<ChatOverlayTopBar>().Single();
private ChannelListItem channelSelectorButton =>
chatOverlay.ChildrenOfType<ChannelListItem>().Single(item => item.Channel is ChannelListing.ChannelListingChannel);
private void clickDrawable(Drawable d) private void clickDrawable(Drawable d)
{ {
InputManager.MoveMouseTo(d); InputManager.MoveMouseTo(d);

View File

@ -14,6 +14,7 @@ using osu.Game.Input;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Chat.Listing;
using osu.Game.Overlays.Chat.Tabs; using osu.Game.Overlays.Chat.Tabs;
namespace osu.Game.Online.Chat namespace osu.Game.Online.Chat
@ -133,7 +134,9 @@ namespace osu.Game.Online.Chat
private void currentChannelChanged(ValueChangedEvent<Channel> e) private void currentChannelChanged(ValueChangedEvent<Channel> e)
{ {
if (!(e.NewValue is ChannelSelectorTabItem.ChannelSelectorTabChannel)) bool isSelectorChannel = e.NewValue is ChannelSelectorTabItem.ChannelSelectorTabChannel || e.NewValue is ChannelListing.ChannelListingChannel;
if (!isSelectorChannel)
JoinChannel(e.NewValue); JoinChannel(e.NewValue);
} }
@ -420,11 +423,10 @@ namespace osu.Game.Online.Chat
/// Joins a channel if it has not already been joined. Must be called from the update thread. /// Joins a channel if it has not already been joined. Must be called from the update thread.
/// </summary> /// </summary>
/// <param name="channel">The channel to join.</param> /// <param name="channel">The channel to join.</param>
/// <param name="setCurrent">Set the channel to join as the current channel if the current channel is null.</param>
/// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns> /// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns>
public Channel JoinChannel(Channel channel, bool setCurrent = true) => joinChannel(channel, true, setCurrent); public Channel JoinChannel(Channel channel) => joinChannel(channel, true);
private Channel joinChannel(Channel channel, bool fetchInitialMessages = false, bool setCurrent = true) private Channel joinChannel(Channel channel, bool fetchInitialMessages = false)
{ {
if (channel == null) return null; if (channel == null) return null;
@ -440,7 +442,7 @@ namespace osu.Game.Online.Chat
case ChannelType.Multiplayer: case ChannelType.Multiplayer:
// join is implicit. happens when you join a multiplayer game. // join is implicit. happens when you join a multiplayer game.
// this will probably change in the future. // this will probably change in the future.
joinChannel(channel, fetchInitialMessages, setCurrent); joinChannel(channel, fetchInitialMessages);
return channel; return channel;
case ChannelType.PM: case ChannelType.PM:
@ -461,7 +463,7 @@ namespace osu.Game.Online.Chat
default: default:
var req = new JoinChannelRequest(channel); var req = new JoinChannelRequest(channel);
req.Success += () => joinChannel(channel, fetchInitialMessages, setCurrent); req.Success += () => joinChannel(channel, fetchInitialMessages);
req.Failure += ex => LeaveChannel(channel); req.Failure += ex => LeaveChannel(channel);
api.Queue(req); api.Queue(req);
return channel; return channel;
@ -473,8 +475,7 @@ namespace osu.Game.Online.Chat
this.fetchInitialMessages(channel); this.fetchInitialMessages(channel);
} }
if (setCurrent) CurrentChannel.Value ??= channel;
CurrentChannel.Value ??= channel;
return channel; return channel;
} }

View File

@ -13,18 +13,22 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat.Listing;
namespace osu.Game.Overlays.Chat.ChannelList namespace osu.Game.Overlays.Chat.ChannelList
{ {
public class ChannelList : Container public class ChannelList : Container
{ {
public Action<Channel?>? OnRequestSelect; public Action<Channel>? OnRequestSelect;
public Action<Channel>? OnRequestLeave; public Action<Channel>? OnRequestLeave;
public readonly ChannelListing.ChannelListingChannel ChannelListingChannel = new ChannelListing.ChannelListingChannel();
private readonly Dictionary<Channel, ChannelListItem> channelMap = new Dictionary<Channel, ChannelListItem>(); private readonly Dictionary<Channel, ChannelListItem> channelMap = new Dictionary<Channel, ChannelListItem>();
private ChannelListItemFlow publicChannelFlow = null!; private ChannelListItemFlow publicChannelFlow = null!;
private ChannelListItemFlow privateChannelFlow = null!; private ChannelListItemFlow privateChannelFlow = null!;
private ChannelListItem selector = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider) private void load(OverlayColourProvider colourProvider)
@ -50,16 +54,17 @@ namespace osu.Game.Overlays.Chat.ChannelList
Children = new Drawable[] Children = new Drawable[]
{ {
publicChannelFlow = new ChannelListItemFlow("CHANNELS"), publicChannelFlow = new ChannelListItemFlow("CHANNELS"),
new ChannelListSelector selector = new ChannelListItem(ChannelListingChannel)
{ {
Margin = new MarginPadding { Bottom = 10 }, Margin = new MarginPadding { Bottom = 10 },
Action = () => OnRequestSelect?.Invoke(null),
}, },
privateChannelFlow = new ChannelListItemFlow("DIRECT MESSAGES"), privateChannelFlow = new ChannelListItemFlow("DIRECT MESSAGES"),
}, },
}, },
}, },
}; };
selector.OnRequestSelect += chan => OnRequestSelect?.Invoke(chan);
} }
public void AddChannel(Channel channel) public void AddChannel(Channel channel)

View File

@ -15,6 +15,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays.Chat.Listing;
using osu.Game.Users.Drawables; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
@ -34,7 +35,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
private Box hoverBox = null!; private Box hoverBox = null!;
private Box selectBox = null!; private Box selectBox = null!;
private OsuSpriteText text = null!; private OsuSpriteText text = null!;
private ChannelListItemCloseButton close = null!; private ChannelListItemCloseButton? close;
[Resolved] [Resolved]
private Bindable<Channel> selectedChannel { get; set; } = null!; private Bindable<Channel> selectedChannel { get; set; } = null!;
@ -83,7 +84,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
}, },
Content = new[] Content = new[]
{ {
new[] new Drawable?[]
{ {
createIcon(), createIcon(),
text = new OsuSpriteText text = new OsuSpriteText
@ -97,20 +98,8 @@ namespace osu.Game.Overlays.Chat.ChannelList
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Truncate = true, Truncate = true,
}, },
new ChannelListItemMentionPill createMentionPill(),
{ close = createCloseButton(),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Mentions = { BindTarget = Mentions },
},
close = new ChannelListItemCloseButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Action = () => OnRequestLeave?.Invoke(Channel),
}
} }
}, },
}, },
@ -131,21 +120,23 @@ namespace osu.Game.Overlays.Chat.ChannelList
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)
{ {
hoverBox.FadeIn(300, Easing.OutQuint); hoverBox.FadeIn(300, Easing.OutQuint);
close.FadeIn(300, Easing.OutQuint); close?.FadeIn(300, Easing.OutQuint);
return base.OnHover(e); return base.OnHover(e);
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
hoverBox.FadeOut(200, Easing.OutQuint); hoverBox.FadeOut(200, Easing.OutQuint);
close.FadeOut(200, Easing.OutQuint); close?.FadeOut(200, Easing.OutQuint);
base.OnHoverLost(e); base.OnHoverLost(e);
} }
private Drawable createIcon() private UpdateableAvatar? createIcon()
{ {
if (Channel.Type != ChannelType.PM) if (Channel.Type != ChannelType.PM)
return Drawable.Empty(); return null;
return new UpdateableAvatar(Channel.Users.First(), isInteractive: false) return new UpdateableAvatar(Channel.Users.First(), isInteractive: false)
{ {
@ -158,6 +149,34 @@ namespace osu.Game.Overlays.Chat.ChannelList
}; };
} }
private ChannelListItemMentionPill? createMentionPill()
{
if (isSelector)
return null;
return new ChannelListItemMentionPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Mentions = { BindTarget = Mentions },
};
}
private ChannelListItemCloseButton? createCloseButton()
{
if (isSelector)
return null;
return new ChannelListItemCloseButton
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 3 },
Action = () => OnRequestLeave?.Invoke(Channel),
};
}
private void updateState() private void updateState()
{ {
bool selected = selectedChannel.Value == Channel; bool selected = selectedChannel.Value == Channel;
@ -172,5 +191,7 @@ namespace osu.Game.Overlays.Chat.ChannelList
else else
text.FadeColour(colourProvider.Light3, 200, Easing.OutQuint); text.FadeColour(colourProvider.Light3, 200, Easing.OutQuint);
} }
private bool isSelector => Channel is ChannelListing.ChannelListingChannel;
} }
} }

View File

@ -1,103 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.Chat.ChannelList
{
public class ChannelListSelector : OsuClickableContainer
{
private Box hoverBox = null!;
private Box selectBox = null!;
private OsuSpriteText text = null!;
[Resolved]
private Bindable<Channel> currentChannel { get; set; } = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Height = 30;
RelativeSizeAxes = Axes.X;
Children = new Drawable[]
{
hoverBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background3,
Alpha = 0f,
},
selectBox = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background4,
Alpha = 0f,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Left = 18, Right = 10 },
Child = text = new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Add more channels",
Font = OsuFont.Torus.With(size: 17, weight: FontWeight.SemiBold),
Colour = colourProvider.Light3,
Margin = new MarginPadding { Bottom = 2 },
RelativeSizeAxes = Axes.X,
Truncate = true,
},
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
currentChannel.BindValueChanged(channel =>
{
// This logic should be handled by the chat overlay rather than this component.
// Selected state should be moved to an abstract class and shared with ChannelListItem.
if (channel.NewValue == null)
{
text.FadeColour(colourProvider.Content1, 300, Easing.OutQuint);
selectBox.FadeIn(300, Easing.OutQuint);
}
else
{
text.FadeColour(colourProvider.Light3, 200, Easing.OutQuint);
selectBox.FadeOut(200, Easing.OutQuint);
}
}, true);
}
protected override bool OnHover(HoverEvent e)
{
hoverBox.FadeIn(300, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
hoverBox.FadeOut(200, Easing.OutQuint);
base.OnHoverLost(e);
}
}
}

View File

@ -75,5 +75,14 @@ namespace osu.Game.Overlays.Chat.Listing
protected override void PopIn() => this.FadeIn(); protected override void PopIn() => this.FadeIn();
protected override void PopOut() => this.FadeOut(); protected override void PopOut() => this.FadeOut();
public class ChannelListingChannel : Channel
{
public ChannelListingChannel()
{
Name = "Add more channels";
Type = ChannelType.System;
}
}
} }
} }

View File

@ -65,6 +65,9 @@ namespace osu.Game.Overlays
[Cached] [Cached]
private readonly Bindable<Channel> currentChannel = new Bindable<Channel>(); private readonly Bindable<Channel> currentChannel = new Bindable<Channel>();
private readonly IBindableList<Channel> availableChannels = new BindableList<Channel>();
private readonly IBindableList<Channel> joinedChannels = new BindableList<Channel>();
public ChatOverlayV2() public ChatOverlayV2()
{ {
Height = default_chat_height; Height = default_chat_height;
@ -150,14 +153,18 @@ namespace osu.Game.Overlays
chatHeight.BindValueChanged(height => { Height = height.NewValue; }, true); chatHeight.BindValueChanged(height => { Height = height.NewValue; }, true);
currentChannel.BindTo(channelManager.CurrentChannel); currentChannel.BindTo(channelManager.CurrentChannel);
channelManager.CurrentChannel.BindValueChanged(currentChannelChanged, true); currentChannel.BindValueChanged(currentChannelChanged, true);
channelManager.JoinedChannels.BindCollectionChanged(joinedChannelsChanged, true);
channelManager.AvailableChannels.BindCollectionChanged(availableChannelsChanged, true); joinedChannels.BindTo(channelManager.JoinedChannels);
joinedChannels.BindCollectionChanged(joinedChannelsChanged, true);
availableChannels.BindTo(channelManager.AvailableChannels);
availableChannels.BindCollectionChanged(availableChannelsChanged, true);
channelList.OnRequestSelect += channel => channelManager.CurrentChannel.Value = channel; channelList.OnRequestSelect += channel => channelManager.CurrentChannel.Value = channel;
channelList.OnRequestLeave += channel => channelManager.LeaveChannel(channel); channelList.OnRequestLeave += channel => channelManager.LeaveChannel(channel);
channelListing.OnRequestJoin += channel => channelManager.JoinChannel(channel, false); channelListing.OnRequestJoin += channel => channelManager.JoinChannel(channel);
channelListing.OnRequestLeave += channel => channelManager.LeaveChannel(channel); channelListing.OnRequestLeave += channel => channelManager.LeaveChannel(channel);
textBar.OnSearchTermsChanged += searchTerms => channelListing.SearchTerm = searchTerms; textBar.OnSearchTermsChanged += searchTerms => channelListing.SearchTerm = searchTerms;
@ -176,7 +183,7 @@ namespace osu.Game.Overlays
if (currentChannel.Value?.Id != channel.Id) if (currentChannel.Value?.Id != channel.Id)
{ {
if (!channel.Joined.Value) if (!channel.Joined.Value)
channel = channelManager.JoinChannel(channel, false); channel = channelManager.JoinChannel(channel);
channelManager.CurrentChannel.Value = channel; channelManager.CurrentChannel.Value = channel;
} }
@ -240,9 +247,15 @@ namespace osu.Game.Overlays
{ {
Channel? newChannel = channel.NewValue; Channel? newChannel = channel.NewValue;
// null channel denotes that we should be showing the listing.
if (newChannel == null) if (newChannel == null)
{ {
// null channel denotes that we should be showing the listing. currentChannel.Value = channelList.ChannelListingChannel;
return;
}
if (newChannel is ChannelListing.ChannelListingChannel)
{
currentChannelContainer.Clear(false); currentChannelContainer.Clear(false);
channelListing.Show(); channelListing.Show();
textBar.ShowSearch.Value = true; textBar.ShowSearch.Value = true;
@ -290,9 +303,9 @@ namespace osu.Game.Overlays
switch (args.Action) switch (args.Action)
{ {
case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Add:
IEnumerable<Channel> joinedChannels = filterChannels(args.NewItems); IEnumerable<Channel> newChannels = filterChannels(args.NewItems);
foreach (var channel in joinedChannels) foreach (var channel in newChannels)
channelList.AddChannel(channel); channelList.AddChannel(channel);
break; break;