Merge branch 'master' into keyboard_shortcuts

This commit is contained in:
Dean Herbert
2021-05-27 16:30:34 +09:00
committed by GitHub
1595 changed files with 60121 additions and 14744 deletions

View File

@ -71,7 +71,7 @@ namespace osu.Game.Online.Chat
{
CurrentChannel.ValueChanged += currentChannelChanged;
HighPollRate.BindValueChanged(enabled => TimeBetweenPolls = enabled.NewValue ? 1000 : 6000, true);
HighPollRate.BindValueChanged(enabled => TimeBetweenPolls.Value = enabled.NewValue ? 1000 : 6000, true);
}
/// <summary>
@ -166,7 +166,7 @@ namespace osu.Game.Online.Chat
createNewPrivateMessageRequest.Failure += exception =>
{
Logger.Error(exception, "Posting message failed.");
handlePostException(exception);
target.ReplaceMessage(message, null);
dequeueAndRun();
};
@ -185,7 +185,7 @@ namespace osu.Game.Online.Chat
req.Failure += exception =>
{
Logger.Error(exception, "Posting message failed.");
handlePostException(exception);
target.ReplaceMessage(message, null);
dequeueAndRun();
};
@ -198,6 +198,14 @@ namespace osu.Game.Online.Chat
dequeueAndRun();
}
private static void handlePostException(Exception exception)
{
if (exception is APIException apiException)
Logger.Log(apiException.Message, level: LogLevel.Important);
else
Logger.Error(exception, "Posting message failed.");
}
/// <summary>
/// Posts a command locally. Commands like /help will result in a help message written in the current channel.
/// </summary>
@ -353,7 +361,7 @@ namespace osu.Game.Online.Chat
}
/// <summary>
/// Joins a channel if it has not already been joined.
/// Joins a channel if it has not already been joined. Must be called from the update thread.
/// </summary>
/// <param name="channel">The channel to join.</param>
/// <returns>The joined channel. Note that this may not match the parameter channel as it is a backed object.</returns>
@ -413,7 +421,11 @@ namespace osu.Game.Online.Chat
return channel;
}
public void LeaveChannel(Channel channel)
/// <summary>
/// Leave the specified channel. Can be called from any thread.
/// </summary>
/// <param name="channel">The channel to leave.</param>
public void LeaveChannel(Channel channel) => Schedule(() =>
{
if (channel == null) return;
@ -439,7 +451,7 @@ namespace osu.Game.Online.Chat
api.Queue(new LeaveChannelRequest(channel));
channel.Joined.Value = false;
}
}
});
/// <summary>
/// Opens the most recently closed channel that has not

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Online.Chat
@ -20,7 +21,10 @@ namespace osu.Game.Online.Chat
/// <summary>
/// Each word part of a chat link (split for word-wrap support).
/// </summary>
public List<Drawable> Parts;
public readonly List<Drawable> Parts;
[Resolved(CanBeNull = true)]
private OverlayColourProvider overlayColourProvider { get; set; }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parts.Any(d => d.ReceivePositionalInputAt(screenSpacePos));
@ -34,7 +38,7 @@ namespace osu.Game.Online.Chat
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
IdleColour = colours.Blue;
IdleColour = overlayColourProvider?.Light2 ?? colours.Blue;
}
protected override IEnumerable<Drawable> EffectTargets => Parts;

View File

@ -8,10 +8,8 @@ namespace osu.Game.Online.Chat
{
public class InfoMessage : LocalMessage
{
private static int infoID = -1;
public InfoMessage(string message)
: base(infoID--)
: base(null)
{
Timestamp = DateTimeOffset.Now;
Content = message;

View File

@ -59,7 +59,7 @@ namespace osu.Game.Online.Chat
return Id.Value.CompareTo(other.Id.Value);
}
public virtual bool Equals(Message other) => Id == other?.Id;
public virtual bool Equals(Message other) => Id.HasValue && Id == other?.Id;
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
public override int GetHashCode() => Id.GetHashCode();

View File

@ -49,6 +49,18 @@ namespace osu.Game.Online.Chat
// Unicode emojis
private static readonly Regex emoji_regex = new Regex(@"(\uD83D[\uDC00-\uDE4F])");
/// <summary>
/// The root URL for the website, used for chat link matching.
/// </summary>
public static string WebsiteRootUrl
{
set => websiteRootUrl = value
.Trim('/') // trim potential trailing slash/
.Split('/').Last(); // only keep domain name, ignoring protocol.
}
private static string websiteRootUrl = "osu.ppy.sh";
private static void handleMatches(Regex regex, string display, string link, MessageFormatterResult result, int startIndex = 0, LinkAction? linkActionOverride = null, char[] escapeChars = null)
{
int captureOffset = 0;
@ -119,22 +131,42 @@ namespace osu.Game.Online.Chat
case "http":
case "https":
// length > 3 since all these links need another argument to work
if (args.Length > 3 && args[1] == "osu.ppy.sh")
if (args.Length > 3 && args[1].EndsWith(websiteRootUrl, StringComparison.OrdinalIgnoreCase))
{
var mainArg = args[3];
switch (args[2])
{
// old site only
case "b":
case "beatmaps":
return new LinkDetails(LinkAction.OpenBeatmap, args[3]);
{
string trimmed = mainArg.Split('?').First();
if (int.TryParse(trimmed, out var id))
return new LinkDetails(LinkAction.OpenBeatmap, id.ToString());
break;
}
case "s":
case "beatmapsets":
case "d":
return new LinkDetails(LinkAction.OpenBeatmapSet, args[3]);
{
if (args.Length > 4 && int.TryParse(args[4], out var id))
// https://osu.ppy.sh/beatmapsets/1154158#osu/2768184
return new LinkDetails(LinkAction.OpenBeatmap, id.ToString());
// https://osu.ppy.sh/beatmapsets/1154158#whatever
string trimmed = mainArg.Split('#').First();
if (int.TryParse(trimmed, out id))
return new LinkDetails(LinkAction.OpenBeatmapSet, id.ToString());
break;
}
case "u":
case "users":
return new LinkDetails(LinkAction.OpenUserProfile, args[3]);
return new LinkDetails(LinkAction.OpenUserProfile, mainArg);
}
}
@ -183,10 +215,9 @@ namespace osu.Game.Online.Chat
case "osump":
return new LinkDetails(LinkAction.JoinMultiplayerMatch, args[1]);
default:
return new LinkDetails(LinkAction.External, null);
}
return new LinkDetails(LinkAction.External, null);
}
private static MessageFormatterResult format(string toFormat, int startIndex = 0, int space = 3)
@ -259,8 +290,9 @@ namespace osu.Game.Online.Chat
public class LinkDetails
{
public LinkAction Action;
public string Argument;
public readonly LinkAction Action;
public readonly string Argument;
public LinkDetails(LinkAction action, string argument)
{

View File

@ -46,7 +46,7 @@ namespace osu.Game.Online.Chat
break;
}
var beatmapString = beatmap.OnlineBeatmapID.HasValue ? $"[https://osu.ppy.sh/b/{beatmap.OnlineBeatmapID} {beatmap}]" : beatmap.ToString();
var beatmapString = beatmap.OnlineBeatmapID.HasValue ? $"[{api.WebsiteRootUrl}/b/{beatmap.OnlineBeatmapID} {beatmap}]" : beatmap.ToString();
channelManager.PostMessage($"is {verb} {beatmapString}", true);
Expire();