mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 22:26:41 +09:00
Fixed bugs and added tests
This commit is contained in:
@ -7,7 +7,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Graphics.Containers
|
||||
{
|
||||
@ -20,19 +20,36 @@ namespace osu.Game.Graphics.Containers
|
||||
|
||||
public override bool HandleInput => true;
|
||||
|
||||
private BeatmapSetOverlay beatmapSetOverlay;
|
||||
private ChatOverlay chat;
|
||||
private OsuGame game;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(BeatmapSetOverlay beatmapSetOverlay, ChatOverlay chat, OsuGame game)
|
||||
private void load(OsuGame game)
|
||||
{
|
||||
this.beatmapSetOverlay = beatmapSetOverlay;
|
||||
this.chat = chat;
|
||||
// this will be null in tests
|
||||
// will be null in tests
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public void AddLinks(string text, List<Link> links)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text) || links == null)
|
||||
return;
|
||||
|
||||
if (links.Count == 0)
|
||||
{
|
||||
AddText(text);
|
||||
return;
|
||||
}
|
||||
|
||||
int previousLinkEnd = 0;
|
||||
foreach (var link in links)
|
||||
{
|
||||
AddText(text.Substring(previousLinkEnd, link.Index - previousLinkEnd));
|
||||
|
||||
AddLink(text.Substring(link.Index, link.Length), link.Url, link.Action, link.Argument);
|
||||
previousLinkEnd = link.Index + link.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddLink(string text, string url, LinkAction linkType = LinkAction.External, string linkArgument = null, string tooltipText = null)
|
||||
{
|
||||
AddInternal(new DrawableLinkCompiler(AddText(text).ToList())
|
||||
@ -47,10 +64,10 @@ namespace osu.Game.Graphics.Containers
|
||||
break;
|
||||
case LinkAction.OpenBeatmapSet:
|
||||
if (int.TryParse(linkArgument, out int setId))
|
||||
beatmapSetOverlay.ShowBeatmapSet(setId);
|
||||
game?.ShowBeatmapSet(setId);
|
||||
break;
|
||||
case LinkAction.OpenChannel:
|
||||
chat.OpenChannel(chat.AvailableChannels.Find(c => c.Name == linkArgument));
|
||||
game?.OpenChannel(linkArgument);
|
||||
break;
|
||||
case LinkAction.OpenEditorTimestamp:
|
||||
game?.LoadEditorTimestamp();
|
||||
|
@ -41,6 +41,15 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The text that is displayed in chat.
|
||||
/// </summary>
|
||||
public string DisplayContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The links found in this message.
|
||||
/// </summary>
|
||||
/// <remarks>The links' positions are according to <see cref="DisplayContent"/></remarks>
|
||||
public List<Link> Links;
|
||||
|
||||
public Message(long? id)
|
||||
|
@ -66,7 +66,7 @@ namespace osu.Game.Online.Chat
|
||||
//since we just changed the line display text, offset any already processed links.
|
||||
result.Links.ForEach(l => l.Index -= l.Index > index ? m.Length - displayText.Length : 0);
|
||||
|
||||
var details = getLinkDetails(link);
|
||||
var details = getLinkDetails(linkText);
|
||||
result.Links.Add(new Link(linkText, index, displayText.Length, linkActionOverride ?? details.linkType, details.linkArgument));
|
||||
|
||||
//adjust the offset for processing the current matches group.
|
||||
@ -119,7 +119,7 @@ namespace osu.Game.Online.Chat
|
||||
case "s":
|
||||
case "beatmapsets":
|
||||
case "d":
|
||||
return (LinkAction.External, args[3]);
|
||||
return (LinkAction.OpenBeatmapSet, args[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
var result = format(inputMessage.Content);
|
||||
|
||||
inputMessage.Content = result.Text;
|
||||
inputMessage.DisplayContent = result.Text;
|
||||
|
||||
// Sometimes, regex matches are not in order
|
||||
result.Links.Sort();
|
||||
|
@ -119,7 +119,12 @@ namespace osu.Game
|
||||
|
||||
private ScheduledDelegate scoreLoad;
|
||||
|
||||
// TODO: Implement this properly as soon as the Editor is done
|
||||
#region chat link actions
|
||||
|
||||
internal void OpenChannel(string channelName) => chat.OpenChannel(chat.AvailableChannels.Find(c => c.Name == channelName));
|
||||
|
||||
internal void ShowBeatmapSet(int setId) => beatmapSetOverlay.ShowBeatmapSet(setId);
|
||||
|
||||
internal void LoadEditorTimestamp()
|
||||
{
|
||||
notifications.Post(new SimpleNotification
|
||||
@ -147,6 +152,8 @@ namespace osu.Game
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected void LoadScore(Score s)
|
||||
{
|
||||
scoreLoad?.Cancel();
|
||||
|
@ -225,42 +225,17 @@ namespace osu.Game.Overlays.Chat
|
||||
timestamp.Text = $@"{message.Timestamp.LocalDateTime:HH:mm:ss}";
|
||||
username.Text = $@"{message.Sender.Username}" + (senderHasBackground || message.IsAction ? "" : ":");
|
||||
|
||||
// remove any non-existent channels from the link list
|
||||
var linksToRemove = new List<Link>();
|
||||
foreach (var link in message.Links)
|
||||
if (link.Action == LinkAction.OpenChannel && chat?.AvailableChannels.TrueForAll(c => c.Name != link.Argument) != false)
|
||||
linksToRemove.Add(link);
|
||||
|
||||
foreach (var link in linksToRemove)
|
||||
message.Links.Remove(link);
|
||||
|
||||
contentFlow.Clear();
|
||||
|
||||
if (message.Links == null || message.Links.Count == 0)
|
||||
contentFlow.AddText(message.Content);
|
||||
else
|
||||
{
|
||||
int lastLinkEndIndex = 0;
|
||||
List<Link> linksToRemove = new List<Link>();
|
||||
|
||||
foreach (var link in message.Links)
|
||||
{
|
||||
contentFlow.AddText(message.Content.Substring(lastLinkEndIndex, link.Index - lastLinkEndIndex));
|
||||
lastLinkEndIndex = link.Index + link.Length;
|
||||
|
||||
const string channel_link_prefix = "osu://chan/";
|
||||
// If a channel doesn't exist, add it as normal text instead
|
||||
if (link.Url.StartsWith(channel_link_prefix))
|
||||
{
|
||||
var channelName = link.Url.Substring(channel_link_prefix.Length).Split('/')[0];
|
||||
if (chat?.AvailableChannels.TrueForAll(c => c.Name != channelName) != false)
|
||||
{
|
||||
linksToRemove.Add(link);
|
||||
contentFlow.AddText(message.Content.Substring(link.Index, link.Length));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
contentFlow.AddLink(message.Content.Substring(link.Index, link.Length), link.Url);
|
||||
}
|
||||
|
||||
var lastLink = message.Links[message.Links.Count - 1];
|
||||
contentFlow.AddText(message.Content.Substring(lastLink.Index + lastLink.Length));
|
||||
|
||||
foreach (var link in linksToRemove)
|
||||
message.Links.Remove(link);
|
||||
}
|
||||
contentFlow.AddLinks(message.DisplayContent, message.Links);
|
||||
}
|
||||
|
||||
private class MessageSender : OsuClickableContainer, IHasContextMenu
|
||||
|
Reference in New Issue
Block a user