Display Announce type channels separately in new chat overlay

This commit is contained in:
Jai Sharma 2022-05-27 16:06:23 +01:00
parent aadcf25129
commit 320b6ca631
4 changed files with 66 additions and 11 deletions

View File

@ -87,7 +87,7 @@ namespace osu.Game.Tests.Visual.Online
{ {
leaveText.Text = $"OnRequestLeave: {channel.Name}"; leaveText.Text = $"OnRequestLeave: {channel.Name}";
leaveText.FadeOutFromOne(1000, Easing.InQuint); leaveText.FadeOutFromOne(1000, Easing.InQuint);
selected.Value = null; selected.Value = channelList.ChannelListingChannel;
channelList.RemoveChannel(channel); channelList.RemoveChannel(channel);
}; };
@ -112,6 +112,12 @@ namespace osu.Game.Tests.Visual.Online
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
channelList.AddChannel(createRandomPrivateChannel()); channelList.AddChannel(createRandomPrivateChannel());
}); });
AddStep("Add Announce Channels", () =>
{
for (int i = 0; i < 2; i++)
channelList.AddChannel(createRandomAnnounceChannel());
});
} }
[Test] [Test]
@ -170,5 +176,16 @@ namespace osu.Game.Tests.Visual.Online
Username = $"test user {id}", Username = $"test user {id}",
}); });
} }
private Channel createRandomAnnounceChannel()
{
int id = RNG.Next(0, 10000);
return new Channel
{
Name = $"Announce {id}",
Type = ChannelType.Announce,
Id = id,
};
}
} }
} }

View File

