1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 20:03:20 +08:00
osu-lazer/osu.Game/Overlays/Profile/Sections/Kudosu/DrawableKudosuHistoryItem.cs

151 lines
5.2 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.
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.Online.API.Requests.Responses;
2019-08-19 02:28:07 +08:00
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.Profile.Sections.Kudosu
{
2019-08-20 20:00:14 +08:00
public class DrawableKudosuHistoryItem : CompositeDrawable
{
2019-08-20 20:00:14 +08:00
private const int height = 25;
[Resolved]
private OsuColour colours { get; set; }
private readonly APIKudosuHistory historyItem;
2019-08-20 20:00:14 +08:00
private readonly LinkFlowContainer linkFlowContainer;
private readonly DrawableDate date;
public DrawableKudosuHistoryItem(APIKudosuHistory historyItem)
{
this.historyItem = historyItem;
2019-08-20 20:00:14 +08:00
Height = height;
RelativeSizeAxes = Axes.X;
AddRangeInternal(new Drawable[]
{
linkFlowContainer = new LinkFlowContainer
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
},
date = new DrawableDate(historyItem.CreatedAt)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
});
}
[BackgroundDependencyLoader]
private void load()
{
2019-08-20 20:00:14 +08:00
date.Colour = colours.GreySeafoamLighter;
2019-08-20 21:11:59 +08:00
string userLinkTemplate() => $"[{historyItem.Giver?.Url} {historyItem.Giver?.Username}]";
2019-08-20 20:00:14 +08:00
switch (historyItem.Action)
{
2019-08-20 20:00:14 +08:00
case KudosuAction.VoteGive:
2019-08-20 21:11:59 +08:00
linkFlowContainer.AddText(@"Received ");
addKudosuPart();
2019-08-20 21:19:21 +08:00
addMainPart(@" from obtaining votes in modding post of ");
2019-08-20 21:11:59 +08:00
addPostPart();
break;
2019-08-20 20:00:14 +08:00
case KudosuAction.Give:
2019-08-20 20:29:32 +08:00
linkFlowContainer.AddText(@"Received ");
2019-08-20 20:00:14 +08:00
addKudosuPart();
2019-08-20 21:19:21 +08:00
addMainPart($@" from {userLinkTemplate()} for a post at ");
2019-08-20 20:00:14 +08:00
addPostPart();
break;
case KudosuAction.Reset:
2019-08-20 21:11:59 +08:00
addMainPart($@"Kudosu reset by {userLinkTemplate()} for the post ");
2019-08-20 20:00:14 +08:00
addPostPart();
break;
case KudosuAction.VoteReset:
2019-08-20 20:29:32 +08:00
linkFlowContainer.AddText(@"Lost ");
2019-08-20 20:00:14 +08:00
addKudosuPart();
2019-08-20 21:11:59 +08:00
addMainPart(@" from losing votes in modding post of ");
2019-08-20 20:00:14 +08:00
addPostPart();
break;
case KudosuAction.DenyKudosuReset:
2019-08-20 20:29:32 +08:00
linkFlowContainer.AddText(@"Denied ");
2019-08-20 20:00:14 +08:00
addKudosuPart();
2019-08-20 21:11:59 +08:00
addMainPart(@" from modding post ");
2019-08-20 20:00:14 +08:00
addPostPart();
break;
case KudosuAction.Revoke:
2019-08-20 21:11:59 +08:00
addMainPart($@"Denied kudosu by {userLinkTemplate()} for the post ");
2019-08-20 20:00:14 +08:00
addPostPart();
break;
2019-08-22 21:50:54 +08:00
case KudosuAction.AllowKudosuGive:
linkFlowContainer.AddText(@"Received ");
addKudosuPart();
addMainPart(@" from kudosu deny repeal of modding post ");
addPostPart();
break;
case KudosuAction.DeleteReset:
linkFlowContainer.AddText(@"Lost ");
addKudosuPart();
addMainPart(@" from modding post deletion of ");
addPostPart();
break;
case KudosuAction.RestoreGive:
linkFlowContainer.AddText(@"Received ");
addKudosuPart();
addMainPart(@" from modding post restoration of ");
addPostPart();
break;
case KudosuAction.RecalculateGive:
linkFlowContainer.AddText(@"Received ");
addKudosuPart();
addMainPart(@" from votes recalculation in modding post of ");
addPostPart();
break;
case KudosuAction.RecalculateReset:
linkFlowContainer.AddText(@"Lost ");
addKudosuPart();
addMainPart(@" from votes recalculation in modding post of ");
addPostPart();
break;
2019-08-20 20:00:14 +08:00
}
}
2019-08-20 20:00:14 +08:00
private void addKudosuPart()
{
linkFlowContainer.AddText($@"{historyItem.Amount} kudosu", t =>
{
2019-08-20 20:00:14 +08:00
t.Font = t.Font.With(italics: true);
t.Colour = colours.Blue;
});
2019-08-20 20:00:14 +08:00
}
2019-08-20 21:11:59 +08:00
private void addMainPart(string text)
2019-08-20 20:00:14 +08:00
{
2019-08-20 21:11:59 +08:00
var formatted = MessageFormatter.FormatText(text);
2019-08-20 21:11:59 +08:00
linkFlowContainer.AddLinks(formatted.Text, formatted.Links);
}
2019-08-20 20:00:14 +08:00
private void addPostPart() => linkFlowContainer.AddLink(historyItem.Post.Title, historyItem.Post.Url);
}
}