From ab4be3b75f1ae455a18d21fc3609c96e9dbab00c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 3 Apr 2019 15:20:38 +0900 Subject: [PATCH] General refactoring --- .../TestCaseBeatmapScoresContainer.cs | 1 + .../Graphics/Containers/OsuHoverContainer.cs | 4 +- .../Scores/ClickableUserContainer.cs | 29 ++++---- .../BeatmapSet/Scores/DrawableTopScore.cs | 66 ++++++++----------- .../BeatmapSet/Scores/ScoreTableScoreRow.cs | 2 +- 5 files changed, 48 insertions(+), 54 deletions(-) diff --git a/osu.Game.Tests/Visual/SongSelect/TestCaseBeatmapScoresContainer.cs b/osu.Game.Tests/Visual/SongSelect/TestCaseBeatmapScoresContainer.cs index c72d12c09c..4a38f98810 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestCaseBeatmapScoresContainer.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestCaseBeatmapScoresContainer.cs @@ -24,6 +24,7 @@ namespace osu.Game.Tests.Visual.SongSelect { public override IReadOnlyList RequiredTypes => new[] { + typeof(DrawableTopScore), typeof(ScoresContainer), typeof(ScoreTable), typeof(ScoreTableRow), diff --git a/osu.Game/Graphics/Containers/OsuHoverContainer.cs b/osu.Game/Graphics/Containers/OsuHoverContainer.cs index 091499b7cd..880807c8b4 100644 --- a/osu.Game/Graphics/Containers/OsuHoverContainer.cs +++ b/osu.Game/Graphics/Containers/OsuHoverContainer.cs @@ -12,12 +12,12 @@ namespace osu.Game.Graphics.Containers { public class OsuHoverContainer : OsuClickableContainer { + protected const float FADE_DURATION = 500; + protected Color4 HoverColour; protected Color4 IdleColour = Color4.White; - protected const float FADE_DURATION = 500; - protected virtual IEnumerable EffectTargets => new[] { Content }; protected override bool OnHover(HoverEvent e) diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ClickableUserContainer.cs b/osu.Game/Overlays/BeatmapSet/Scores/ClickableUserContainer.cs index cf1c3d7fcf..2448ae17f8 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ClickableUserContainer.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ClickableUserContainer.cs @@ -13,6 +13,17 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { private UserProfileOverlay profile; + protected ClickableUserContainer() + { + AutoSizeAxes = Axes.Both; + } + + [BackgroundDependencyLoader(true)] + private void load(UserProfileOverlay profile) + { + this.profile = profile; + } + private User user; public User User @@ -20,26 +31,16 @@ namespace osu.Game.Overlays.BeatmapSet.Scores get => user; set { - if (user == value) return; + if (user == value) + return; user = value; - OnUserChange(user); + OnUserChanged(user); } } - protected ClickableUserContainer() - { - AutoSizeAxes = Axes.Both; - } - - protected abstract void OnUserChange(User user); - - [BackgroundDependencyLoader(true)] - private void load(UserProfileOverlay profile) - { - this.profile = profile; - } + protected abstract void OnUserChanged(User user); protected override bool OnClick(ClickEvent e) { diff --git a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs index 82905d065e..e3141624b5 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/DrawableTopScore.cs @@ -19,6 +19,7 @@ using osu.Game.Users; using osuTK; using osuTK.Graphics; using System.Collections.Generic; +using osu.Game.Graphics.Sprites; namespace osu.Game.Overlays.BeatmapSet.Scores { @@ -164,7 +165,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, - TextSize = 20, }, date = new SpriteText { @@ -263,67 +263,59 @@ namespace osu.Game.Overlays.BeatmapSet.Scores { private const float username_fade_duration = 500; - private readonly Box underscore; - private readonly Container underscoreContainer; - private readonly SpriteText text; + private readonly FillFlowContainer hoverContainer; - private Color4 hoverColour; - - public float TextSize - { - set - { - if (text.TextSize == value) - return; - - text.TextSize = value; - } - get => text.TextSize; - } + private readonly SpriteText normalText; + private readonly SpriteText hoveredText; public ClickableTopScoreUsername() { - Add(underscoreContainer = new Container + var font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold, italics: true); + + Children = new Drawable[] { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.X, - Height = 1, - Child = underscore = new Box + normalText = new OsuSpriteText { Font = font }, + hoverContainer = new FillFlowContainer { - RelativeSizeAxes = Axes.Both, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, Alpha = 0, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 1), + Children = new Drawable[] + { + hoveredText = new OsuSpriteText { Font = font }, + new Box + { + BypassAutoSizeAxes = Axes.Both, + RelativeSizeAxes = Axes.X, + Height = 1 + } + } } - }); - Add(text = new SpriteText - { - Font = @"Exo2.0-BoldItalic", - }); + }; } [BackgroundDependencyLoader] private void load(OsuColour colours) { - hoverColour = underscore.Colour = colours.Blue; - underscoreContainer.Position = new Vector2(0, TextSize / 2 - 1); + hoverContainer.Colour = colours.Blue; } - protected override void OnUserChange(User user) + protected override void OnUserChanged(User user) { - text.Text = user.Username; + normalText.Text = hoveredText.Text = user.Username; } protected override bool OnHover(HoverEvent e) { - text.FadeColour(hoverColour, username_fade_duration, Easing.OutQuint); - underscore.FadeIn(username_fade_duration, Easing.OutQuint); + hoverContainer.FadeIn(username_fade_duration, Easing.OutQuint); return base.OnHover(e); } protected override void OnHoverLost(HoverLostEvent e) { - text.FadeColour(Color4.White, username_fade_duration, Easing.OutQuint); - underscore.FadeOut(username_fade_duration, Easing.OutQuint); + hoverContainer.FadeOut(username_fade_duration, Easing.OutQuint); base.OnHoverLost(e); } } diff --git a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTableScoreRow.cs b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTableScoreRow.cs index cd1ade934a..a0c6db9a56 100644 --- a/osu.Game/Overlays/BeatmapSet/Scores/ScoreTableScoreRow.cs +++ b/osu.Game/Overlays/BeatmapSet/Scores/ScoreTableScoreRow.cs @@ -145,7 +145,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores }); } - protected override void OnUserChange(User user) + protected override void OnUserChanged(User user) { text.Text = textBold.Text = user.Username; }