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 ;
2018-02-27 23:51:53 +08:00
private string userLinkTemplate ;
private string beatmapLinkTemplate ;
private 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 ;
}
[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 ;
2018-02-27 23:51:53 +08:00
userLinkTemplate = $"[{toAbsoluteUrl(activity.User?.Url)} {activity.User?.Username}]" ;
beatmapLinkTemplate = $"[{toAbsoluteUrl(activity.Beatmap?.Url)} {activity.Beatmap?.Title}]" ;
beatmapsetLinkTemplate = $"[{toAbsoluteUrl(activity.Beatmapset?.Url)} {activity.Beatmapset?.Title}]" ;
LeftFlowContainer . Padding = new MarginPadding { Left = 10 , Right = 160 } ;
2018-02-26 03:06:55 +08:00
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 15:38:12 +08:00
case RecentActivityType . Achievement :
return new MedalIcon ( activity . Achievement . Slug )
{
RelativeSizeAxes = Axes . Y ,
Width = 60 ,
FillMode = FillMode . Fit ,
} ;
2018-02-26 01:11:47 +08:00
default :
return new Container
{
RelativeSizeAxes = Axes . Y ,
Width = 60 ,
FillMode = FillMode . Fit ,
} ;
}
}
2018-02-27 23:51:53 +08:00
private string toAbsoluteUrl ( string url ) = > $"{api.Endpoint}{url}" ;
2018-02-26 03:06:55 +08:00
2018-02-26 01:11:47 +08:00
private string activityToString ( )
{
switch ( activity . Type )
{
case RecentActivityType . Achievement :
2018-02-26 15:38:12 +08:00
return $"{userLinkTemplate} unlocked the {activity.Achievement.Name} medal!" ;
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 15:38:12 +08:00
// 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)
return string . Empty ;
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 ;
}
}
}
}