1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-31 00:42:55 +08:00
osu-lazer/osu.Game/Overlays/Profile/Sections/Recent/DrawableRecentActivity.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

235 lines
9.0 KiB
C#
Raw Normal View History

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
2018-04-13 17:19:50 +08:00
2020-02-02 17:03:51 +08:00
using System.Linq;
using osu.Framework.Allocation;
2022-12-30 20:17:59 +08:00
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Online.Leaderboards;
2020-02-02 17:03:51 +08:00
using osu.Game.Rulesets;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Profile.Sections.Recent
{
public partial class DrawableRecentActivity : CompositeDrawable
{
2020-01-30 15:54:58 +08:00
private const int font_size = 14;
2020-02-02 17:03:51 +08:00
[Resolved]
2022-12-30 20:17:59 +08:00
private IAPIProvider api { get; set; } = null!;
2020-02-02 17:03:51 +08:00
[Resolved]
2022-12-30 20:17:59 +08:00
private IRulesetStore rulesets { get; set; } = null!;
2018-04-13 17:19:50 +08:00
private readonly APIRecentActivity activity;
2018-04-13 17:19:50 +08:00
2022-12-30 20:17:59 +08:00
private LinkFlowContainer content = null!;
2018-04-13 17:19:50 +08:00
public DrawableRecentActivity(APIRecentActivity activity)
{
this.activity = activity;
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
2020-02-02 17:03:51 +08:00
private void load(OverlayColourProvider colourProvider)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
AddInternal(new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{
2020-01-30 16:16:58 +08:00
new Dimension(GridSizeMode.Absolute, size: 28),
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = createIcon().With(icon =>
{
icon.Anchor = Anchor.Centre;
icon.Origin = Anchor.Centre;
})
},
2020-01-30 15:54:58 +08:00
content = new LinkFlowContainer(t => t.Font = OsuFont.GetFont(size: font_size))
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
},
new DrawableDate(activity.CreatedAt)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Colour = colourProvider.Foreground1,
2020-01-30 15:54:58 +08:00
Font = OsuFont.GetFont(size: font_size),
}
}
}
});
2018-04-13 17:19:50 +08:00
createMessage();
}
2018-04-13 17:19:50 +08:00
private Drawable createIcon()
{
switch (activity.Type)
{
case RecentActivityType.Rank:
return new UpdateableRank(activity.ScoreRank)
{
RelativeSizeAxes = Axes.X,
2020-01-30 16:16:58 +08:00
Height = 11,
FillMode = FillMode.Fit,
2020-01-30 16:16:58 +08:00
Margin = new MarginPadding { Top = 2 }
};
2018-04-13 17:19:50 +08:00
case RecentActivityType.Achievement:
2019-11-29 15:19:57 +08:00
return new DelayedLoadWrapper(new MedalIcon(activity.Achievement.Slug)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2019-11-29 15:19:57 +08:00
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fit,
})
{
RelativeSizeAxes = Axes.X,
2020-01-30 16:16:58 +08:00
Width = 0.5f,
Height = 18
};
2018-04-13 17:19:50 +08:00
default:
return new RecentActivityIcon(activity)
{
RelativeSizeAxes = Axes.X,
Height = 11,
FillMode = FillMode.Fit,
Margin = new MarginPadding { Top = 2, Vertical = 2 }
};
}
}
2018-04-13 17:19:50 +08:00
private void createMessage()
{
switch (activity.Type)
{
case RecentActivityType.Achievement:
addUserLink();
addText($" unlocked the \"{activity.Achievement.Name}\" medal!");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.BeatmapPlaycount:
addBeatmapLink();
addText($" has been played {activity.Count} times!");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.BeatmapsetApprove:
addBeatmapsetLink();
addText($" has been {activity.Approval.ToString().ToLowerInvariant()}!");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.BeatmapsetDelete:
addBeatmapsetLink();
addText(" has been deleted.");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.BeatmapsetRevive:
addBeatmapsetLink();
addText(" has been revived from eternal slumber by ");
addUserLink();
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.BeatmapsetUpdate:
addUserLink();
addText(" has updated the beatmap ");
addBeatmapsetLink();
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.BeatmapsetUpload:
addUserLink();
addText(" has submitted a new beatmap ");
addBeatmapsetLink();
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.Medal:
// apparently this shouldn't exist look at achievement instead (https://github.com/ppy/osu-web/blob/master/resources/assets/coffee/react/profile-page/recent-activity.coffee#L111)
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.Rank:
addUserLink();
addText($" achieved rank #{activity.Rank} on ");
addBeatmapLink();
2020-02-02 17:03:51 +08:00
addText($" ({getRulesetName()})");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.RankLost:
addUserLink();
addText(" has lost first place on ");
addBeatmapLink();
2020-02-02 17:03:51 +08:00
addText($" ({getRulesetName()})");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.UserSupportAgain:
addUserLink();
addText(" has once again chosen to support osu! - thanks for your generosity!");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.UserSupportFirst:
addUserLink();
addText(" has become an osu!supporter - thanks for your generosity!");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.UserSupportGift:
addUserLink();
addText(" has received the gift of osu!supporter!");
break;
2018-04-13 17:19:50 +08:00
case RecentActivityType.UsernameChange:
addText($"{activity.User?.PreviousUsername} has changed their username to ");
addUserLink();
break;
}
}
private string getRulesetName() =>
rulesets.AvailableRulesets.FirstOrDefault(r => r.ShortName == activity.Mode)?.Name ?? activity.Mode;
private void addUserLink()
2022-12-30 20:17:59 +08:00
=> content.AddLink(activity.User.AsNonNull().Username, LinkAction.OpenUserProfile, getLinkArgument(activity.User.AsNonNull().Url), creationParameters: t => t.Font = getLinkFont(FontWeight.Bold));
private void addBeatmapLink()
2022-12-30 20:17:59 +08:00
=> content.AddLink(activity.Beatmap.AsNonNull().Title, LinkAction.OpenBeatmap, getLinkArgument(activity.Beatmap.AsNonNull().Url), creationParameters: t => t.Font = getLinkFont());
private void addBeatmapsetLink()
2022-12-30 20:17:59 +08:00
=> content.AddLink(activity.Beatmapset.AsNonNull().Title, LinkAction.OpenBeatmapSet, getLinkArgument(activity.Beatmapset.AsNonNull().Url), creationParameters: t => t.Font = getLinkFont());
2022-12-30 20:17:59 +08:00
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.WebsiteRootUrl}{url}").Argument.ToString().AsNonNull();
private FontUsage getLinkFont(FontWeight fontWeight = FontWeight.Regular)
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);
private void addText(string text)
=> content.AddText(text, t => t.Font = OsuFont.GetFont(size: font_size, weight: FontWeight.SemiBold));
}
}