mirror of
https://github.com/osukey/osukey.git
synced 2025-06-09 21:37:59 +09:00
small style fixes plus new assert in test
This commit is contained in:
parent
7454633f63
commit
ae79be7b51
@ -53,7 +53,10 @@ namespace osu.Game.Tests.Visual
|
|||||||
textContainer.Add(newLine);
|
textContainer.Add(newLine);
|
||||||
|
|
||||||
AddAssert($"msg #{textContainer.Count} has {linkAmount} link(s)", () => newLine.Message.Links.Count == linkAmount);
|
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)
|
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));
|
|| !sprite.HandleInput && sprite.TextColour.Equals((SRGBColour)Color4.White));
|
||||||
|
@ -23,7 +23,8 @@ namespace osu.Game.Graphics.Containers
|
|||||||
{
|
{
|
||||||
public override bool HandleInput => true;
|
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 =>
|
return AddText(text, link =>
|
||||||
{
|
{
|
||||||
|
((OsuSpriteLink)link).Url = url;
|
||||||
creationParameters?.Invoke(link);
|
creationParameters?.Invoke(link);
|
||||||
((T)link).Url = url;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +52,6 @@ namespace osu.Game.Graphics.Containers
|
|||||||
return base.AddText(text, sprite =>
|
return base.AddText(text, sprite =>
|
||||||
{
|
{
|
||||||
((OsuSpriteLink)sprite).TextColour = TextColour;
|
((OsuSpriteLink)sprite).TextColour = TextColour;
|
||||||
|
|
||||||
creationParameters?.Invoke(sprite);
|
creationParameters?.Invoke(sprite);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ namespace osu.Game.Graphics.Sprites
|
|||||||
|
|
||||||
protected override Container<Drawable> Content => content;
|
protected override Container<Drawable> Content => content;
|
||||||
|
|
||||||
private readonly Container content;
|
private readonly OsuHoverContainer content;
|
||||||
|
|
||||||
public OsuSpriteLink()
|
public OsuSpriteLink()
|
||||||
{
|
{
|
||||||
|
@ -85,7 +85,6 @@ namespace osu.Game.Overlays.Chat
|
|||||||
private OsuSpriteText username;
|
private OsuSpriteText username;
|
||||||
private OsuLinkFlowContainer<ChatLink> contentFlow;
|
private OsuLinkFlowContainer<ChatLink> contentFlow;
|
||||||
|
|
||||||
// this is only used for testing
|
|
||||||
public OsuTextFlowContainer ContentFlow => contentFlow;
|
public OsuTextFlowContainer ContentFlow => contentFlow;
|
||||||
|
|
||||||
public Message Message
|
public Message Message
|
||||||
@ -196,7 +195,7 @@ namespace osu.Game.Overlays.Chat
|
|||||||
contentFlow = new OsuLinkFlowContainer<ChatLink>(t =>
|
contentFlow = new OsuLinkFlowContainer<ChatLink>(t =>
|
||||||
{
|
{
|
||||||
if (Message.IsAction)
|
if (Message.IsAction)
|
||||||
t.Font = "Exo2.0-MediumItalic";
|
t.Font = @"Exo2.0-MediumItalic";
|
||||||
t.TextSize = text_size;
|
t.TextSize = text_size;
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
@ -230,18 +229,19 @@ namespace osu.Game.Overlays.Chat
|
|||||||
contentFlow.AddText(message.Content);
|
contentFlow.AddText(message.Content);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int prevIndex = 0;
|
int lastLinkEndIndex = 0;
|
||||||
List<MessageFormatter.Link> linksToRemove = new List<MessageFormatter.Link>();
|
List<MessageFormatter.Link> linksToRemove = new List<MessageFormatter.Link>();
|
||||||
|
|
||||||
foreach (var link in message.Links)
|
foreach (var link in message.Links)
|
||||||
{
|
{
|
||||||
contentFlow.AddText(message.Content.Substring(prevIndex, link.Index - prevIndex));
|
contentFlow.AddText(message.Content.Substring(lastLinkEndIndex, link.Index - lastLinkEndIndex));
|
||||||
prevIndex = link.Index + link.Length;
|
lastLinkEndIndex = link.Index + link.Length;
|
||||||
|
|
||||||
|
const string channelPrefix = "osu://chan/";
|
||||||
// If a channel doesn't exist, add it as normal text instead
|
// 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)
|
if (chat?.AvailableChannels.TrueForAll(c => c.Name != channelName) != false)
|
||||||
{
|
{
|
||||||
linksToRemove.Add(link);
|
linksToRemove.Add(link);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user