2019-01-24 16:43:03 +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.
2018-04-13 17:19:50 +08:00
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 ;
using osu.Game.Online.API.Requests ;
2018-06-08 10:41:54 +08:00
using osu.Game.Online.API.Requests.Responses ;
2018-04-13 17:19:50 +08:00
using osu.Game.Online.Chat ;
2018-12-14 18:51:27 +08:00
using osu.Game.Online.Leaderboards ;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Profile.Sections.Recent
{
2020-01-30 02:01:40 +08:00
public class DrawableRecentActivity : CompositeDrawable
2018-04-13 17:19:50 +08:00
{
2020-01-30 15:54:58 +08:00
private const int font_size = 14 ;
2019-03-13 11:56:47 +08:00
private IAPIProvider api ;
2018-04-13 17:19:50 +08:00
2018-06-08 10:41:54 +08:00
private readonly APIRecentActivity activity ;
2018-04-13 17:19:50 +08:00
private LinkFlowContainer content ;
2018-06-08 10:41:54 +08:00
public DrawableRecentActivity ( APIRecentActivity activity )
2018-04-13 17:19:50 +08:00
{
this . activity = activity ;
}
[BackgroundDependencyLoader]
2020-01-30 02:01:40 +08:00
private void load ( IAPIProvider api , OverlayColourProvider colourProvider )
2018-04-13 17:19:50 +08:00
{
this . api = api ;
2020-01-30 02:01:40 +08:00
RelativeSizeAxes = Axes . X ;
AutoSizeAxes = Axes . Y ;
AddInternal ( new GridContainer
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes . X ,
2020-01-30 02:01:40 +08:00
AutoSizeAxes = Axes . Y ,
ColumnDimensions = new [ ]
{
2020-01-30 16:16:58 +08:00
new Dimension ( GridSizeMode . Absolute , size : 28 ) ,
2020-01-30 02:01:40 +08:00
new Dimension ( ) ,
new Dimension ( GridSizeMode . AutoSize )
} ,
RowDimensions = new [ ]
{
new Dimension ( GridSizeMode . AutoSize )
} ,
Content = new [ ]
{
new Drawable [ ]
{
new Container
{
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y ,
Child = createIcon ( ) . With ( icon = >
{
icon . Anchor = Anchor . Centre ;
icon . Origin = Anchor . Centre ;
} )
} ,
2020-01-30 15:54:58 +08:00
content = new LinkFlowContainer ( t = > t . Font = OsuFont . GetFont ( size : font_size ) )
2020-01-30 02:01:40 +08:00
{
Anchor = Anchor . CentreLeft ,
Origin = Anchor . CentreLeft ,
AutoSizeAxes = Axes . Y ,
RelativeSizeAxes = Axes . X ,
} ,
new DrawableDate ( activity . CreatedAt )
{
Anchor = Anchor . CentreRight ,
Origin = Anchor . CentreRight ,
Colour = colourProvider . Foreground1 ,
2020-01-30 15:54:58 +08:00
Font = OsuFont . GetFont ( size : font_size ) ,
2020-01-30 02:01:40 +08:00
}
}
}
2018-04-13 17:19:50 +08:00
} ) ;
var formatted = createMessage ( ) ;
content . AddLinks ( formatted . Text , formatted . Links ) ;
}
2020-01-30 02:01:40 +08:00
private Drawable createIcon ( )
2018-04-13 17:19:50 +08:00
{
switch ( activity . Type )
{
case RecentActivityType . Rank :
2019-06-18 01:04:09 +08:00
return new UpdateableRank ( activity . ScoreRank )
2018-04-13 17:19:50 +08:00
{
2020-01-30 02:01:40 +08:00
RelativeSizeAxes = Axes . X ,
2020-01-30 16:16:58 +08:00
Height = 11 ,
2018-04-13 17:19:50 +08:00
FillMode = FillMode . Fit ,
2020-01-30 16:16:58 +08:00
Margin = new MarginPadding { Top = 2 }
2018-04-13 17:19:50 +08:00
} ;
case RecentActivityType . Achievement :
2019-11-29 15:19:57 +08:00
return new DelayedLoadWrapper ( new MedalIcon ( activity . Achievement . Slug )
{
2020-01-30 02:01:40 +08:00
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
2019-11-29 15:19:57 +08:00
RelativeSizeAxes = Axes . Both ,
FillMode = FillMode . Fit ,
} )
2018-04-13 17:19:50 +08:00
{
2020-01-30 02:01:40 +08:00
RelativeSizeAxes = Axes . X ,
2020-01-30 16:16:58 +08:00
Width = 0.5f ,
Height = 18
2018-04-13 17:19:50 +08:00
} ;
default :
2020-01-30 02:01:40 +08:00
return Empty ( ) ;
2018-04-13 17:19:50 +08:00
}
}
private string toAbsoluteUrl ( string url ) = > $"{api.Endpoint}{url}" ;
private MessageFormatter . MessageFormatterResult createMessage ( )
{
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 ;
switch ( activity . Type )
{
case RecentActivityType . Achievement :
message = $"{userLinkTemplate()} unlocked the {activity.Achievement.Name} medal!" ;
break ;
case RecentActivityType . BeatmapPlaycount :
message = $"{beatmapLinkTemplate()} has been played {activity.Count} times!" ;
break ;
case RecentActivityType . BeatmapsetApprove :
message = $"{beatmapsetLinkTemplate()} has been {activity.Approval.ToString().ToLowerInvariant()}!" ;
break ;
case RecentActivityType . BeatmapsetDelete :
message = $"{beatmapsetLinkTemplate()} has been deleted." ;
break ;
case RecentActivityType . BeatmapsetRevive :
message = $"{beatmapsetLinkTemplate()} has been revived from eternal slumber by {userLinkTemplate()}." ;
break ;
case RecentActivityType . BeatmapsetUpdate :
message = $"{userLinkTemplate()} has updated the beatmap {beatmapsetLinkTemplate()}!" ;
break ;
case RecentActivityType . BeatmapsetUpload :
message = $"{userLinkTemplate()} has submitted a new beatmap {beatmapsetLinkTemplate()}!" ;
break ;
case RecentActivityType . Medal :
// 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)
message = string . Empty ;
break ;
case RecentActivityType . Rank :
message = $"{userLinkTemplate()} achieved rank #{activity.Rank} on {beatmapLinkTemplate()} ({activity.Mode}!)" ;
break ;
case RecentActivityType . RankLost :
message = $"{userLinkTemplate()} has lost first place on {beatmapLinkTemplate()} ({activity.Mode}!)" ;
break ;
case RecentActivityType . UserSupportAgain :
message = $"{userLinkTemplate()} has once again chosen to support osu! - thanks for your generosity!" ;
break ;
case RecentActivityType . UserSupportFirst :
2018-06-28 08:57:55 +08:00
message = $"{userLinkTemplate()} has become an osu!supporter - thanks for your generosity!" ;
2018-04-13 17:19:50 +08:00
break ;
case RecentActivityType . UserSupportGift :
2018-06-28 08:57:55 +08:00
message = $"{userLinkTemplate()} has received the gift of osu!supporter!" ;
2018-04-13 17:19:50 +08:00
break ;
case RecentActivityType . UsernameChange :
message = $"{activity.User?.PreviousUsername} has changed their username to {userLinkTemplate()}!" ;
break ;
default :
message = string . Empty ;
break ;
}
return MessageFormatter . FormatText ( message ) ;
}
}
}