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

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

145 lines
4.9 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;
using osu.Game.Online.Chat;
2019-08-30 15:13:21 +08:00
using System;
2019-08-30 15:22:49 +08:00
using osuTK;
namespace osu.Game.Overlays.Profile.Sections.Kudosu
{
2019-08-20 20:00:14 +08:00
public partial class DrawableKudosuHistoryItem : CompositeDrawable
{
2019-08-20 20:00:14 +08:00
private const int height = 25;
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,
2019-09-02 14:37:38 +08:00
Spacing = new Vector2(0, 3),
2019-08-20 20:00:14 +08:00
},
date = new DrawableDate(historyItem.CreatedAt)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
}
});
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
date.Colour = colourProvider.Foreground1;
var formattedSource = MessageFormatter.FormatText(getString(historyItem));
2019-09-02 14:37:38 +08:00
linkFlowContainer.AddLinks(formattedSource.Text, formattedSource.Links);
2019-08-28 16:29:18 +08:00
}
private string getString(APIKudosuHistory item)
2019-08-28 16:29:18 +08:00
{
string amount = $"{Math.Abs(item.Amount)} kudosu";
string post = $"[{item.Post.Title}]({item.Post.Url})";
2019-08-20 21:11:59 +08:00
switch (item.Source)
{
case KudosuSource.AllowKudosu:
switch (item.Action)
{
case KudosuAction.Give:
return $"Received {amount} from kudosu deny repeal of modding post {post}";
}
2019-08-20 21:11:59 +08:00
break;
2019-08-20 20:00:14 +08:00
case KudosuSource.DenyKudosu:
switch (item.Action)
{
case KudosuAction.Reset:
return $"Denied {amount} from modding post {post}";
}
2019-08-20 20:00:14 +08:00
break;
2019-08-20 20:00:14 +08:00
case KudosuSource.Delete:
switch (item.Action)
{
case KudosuAction.Reset:
return $"Lost {amount} from modding post deletion of {post}";
}
2019-08-20 20:00:14 +08:00
break;
2019-08-22 21:50:54 +08:00
case KudosuSource.Restore:
switch (item.Action)
{
case KudosuAction.Give:
return $"Received {amount} from modding post restoration of {post}";
}
2019-08-22 21:50:54 +08:00
break;
2019-08-22 21:50:54 +08:00
case KudosuSource.Vote:
switch (item.Action)
{
case KudosuAction.Give:
return $"Received {amount} from obtaining votes in modding post of {post}";
2019-08-22 21:50:54 +08:00
case KudosuAction.Reset:
return $"Lost {amount} from losing votes in modding post of {post}";
}
2019-08-22 21:50:54 +08:00
break;
2019-08-27 20:30:41 +08:00
case KudosuSource.Recalculate:
switch (item.Action)
{
case KudosuAction.Give:
return $"Received {amount} from votes recalculation in modding post of {post}";
case KudosuAction.Reset:
return $"Lost {amount} from votes recalculation in modding post of {post}";
}
break;
case KudosuSource.Forum:
string giver = $"[{item.Giver?.Username}]({item.Giver?.Url})";
switch (historyItem.Action)
{
case KudosuAction.Give:
return $"Received {amount} from {giver} for a post at {post}";
case KudosuAction.Reset:
return $"Kudosu reset by {giver} for the post {post}";
case KudosuAction.Revoke:
return $"Denied kudosu by {giver} for the post {post}";
}
break;
2019-08-28 16:29:18 +08:00
}
return $"Unknown event ({amount} change)";
2019-08-28 16:29:18 +08:00
}
}
}