2019-08-09 16:14:38 +08:00
|
|
|
|
// 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;
|
2019-08-09 16:14:38 +08:00
|
|
|
|
using osu.Game.Online.Chat;
|
2019-08-30 15:13:21 +08:00
|
|
|
|
using System;
|
2019-08-09 16:14:38 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Sections.Kudosu
|
|
|
|
|
{
|
2019-08-20 20:00:14 +08:00
|
|
|
|
public class DrawableKudosuHistoryItem : CompositeDrawable
|
2019-08-09 16:14:38 +08:00
|
|
|
|
{
|
2019-08-20 20:00:14 +08:00
|
|
|
|
private const int height = 25;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
2019-08-09 16:14:38 +08:00
|
|
|
|
private readonly APIKudosuHistory historyItem;
|
2019-08-20 20:00:14 +08:00
|
|
|
|
private readonly LinkFlowContainer linkFlowContainer;
|
|
|
|
|
private readonly DrawableDate date;
|
2019-08-09 16:14:38 +08:00
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-08-09 16:14:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2019-08-20 20:00:14 +08:00
|
|
|
|
date.Colour = colours.GreySeafoamLighter;
|
2019-08-09 16:14:38 +08:00
|
|
|
|
|
2019-08-28 16:29:18 +08:00
|
|
|
|
string prefix = getPrefix(historyItem);
|
|
|
|
|
var formattedSource = MessageFormatter.FormatText(getSource(historyItem));
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(prefix))
|
|
|
|
|
{
|
|
|
|
|
linkFlowContainer.AddText(prefix);
|
2019-08-30 15:13:21 +08:00
|
|
|
|
linkFlowContainer.AddText($@" {Math.Abs(historyItem.Amount)} kudosu", t =>
|
2019-08-28 16:29:18 +08:00
|
|
|
|
{
|
|
|
|
|
t.Font = t.Font.With(italics: true);
|
|
|
|
|
t.Colour = colours.Blue;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
linkFlowContainer.AddLinks(formattedSource.Text + " ", formattedSource.Links);
|
|
|
|
|
linkFlowContainer.AddLink(historyItem.Post.Title, historyItem.Post.Url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string getSource(APIKudosuHistory historyItem)
|
|
|
|
|
{
|
|
|
|
|
string userLink() => $"[{historyItem.Giver?.Url} {historyItem.Giver?.Username}]";
|
2019-08-20 21:11:59 +08:00
|
|
|
|
|
2019-08-20 20:00:14 +08:00
|
|
|
|
switch (historyItem.Action)
|
2019-08-09 16:14:38 +08:00
|
|
|
|
{
|
2019-08-20 20:00:14 +08:00
|
|
|
|
case KudosuAction.VoteGive:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from obtaining votes in modding post of";
|
2019-08-20 21:11:59 +08:00
|
|
|
|
|
2019-08-20 20:00:14 +08:00
|
|
|
|
case KudosuAction.Give:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return $@" from {userLink()} for a post at";
|
2019-08-20 20:00:14 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.Reset:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return $@"Kudosu reset by {userLink()} for the post";
|
2019-08-20 20:00:14 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.VoteReset:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from losing votes in modding post of";
|
2019-08-20 20:00:14 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.DenyKudosuReset:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from modding post";
|
2019-08-20 20:00:14 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.Revoke:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return $@"Denied kudosu by {userLink()} for the post";
|
2019-08-22 21:50:54 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.AllowKudosuGive:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from kudosu deny repeal of modding post";
|
2019-08-22 21:50:54 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.DeleteReset:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from modding post deletion of";
|
2019-08-22 21:50:54 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.RestoreGive:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from modding post restoration of";
|
2019-08-22 21:50:54 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.RecalculateGive:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from votes recalculation in modding post of";
|
2019-08-22 21:50:54 +08:00
|
|
|
|
|
|
|
|
|
case KudosuAction.RecalculateReset:
|
2019-08-28 16:29:18 +08:00
|
|
|
|
return @" from votes recalculation in modding post of";
|
2019-08-27 20:30:41 +08:00
|
|
|
|
|
2019-08-28 16:29:18 +08:00
|
|
|
|
default:
|
|
|
|
|
return @" from unknown event ";
|
|
|
|
|
}
|
2019-08-20 20:00:14 +08:00
|
|
|
|
}
|
2019-08-09 16:14:38 +08:00
|
|
|
|
|
2019-08-28 16:29:18 +08:00
|
|
|
|
private string getPrefix(APIKudosuHistory historyItem)
|
2019-08-20 20:00:14 +08:00
|
|
|
|
{
|
2019-08-28 16:29:18 +08:00
|
|
|
|
switch (historyItem.Action)
|
2019-08-09 16:14:38 +08:00
|
|
|
|
{
|
2019-08-28 16:29:18 +08:00
|
|
|
|
case KudosuAction.VoteGive:
|
|
|
|
|
return @"Received";
|
2019-08-09 16:14:38 +08:00
|
|
|
|
|
2019-08-28 16:29:18 +08:00
|
|
|
|
case KudosuAction.Give:
|
|
|
|
|
return @"Received";
|
2019-08-09 16:14:38 +08:00
|
|
|
|
|
2019-08-28 16:29:18 +08:00
|
|
|
|
case KudosuAction.VoteReset:
|
|
|
|
|
return @"Lost";
|
|
|
|
|
|
|
|
|
|
case KudosuAction.DenyKudosuReset:
|
|
|
|
|
return @"Denied";
|
|
|
|
|
|
|
|
|
|
case KudosuAction.AllowKudosuGive:
|
|
|
|
|
return @"Received";
|
|
|
|
|
|
|
|
|
|
case KudosuAction.DeleteReset:
|
|
|
|
|
return @"Lost";
|
2019-08-09 16:14:38 +08:00
|
|
|
|
|
2019-08-28 16:29:18 +08:00
|
|
|
|
case KudosuAction.RestoreGive:
|
|
|
|
|
return @"Received";
|
|
|
|
|
|
|
|
|
|
case KudosuAction.RecalculateGive:
|
|
|
|
|
return @"Received";
|
|
|
|
|
|
|
|
|
|
case KudosuAction.RecalculateReset:
|
|
|
|
|
return @"Lost";
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-09 16:14:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|