@ -452,6 +452,7 @@ namespace osu.Game.Tests.Visual.Online
[Test] [Test]
public void TestKeyboardNextChannel() public void TestKeyboardNextChannel()
{ {
Channel announceChannel = createAnnounceChannel();
Channel pmChannel1 = createPrivateChannel(); Channel pmChannel1 = createPrivateChannel();
Channel pmChannel2 = createPrivateChannel(); Channel pmChannel2 = createPrivateChannel();
@ -461,6 +462,7 @@ namespace osu.Game.Tests.Visual.Online
channelManager.JoinChannel(testChannel2); channelManager.JoinChannel(testChannel2);
channelManager.JoinChannel(pmChannel1); channelManager.JoinChannel(pmChannel1);
channelManager.JoinChannel(pmChannel2); channelManager.JoinChannel(pmChannel2);
channelManager.JoinChannel(announceChannel);
chatOverlay.Show(); chatOverlay.Show();
}); });
@ -475,6 +477,9 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Press document next keys", () => InputManager.Keys(PlatformAction.DocumentNext)); AddStep("Press document next keys", () => InputManager.Keys(PlatformAction.DocumentNext));
AddAssert("PM Channel 2 displayed", () => channelIsVisible && currentDrawableChannel.Channel == pmChannel2); AddAssert("PM Channel 2 displayed", () => channelIsVisible && currentDrawableChannel.Channel == pmChannel2);
AddStep("Press document next keys", () => InputManager.Keys(PlatformAction.DocumentNext));
AddAssert("Announce channel displayed", () => channelIsVisible && currentDrawableChannel.Channel == announceChannel);
AddStep("Press document next keys", () => InputManager.Keys(PlatformAction.DocumentNext)); AddStep("Press document next keys", () => InputManager.Keys(PlatformAction.DocumentNext));
AddAssert("Channel 1 displayed", () => channelIsVisible && currentDrawableChannel.Channel == testChannel1); AddAssert("Channel 1 displayed", () => channelIsVisible && currentDrawableChannel.Channel == testChannel1);
} }
@ -539,6 +544,17 @@ namespace osu.Game.Tests.Visual.Online
}); });
} }
private Channel createAnnounceChannel()
{
int id = RNG.Next(0, 10000);
return new Channel
{
Name = $"Announce {id}",
Type = ChannelType.Announce,
Id = id,
};
}
private class TestChatOverlayV2 : ChatOverlayV2 private class TestChatOverlayV2 : ChatOverlayV2
{ {
public bool SlowLoading { get; set; } public bool SlowLoading { get; set; }

View File

@ -26,13 +26,16 @@ namespace osu.Game.Overlays.Chat.ChannelList
public Action<Channel>? OnRequestSelect; public Action<Channel>? OnRequestSelect;
public Action<Channel>? OnRequestLeave; public Action<Channel>? OnRequestLeave;
public IEnumerable<Channel> Channels => publicChannelFlow.Channels.Concat(privateChannelFlow.Channels); public IEnumerable<Channel> Channels =>
announceChannelFlow.Channels.Concat(publicChannelFlow.Channels).Concat(privateChannelFlow.Channels);
public readonly ChannelListing.ChannelListingChannel ChannelListingChannel = new ChannelListing.ChannelListingChannel(); 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 OsuScrollContainer scroll = null!; private OsuScrollContainer scroll = null!;
private ChannelListLabel announceChannelLabel = null!;
private ChannelListItemFlow announceChannelFlow = null!;
private ChannelListItemFlow publicChannelFlow = null!; private ChannelListItemFlow publicChannelFlow = null!;
private ChannelListItemFlow privateChannelFlow = null!; private ChannelListItemFlow privateChannelFlow = null!;
private ChannelListItem selector = null!; private ChannelListItem selector = null!;
@ -49,7 +52,6 @@ namespace osu.Game.Overlays.Chat.ChannelList
}, },
scroll = new OsuScrollContainer scroll = new OsuScrollContainer
{ {
Padding = new MarginPadding { Vertical = 7 },
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarAnchor = Anchor.TopRight, ScrollbarAnchor = Anchor.TopRight,
ScrollDistance = 35f, ScrollDistance = 35f,
@ -60,12 +62,11 @@ namespace osu.Game.Overlays.Chat.ChannelList
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Children = new Drawable[] Children = new Drawable[]
{ {
announceChannelLabel = new ChannelListLabel(ChatStrings.ChannelsListTitleANNOUNCE.ToUpper()),
announceChannelFlow = new ChannelListItemFlow(),
new ChannelListLabel(ChatStrings.ChannelsListTitlePUBLIC.ToUpper()), new ChannelListLabel(ChatStrings.ChannelsListTitlePUBLIC.ToUpper()),
publicChannelFlow = new ChannelListItemFlow(), publicChannelFlow = new ChannelListItemFlow(),
selector = new ChannelListItem(ChannelListingChannel) selector = new ChannelListItem(ChannelListingChannel),
{
Margin = new MarginPadding { Bottom = 10 },
},
new ChannelListLabel(ChatStrings.ChannelsListTitlePM.ToUpper()), new ChannelListLabel(ChatStrings.ChannelsListTitlePM.ToUpper()),
privateChannelFlow = new ChannelListItemFlow(), privateChannelFlow = new ChannelListItemFlow(),
}, },
@ -88,6 +89,8 @@ namespace osu.Game.Overlays.Chat.ChannelList
ChannelListItemFlow flow = getFlowForChannel(channel); ChannelListItemFlow flow = getFlowForChannel(channel);
channelMap.Add(channel, item); channelMap.Add(channel, item);
flow.Add(item); flow.Add(item);
updateVisibility();
} }
public void RemoveChannel(Channel channel) public void RemoveChannel(Channel channel)
@ -100,6 +103,8 @@ namespace osu.Game.Overlays.Chat.ChannelList
channelMap.Remove(channel); channelMap.Remove(channel);
flow.Remove(item); flow.Remove(item);
updateVisibility();
} }
public ChannelListItem GetItem(Channel channel) public ChannelListItem GetItem(Channel channel)
@ -122,17 +127,34 @@ namespace osu.Game.Overlays.Chat.ChannelList
case ChannelType.PM: case ChannelType.PM:
return privateChannelFlow; return privateChannelFlow;
case ChannelType.Announce:
return announceChannelFlow;
default: default:
return publicChannelFlow; return publicChannelFlow;
} }
} }
private void updateVisibility()
{
if (announceChannelFlow.Channels.Count() == 0)
{
announceChannelLabel.Hide();
announceChannelFlow.Hide();
}
else
{
announceChannelLabel.Show();
announceChannelFlow.Show();
}
}
private class ChannelListLabel : OsuSpriteText private class ChannelListLabel : OsuSpriteText
{ {
public ChannelListLabel(LocalisableString label) public ChannelListLabel(LocalisableString label)
{ {
Text = label; Text = label;
Margin = new MarginPadding { Left = 18, Bottom = 5 }; Margin = new MarginPadding { Left = 18, Bottom = 5, Top = 8 };
Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold); Font = OsuFont.Torus.With(size: 12, weight: FontWeight.SemiBold);
} }
} }

View File

@ -141,8 +141,8 @@ namespace osu.Game.Overlays.Chat
switch (newChannel?.Type) switch (newChannel?.Type)
{ {
case ChannelType.Public: case null:
chattingText.Text = ChatStrings.TalkingIn(newChannel.Name); chattingText.Text = string.Empty;
break; break;
case ChannelType.PM: case ChannelType.PM:
@ -150,7 +150,7 @@ namespace osu.Game.Overlays.Chat
break; break;
default: default:
chattingText.Text = string.Empty; chattingText.Text = ChatStrings.TalkingIn(newChannel.Name);
break; break;
} }
}, true); }, true);