From aadc699e733701ed7bb3f7eecb35463e6ce292f0 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Tue, 24 Oct 2017 20:31:38 +0200 Subject: [PATCH 01/12] show recent scores --- .../Profile/Sections/HistoricalSection.cs | 17 ++ .../Profile/Sections/Ranks/DrawableScore.cs | 84 +++++++--- .../Profile/Sections/Ranks/ScoreContainer.cs | 157 ++++++++++++++++++ .../Overlays/Profile/Sections/RanksSection.cs | 131 +-------------- osu.Game/Overlays/UserProfileOverlay.cs | 2 +- osu.Game/osu.Game.csproj | 1 + 6 files changed, 236 insertions(+), 156 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs diff --git a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs index 78ed6bf846..e38660fb45 100644 --- a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs +++ b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs @@ -1,6 +1,10 @@ // 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; +using osu.Game.Users; + namespace osu.Game.Overlays.Profile.Sections { public class HistoricalSection : ProfileSection @@ -8,5 +12,18 @@ namespace osu.Game.Overlays.Profile.Sections public override string Title => "Historical"; public override string Identifier => "historical"; + + private readonly ScoreContainer recent; + + public HistoricalSection() + { + Child = recent = new ScoreContainer.TotalScoreContainer(ScoreType.Recent, "Recent Plays (24h)", "No performance records. :("); + } + + public override User User + { + get => base.User; + set => base.User = recent.User = value; + } } } diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index af336c2529..c9ae9657e6 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -24,12 +24,10 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks private readonly FillFlowContainer metadata; private readonly ModContainer modContainer; private readonly Score score; - private readonly double? weight; - public DrawableScore(Score score, double? weight = null) + private DrawableScore(Score score) { this.score = score; - this.weight = weight; Children = new Drawable[] { @@ -77,29 +75,6 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks [BackgroundDependencyLoader] private void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) { - 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", - }); - } - stats.Add(new OsuSpriteText { Text = $"accuracy: {score.Accuracy:P2}", @@ -108,6 +83,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks Colour = colour.GrayA, TextSize = 11, Font = "Exo2.0-RegularItalic", + Depth = -1, }); metadata.Add(new OsuHoverContainer @@ -159,5 +135,61 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks yield return new Vector2(DrawWidth * i * (count == 1 ? 0 : 1f / (count - 1)), 0); } } + + public class PPScore : DrawableScore + { + private readonly double? weight; + + public PPScore(Score score, double? weight = null) : base(score) + { + this.weight = weight; + } + + [BackgroundDependencyLoader] + private new void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) + { + 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", + }); + } + } + } + + public class TotalScore : DrawableScore + { + public TotalScore(Score score) : base(score) + { } + + [BackgroundDependencyLoader] + private new void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) + { + 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/ScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs new file mode 100644 index 0000000000..840678a6bb --- /dev/null +++ b/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs @@ -0,0 +1,157 @@ +// 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.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 abstract 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 RulesetStore rulesets; + private APIAccess api; + + public User User + { + set + { + user = value; + visiblePages = 0; + scoreContainer.Clear(); + showMoreButton.Hide(); + missing.Show(); + showMore(); + } + } + + private ScoreContainer(ScoreType type, string header, string missingText) + { + this.type = type; + + 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 = missingText, + }, + }; + } + + [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) + { + var drawableScore = CreateScore(score, scoreContainer.Count); + drawableScore.RelativeSizeAxes = Axes.X; + drawableScore.Height = 60; + scoreContainer.Add(drawableScore); + } + } + }; + + Schedule(() => { api.Queue(req); }); + } + + protected abstract DrawableScore CreateScore(OnlineScore score, int index); + + public class PPScoreContainer : ScoreContainer + { + private readonly bool includeWeight; + + public PPScoreContainer(ScoreType type, string header, string missing, bool includeWeight = false) : base(type, header, missing) + { + this.includeWeight = includeWeight; + } + + protected override DrawableScore CreateScore(OnlineScore score, int index) => new DrawableScore.PPScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); + } + + public class TotalScoreContainer : ScoreContainer + { + public TotalScoreContainer(ScoreType type, string header, string missing) : base(type, header, missing) + { } + + protected override DrawableScore CreateScore(OnlineScore score, int index) => new DrawableScore.TotalScore(score); + } + } +} diff --git a/osu.Game/Overlays/Profile/Sections/RanksSection.cs b/osu.Game/Overlays/Profile/Sections/RanksSection.cs index 3b2c9d83ed..60b52f14bd 100644 --- a/osu.Game/Overlays/Profile/Sections/RanksSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RanksSection.cs @@ -2,19 +2,9 @@ // 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 { @@ -30,8 +20,8 @@ namespace osu.Game.Overlays.Profile.Sections { Children = new Drawable[] { - best = new ScoreContainer(ScoreType.Best, "Best Performance", true), - first = new ScoreContainer(ScoreType.Firsts, "First Place Ranks"), + best = new ScoreContainer.PPScoreContainer(ScoreType.Best, "Best Performance", "No awesome performance records yet. :(", true), + first = new ScoreContainer.PPScoreContainer(ScoreType.Firsts, "First Place Ranks", "No awesome performance records yet. :("), }; } @@ -49,122 +39,5 @@ namespace osu.Game.Overlays.Profile.Sections 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..25925c69cc 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() }; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 7b65aa8d66..a9116c6f15 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -289,6 +289,7 @@ + From f65d4b626e4ced159348b19ea16a291278c96632 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Tue, 24 Oct 2017 20:46:15 +0200 Subject: [PATCH 02/12] don't use c# 7 feature --- osu.Game/Overlays/Profile/Sections/HistoricalSection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs index e38660fb45..95df2bc241 100644 --- a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs +++ b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs @@ -22,8 +22,8 @@ namespace osu.Game.Overlays.Profile.Sections public override User User { - get => base.User; - set => base.User = recent.User = value; + get { return base.User; } + set { base.User = recent.User = value; } } } } From a2dfef301aafde9582364b45f6a35df838f2d27b Mon Sep 17 00:00:00 2001 From: Jorolf Date: Tue, 24 Oct 2017 20:56:05 +0200 Subject: [PATCH 03/12] remove unused parameters --- osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index c9ae9657e6..a9aaf5ee03 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -146,7 +146,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks } [BackgroundDependencyLoader] - private new void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) + private new void load(OsuColour colour) { double pp = score.PP ?? 0; stats.Add(new OsuSpriteText @@ -179,7 +179,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks { } [BackgroundDependencyLoader] - private new void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) + private new void load() { stats.Add(new OsuSpriteText { From 0449639f41dbd4f3f9205e5404358f8c931d60a4 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Wed, 25 Oct 2017 20:07:12 +0200 Subject: [PATCH 04/12] remove inner classes and make User property a bindable --- osu.Game.Tests/Visual/TestCaseUserRanks.cs | 2 +- osu.Game/Overlays/Profile/ProfileSection.cs | 9 +- .../Profile/Sections/HistoricalSection.cs | 8 +- .../Profile/Sections/Ranks/DrawableScore.cs | 111 +++++++++--------- .../Profile/Sections/Ranks/ScoreContainer.cs | 55 +++------ .../Overlays/Profile/Sections/RanksSection.cs | 19 +-- osu.Game/Overlays/UserProfileOverlay.cs | 2 +- 7 files changed, 79 insertions(+), 127 deletions(-) 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/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 95df2bc241..1af3475dff 100644 --- a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs +++ b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs @@ -17,13 +17,7 @@ namespace osu.Game.Overlays.Profile.Sections public HistoricalSection() { - Child = recent = new ScoreContainer.TotalScoreContainer(ScoreType.Recent, "Recent Plays (24h)", "No performance records. :("); - } - - public override User User - { - get { return base.User; } - set { base.User = recent.User = value; } + Child = recent = new ScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)"); } } } diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index a9aaf5ee03..c45296d866 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -20,14 +20,14 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks { public class DrawableScore : Container { - private readonly FillFlowContainer stats; + protected readonly FillFlowContainer Stats; private readonly FillFlowContainer metadata; private readonly ModContainer modContainer; - private readonly Score score; + protected readonly Score Score; - private DrawableScore(Score score) + public DrawableScore(Score score) { - this.score = score; + this.Score = score; Children = new Drawable[] { @@ -37,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, @@ -75,9 +75,9 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks [BackgroundDependencyLoader] private void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) { - stats.Add(new OsuSpriteText + Stats.Add(new OsuSpriteText { - Text = $"accuracy: {score.Accuracy:P2}", + Text = $"accuracy: {Score.Accuracy:P2}", Anchor = Anchor.TopRight, Origin = Anchor.TopRight, Colour = colour.GrayA, @@ -91,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 { @@ -101,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", @@ -118,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, @@ -135,61 +135,60 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks yield return new Vector2(DrawWidth * i * (count == 1 ? 0 : 1f / (count - 1)), 0); } } + } + public class PPScore : DrawableScore + { + private readonly double? weight; - public class PPScore : DrawableScore + public PPScore(Score score, double? weight = null) : base(score) { - private readonly double? weight; - - public PPScore(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", - }); - } - } + this.weight = weight; } - public class TotalScore : DrawableScore + [BackgroundDependencyLoader] + private new void load(OsuColour colour) { - public TotalScore(Score score) : base(score) - { } - - [BackgroundDependencyLoader] - private new void load() + 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 = score.TotalScore.ToString("#,###"), + Text = $"weighted: {pp * weight:0}pp ({weight:P0})", Anchor = Anchor.TopRight, Origin = Anchor.TopRight, - TextSize = 18, - Font = "Exo2.0-BoldItalic", + Colour = colour.GrayA, + TextSize = 11, + Font = "Exo2.0-RegularItalic", }); } } } + + public class TotalScore : DrawableScore + { + public TotalScore(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/ScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs index 840678a6bb..a7a49d826f 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs @@ -3,6 +3,7 @@ using OpenTK; using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Containers; @@ -17,36 +18,36 @@ using System.Linq; namespace osu.Game.Overlays.Profile.Sections.Ranks { - public abstract class ScoreContainer : FillFlowContainer + public class ScoreContainer : 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 User user; + private readonly Bindable user; private RulesetStore rulesets; private APIAccess api; - public User User + private void setUser(User newUser) { - set - { - user = value; - visiblePages = 0; - scoreContainer.Clear(); - showMoreButton.Hide(); - missing.Show(); - showMore(); - } + visiblePages = 0; + scoreContainer.Clear(); + showMoreButton.Hide(); + missing.Show(); + showMore(); } - private ScoreContainer(ScoreType type, string header, string missingText) + public ScoreContainer(ScoreType type, Bindable user, string header, bool includeWeight = false) { this.type = type; + this.includeWeight = includeWeight; + this.user = user; + user.ValueChanged += setUser; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -89,7 +90,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks missing = new OsuSpriteText { TextSize = 14, - Text = missingText, + Text = type == ScoreType.Recent ? "No performance records. :(" : "No awesome performance records yet. :(", }, }; } @@ -103,7 +104,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks private void showMore() { - var req = new GetUserScoresRequest(user.Id, type, visiblePages++ * 5); + var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5); showMoreLoading.Show(); showMoreButton.Hide(); @@ -121,7 +122,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks missing.Hide(); foreach (OnlineScore score in scores) { - var drawableScore = CreateScore(score, scoreContainer.Count); + var drawableScore = type == ScoreType.Recent ? (DrawableScore)new TotalScore(score) : new PPScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); drawableScore.RelativeSizeAxes = Axes.X; drawableScore.Height = 60; scoreContainer.Add(drawableScore); @@ -131,27 +132,5 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks Schedule(() => { api.Queue(req); }); } - - protected abstract DrawableScore CreateScore(OnlineScore score, int index); - - public class PPScoreContainer : ScoreContainer - { - private readonly bool includeWeight; - - public PPScoreContainer(ScoreType type, string header, string missing, bool includeWeight = false) : base(type, header, missing) - { - this.includeWeight = includeWeight; - } - - protected override DrawableScore CreateScore(OnlineScore score, int index) => new DrawableScore.PPScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); - } - - public class TotalScoreContainer : ScoreContainer - { - public TotalScoreContainer(ScoreType type, string header, string missing) : base(type, header, missing) - { } - - protected override DrawableScore CreateScore(OnlineScore score, int index) => new DrawableScore.TotalScore(score); - } } } diff --git a/osu.Game/Overlays/Profile/Sections/RanksSection.cs b/osu.Game/Overlays/Profile/Sections/RanksSection.cs index 60b52f14bd..284053a0dc 100644 --- a/osu.Game/Overlays/Profile/Sections/RanksSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RanksSection.cs @@ -20,24 +20,9 @@ namespace osu.Game.Overlays.Profile.Sections { Children = new Drawable[] { - best = new ScoreContainer.PPScoreContainer(ScoreType.Best, "Best Performance", "No awesome performance records yet. :(", true), - first = new ScoreContainer.PPScoreContainer(ScoreType.Firsts, "First Place Ranks", "No awesome performance records yet. :("), + best = new ScoreContainer(ScoreType.Best, User, "Best Performance", true), + first = new ScoreContainer(ScoreType.Firsts, User, "First Place Ranks"), }; } - - public override User User - { - get - { - return base.User; - } - - set - { - base.User = value; - best.User = value; - first.User = value; - } - } } } diff --git a/osu.Game/Overlays/UserProfileOverlay.cs b/osu.Game/Overlays/UserProfileOverlay.cs index 25925c69cc..5032f2d55b 100644 --- a/osu.Game/Overlays/UserProfileOverlay.cs +++ b/osu.Game/Overlays/UserProfileOverlay.cs @@ -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); From b2c3ba05d759668423d4314d6aa6c7c15905cf1e Mon Sep 17 00:00:00 2001 From: Jorolf Date: Wed, 25 Oct 2017 20:15:45 +0200 Subject: [PATCH 05/12] remove redundant stuff --- .../Overlays/Profile/Sections/HistoricalSection.cs | 5 +---- .../Overlays/Profile/Sections/Ranks/DrawableScore.cs | 2 +- osu.Game/Overlays/Profile/Sections/RanksSection.cs | 10 +++------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs index 1af3475dff..8bc13118b2 100644 --- a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs +++ b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs @@ -3,7 +3,6 @@ using osu.Game.Online.API.Requests; using osu.Game.Overlays.Profile.Sections.Ranks; -using osu.Game.Users; namespace osu.Game.Overlays.Profile.Sections { @@ -13,11 +12,9 @@ namespace osu.Game.Overlays.Profile.Sections public override string Identifier => "historical"; - private readonly ScoreContainer recent; - public HistoricalSection() { - Child = recent = new ScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)"); + Child = new ScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)"); } } } diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index c45296d866..3949d6ca59 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks public DrawableScore(Score score) { - this.Score = score; + Score = score; Children = new Drawable[] { diff --git a/osu.Game/Overlays/Profile/Sections/RanksSection.cs b/osu.Game/Overlays/Profile/Sections/RanksSection.cs index 284053a0dc..aeb9bdc31e 100644 --- a/osu.Game/Overlays/Profile/Sections/RanksSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RanksSection.cs @@ -1,10 +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.Game.Overlays.Profile.Sections.Ranks; using osu.Game.Online.API.Requests; -using osu.Game.Users; namespace osu.Game.Overlays.Profile.Sections { @@ -14,14 +12,12 @@ 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, User, "Best Performance", true), - first = new ScoreContainer(ScoreType.Firsts, User, "First Place Ranks"), + new ScoreContainer(ScoreType.Best, User, "Best Performance", true), + new ScoreContainer(ScoreType.Firsts, User, "First Place Ranks"), }; } } From dce7d1c910be2a46e7d533645c43e3ff4e1b8553 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 30 Oct 2017 19:05:13 +0900 Subject: [PATCH 06/12] Move pp score representation to own file --- .../Ranks/DrawablePerformanceScore.cs | 49 +++++++++++++++++++ .../Profile/Sections/Ranks/DrawableScore.cs | 42 ++-------------- .../Profile/Sections/Ranks/ScoreContainer.cs | 2 +- osu.Game/osu.Game.csproj | 3 +- 4 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Sections/Ranks/DrawablePerformanceScore.cs 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 3949d6ca59..4464a788b8 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -136,47 +136,13 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks } } } - public class PPScore : DrawableScore - { - private readonly double? weight; - - public PPScore(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", - }); - } - } - } public class TotalScore : DrawableScore { - public TotalScore(Score score) : base(score) - { } + public TotalScore(Score score) + : base(score) + { + } [BackgroundDependencyLoader] private new void load() diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs index a7a49d826f..7568aec226 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs @@ -122,7 +122,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks missing.Hide(); foreach (OnlineScore score in scores) { - var drawableScore = type == ScoreType.Recent ? (DrawableScore)new TotalScore(score) : new PPScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); + var drawableScore = type == ScoreType.Recent ? (DrawableScore)new TotalScore(score) : new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); drawableScore.RelativeSizeAxes = Axes.X; drawableScore.Height = 60; scoreContainer.Add(drawableScore); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 37148dfa31..262e94f6dd 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -294,6 +294,7 @@ + @@ -822,4 +823,4 @@ - + \ No newline at end of file From b660366d969ff9e4a297e7fd20aa2c83ad187ef2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 30 Oct 2017 19:06:40 +0900 Subject: [PATCH 07/12] ScoreContainer -> PaginatedScoreContainer --- osu.Game/Overlays/Profile/Sections/HistoricalSection.cs | 2 +- .../Ranks/{ScoreContainer.cs => PaginatedScoreContainer.cs} | 4 ++-- osu.Game/Overlays/Profile/Sections/RanksSection.cs | 4 ++-- osu.Game/osu.Game.csproj | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename osu.Game/Overlays/Profile/Sections/Ranks/{ScoreContainer.cs => PaginatedScoreContainer.cs} (93%) diff --git a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs index 8bc13118b2..d25407f4a3 100644 --- a/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs +++ b/osu.Game/Overlays/Profile/Sections/HistoricalSection.cs @@ -14,7 +14,7 @@ namespace osu.Game.Overlays.Profile.Sections public HistoricalSection() { - Child = new ScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)"); + Child = new PaginatedScoreContainer(ScoreType.Recent, User, "Recent Plays (24h)"); } } } diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs similarity index 93% rename from osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs rename to osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs index 7568aec226..a9f1226dbb 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/ScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -18,7 +18,7 @@ using System.Linq; namespace osu.Game.Overlays.Profile.Sections.Ranks { - public class ScoreContainer : FillFlowContainer + public class PaginatedScoreContainer : FillFlowContainer { private readonly FillFlowContainer scoreContainer; private readonly OsuSpriteText missing; @@ -42,7 +42,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks showMore(); } - public ScoreContainer(ScoreType type, Bindable user, string header, bool includeWeight = false) + public PaginatedScoreContainer(ScoreType type, Bindable user, string header, bool includeWeight = false) { this.type = type; this.includeWeight = includeWeight; diff --git a/osu.Game/Overlays/Profile/Sections/RanksSection.cs b/osu.Game/Overlays/Profile/Sections/RanksSection.cs index aeb9bdc31e..553691ef77 100644 --- a/osu.Game/Overlays/Profile/Sections/RanksSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RanksSection.cs @@ -16,8 +16,8 @@ namespace osu.Game.Overlays.Profile.Sections { Children = new[] { - new ScoreContainer(ScoreType.Best, User, "Best Performance", true), - new ScoreContainer(ScoreType.Firsts, User, "First Place Ranks"), + new PaginatedScoreContainer(ScoreType.Best, User, "Best Performance", true), + new PaginatedScoreContainer(ScoreType.Firsts, User, "First Place Ranks"), }; } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 262e94f6dd..c1003a0207 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -295,7 +295,7 @@ - + From 096998d5f46809cc2ded83232d4f46067f5b7520 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 30 Oct 2017 19:08:15 +0900 Subject: [PATCH 08/12] Fix user bindable being assigned rather than bound --- .../Sections/Ranks/PaginatedScoreContainer.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs index a9f1226dbb..d1e920d49c 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -28,26 +28,18 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks private readonly bool includeWeight; private readonly ScoreType type; private int visiblePages; - private readonly Bindable user; + + private readonly Bindable user = new Bindable(); private RulesetStore rulesets; private APIAccess api; - private void setUser(User newUser) - { - visiblePages = 0; - scoreContainer.Clear(); - showMoreButton.Hide(); - missing.Show(); - showMore(); - } - public PaginatedScoreContainer(ScoreType type, Bindable user, string header, bool includeWeight = false) { this.type = type; this.includeWeight = includeWeight; - this.user = user; - user.ValueChanged += setUser; + this.user.BindTo(user); + this.user.ValueChanged += user_ValueChanged; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -95,6 +87,15 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks }; } + private void user_ValueChanged(User newUser) + { + visiblePages = 0; + scoreContainer.Clear(); + showMoreButton.Hide(); + missing.Show(); + showMore(); + } + [BackgroundDependencyLoader] private void load(APIAccess api, RulesetStore rulesets) { From 069f4b1fcf6497d1637a3bb82a504484eb04e951 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 30 Oct 2017 19:15:19 +0900 Subject: [PATCH 09/12] Make DrawableScore abstract and move shared class to own file --- .../Profile/Sections/Ranks/DrawableScore.cs | 25 ++------------- .../Sections/Ranks/DrawableTotalScore.cs | 31 +++++++++++++++++++ .../Sections/Ranks/PaginatedScoreContainer.cs | 2 +- osu.Game/osu.Game.csproj | 1 + 4 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 osu.Game/Overlays/Profile/Sections/Ranks/DrawableTotalScore.cs diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index 4464a788b8..9e3cd9696b 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -18,14 +18,14 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Overlays.Profile.Sections.Ranks { - public class DrawableScore : Container + public abstract class DrawableScore : Container { protected readonly FillFlowContainer Stats; private readonly FillFlowContainer metadata; private readonly ModContainer modContainer; protected readonly Score Score; - public DrawableScore(Score score) + protected DrawableScore(Score score) { Score = score; @@ -136,25 +136,4 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks } } } - - public class TotalScore : DrawableScore - { - public TotalScore(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/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 index d1e920d49c..a9fab64a74 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -123,7 +123,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks missing.Hide(); foreach (OnlineScore score in scores) { - var drawableScore = type == ScoreType.Recent ? (DrawableScore)new TotalScore(score) : new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); + var drawableScore = type == ScoreType.Recent ? (DrawableScore)new DrawableTotalScore(score) : new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); drawableScore.RelativeSizeAxes = Axes.X; drawableScore.Height = 60; scoreContainer.Add(drawableScore); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index c1003a0207..a99e97eabb 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -296,6 +296,7 @@ + From a51e64b2d14cfc14b9b868bb1a9ade9a6381092b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 30 Oct 2017 19:16:16 +0900 Subject: [PATCH 10/12] Remove unnecessary schedule --- .../Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs index a9fab64a74..75460dd9d7 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -131,7 +131,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks } }; - Schedule(() => { api.Queue(req); }); + api.Queue(req); } } } From 1ae0eff6ad15a623dea6690e9dafb944f6622c00 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 30 Oct 2017 19:31:10 +0900 Subject: [PATCH 11/12] Add some sanity to request/drawable creation logic --- .../Sections/Ranks/PaginatedScoreContainer.cs | 114 ++++++++++-------- 1 file changed, 64 insertions(+), 50 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs index 75460dd9d7..aa87091806 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -39,7 +39,6 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks this.type = type; this.includeWeight = includeWeight; this.user.BindTo(user); - this.user.ValueChanged += user_ValueChanged; RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -47,46 +46,56 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks 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 + 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 = type == ScoreType.Recent ? "No performance records. :(" : "No awesome performance records yet. :(", - }, + 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; @@ -96,13 +105,6 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks showMore(); } - [BackgroundDependencyLoader] - private void load(APIAccess api, RulesetStore rulesets) - { - this.api = api; - this.rulesets = rulesets; - } - private void showMore() { var req = new GetUserScoresRequest(user.Value.Id, type, visiblePages++ * 5); @@ -118,16 +120,28 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks showMoreButton.FadeTo(scores.Count == 5 ? 1 : 0); showMoreLoading.Hide(); - if (scores.Any()) + if (!scores.Any()) return; + + missing.Hide(); + + foreach (OnlineScore score in scores) { - missing.Hide(); - foreach (OnlineScore score in scores) + DrawableScore drawableScore; + + switch (type) { - var drawableScore = type == ScoreType.Recent ? (DrawableScore)new DrawableTotalScore(score) : new DrawablePerformanceScore(score, includeWeight ? Math.Pow(0.95, scoreContainer.Count) : (double?)null); - drawableScore.RelativeSizeAxes = Axes.X; - drawableScore.Height = 60; - scoreContainer.Add(drawableScore); + 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); } }; From d871c3fddab0b70de5931875be2eaef72de747ad Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 30 Oct 2017 20:55:23 +0900 Subject: [PATCH 12/12] Fix test not working due to null refs --- osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs | 4 ++-- .../Profile/Sections/Ranks/PaginatedScoreContainer.cs | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index 9e3cd9696b..91f5650b92 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -72,7 +72,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks }; } - [BackgroundDependencyLoader] + [BackgroundDependencyLoader(true)] private void load(OsuColour colour, LocalisationEngine locale, BeatmapSetOverlay beatmapSetOverlay) { Stats.Add(new OsuSpriteText @@ -91,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 { diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs index aa87091806..060bb03014 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/PaginatedScoreContainer.cs @@ -102,7 +102,9 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks scoreContainer.Clear(); showMoreButton.Hide(); missing.Show(); - showMore(); + + if (newUser != null) + showMore(); } private void showMore()