diff --git a/osu.Desktop.VisualTests/Tests/TestCaseUserRanks.cs b/osu.Desktop.VisualTests/Tests/TestCaseUserRanks.cs index 54e6b660f5..607a6b9a91 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseUserRanks.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseUserRanks.cs @@ -39,7 +39,7 @@ namespace osu.Desktop.VisualTests.Tests } }); - AddStep("Add First Place", () => ranks.FirstPlaceScores = new[] + AddStep("Add First Place", () => ranks.ScoresFirst = new[] { new Score { @@ -89,7 +89,7 @@ namespace osu.Desktop.VisualTests.Tests if(i < availableMods.Length) selectedMods.Remove(availableMods[i]); } - ranks.BestScores = scores; + ranks.ScoresBest = scores.ToArray(); }); } } diff --git a/osu.Game/Overlays/Profile/Sections/RanksSection.cs b/osu.Game/Overlays/Profile/Sections/RanksSection.cs index 846f0e0e47..b0f5e2080a 100644 --- a/osu.Game/Overlays/Profile/Sections/RanksSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RanksSection.cs @@ -1,13 +1,17 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using OpenTK.Graphics; +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Input; +using osu.Game.Graphics; +using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Overlays.Profile.Sections.Ranks; using osu.Game.Rulesets.Scoring; using System; -using System.Collections.Generic; namespace osu.Game.Overlays.Profile.Sections { @@ -17,64 +21,178 @@ namespace osu.Game.Overlays.Profile.Sections public override string Identifier => "top_ranks"; - private readonly FillFlowContainer best, firstPlace; + private readonly ScoreFlowContainer best, first; + private readonly OsuSpriteText bestMissing, firstMissing; public RanksSection() { Children = new Drawable[] { - new OsuSpriteText { + new OsuSpriteText + { TextSize = 15, Text = "Best Performance", Font = "Exo2.0-RegularItalic", + Margin = new MarginPadding { Top = 10, Bottom = 10 }, }, - best = new FillFlowContainer + best = new ScoreFlowContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, - Direction = FillDirection.Vertical, }, - new OsuSpriteText { + bestMissing = new OsuSpriteText + { + TextSize = 14, + Text = "No awesome performance records yet. :(", + }, + new OsuSpriteText + { TextSize = 15, Text = "First Place Ranks", Font = "Exo2.0-RegularItalic", + Margin = new MarginPadding { Top = 20, Bottom = 10 }, }, - firstPlace = new FillFlowContainer + first = new ScoreFlowContainer { AutoSizeAxes = Axes.Y, RelativeSizeAxes = Axes.X, - Direction = FillDirection.Vertical, + }, + firstMissing = new OsuSpriteText + { + TextSize = 14, + Text = "No awesome performance records yet. :(", }, }; } - public IEnumerable BestScores + public Score[] ScoresBest { set { - int i = 0; - foreach (Score score in value) + best.Clear(); + if (value.Length == 0) { - best.Add(new DrawableScore(score, Math.Pow(0.95, i)) - { - RelativeSizeAxes = Axes.X, - Height = 60, - }); - i++; + bestMissing.Show(); } + else + { + bestMissing.Hide(); + int i = 0; + foreach (Score score in value) + { + best.Add(new DrawableScore(score, Math.Pow(0.95, i)) + { + RelativeSizeAxes = Axes.X, + Height = 60, + }); + i++; + } + } + best.ShowMore(); } } - public IEnumerable FirstPlaceScores + public Score[] ScoresFirst { set { - foreach (Score score in value) - firstPlace.Add(new DrawableScore(score) + first.Clear(); + if (value.Length == 0) + { + firstMissing.Show(); + } + else + { + firstMissing.Hide(); + foreach (Score score in value) + first.Add(new DrawableScore(score) + { + RelativeSizeAxes = Axes.X, + Height = 60, + }); + } + first.ShowMore(); + } + } + + private class ScoreFlowContainer : Container + { + private readonly FillFlowContainer scores; + private readonly OsuClickableContainer showMoreText; + + protected override Container Content => scores; + + private int shownScores; + + public ScoreFlowContainer() + { + InternalChild = new FillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + Children = new Drawable[] { - RelativeSizeAxes = Axes.X, - Height = 60, - }); + scores = new FillFlowContainer() + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + }, + showMoreText = new ShowMoreContainer + { + Action = ShowMore, + AutoSizeAxes = Axes.Both, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + Alpha = 0, + Child = new OsuSpriteText + { + TextSize = 14, + Text = "show more", + } + } + }, + }; + } + + public override void Clear(bool disposeChildren) + { + base.Clear(disposeChildren); + shownScores = 0; + showMoreText.Show(); + } + + public void ShowMore() + { + shownScores = Math.Min(Children.Count, shownScores + 5); + int i = 0; + foreach(DrawableScore score in Children) + score.FadeTo(i++ < shownScores ? 1 : 0); + showMoreText.FadeTo(shownScores == Children.Count ? 0 : 1); + } + + private class ShowMoreContainer : OsuClickableContainer + { + private Color4 hoverColour; + + protected override bool OnHover(InputState state) + { + this.FadeColour(hoverColour, 500, Easing.OutQuint); + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + this.FadeColour(Color4.White, 500, Easing.OutQuint); + base.OnHoverLost(state); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + hoverColour = colours.Yellow; + } } } }