From 0449639f41dbd4f3f9205e5404358f8c931d60a4 Mon Sep 17 00:00:00 2001 From: Jorolf Date: Wed, 25 Oct 2017 20:07:12 +0200 Subject: [PATCH] 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);