From 7e4bd363916f6c85b18b94807c3b83981c7f323f Mon Sep 17 00:00:00 2001 From: naoey Date: Sun, 25 Feb 2018 22:41:47 +0530 Subject: [PATCH] Create drawable and add response to profile. - Add missing JSON fields to response model - Add missing enum value --- .../GetUserRecentActivitiesRequest.cs | 21 +++- .../Sections/Recent/DrawableRecentActivity.cs | 117 ++++++++++++++++++ .../PaginatedRecentActivityContainer.cs | 59 ++++----- osu.Game/osu.Game.csproj | 1 + 4 files changed, 161 insertions(+), 37 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Sections/Recent/DrawableRecentActivity.cs diff --git a/osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs b/osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs index cb7d0323f4..14997b070b 100644 --- a/osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs +++ b/osu.Game/Online/API/Requests/GetUserRecentActivitiesRequest.cs @@ -7,12 +7,21 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using osu.Game.Rulesets; -using osu.Game.Overlays.Profile.Sections.Recent; namespace osu.Game.Online.API.Requests { public class GetUserRecentActivitiesRequest : APIRequest> { + private readonly long userId; + private readonly int offset; + + public GetUserRecentActivitiesRequest(long userId, int offset = 0) + { + this.userId = userId; + this.offset = offset; + } + + protected override string Target => $"users/{userId}/recent_activity?offset={offset}"; } public class RecentActivity @@ -42,6 +51,9 @@ namespace osu.Game.Online.API.Requests [JsonProperty("rank")] public int Rank; + [JsonProperty("count")] + public int Count; + [JsonProperty("mode")] public string Mode; @@ -51,6 +63,9 @@ namespace osu.Game.Online.API.Requests [JsonProperty("user")] public RecentActivityUser User; + [JsonProperty("achivementName")] + public string AchivementName; + public class RecentActivityBeatmap { [JsonProperty("title")] @@ -67,6 +82,9 @@ namespace osu.Game.Online.API.Requests [JsonProperty("url")] public string Url; + + [JsonProperty("previousUsername")] + public string PreviousUsername; } } @@ -78,6 +96,7 @@ namespace osu.Game.Online.API.Requests BeatmapsetDelete, BeatmapsetRevive, BeatmapsetUpdate, + BeatmapsetUpload, Medal, Rank, RankLost, diff --git a/osu.Game/Overlays/Profile/Sections/Recent/DrawableRecentActivity.cs b/osu.Game/Overlays/Profile/Sections/Recent/DrawableRecentActivity.cs new file mode 100644 index 0000000000..e0f7a97140 --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/Recent/DrawableRecentActivity.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Online.API.Requests; +using osu.Game.Screens.Select.Leaderboards; +using osu.Game.Users; + +namespace osu.Game.Overlays.Profile.Sections.Recent +{ + public class DrawableRecentActivity : DrawableProfileRow + { + private RecentActivity activity; + private User user; + + public DrawableRecentActivity(RecentActivity activity, User user) + { + this.activity = activity; + this.user = user; + } + + [BackgroundDependencyLoader] + private void load() + { + LeftFlowContainer.Add(new OsuSpriteText + { + Text = activityToString(), + }); + + 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), + }); + } + + protected override Drawable CreateLeftVisual() + { + switch (activity.Type) + { + case RecentActivityType.Rank: + return new DrawableRank(activity.ScoreRank) + { + RelativeSizeAxes = Axes.Y, + Width = 60, + FillMode = FillMode.Fit, + }; + + default: + return new Container + { + RelativeSizeAxes = Axes.Y, + Width = 60, + FillMode = FillMode.Fit, + }; + } + } + + private string activityToString() + { + switch (activity.Type) + { + case RecentActivityType.Achievement: + return $"{activity.User.Username} unlocked the {activity.AchivementName} achievement!"; + + case RecentActivityType.BeatmapPlaycount: + return $"{activity.Beatmap.Title} has been played {activity.Count} times!"; + + case RecentActivityType.BeatmapsetDelete: + return $"{activity.Beatmap.Title} has been deleted."; + + case RecentActivityType.BeatmapsetRevive: + return $"{activity.Beatmap.Title} has been revived from eternal slumber by ${activity.User.Username}"; + + case RecentActivityType.BeatmapsetUpdate: + return $"{activity.User.Username} has updated the beatmap ${activity.Beatmap.Title}"; + + case RecentActivityType.BeatmapsetUpload: + return $"{activity.User.Username} has submitted a new beatmap ${activity.Beatmap.Title}"; + + case RecentActivityType.Medal: + return $"{activity.User.Username} has unlocked the {activity.AchivementName} medal!"; + + case RecentActivityType.Rank: + return $"{activity.User.Username} achieved rank #{activity.Rank} on {activity.Beatmap?.Title}"; + + case RecentActivityType.RankLost: + return $"{activity.User.Username} has lost first place on {activity.Beatmap.Title}!"; + + case RecentActivityType.UserSupportAgain: + return $"{activity.User.Username} has once again chosen to support osu! - thanks for your generosity!"; + + case RecentActivityType.UserSupportFirst: + return $"{activity.User.Username} has become an osu! supporter - thanks for your generosity!"; + + case RecentActivityType.UsernameChange: + return $"{activity.User.PreviousUsername} has changed their username to {activity.User.Username}"; + + case RecentActivityType.UserSupportGift: + return $"{activity.User.Username} has received the gift of osu! supporter!"; + + default: + return string.Empty; + } + } + } +} diff --git a/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs index 11b48ad68e..307c06b744 100644 --- a/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Recent/PaginatedRecentActivityContainer.cs @@ -1,5 +1,7 @@ using osu.Framework.Configuration; +using osu.Framework.Graphics; using osu.Game.Online.API.Requests; +using osu.Game.Overlays.Profile.Sections.Recent; using osu.Game.Users; using System; using System.Collections.Generic; @@ -17,47 +19,32 @@ namespace osu.Game.Overlays.Profile.Sections ItemsPerPage = 5; } - //protected override void ShowMore() - //{ - // base.ShowMore(); + protected override void ShowMore() + { + base.ShowMore(); - // var req = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage); + var req = new GetUserRecentActivitiesRequest(User.Value.Id, VisiblePages++ * ItemsPerPage); - // req.Success += scores => - // { - // foreach (var s in scores) - // s.ApplyRuleset(Rulesets.GetRuleset(s.OnlineRulesetID)); + req.Success += activities => + { + ShowMoreButton.FadeTo(activities.Count == ItemsPerPage ? 1 : 0); + ShowMoreLoading.Hide(); - // ShowMoreButton.FadeTo(scores.Count == ItemsPerPage ? 1 : 0); - // ShowMoreLoading.Hide(); + if (!activities.Any() && VisiblePages == 1) + { + MissingText.Show(); + return; + } - // if (!scores.Any() && VisiblePages == 1) - // { - // MissingText.Show(); - // return; - // } + MissingText.Hide(); - // MissingText.Hide(); + foreach (RecentActivity activity in activities) + { + ItemsContainer.Add(new DrawableRecentActivity(activity, User)); + } + }; - // foreach (OnlineScore score in scores) - // { - // DrawableProfileScore drawableScore; - - // switch (type) - // { - // default: - // drawableScore = new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, ItemsContainer.Count) : (double?)null); - // break; - // case ScoreType.Recent: - // drawableScore = new DrawableTotalScore(score); - // break; - // } - - // ItemsContainer.Add(drawableScore); - // } - // }; - - // Api.Queue(req); - //} + Api.Queue(req); + } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index ad9105f1e8..cd40b42365 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -300,6 +300,7 @@ 20180125143340_Settings.cs +