2018-02-26 12:08:37 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2018-02-26 01:11:47 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
2018-02-26 03:06:55 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-02-26 01:11:47 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-02-26 03:06:55 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2018-02-26 01:11:47 +08:00
|
|
|
|
using osu.Game.Online.API.Requests;
|
2018-02-26 03:06:55 +08:00
|
|
|
|
using osu.Game.Online.Chat;
|
2018-02-26 01:11:47 +08:00
|
|
|
|
using osu.Game.Screens.Select.Leaderboards;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections.Recent
|
|
|
|
|
{
|
|
|
|
|
public class DrawableRecentActivity : DrawableProfileRow
|
|
|
|
|
{
|
2018-02-26 03:06:55 +08:00
|
|
|
|
private APIAccess api;
|
|
|
|
|
|
2018-02-26 03:46:46 +08:00
|
|
|
|
private readonly RecentActivity activity;
|
|
|
|
|
private readonly string userLinkTemplate;
|
|
|
|
|
private readonly string beatmapLinkTemplate;
|
2018-02-26 14:16:16 +08:00
|
|
|
|
private readonly string beatmapsetLinkTemplate;
|
2018-02-26 03:06:55 +08:00
|
|
|
|
|
|
|
|
|
private LinkFlowContainer content;
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
2018-02-26 03:46:46 +08:00
|
|
|
|
public DrawableRecentActivity(RecentActivity activity)
|
2018-02-26 01:11:47 +08:00
|
|
|
|
{
|
|
|
|
|
this.activity = activity;
|
2018-02-26 03:06:55 +08:00
|
|
|
|
|
2018-02-26 03:28:20 +08:00
|
|
|
|
userLinkTemplate = $"[{urlToAbsolute(activity.User?.Url)} {activity.User?.Username}]";
|
|
|
|
|
beatmapLinkTemplate = $"[{urlToAbsolute(activity.Beatmap?.Url)} {activity.Beatmap?.Title}]";
|
2018-02-26 14:16:16 +08:00
|
|
|
|
beatmapsetLinkTemplate = $"[{urlToAbsolute(activity.Beatmapset?.Url)} {activity.Beatmapset?.Title}]";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2018-02-26 03:06:55 +08:00
|
|
|
|
private void load(APIAccess api)
|
2018-02-26 01:11:47 +08:00
|
|
|
|
{
|
2018-02-26 03:06:55 +08:00
|
|
|
|
this.api = api;
|
|
|
|
|
|
|
|
|
|
LeftFlowContainer.Add(content = new LinkFlowContainer
|
2018-02-26 01:11:47 +08:00
|
|
|
|
{
|
2018-02-26 03:06:55 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2018-02-26 01:11:47 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
|
});
|
2018-02-26 03:06:55 +08:00
|
|
|
|
|
2018-02-26 03:28:20 +08:00
|
|
|
|
var formatted = MessageFormatter.FormatText(activityToString());
|
2018-02-26 03:06:55 +08:00
|
|
|
|
|
2018-02-26 03:28:20 +08:00
|
|
|
|
content.AddLinks(formatted.Text, formatted.Links);
|
2018-02-26 01:11:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Drawable CreateLeftVisual()
|
|
|
|
|
{
|
|
|
|
|
switch (activity.Type)
|
|
|
|
|
{
|
|
|
|
|
case RecentActivityType.Rank:
|
|
|
|
|
return new DrawableRank(activity.ScoreRank)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Width = 60,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
};
|
|
|
|
|
|
2018-02-26 14:16:16 +08:00
|
|
|
|
case RecentActivityType.Medal:
|
|
|
|
|
// TODO: add medal visual
|
2018-02-26 01:11:47 +08:00
|
|
|
|
default:
|
|
|
|
|
return new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Width = 60,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 03:06:55 +08:00
|
|
|
|
private string urlToAbsolute(string url) => $"{api?.Endpoint ?? @"https://osu.ppy.sh"}{url}";
|
|
|
|
|
|
2018-02-26 01:11:47 +08:00
|
|
|
|
private string activityToString()
|
|
|
|
|
{
|
|
|
|
|
switch (activity.Type)
|
|
|
|
|
{
|
|
|
|
|
case RecentActivityType.Achievement:
|
2018-02-26 03:06:55 +08:00
|
|
|
|
return $"{userLinkTemplate} unlocked the {activity.AchivementName} achievement!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.BeatmapPlaycount:
|
2018-02-26 03:06:55 +08:00
|
|
|
|
return $"{beatmapLinkTemplate} has been played {activity.Count} times!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
2018-02-26 14:16:16 +08:00
|
|
|
|
case RecentActivityType.BeatmapsetApprove:
|
|
|
|
|
return $"{beatmapsetLinkTemplate} has been {activity.Approval.ToString().ToLowerInvariant()}!";
|
|
|
|
|
|
2018-02-26 01:11:47 +08:00
|
|
|
|
case RecentActivityType.BeatmapsetDelete:
|
2018-02-26 14:16:16 +08:00
|
|
|
|
return $"{beatmapsetLinkTemplate} has been deleted.";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.BeatmapsetRevive:
|
2018-02-26 14:16:16 +08:00
|
|
|
|
return $"{beatmapsetLinkTemplate} has been revived from eternal slumber by {userLinkTemplate}.";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.BeatmapsetUpdate:
|
2018-02-26 14:16:16 +08:00
|
|
|
|
return $"{userLinkTemplate} has updated the beatmap {beatmapsetLinkTemplate}!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.BeatmapsetUpload:
|
2018-02-26 14:16:16 +08:00
|
|
|
|
return $"{userLinkTemplate} has submitted a new beatmap {beatmapsetLinkTemplate}!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.Medal:
|
2018-02-26 03:06:55 +08:00
|
|
|
|
return $"{userLinkTemplate} has unlocked the {activity.AchivementName} medal!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.Rank:
|
2018-02-26 14:16:16 +08:00
|
|
|
|
return $"{userLinkTemplate} achieved rank #{activity.Rank} on {beatmapLinkTemplate} ({activity.Mode}!)";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.RankLost:
|
2018-02-26 14:16:16 +08:00
|
|
|
|
return $"{userLinkTemplate} has lost first place on {beatmapLinkTemplate} ({activity.Mode}!)";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.UserSupportAgain:
|
2018-02-26 03:06:55 +08:00
|
|
|
|
return $"{userLinkTemplate} has once again chosen to support osu! - thanks for your generosity!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.UserSupportFirst:
|
2018-02-26 03:06:55 +08:00
|
|
|
|
return $"{userLinkTemplate} has become an osu! supporter - thanks for your generosity!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
|
|
|
|
case RecentActivityType.UserSupportGift:
|
2018-02-26 03:06:55 +08:00
|
|
|
|
return $"{userLinkTemplate} has received the gift of osu! supporter!";
|
2018-02-26 01:11:47 +08:00
|
|
|
|
|
2018-02-26 14:16:16 +08:00
|
|
|
|
case RecentActivityType.UsernameChange:
|
|
|
|
|
return $"{activity.User.PreviousUsername} has changed their username to {userLinkTemplate}!";
|
|
|
|
|
|
2018-02-26 01:11:47 +08:00
|
|
|
|
default:
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|