From 274ebbd1f7f1ff197c8212f7ca6655fa33f7befe Mon Sep 17 00:00:00 2001 From: Jorolf Date: Wed, 9 Aug 2017 18:45:37 +0200 Subject: [PATCH] remove duplicated code and "simplify" ShowMore logic --- osu.Desktop.Tests/Visual/TestCaseUserRanks.cs | 2 +- .../Profile/Sections/Ranks/DrawableScore.cs | 71 ++++--------------- .../Overlays/Profile/Sections/RanksSection.cs | 44 ++---------- 3 files changed, 19 insertions(+), 98 deletions(-) diff --git a/osu.Desktop.Tests/Visual/TestCaseUserRanks.cs b/osu.Desktop.Tests/Visual/TestCaseUserRanks.cs index 607a6b9a91..d8e3449b1e 100644 --- a/osu.Desktop.Tests/Visual/TestCaseUserRanks.cs +++ b/osu.Desktop.Tests/Visual/TestCaseUserRanks.cs @@ -47,7 +47,7 @@ namespace osu.Desktop.VisualTests.Tests Accuracy = 0.735, PP = 666, Date = DateTimeOffset.UtcNow, - Mods = new Mod[] { new ModAutoplay(), new ModDoubleTime() }, + Mods = new Mod[] { new ModAutoplay(), new ModDoubleTime(), new OsuModEasy() }, Beatmap = new BeatmapInfo { Metadata = new BeatmapMetadata diff --git a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs index 9279bd0156..9318798ec3 100644 --- a/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs +++ b/osu.Game/Overlays/Profile/Sections/Ranks/DrawableScore.cs @@ -12,12 +12,11 @@ using osu.Game.Graphics.Sprites; using osu.Game.Rulesets.Mods; using osu.Game.Screens.Select.Leaderboards; using System.Linq; -using OpenTK.Graphics; using System.Diagnostics; -using osu.Framework.Input; using osu.Framework.Localisation; using System.Globalization; using osu.Game.Rulesets.Scoring; +using osu.Framework.Graphics.Cursor; namespace osu.Game.Overlays.Profile.Sections.Ranks { @@ -72,7 +71,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks Anchor = Anchor.CentreRight, Origin = Anchor.CentreRight, Width = 60, - Margin = new MarginPadding{ Right = 140 } + Margin = new MarginPadding{ Right = 150 } } }; } @@ -108,10 +107,10 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks Font = "Exo2.0-RegularItalic", }); - metadata.Add(new LinkContainer + metadata.Add(new OsuHoverContainer { AutoSizeAxes = Axes.Both, - Url = $"https://osu.ppy.sh/beatmaps/{score.Beatmap.OnlineBeatmapID}", + Action = () => Process.Start($"https://osu.ppy.sh/beatmaps/{score.Beatmap.OnlineBeatmapID}"), Child = new FillFlowContainer { AutoSizeAxes = Axes.Both, @@ -135,7 +134,11 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks }); foreach (Mod mod in score.Mods) - modContainer.Add(new ModIcon(mod.Icon, colour.Yellow)); + modContainer.Add(new ModIcon(mod) + { + AutoSizeAxes = Axes.Both, + Scale = new Vector2(0.5f), + }); } private class ModContainer : FlowContainer @@ -148,62 +151,14 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks } } - private class ModIcon : Container + private class ModIcon : Rulesets.UI.ModIcon, IHasTooltip { - public ModIcon(FontAwesome icon, Color4 colour) + public ModIcon(Mod mod) : base(mod) { - AutoSizeAxes = Axes.Both; - - Children = new[] - { - new SpriteIcon - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Icon = FontAwesome.fa_osu_mod_bg, - Colour = colour, - Shadow = true, - }, - new SpriteIcon - { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - Icon = icon, - Colour = OsuColour.Gray(84), - Position = new Vector2(0f, 2f), - }, - }; - } - } - - private class LinkContainer : OsuClickableContainer - { - public string Url; - - private Color4 hoverColour; - - public LinkContainer() - { - Action = () => Process.Start(Url); + TooltipText = mod.Name; } - 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; - } + public string TooltipText { get; } } } } diff --git a/osu.Game/Overlays/Profile/Sections/RanksSection.cs b/osu.Game/Overlays/Profile/Sections/RanksSection.cs index a99aceb893..e9cc0bc00c 100644 --- a/osu.Game/Overlays/Profile/Sections/RanksSection.cs +++ b/osu.Game/Overlays/Profile/Sections/RanksSection.cs @@ -1,17 +1,14 @@ // 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.Linq; namespace osu.Game.Overlays.Profile.Sections { @@ -84,6 +81,7 @@ namespace osu.Game.Overlays.Profile.Sections { RelativeSizeAxes = Axes.X, Height = 60, + Alpha = 0, }); i++; } @@ -109,6 +107,7 @@ namespace osu.Game.Overlays.Profile.Sections { RelativeSizeAxes = Axes.X, Height = 60, + Alpha = 0, }); } first.ShowMore(); @@ -122,8 +121,6 @@ namespace osu.Game.Overlays.Profile.Sections protected override Container Content => scores; - private int shownScores; - public ScoreFlowContainer() { InternalChild = new FillFlowContainer @@ -139,7 +136,7 @@ namespace osu.Game.Overlays.Profile.Sections RelativeSizeAxes = Axes.X, Direction = FillDirection.Vertical, }, - showMoreText = new ShowMoreContainer + showMoreText = new OsuHoverContainer { Action = ShowMore, AutoSizeAxes = Axes.Both, @@ -159,41 +156,10 @@ namespace osu.Game.Overlays.Profile.Sections 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; - } - } + public void ShowMore() => showMoreText.Alpha = Children.Where(d => !d.IsPresent).Where((d, i) => (d.Alpha = (i < 5 ? 1 : 0)) == 0).Any() ? 1 : 0; } } }