mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 04:53:12 +08:00
Add link handling to recent activities.
- Add a show user action to link handling
This commit is contained in:
parent
7e4bd36391
commit
bb40919f9c
@ -23,14 +23,16 @@ namespace osu.Game.Graphics.Containers
|
|||||||
public override bool HandleMouseInput => true;
|
public override bool HandleMouseInput => true;
|
||||||
|
|
||||||
private OsuGame game;
|
private OsuGame game;
|
||||||
|
private UserProfileOverlay userProfile;
|
||||||
|
|
||||||
private Action showNotImplementedError;
|
private Action showNotImplementedError;
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(OsuGame game, NotificationOverlay notifications)
|
private void load(OsuGame game, NotificationOverlay notifications, UserProfileOverlay userProfile)
|
||||||
{
|
{
|
||||||
// will be null in tests
|
// will be null in tests
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
this.userProfile = userProfile;
|
||||||
|
|
||||||
showNotImplementedError = () => notifications?.Post(new SimpleNotification
|
showNotImplementedError = () => notifications?.Post(new SimpleNotification
|
||||||
{
|
{
|
||||||
@ -90,6 +92,9 @@ namespace osu.Game.Graphics.Containers
|
|||||||
case LinkAction.External:
|
case LinkAction.External:
|
||||||
Process.Start(url);
|
Process.Start(url);
|
||||||
break;
|
break;
|
||||||
|
case LinkAction.OpenUserProfile:
|
||||||
|
userProfile?.ShowUser(Convert.ToInt64(linkArgument));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
|
throw new NotImplementedException($"This {nameof(LinkAction)} ({linkType.ToString()}) is missing an associated action.");
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,8 @@ namespace osu.Game.Online.Chat
|
|||||||
case "beatmapsets":
|
case "beatmapsets":
|
||||||
case "d":
|
case "d":
|
||||||
return new LinkDetails(LinkAction.OpenBeatmapSet, args[3]);
|
return new LinkDetails(LinkAction.OpenBeatmapSet, args[3]);
|
||||||
|
case "u":
|
||||||
|
return new LinkDetails(LinkAction.OpenUserProfile, args[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,6 +148,9 @@ namespace osu.Game.Online.Chat
|
|||||||
case "spectate":
|
case "spectate":
|
||||||
linkType = LinkAction.Spectate;
|
linkType = LinkAction.Spectate;
|
||||||
break;
|
break;
|
||||||
|
case "u":
|
||||||
|
linkType = LinkAction.OpenUserProfile;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
linkType = LinkAction.External;
|
linkType = LinkAction.External;
|
||||||
break;
|
break;
|
||||||
@ -205,6 +210,15 @@ namespace osu.Game.Online.Chat
|
|||||||
return inputMessage;
|
return inputMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Link> GetLinks(string text)
|
||||||
|
{
|
||||||
|
var result = format(text);
|
||||||
|
|
||||||
|
result.Links.Sort();
|
||||||
|
|
||||||
|
return result.Links;
|
||||||
|
}
|
||||||
|
|
||||||
public class MessageFormatterResult
|
public class MessageFormatterResult
|
||||||
{
|
{
|
||||||
public List<Link> Links = new List<Link>();
|
public List<Link> Links = new List<Link>();
|
||||||
@ -239,6 +253,7 @@ namespace osu.Game.Online.Chat
|
|||||||
OpenEditorTimestamp,
|
OpenEditorTimestamp,
|
||||||
JoinMultiplayerMatch,
|
JoinMultiplayerMatch,
|
||||||
Spectate,
|
Spectate,
|
||||||
|
OpenUserProfile,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Link : IComparable<Link>
|
public class Link : IComparable<Link>
|
||||||
|
@ -7,10 +7,14 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Online.Chat;
|
||||||
using osu.Game.Screens.Select.Leaderboards;
|
using osu.Game.Screens.Select.Leaderboards;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
using static osu.Game.Online.API.Requests.RecentActivity;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Sections.Recent
|
namespace osu.Game.Overlays.Profile.Sections.Recent
|
||||||
{
|
{
|
||||||
@ -18,19 +22,31 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
|
|||||||
{
|
{
|
||||||
private RecentActivity activity;
|
private RecentActivity activity;
|
||||||
private User user;
|
private User user;
|
||||||
|
private APIAccess api;
|
||||||
|
|
||||||
|
private string userLinkTemplate;
|
||||||
|
private string beatmapLinkTemplate;
|
||||||
|
|
||||||
|
private LinkFlowContainer content;
|
||||||
|
|
||||||
public DrawableRecentActivity(RecentActivity activity, User user)
|
public DrawableRecentActivity(RecentActivity activity, User user)
|
||||||
{
|
{
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
|
||||||
|
userLinkTemplate = $"[{activity.User?.Username}]({urlToAbsolute(activity.User?.Url)})";
|
||||||
|
beatmapLinkTemplate = $"[{activity.Beatmap?.Title}]({urlToAbsolute(activity.Beatmap?.Url)})";
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load(APIAccess api)
|
||||||
{
|
{
|
||||||
LeftFlowContainer.Add(new OsuSpriteText
|
this.api = api;
|
||||||
|
|
||||||
|
LeftFlowContainer.Add(content = new LinkFlowContainer
|
||||||
{
|
{
|
||||||
Text = activityToString(),
|
AutoSizeAxes = Axes.Y,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
});
|
});
|
||||||
|
|
||||||
RightFlowContainer.Add(new OsuSpriteText
|
RightFlowContainer.Add(new OsuSpriteText
|
||||||
@ -42,6 +58,10 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
|
|||||||
TextSize = 12,
|
TextSize = 12,
|
||||||
Colour = OsuColour.Gray(0xAA),
|
Colour = OsuColour.Gray(0xAA),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
string text = activityToString();
|
||||||
|
|
||||||
|
content.AddLinks(text, MessageFormatter.GetLinks(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateLeftVisual()
|
protected override Drawable CreateLeftVisual()
|
||||||
@ -66,48 +86,50 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string urlToAbsolute(string url) => $"{api?.Endpoint ?? @"https://osu.ppy.sh"}{url}";
|
||||||
|
|
||||||
private string activityToString()
|
private string activityToString()
|
||||||
{
|
{
|
||||||
switch (activity.Type)
|
switch (activity.Type)
|
||||||
{
|
{
|
||||||
case RecentActivityType.Achievement:
|
case RecentActivityType.Achievement:
|
||||||
return $"{activity.User.Username} unlocked the {activity.AchivementName} achievement!";
|
return $"{userLinkTemplate} unlocked the {activity.AchivementName} achievement!";
|
||||||
|
|
||||||
case RecentActivityType.BeatmapPlaycount:
|
case RecentActivityType.BeatmapPlaycount:
|
||||||
return $"{activity.Beatmap.Title} has been played {activity.Count} times!";
|
return $"{beatmapLinkTemplate} has been played {activity.Count} times!";
|
||||||
|
|
||||||
case RecentActivityType.BeatmapsetDelete:
|
case RecentActivityType.BeatmapsetDelete:
|
||||||
return $"{activity.Beatmap.Title} has been deleted.";
|
return $"{beatmapLinkTemplate} has been deleted.";
|
||||||
|
|
||||||
case RecentActivityType.BeatmapsetRevive:
|
case RecentActivityType.BeatmapsetRevive:
|
||||||
return $"{activity.Beatmap.Title} has been revived from eternal slumber by ${activity.User.Username}";
|
return $"{beatmapLinkTemplate} has been revived from eternal slumber by ${userLinkTemplate}";
|
||||||
|
|
||||||
case RecentActivityType.BeatmapsetUpdate:
|
case RecentActivityType.BeatmapsetUpdate:
|
||||||
return $"{activity.User.Username} has updated the beatmap ${activity.Beatmap.Title}";
|
return $"{userLinkTemplate} has updated the beatmap ${beatmapLinkTemplate}";
|
||||||
|
|
||||||
case RecentActivityType.BeatmapsetUpload:
|
case RecentActivityType.BeatmapsetUpload:
|
||||||
return $"{activity.User.Username} has submitted a new beatmap ${activity.Beatmap.Title}";
|
return $"{userLinkTemplate} has submitted a new beatmap ${beatmapLinkTemplate}";
|
||||||
|
|
||||||
case RecentActivityType.Medal:
|
case RecentActivityType.Medal:
|
||||||
return $"{activity.User.Username} has unlocked the {activity.AchivementName} medal!";
|
return $"{userLinkTemplate} has unlocked the {activity.AchivementName} medal!";
|
||||||
|
|
||||||
case RecentActivityType.Rank:
|
case RecentActivityType.Rank:
|
||||||
return $"{activity.User.Username} achieved rank #{activity.Rank} on {activity.Beatmap?.Title}";
|
return $"{userLinkTemplate} achieved rank #{activity.Rank} on {beatmapLinkTemplate}";
|
||||||
|
|
||||||
case RecentActivityType.RankLost:
|
case RecentActivityType.RankLost:
|
||||||
return $"{activity.User.Username} has lost first place on {activity.Beatmap.Title}!";
|
return $"{userLinkTemplate} has lost first place on {beatmapLinkTemplate}!";
|
||||||
|
|
||||||
case RecentActivityType.UserSupportAgain:
|
case RecentActivityType.UserSupportAgain:
|
||||||
return $"{activity.User.Username} has once again chosen to support osu! - thanks for your generosity!";
|
return $"{userLinkTemplate} has once again chosen to support osu! - thanks for your generosity!";
|
||||||
|
|
||||||
case RecentActivityType.UserSupportFirst:
|
case RecentActivityType.UserSupportFirst:
|
||||||
return $"{activity.User.Username} has become an osu! supporter - thanks for your generosity!";
|
return $"{userLinkTemplate} has become an osu! supporter - thanks for your generosity!";
|
||||||
|
|
||||||
case RecentActivityType.UsernameChange:
|
case RecentActivityType.UsernameChange:
|
||||||
return $"{activity.User.PreviousUsername} has changed their username to {activity.User.Username}";
|
return $"{activity.User.PreviousUsername} has changed their username to {userLinkTemplate}";
|
||||||
|
|
||||||
case RecentActivityType.UserSupportGift:
|
case RecentActivityType.UserSupportGift:
|
||||||
return $"{activity.User.Username} has received the gift of osu! supporter!";
|
return $"{userLinkTemplate} has received the gift of osu! supporter!";
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
|
@ -73,6 +73,11 @@ namespace osu.Game.Overlays
|
|||||||
FadeEdgeEffectTo(0, DISAPPEAR_DURATION, Easing.Out);
|
FadeEdgeEffectTo(0, DISAPPEAR_DURATION, Easing.Out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShowUser(long userId)
|
||||||
|
{
|
||||||
|
ShowUser(new User { Id = userId }, true);
|
||||||
|
}
|
||||||
|
|
||||||
public void ShowUser(User user, bool fetchOnline = true)
|
public void ShowUser(User user, bool fetchOnline = true)
|
||||||
{
|
{
|
||||||
userReq?.Cancel();
|
userReq?.Cancel();
|
||||||
|
Loading…
Reference in New Issue
Block a user