From ae79be7b513ea30ce8eeb8385806b9e7b8a54ed2 Mon Sep 17 00:00:00 2001 From: FreezyLemon Date: Thu, 28 Dec 2017 21:45:58 +0100 Subject: [PATCH] small style fixes plus new assert in test --- osu.Game.Tests/Visual/TestCaseChatLink.cs | 5 ++++- .../Graphics/Containers/OsuLinkFlowContainer.cs | 6 +++--- osu.Game/Graphics/Sprites/OsuSpriteLink.cs | 2 +- osu.Game/Overlays/Chat/ChatLine.cs | 14 +++++++------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/osu.Game.Tests/Visual/TestCaseChatLink.cs b/osu.Game.Tests/Visual/TestCaseChatLink.cs index 31544c9364..1ad297d1f9 100644 --- a/osu.Game.Tests/Visual/TestCaseChatLink.cs +++ b/osu.Game.Tests/Visual/TestCaseChatLink.cs @@ -53,7 +53,10 @@ namespace osu.Game.Tests.Visual textContainer.Add(newLine); AddAssert($"msg #{textContainer.Count} has {linkAmount} link(s)", () => newLine.Message.Links.Count == linkAmount); - AddAssert($"msg #{textContainer.Count} shows link(s)", () => newLine.ContentFlow.Any() && isShowingLinks(newLine.ContentFlow)); + AddAssert($"msg #{textContainer.Count} is " + (isAction ? "italic" : "not italic"), () => newLine.ContentFlow.Any() && isAction == isItalic(newLine.ContentFlow)); + AddAssert($"msg #{textContainer.Count} shows link(s)", () => isShowingLinks(newLine.ContentFlow)); + + bool isItalic(OsuTextFlowContainer c) => c.Cast().All(sprite => sprite.Font == @"Exo2.0-MediumItalic"); bool isShowingLinks(OsuTextFlowContainer c) => c.Cast().All(sprite => sprite.HandleInput && !sprite.TextColour.Equals((SRGBColour)Color4.White) || !sprite.HandleInput && sprite.TextColour.Equals((SRGBColour)Color4.White)); diff --git a/osu.Game/Graphics/Containers/OsuLinkFlowContainer.cs b/osu.Game/Graphics/Containers/OsuLinkFlowContainer.cs index 5f318668a2..48910a04ca 100644 --- a/osu.Game/Graphics/Containers/OsuLinkFlowContainer.cs +++ b/osu.Game/Graphics/Containers/OsuLinkFlowContainer.cs @@ -23,7 +23,8 @@ namespace osu.Game.Graphics.Containers { public override bool HandleInput => true; - public OsuLinkFlowContainer(Action defaultCreationParameters = null) : base(defaultCreationParameters) + public OsuLinkFlowContainer(Action defaultCreationParameters = null) + : base(defaultCreationParameters) { } @@ -41,8 +42,8 @@ namespace osu.Game.Graphics.Containers return AddText(text, link => { + ((OsuSpriteLink)link).Url = url; creationParameters?.Invoke(link); - ((T)link).Url = url; }); } @@ -51,7 +52,6 @@ namespace osu.Game.Graphics.Containers return base.AddText(text, sprite => { ((OsuSpriteLink)sprite).TextColour = TextColour; - creationParameters?.Invoke(sprite); }); } diff --git a/osu.Game/Graphics/Sprites/OsuSpriteLink.cs b/osu.Game/Graphics/Sprites/OsuSpriteLink.cs index e42337dff3..1c2a219b53 100644 --- a/osu.Game/Graphics/Sprites/OsuSpriteLink.cs +++ b/osu.Game/Graphics/Sprites/OsuSpriteLink.cs @@ -16,7 +16,7 @@ namespace osu.Game.Graphics.Sprites protected override Container Content => content; - private readonly Container content; + private readonly OsuHoverContainer content; public OsuSpriteLink() { diff --git a/osu.Game/Overlays/Chat/ChatLine.cs b/osu.Game/Overlays/Chat/ChatLine.cs index add0bb1fd8..e877a35a75 100644 --- a/osu.Game/Overlays/Chat/ChatLine.cs +++ b/osu.Game/Overlays/Chat/ChatLine.cs @@ -85,7 +85,6 @@ namespace osu.Game.Overlays.Chat private OsuSpriteText username; private OsuLinkFlowContainer contentFlow; - // this is only used for testing public OsuTextFlowContainer ContentFlow => contentFlow; public Message Message @@ -196,7 +195,7 @@ namespace osu.Game.Overlays.Chat contentFlow = new OsuLinkFlowContainer(t => { if (Message.IsAction) - t.Font = "Exo2.0-MediumItalic"; + t.Font = @"Exo2.0-MediumItalic"; t.TextSize = text_size; }) { @@ -230,18 +229,19 @@ namespace osu.Game.Overlays.Chat contentFlow.AddText(message.Content); else { - int prevIndex = 0; + int lastLinkEndIndex = 0; List linksToRemove = new List(); foreach (var link in message.Links) { - contentFlow.AddText(message.Content.Substring(prevIndex, link.Index - prevIndex)); - prevIndex = link.Index + link.Length; + contentFlow.AddText(message.Content.Substring(lastLinkEndIndex, link.Index - lastLinkEndIndex)); + lastLinkEndIndex = link.Index + link.Length; + const string channelPrefix = "osu://chan/"; // If a channel doesn't exist, add it as normal text instead - if (link.Url.StartsWith("osu://chan/")) + if (link.Url.StartsWith(channelPrefix)) { - var channelName = link.Url.Substring(11).Split('/')[0]; + var channelName = link.Url.Substring(channelPrefix.Length).Split('/')[0]; if (chat?.AvailableChannels.TrueForAll(c => c.Name != channelName) != false) { linksToRemove.Add(link);