Create drawable and add response to profile.

- Add missing JSON fields to response model
- Add missing enum value
This commit is contained in:
naoey 2018-02-25 22:41:47 +05:30
parent e3a1b07172
commit 7e4bd36391
No known key found for this signature in database
GPG Key ID: 3908EC682A3E19C7
4 changed files with 161 additions and 37 deletions

View File

@ -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<List<RecentActivity>>
{
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,

View File

@ -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;
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -300,6 +300,7 @@
<DependentUpon>20180125143340_Settings.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\20180131154205_AddMuteBinding.cs" />
<Compile Include="Overlays\Profile\Sections\Recent\DrawableRecentActivity.cs" />
<Compile Include="Overlays\Profile\Sections\Recent\PaginatedRecentActivityContainer.cs" />
<Compile Include="Overlays\Profile\SupporterIcon.cs" />
<Compile Include="Online\API\Requests\GetFriendsRequest.cs" />