1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 10:42:55 +08:00

remove duplicated code and "simplify" ShowMore logic

This commit is contained in:
Jorolf 2017-08-09 18:45:37 +02:00
parent 9f005488f7
commit 274ebbd1f7
3 changed files with 19 additions and 98 deletions

View File

@ -47,7 +47,7 @@ namespace osu.Desktop.VisualTests.Tests
Accuracy = 0.735, Accuracy = 0.735,
PP = 666, PP = 666,
Date = DateTimeOffset.UtcNow, Date = DateTimeOffset.UtcNow,
Mods = new Mod[] { new ModAutoplay(), new ModDoubleTime() }, Mods = new Mod[] { new ModAutoplay(), new ModDoubleTime(), new OsuModEasy() },
Beatmap = new BeatmapInfo Beatmap = new BeatmapInfo
{ {
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata

View File

@ -12,12 +12,11 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Select.Leaderboards; using osu.Game.Screens.Select.Leaderboards;
using System.Linq; using System.Linq;
using OpenTK.Graphics;
using System.Diagnostics; using System.Diagnostics;
using osu.Framework.Input;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using System.Globalization; using System.Globalization;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Framework.Graphics.Cursor;
namespace osu.Game.Overlays.Profile.Sections.Ranks namespace osu.Game.Overlays.Profile.Sections.Ranks
{ {
@ -72,7 +71,7 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
Width = 60, 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", Font = "Exo2.0-RegularItalic",
}); });
metadata.Add(new LinkContainer metadata.Add(new OsuHoverContainer
{ {
AutoSizeAxes = Axes.Both, 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 Child = new FillFlowContainer
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -135,7 +134,11 @@ namespace osu.Game.Overlays.Profile.Sections.Ranks
}); });
foreach (Mod mod in score.Mods) 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<ModIcon> private class ModContainer : FlowContainer<ModIcon>
@ -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; TooltipText = mod.Name;
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);
} }
protected override bool OnHover(InputState state) public string TooltipText { get; }
{
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;
}
} }
} }
} }

View File

@ -1,17 +1,14 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // 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;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays.Profile.Sections.Ranks; using osu.Game.Overlays.Profile.Sections.Ranks;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using System; using System;
using System.Linq;
namespace osu.Game.Overlays.Profile.Sections namespace osu.Game.Overlays.Profile.Sections
{ {
@ -84,6 +81,7 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 60, Height = 60,
Alpha = 0,
}); });
i++; i++;
} }
@ -109,6 +107,7 @@ namespace osu.Game.Overlays.Profile.Sections
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 60, Height = 60,
Alpha = 0,
}); });
} }
first.ShowMore(); first.ShowMore();
@ -122,8 +121,6 @@ namespace osu.Game.Overlays.Profile.Sections
protected override Container<DrawableScore> Content => scores; protected override Container<DrawableScore> Content => scores;
private int shownScores;
public ScoreFlowContainer() public ScoreFlowContainer()
{ {
InternalChild = new FillFlowContainer InternalChild = new FillFlowContainer
@ -139,7 +136,7 @@ namespace osu.Game.Overlays.Profile.Sections
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
}, },
showMoreText = new ShowMoreContainer showMoreText = new OsuHoverContainer
{ {
Action = ShowMore, Action = ShowMore,
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -159,41 +156,10 @@ namespace osu.Game.Overlays.Profile.Sections
public override void Clear(bool disposeChildren) public override void Clear(bool disposeChildren)
{ {
base.Clear(disposeChildren); base.Clear(disposeChildren);
shownScores = 0;
showMoreText.Show(); showMoreText.Show();
} }
public void ShowMore() public void ShowMore() => showMoreText.Alpha = Children.Where(d => !d.IsPresent).Where((d, i) => (d.Alpha = (i < 5 ? 1 : 0)) == 0).Any() ? 1 : 0;
{
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;
}
}
} }
} }
} }