1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:35:35 +08:00

small style fixes plus new assert in test

This commit is contained in:
FreezyLemon 2017-12-28 21:45:58 +01:00
parent 7454633f63
commit ae79be7b51
4 changed files with 15 additions and 12 deletions

View File

@ -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<ChatLink>().All(sprite => sprite.Font == @"Exo2.0-MediumItalic");
bool isShowingLinks(OsuTextFlowContainer c) => c.Cast<ChatLink>().All(sprite => sprite.HandleInput && !sprite.TextColour.Equals((SRGBColour)Color4.White)
|| !sprite.HandleInput && sprite.TextColour.Equals((SRGBColour)Color4.White));

View File

@ -23,7 +23,8 @@ namespace osu.Game.Graphics.Containers
{
public override bool HandleInput => true;
public OsuLinkFlowContainer(Action<SpriteText> defaultCreationParameters = null) : base(defaultCreationParameters)
public OsuLinkFlowContainer(Action<SpriteText> 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);
});
}

View File

@ -16,7 +16,7 @@ namespace osu.Game.Graphics.Sprites
protected override Container<Drawable> Content => content;
private readonly Container content;
private readonly OsuHoverContainer content;
public OsuSpriteLink()
{

View File

@ -85,7 +85,6 @@ namespace osu.Game.Overlays.Chat
private OsuSpriteText username;
private OsuLinkFlowContainer<ChatLink> 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<ChatLink>(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<MessageFormatter.Link> linksToRemove = new List<MessageFormatter.Link>();
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);