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 ;
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
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
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
} ) ;
2018-03-08 11:57:12 +08:00
RightFlowContainer . Add ( new DrawableDate ( activity . CreatedAt )
2018-02-26 01:11:47 +08:00
{
2018-03-08 11:57:12 +08:00
TextSize = 13 ,
Colour = OsuColour . Gray ( 0xAA ) ,
2018-02-26 01:11:47 +08:00
Anchor = Anchor . TopRight ,
Origin = Anchor . TopRight ,
} ) ;
2018-02-26 03:06:55 +08:00
2018-03-04 02:31:47 +08:00
var formatted = createMessage ( ) ;
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-03-04 02:31:47 +08:00
private MessageFormatter . MessageFormatterResult createMessage ( )
2018-02-26 01:11:47 +08:00
{
2018-03-04 02:31:47 +08:00
string userLinkTemplate ( ) = > $"[{toAbsoluteUrl(activity.User?.Url)} {activity.User?.Username}]" ;
string beatmapLinkTemplate ( ) = > $"[{toAbsoluteUrl(activity.Beatmap?.Url)} {activity.Beatmap?.Title}]" ;
string beatmapsetLinkTemplate ( ) = > $"[{toAbsoluteUrl(activity.Beatmapset?.Url)} {activity.Beatmapset?.Title}]" ;
string message ;
2018-02-26 01:11:47 +08:00
switch ( activity . Type )
{
case RecentActivityType . Achievement :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} unlocked the {activity.Achievement.Name} medal!" ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . BeatmapPlaycount :
2018-03-04 02:31:47 +08:00
message = $"{beatmapLinkTemplate()} has been played {activity.Count} times!" ;
break ;
2018-02-26 01:11:47 +08:00
2018-02-26 14:16:16 +08:00
case RecentActivityType . BeatmapsetApprove :
2018-03-04 02:31:47 +08:00
message = $"{beatmapsetLinkTemplate()} has been {activity.Approval.ToString().ToLowerInvariant()}!" ;
break ;
2018-02-26 14:16:16 +08:00
2018-02-26 01:11:47 +08:00
case RecentActivityType . BeatmapsetDelete :
2018-03-04 02:31:47 +08:00
message = $"{beatmapsetLinkTemplate()} has been deleted." ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . BeatmapsetRevive :
2018-03-04 02:31:47 +08:00
message = $"{beatmapsetLinkTemplate()} has been revived from eternal slumber by {userLinkTemplate()}." ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . BeatmapsetUpdate :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} has updated the beatmap {beatmapsetLinkTemplate()}!" ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . BeatmapsetUpload :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} has submitted a new beatmap {beatmapsetLinkTemplate()}!" ;
break ;
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)
2018-03-04 02:31:47 +08:00
message = string . Empty ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . Rank :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} achieved rank #{activity.Rank} on {beatmapLinkTemplate()} ({activity.Mode}!)" ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . RankLost :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} has lost first place on {beatmapLinkTemplate()} ({activity.Mode}!)" ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . UserSupportAgain :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} has once again chosen to support osu! - thanks for your generosity!" ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . UserSupportFirst :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} has become an osu! supporter - thanks for your generosity!" ;
break ;
2018-02-26 01:11:47 +08:00
case RecentActivityType . UserSupportGift :
2018-03-04 02:31:47 +08:00
message = $"{userLinkTemplate()} has received the gift of osu! supporter!" ;
break ;
2018-02-26 01:11:47 +08:00
2018-02-26 14:16:16 +08:00
case RecentActivityType . UsernameChange :
2018-03-04 02:31:47 +08:00
message = $"{activity.User?.PreviousUsername} has changed their username to {userLinkTemplate()}!" ;
break ;
2018-02-26 14:16:16 +08:00
2018-02-26 01:11:47 +08:00
default :
2018-03-04 02:31:47 +08:00
message = string . Empty ;
break ;
2018-02-26 01:11:47 +08:00
}
2018-03-04 02:31:47 +08:00
return MessageFormatter . FormatText ( message ) ;
2018-02-26 01:11:47 +08:00
}
}
}