1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-29 19:07:25 +08:00
osu-lazer/osu.Game/Overlays/Profile/Sections/Recent/DrawableRecentActivity.cs

140 lines
5.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
using osu.Game.Screens.Select.Leaderboards;
using osu.Game.Users;
using static osu.Game.Online.API.Requests.RecentActivity;
namespace osu.Game.Overlays.Profile.Sections.Recent
{
public class DrawableRecentActivity : DrawableProfileRow
{
private RecentActivity activity;
private User user;
private APIAccess api;
private string userLinkTemplate;
private string beatmapLinkTemplate;
private LinkFlowContainer content;
public DrawableRecentActivity(RecentActivity activity, User user)
{
this.activity = activity;
this.user = user;
userLinkTemplate = $"[{activity.User?.Username}]({urlToAbsolute(activity.User?.Url)})";
beatmapLinkTemplate = $"[{activity.Beatmap?.Title}]({urlToAbsolute(activity.Beatmap?.Url)})";
}
[BackgroundDependencyLoader]
private void load(APIAccess api)
{
this.api = api;
LeftFlowContainer.Add(content = new LinkFlowContainer
{
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
});
RightFlowContainer.Add(new OsuSpriteText
{
Text = activity.CreatedAt.LocalDateTime.ToShortDateString(),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Font = "Exo2.0-RegularItalic",
TextSize = 12,
Colour = OsuColour.Gray(0xAA),
});
string text = activityToString();
content.AddLinks(text, MessageFormatter.GetLinks(text));
}
protected override Drawable CreateLeftVisual()
{
switch (activity.Type)
{
case RecentActivityType.Rank:
return new DrawableRank(activity.ScoreRank)
{
RelativeSizeAxes = Axes.Y,
Width = 60,
FillMode = FillMode.Fit,
};
default:
return new Container
{
RelativeSizeAxes = Axes.Y,
Width = 60,
FillMode = FillMode.Fit,
};
}
}
private string urlToAbsolute(string url) => $"{api?.Endpoint ?? @"https://osu.ppy.sh"}{url}";
private string activityToString()
{
switch (activity.Type)
{
case RecentActivityType.Achievement:
return $"{userLinkTemplate} unlocked the {activity.AchivementName} achievement!";
case RecentActivityType.BeatmapPlaycount:
return $"{beatmapLinkTemplate} has been played {activity.Count} times!";
case RecentActivityType.BeatmapsetDelete:
return $"{beatmapLinkTemplate} has been deleted.";
case RecentActivityType.BeatmapsetRevive:
return $"{beatmapLinkTemplate} has been revived from eternal slumber by ${userLinkTemplate}";
case RecentActivityType.BeatmapsetUpdate:
return $"{userLinkTemplate} has updated the beatmap ${beatmapLinkTemplate}";
case RecentActivityType.BeatmapsetUpload:
return $"{userLinkTemplate} has submitted a new beatmap ${beatmapLinkTemplate}";
case RecentActivityType.Medal:
return $"{userLinkTemplate} has unlocked the {activity.AchivementName} medal!";
case RecentActivityType.Rank:
return $"{userLinkTemplate} achieved rank #{activity.Rank} on {beatmapLinkTemplate}";
case RecentActivityType.RankLost:
return $"{userLinkTemplate} has lost first place on {beatmapLinkTemplate}!";
case RecentActivityType.UserSupportAgain:
return $"{userLinkTemplate} has once again chosen to support osu! - thanks for your generosity!";
case RecentActivityType.UserSupportFirst:
return $"{userLinkTemplate} has become an osu! supporter - thanks for your generosity!";
case RecentActivityType.UsernameChange:
return $"{activity.User.PreviousUsername} has changed their username to {userLinkTemplate}";
case RecentActivityType.UserSupportGift:
return $"{userLinkTemplate} has received the gift of osu! supporter!";
default:
return string.Empty;
}
}
}
}