diff --git a/osu-framework b/osu-framework index 5986f21268..ef10edfc75 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 5986f2126832451a5a7ec832a483e1dcec1b38b8 +Subproject commit ef10edfc750b39258edbff46019f1d10700548c2 diff --git a/osu.Desktop.Deploy/Program.cs b/osu.Desktop.Deploy/Program.cs index d52be70b6e..54fb50d0f8 100644 --- a/osu.Desktop.Deploy/Program.cs +++ b/osu.Desktop.Deploy/Program.cs @@ -390,7 +390,7 @@ namespace osu.Desktop.Deploy public static void AuthenticatedBlockingPerform(this WebRequest r) { - r.Headers.Add("Authorization", $"token {GitHubAccessToken}"); + r.AddHeader("Authorization", $"token {GitHubAccessToken}"); r.Perform(); } } diff --git a/osu.Game.Tests/Visual/TestCaseUserRanks.cs b/osu.Game.Tests/Visual/TestCaseUserRanks.cs index 9667897a7d..e17f0e1a46 100644 --- a/osu.Game.Tests/Visual/TestCaseUserRanks.cs +++ b/osu.Game.Tests/Visual/TestCaseUserRanks.cs @@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual } }); - AddStep("Show cookiezi", () => ranks.User = new User { Id = 124493 }); + AddStep("Show cookiezi", () => ranks.User.Value = new User { Id = 124493 }); } } } diff --git a/osu.Game/Online/API/APIRequest.cs b/osu.Game/Online/API/APIRequest.cs index 9a8180778d..71b18103b0 100644 --- a/osu.Game/Online/API/APIRequest.cs +++ b/osu.Game/Online/API/APIRequest.cs @@ -36,7 +36,7 @@ namespace osu.Game.Online.API return request; } - private void request_Progress(WebRequest request, long current, long total) => API.Scheduler.Add(delegate { Progress?.Invoke(current, total); }); + private void request_Progress(long current, long total) => API.Scheduler.Add(delegate { Progress?.Invoke(current, total); }); protected APIDownloadRequest() { @@ -99,8 +99,8 @@ namespace osu.Game.Online.API throw new TimeoutException(@"API request timeout hit"); WebRequest = CreateWebRequest(); - WebRequest.RetryCount = 0; - WebRequest.Headers[@"Authorization"] = $@"Bearer {api.AccessToken}"; + WebRequest.AllowRetryOnTimeout = false; + WebRequest.AddHeader("Authorization", $"Bearer {api.AccessToken}"); if (checkAndProcessFailure()) return; diff --git a/osu.Game/Online/API/OAuth.cs b/osu.Game/Online/API/OAuth.cs index 445688f2ce..2e00fe6f1b 100644 --- a/osu.Game/Online/API/OAuth.cs +++ b/osu.Game/Online/API/OAuth.cs @@ -127,7 +127,8 @@ namespace osu.Game.Online.API protected override void PrePerform() { - Parameters[@"refresh_token"] = RefreshToken; + AddParameter("refresh_token", RefreshToken); + base.PrePerform(); } } @@ -146,8 +147,9 @@ namespace osu.Game.Online.API protected override void PrePerform() { - Parameters[@"username"] = Username; - Parameters[@"password"] = Password; + AddParameter("username", Username); + AddParameter("password", Password); + base.PrePerform(); } } @@ -161,9 +163,10 @@ namespace osu.Game.Online.API protected override void PrePerform() { - Parameters[@"grant_type"] = GrantType; - Parameters[@"client_id"] = ClientId; - Parameters[@"client_secret"] = ClientSecret; + AddParameter("grant_type", GrantType); + AddParameter("client_id", ClientId); + AddParameter("client_secret", ClientSecret); + base.PrePerform(); } } diff --git a/osu.Game/Overlays/Profile/ProfileSection.cs b/osu.Game/Overlays/Profile/ProfileSection.cs index df7c0e117f..99178570a6 100644 --- a/osu.Game/Overlays/Profile/ProfileSection.cs +++ b/osu.Game/Overlays/Profile/ProfileSection.cs @@ -9,6 +9,7 @@ using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Users; using OpenTK.Graphics; +using osu.Framework.Configuration; namespace osu.Game.Overlays.Profile { @@ -22,13 +23,7 @@ namespace osu.Game.Overlays.Profile protected override Container Content => content; - public virtual User User - { - get { return user; } - set { user = value; } - } - - private User user; + public readonly Bindable User = new Bindable(); protected ProfileSection() { diff --git a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs index 78ed6bf846..d25407f4a3 100644 --- a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs +++ b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs @@ -1,6 +1,9 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Online.API.Requests; +using osu.Game.Overlays.Profile.Sections.Ranks; + namespace osu.Game.Overlays.Profile.Sections { public class HistoricalSection : ProfileSection @@ -8,5 +11,10 @@ namespace osu.Game.Overlays.Profile.Sections public override string Title => "Historical"; public override string Identifier => "historical"; + + public HistoricalSection() + { + Child = new PaginatedScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)"); + } } } diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawablePerformanceScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawablePerformanceScore.cs new file mode 100644 index 0000000000..0380b6c4b7 --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawablePerformanceScore.cs @@ -0,0 +1,49 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets.Scoring; + +namespace osu.Game.Overlays.Profile.Sections.Ranks +{ + public class DrawablePerformanceScore : DrawableScore + { + private readonly double? weight; + + public DrawablePerformanceScore(Score score, double? weight = null) + : base(score) + { + this.weight = weight; + } + + [BackgroundDependencyLoader] + private new void load(OsuColour colour) + { + double pp = Score.PP ?? 0; + Stats.Add(new OsuSpriteText + { + Text = $"{pp:0}pp", + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + TextSize = 18, + Font = "Exo2.0-BoldItalic", + }); + + if (weight.HasValue) + { + Stats.Add(new OsuSpriteText + { + Text = $"weighted: {pp * weight:0}pp ({weight:P0})", + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + Colour = colour.GrayA, + TextSize = 11, + Font = "Exo2.0-RegularItalic", + }); + } + } + } +} diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index af336c2529..91f5650b92 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -18,18 +18,16 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Overlays.Profile.Sections.Ranks { - public class DrawableScore : Container + public abstract class DrawableScore : Container { - private readonly FillFlowContainer stats; + protected readonly FillFlowContainer Stats; private readonly FillFlowContainer metadata; private readonly ModContainer modContainer; - private readonly Score score; - private readonly double? weight; + protected readonly Score Score; - public DrawableScore(Score score, double? weight = null) + protected DrawableScore(Score score) { - this.score = score; - this.weight = weight; + Score = score; Children = new Drawable[] { @@ -39,7 +37,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks Width = 60, FillMode = FillMode.Fit, }, - stats = new FillFlowContainer + Stats = new FillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, @@ -74,40 +72,18 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks }; } - [BackgroundDependencyLoader] + [BackgroundDependencyLoader(true)] private void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) { - double pp = score.PP ?? 0; - stats.Add(new OsuSpriteText + Stats.Add(new OsuSpriteText { - Text = $"{pp:0}pp", - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - TextSize = 18, - Font = "Exo2.0-BoldItalic", - }); - - if (weight.HasValue) - { - stats.Add(new OsuSpriteText - { - Text = $"weighted: {pp * weight:0}pp ({weight:P0})", - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight, - Colour = colour.GrayA, - TextSize = 11, - Font = "Exo2.0-RegularItalic", - }); - } - - stats.Add(new OsuSpriteText - { - Text = $"accuracy: {score.Accuracy:P2}", + Text = $"accuracy: {Score.Accuracy:P2}", Anchor = Anchor.TopRight, Origin = Anchor.TopRight, Colour = colour.GrayA, TextSize = 11, Font = "Exo2.0-RegularItalic", + Depth = -1, }); metadata.Add(new OsuHoverContainer @@ -115,7 +91,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks AutoSizeAxes = Axes.Both, Action = () => { - if (score.Beatmap.OnlineBeatmapSetID.HasValue) beatmapSetOverlay.ShowBeatmapSet(score.Beatmap.OnlineBeatmapSetID.Value); + if (Score.Beatmap.OnlineBeatmapSetID.HasValue) beatmapSetOverlay?.ShowBeatmapSet(Score.Beatmap.OnlineBeatmapSetID.Value); }, Child = new FillFlowContainer { @@ -125,15 +101,15 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks new OsuSpriteText { Current = locale.GetUnicodePreference( - $"{score.Beatmap.Metadata.TitleUnicode ?? score.Beatmap.Metadata.Title} [{score.Beatmap.Version}] ", - $"{score.Beatmap.Metadata.Title ?? score.Beatmap.Metadata.TitleUnicode} [{score.Beatmap.Version}] " + $"{Score.Beatmap.Metadata.TitleUnicode ?? Score.Beatmap.Metadata.Title} [{Score.Beatmap.Version}] ", + $"{Score.Beatmap.Metadata.Title ?? Score.Beatmap.Metadata.TitleUnicode} [{Score.Beatmap.Version}] " ), TextSize = 15, Font = "Exo2.0-SemiBoldItalic", }, new OsuSpriteText { - Current = locale.GetUnicodePreference(score.Beatmap.Metadata.ArtistUnicode, score.Beatmap.Metadata.Artist), + Current = locale.GetUnicodePreference(Score.Beatmap.Metadata.ArtistUnicode, Score.Beatmap.Metadata.Artist), TextSize = 12, Padding = new MarginPadding { Top = 3 }, Font = "Exo2.0-RegularItalic", @@ -142,7 +118,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks }, }); - foreach (Mod mod in score.Mods) + foreach (Mod mod in Score.Mods) modContainer.Add(new ModIcon(mod) { AutoSizeAxes = Axes.Both, diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableTotalScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableTotalScore.cs new file mode 100644 index 0000000000..7aa9d75f02 --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableTotalScore.cs @@ -0,0 +1,31 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets.Scoring; + +namespace osu.Game.Overlays.Profile.Sections.Ranks +{ + public class DrawableTotalScore : DrawableScore + { + public DrawableTotalScore(Score score) + : base(score) + { + } + + [BackgroundDependencyLoader] + private new void load() + { + Stats.Add(new OsuSpriteText + { + Text = Score.TotalScore.ToString("#,###"), + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, + TextSize = 18, + Font = "Exo2.0-BoldItalic", + }); + } + } +} diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs new file mode 100644 index 0000000000..060bb03014 --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -0,0 +1,153 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Rulesets; +using osu.Game.Users; +using System; +using System.Linq; + +namespace osu.Game.Overlays.Profile.Sections.Ranks +{ + public class PaginatedScoreContainer : FillFlowContainer + { + private readonly FillFlowContainer scoreContainer; + private readonly OsuSpriteText missing; + private readonly OsuHoverContainer showMoreButton; + private readonly LoadingAnimation showMoreLoading; + + private readonly bool includeWeight; + private readonly ScoreType type; + private int visiblePages; + + private readonly Bindable user = new Bindable(); + + private RulesetStore rulesets; + private APIAccess api; + + public PaginatedScoreContainer(ScoreType type, Bindable user, string header, bool includeWeight = false) + { + this.type = type; + this.includeWeight = includeWeight; + this.user.BindTo(user); + + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + Direction = FillDirection.Vertical; + + Children = new Drawable[] + { + new OsuSpriteText + { + TextSize = 15, + Text = header, + Font = "Exo2.0-RegularItalic", + Margin = new MarginPadding { Top = 10, Bottom = 10 }, + }, + scoreContainer = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + }, + showMoreButton = new OsuHoverContainer + { + Alpha = 0, + Action = showMore, + AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Child = new OsuSpriteText + { + TextSize = 14, + Text = "show more", + } + }, + showMoreLoading = new LoadingAnimation + { + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Size = new Vector2(14), + }, + missing = new OsuSpriteText + { + TextSize = 14, + Text = type == ScoreType.Recent ? "No performance records. :(" : "No awesome performance records yet. :(", + }, + }; + } + + [BackgroundDependencyLoader] + private void load(APIAccess api, RulesetStore rulesets) + { + this.api = api; + this.rulesets = rulesets; + + user.ValueChanged += user_ValueChanged; + user.TriggerChange(); + } + + private void user_ValueChanged(User newUser) + { + visiblePages = 0; + scoreContainer.Clear(); + showMoreButton.Hide(); + missing.Show(); + + if (newUser != null) + showMore(); + } + + private void showMore() + { + var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5); + + showMoreLoading.Show(); + showMoreButton.Hide(); + + req.Success += scores => + { + foreach (var s in scores) + s.ApplyRuleset(rulesets.GetRuleset(s.OnlineRulesetID)); + + showMoreButton.FadeTo(scores.Count == 5 ? 1 : 0); + showMoreLoading.Hide(); + + if (!scores.Any()) return; + + missing.Hide(); + + foreach (OnlineScore score in scores) + { + DrawableScore drawableScore; + + switch (type) + { + default: + drawableScore = new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); + break; + case ScoreType.Recent: + drawableScore = new DrawableTotalScore(score); + break; + } + + drawableScore.RelativeSizeAxes = Axes.X; + drawableScore.Height = 60; + + scoreContainer.Add(drawableScore); + } + }; + + api.Queue(req); + } + } +} diff --git a/osu.Game/Overlays/Profile/Sections/RanksSection.cs b/osu.Game/Overlays/Profile/Sections/RanksSection.cs index 3b2c9d83ed..553691ef77 100644 --- a/osu.Game/Overlays/Profile/Sections/RanksSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RanksSection.cs @@ -1,20 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Game.Graphics.Containers; -using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Profile.Sections.Ranks; -using System; -using System.Linq; -using osu.Game.Online.API; using osu.Game.Online.API.Requests; -using osu.Game.Rulesets; -using osu.Game.Users; -using osu.Game.Graphics.UserInterface; -using OpenTK; -using osu.Framework.Allocation; namespace osu.Game.Overlays.Profile.Sections { @@ -24,147 +12,13 @@ namespace osu.Game.Overlays.Profile.Sections public override string Identifier => "top_ranks"; - private readonly ScoreContainer best, first; - public RanksSection() { - Children = new Drawable[] + Children = new[] { - best = new ScoreContainer(ScoreType.Best, "Best Performance", true), - first = new ScoreContainer(ScoreType.Firsts, "First Place Ranks"), + new PaginatedScoreContainer(ScoreType.Best, User, "Best Performance", true), + new PaginatedScoreContainer(ScoreType.Firsts, User, "First Place Ranks"), }; } - - public override User User - { - get - { - return base.User; - } - - set - { - base.User = value; - best.User = value; - first.User = value; - } - } - - private class ScoreContainer : FillFlowContainer - { - private readonly FillFlowContainer scoreContainer; - private readonly OsuSpriteText missing; - private readonly OsuHoverContainer showMoreButton; - private readonly LoadingAnimation showMoreLoading; - - private readonly ScoreType type; - private int visiblePages; - private User user; - private readonly bool includeWeigth; - - private RulesetStore rulesets; - private APIAccess api; - - public User User - { - set - { - user = value; - visiblePages = 0; - scoreContainer.Clear(); - showMoreButton.Hide(); - missing.Show(); - showMore(); - } - } - - public ScoreContainer(ScoreType type, string header, bool includeWeigth = false) - { - this.type = type; - this.includeWeigth = includeWeigth; - - RelativeSizeAxes = Axes.X; - AutoSizeAxes = Axes.Y; - Direction = FillDirection.Vertical; - - Children = new Drawable[] - { - new OsuSpriteText - { - TextSize = 15, - Text = header, - Font = "Exo2.0-RegularItalic", - Margin = new MarginPadding { Top = 10, Bottom = 10 }, - }, - scoreContainer = new FillFlowContainer - { - AutoSizeAxes = Axes.Y, - RelativeSizeAxes = Axes.X, - Direction = FillDirection.Vertical, - }, - showMoreButton = new OsuHoverContainer - { - Alpha = 0, - Action = showMore, - AutoSizeAxes = Axes.Both, - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Child = new OsuSpriteText - { - TextSize = 14, - Text = "show more", - } - }, - showMoreLoading = new LoadingAnimation - { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - Size = new Vector2(14), - }, - missing = new OsuSpriteText - { - TextSize = 14, - Text = "No awesome performance records yet. :(", - }, - }; - } - - [BackgroundDependencyLoader] - private void load(APIAccess api, RulesetStore rulesets) - { - this.api = api; - this.rulesets = rulesets; - } - - private void showMore() - { - var req = new GetUserScoresRequest(user.Id, type, visiblePages++ * 5); - - showMoreLoading.Show(); - showMoreButton.Hide(); - - req.Success += scores => - { - foreach (var s in scores) - s.ApplyRuleset(rulesets.GetRuleset(s.OnlineRulesetID)); - - showMoreButton.FadeTo(scores.Count == 5 ? 1 : 0); - showMoreLoading.Hide(); - - if (scores.Any()) - { - missing.Hide(); - foreach (OnlineScore score in scores) - scoreContainer.Add(new DrawableScore(score, includeWeigth ? Math.Pow(0.95, scoreContainer.Count) : (double?)null) - { - RelativeSizeAxes = Axes.X, - Height = 60, - }); - } - }; - - Schedule(() => { api.Queue(req); }); - } - } } } diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index e6c45f6826..5032f2d55b 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -95,7 +95,7 @@ namespace osu.Game.Overlays //new RecentSection(), new RanksSection(), //new MedalsSection(), - //new HistoricalSection(), + new HistoricalSection(), //new BeatmapsSection(), //new KudosuSection() }; @@ -175,7 +175,7 @@ namespace osu.Game.Overlays var sec = sections.FirstOrDefault(s => s.Identifier == id); if (sec != null) { - sec.User = user; + sec.User.Value = user; sectionsContainer.Add(sec); tabs.AddItem(sec); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index e47159bb8e..a99e97eabb 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -294,6 +294,9 @@ + + + @@ -821,4 +824,4 @@ - + \ No newline at end of file