2019-01-24 08:43:03 +00: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 09:19:50 +00:00
2020-02-02 09:03:51 +00:00
using System.Linq ;
2018-04-13 09:19:50 +00:00
using osu.Framework.Allocation ;
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
2020-01-30 09:29:35 +00:00
using osu.Framework.Graphics.Sprites ;
2018-04-13 09:19:50 +00:00
using osu.Game.Graphics ;
using osu.Game.Graphics.Containers ;
using osu.Game.Online.API ;
using osu.Game.Online.API.Requests ;
2018-06-08 02:41:54 +00:00
using osu.Game.Online.API.Requests.Responses ;
2018-04-13 09:19:50 +00:00
using osu.Game.Online.Chat ;
2018-12-14 10:51:27 +00:00
using osu.Game.Online.Leaderboards ;
2020-02-02 09:03:51 +00:00
using osu.Game.Rulesets ;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Overlays.Profile.Sections.Recent
{
2020-01-29 18:01:40 +00:00
public class DrawableRecentActivity : CompositeDrawable
2018-04-13 09:19:50 +00:00
{
2020-01-30 07:54:58 +00:00
private const int font_size = 14 ;
2020-02-02 09:03:51 +00:00
[Resolved]
private IAPIProvider api { get ; set ; }
[Resolved]
private RulesetStore rulesets { get ; set ; }
2018-04-13 09:19:50 +00:00
2018-06-08 02:41:54 +00:00
private readonly APIRecentActivity activity ;
2018-04-13 09:19:50 +00:00
private LinkFlowContainer content ;
2018-06-08 02:41:54 +00:00
public DrawableRecentActivity ( APIRecentActivity activity )
2018-04-13 09:19:50 +00:00
{
this . activity = activity ;
}
[BackgroundDependencyLoader]
2020-02-02 09:03:51 +00:00
private void load ( OverlayColourProvider colourProvider )
2018-04-13 09:19:50 +00:00
{
2020-01-29 18:01:40 +00:00
RelativeSizeAxes = Axes . X ;
AutoSizeAxes = Axes . Y ;
AddInternal ( new GridContainer
2018-04-13 09:19:50 +00:00
{
RelativeSizeAxes = Axes . X ,
2020-01-29 18:01:40 +00:00
AutoSizeAxes = Axes . Y ,
ColumnDimensions = new [ ]
{
2020-01-30 08:16:58 +00:00
new Dimension ( GridSizeMode . Absolute , size : 28 ) ,
2020-01-29 18:01:40 +00: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 07:54:58 +00:00
content = new LinkFlowContainer ( t = > t . Font = OsuFont . GetFont ( size : font_size ) )
2020-01-29 18:01:40 +00: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 07:54:58 +00:00
Font = OsuFont . GetFont ( size : font_size ) ,
2020-01-29 18:01:40 +00:00
}
}
}
2018-04-13 09:19:50 +00:00
} ) ;
2020-01-30 09:29:35 +00:00
createMessage ( ) ;
2018-04-13 09:19:50 +00:00
}
2020-01-29 18:01:40 +00:00
private Drawable createIcon ( )
2018-04-13 09:19:50 +00:00
{
switch ( activity . Type )
{
case RecentActivityType . Rank :
2019-06-17 17:04:09 +00:00
return new UpdateableRank ( activity . ScoreRank )
2018-04-13 09:19:50 +00:00
{
2020-01-29 18:01:40 +00:00
RelativeSizeAxes = Axes . X ,
2020-01-30 08:16:58 +00:00
Height = 11 ,
2018-04-13 09:19:50 +00:00
FillMode = FillMode . Fit ,
2020-01-30 08:16:58 +00:00
Margin = new MarginPadding { Top = 2 }
2018-04-13 09:19:50 +00:00
} ;
case RecentActivityType . Achievement :
2019-11-29 07:19:57 +00:00
return new DelayedLoadWrapper ( new MedalIcon ( activity . Achievement . Slug )
{
2020-01-29 18:01:40 +00:00
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
2019-11-29 07:19:57 +00:00
RelativeSizeAxes = Axes . Both ,
FillMode = FillMode . Fit ,
} )
2018-04-13 09:19:50 +00:00
{
2020-01-29 18:01:40 +00:00
RelativeSizeAxes = Axes . X ,
2020-01-30 08:16:58 +00:00
Width = 0.5f ,
Height = 18
2018-04-13 09:19:50 +00:00
} ;
default :
2020-01-29 18:01:40 +00:00
return Empty ( ) ;
2018-04-13 09:19:50 +00:00
}
}
2020-01-30 09:29:35 +00:00
private void createMessage ( )
{
2018-04-13 09:19:50 +00:00
switch ( activity . Type )
{
case RecentActivityType . Achievement :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( $" unlocked the \" { activity . Achievement . Name } \ " medal!" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . BeatmapPlaycount :
2020-01-30 09:29:35 +00:00
addBeatmapLink ( ) ;
addText ( $" has been played {activity.Count} times!" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . BeatmapsetApprove :
2020-01-30 09:29:35 +00:00
addBeatmapsetLink ( ) ;
addText ( $" has been {activity.Approval.ToString().ToLowerInvariant()}!" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . BeatmapsetDelete :
2020-01-30 09:29:35 +00:00
addBeatmapsetLink ( ) ;
addText ( " has been deleted." ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . BeatmapsetRevive :
2020-01-30 09:29:35 +00:00
addBeatmapsetLink ( ) ;
addText ( " has been revived from eternal slumber by " ) ;
addUserLink ( ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . BeatmapsetUpdate :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( " has updated the beatmap " ) ;
addBeatmapsetLink ( ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . BeatmapsetUpload :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( " has submitted a new beatmap " ) ;
addBeatmapsetLink ( ) ;
2018-04-13 09:19:50 +00:00
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)
break ;
case RecentActivityType . Rank :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( $" achieved rank #{activity.Rank} on " ) ;
addBeatmapLink ( ) ;
2020-02-02 09:03:51 +00:00
addText ( $" ({getRulesetName()})" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . RankLost :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( " has lost first place on " ) ;
addBeatmapLink ( ) ;
2020-02-02 09:03:51 +00:00
addText ( $" ({getRulesetName()})" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . UserSupportAgain :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( " has once again chosen to support osu! - thanks for your generosity!" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . UserSupportFirst :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( " has become an osu!supporter - thanks for your generosity!" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . UserSupportGift :
2020-01-30 09:29:35 +00:00
addUserLink ( ) ;
addText ( " has received the gift of osu!supporter!" ) ;
2018-04-13 09:19:50 +00:00
break ;
case RecentActivityType . UsernameChange :
2020-01-30 09:29:35 +00:00
addText ( $"{activity.User?.PreviousUsername} has changed their username to " ) ;
addUserLink ( ) ;
2018-04-13 09:19:50 +00:00
break ;
}
}
2020-02-03 03:46:11 +00:00
private string getRulesetName ( ) = >
rulesets . AvailableRulesets . FirstOrDefault ( r = > r . ShortName = = activity . Mode ) ? . Name ? ? activity . Mode ;
private void addUserLink ( )
= > content . AddLink ( activity . User ? . Username , LinkAction . OpenUserProfile , getLinkArgument ( activity . User ? . Url ) , creationParameters : t = > t . Font = getLinkFont ( FontWeight . Bold ) ) ;
private void addBeatmapLink ( )
= > content . AddLink ( activity . Beatmap ? . Title , LinkAction . OpenBeatmap , getLinkArgument ( activity . Beatmap ? . Url ) , creationParameters : t = > t . Font = getLinkFont ( ) ) ;
private void addBeatmapsetLink ( )
= > content . AddLink ( activity . Beatmapset ? . Title , LinkAction . OpenBeatmapSet , getLinkArgument ( activity . Beatmapset ? . Url ) , creationParameters : t = > t . Font = getLinkFont ( ) ) ;
private string getLinkArgument ( string url ) = > MessageFormatter . GetLinkDetails ( $"{api.Endpoint}{url}" ) . Argument ;
private FontUsage getLinkFont ( FontWeight fontWeight = FontWeight . Regular )
= > OsuFont . GetFont ( size : font_size , weight : fontWeight , italics : true ) ;
private void addText ( string text )
= > content . AddText ( text , t = > t . Font = OsuFont . GetFont ( size : font_size , weight : FontWeight . SemiBold ) ) ;
2018-04-13 09:19:50 +00:00
}
}