General refactoring

This commit is contained in:
smoogipoo 2019-04-03 15:20:38 +09:00
parent 0d127c21f1
commit ab4be3b75f
5 changed files with 48 additions and 54 deletions

View File

@ -24,6 +24,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
public override IReadOnlyList<Type> RequiredTypes => new[] public override IReadOnlyList<Type> RequiredTypes => new[]
{ {
typeof(DrawableTopScore),
typeof(ScoresContainer), typeof(ScoresContainer),
typeof(ScoreTable), typeof(ScoreTable),
typeof(ScoreTableRow), typeof(ScoreTableRow),

View File

@ -12,12 +12,12 @@ namespace osu.Game.Graphics.Containers
{ {
public class OsuHoverContainer : OsuClickableContainer public class OsuHoverContainer : OsuClickableContainer
{ {
protected const float FADE_DURATION = 500;
protected Color4 HoverColour; protected Color4 HoverColour;
protected Color4 IdleColour = Color4.White; protected Color4 IdleColour = Color4.White;
protected const float FADE_DURATION = 500;
protected virtual IEnumerable<Drawable> EffectTargets => new[] { Content }; protected virtual IEnumerable<Drawable> EffectTargets => new[] { Content };
protected override bool OnHover(HoverEvent e) protected override bool OnHover(HoverEvent e)

View File

@ -13,6 +13,17 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
private UserProfileOverlay profile; private UserProfileOverlay profile;
protected ClickableUserContainer()
{
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader(true)]
private void load(UserProfileOverlay profile)
{
this.profile = profile;
}
private User user; private User user;
public User User public User User
@ -20,26 +31,16 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
get => user; get => user;
set set
{ {
if (user == value) return; if (user == value)
return;
user = value; user = value;
OnUserChange(user); OnUserChanged(user);
} }
} }
protected ClickableUserContainer() protected abstract void OnUserChanged(User user);
{
AutoSizeAxes = Axes.Both;
}
protected abstract void OnUserChange(User user);
[BackgroundDependencyLoader(true)]
private void load(UserProfileOverlay profile)
{
this.profile = profile;
}
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {

View File

@ -19,6 +19,7 @@ using osu.Game.Users;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.BeatmapSet.Scores namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
@ -164,7 +165,6 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
TextSize = 20,
}, },
date = new SpriteText date = new SpriteText
{ {
@ -263,67 +263,59 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
{ {
private const float username_fade_duration = 500; private const float username_fade_duration = 500;
private readonly Box underscore; private readonly FillFlowContainer hoverContainer;
private readonly Container underscoreContainer;
private readonly SpriteText text;
private Color4 hoverColour; private readonly SpriteText normalText;
private readonly SpriteText hoveredText;
public float TextSize
{
set
{
if (text.TextSize == value)
return;
text.TextSize = value;
}
get => text.TextSize;
}
public ClickableTopScoreUsername() public ClickableTopScoreUsername()
{ {
Add(underscoreContainer = new Container var font = OsuFont.GetFont(size: 20, weight: FontWeight.Bold, italics: true);
Children = new Drawable[]
{
normalText = new OsuSpriteText { Font = font },
hoverContainer = new FillFlowContainer
{ {
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 1, AutoSizeAxes = Axes.Y,
Child = underscore = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0, Alpha = 0,
} Direction = FillDirection.Vertical,
}); Spacing = new Vector2(0, 1),
Add(text = new SpriteText Children = new Drawable[]
{ {
Font = @"Exo2.0-BoldItalic", hoveredText = new OsuSpriteText { Font = font },
}); new Box
{
BypassAutoSizeAxes = Axes.Both,
RelativeSizeAxes = Axes.X,
Height = 1
}
}
}
};
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
hoverColour = underscore.Colour = colours.Blue; hoverContainer.Colour = colours.Blue;
underscoreContainer.Position = new Vector2(0, TextSize / 2 - 1);
} }
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) protected override bool OnHover(HoverEvent e)
{ {
text.FadeColour(hoverColour, username_fade_duration, Easing.OutQuint); hoverContainer.FadeIn(username_fade_duration, Easing.OutQuint);
underscore.FadeIn(username_fade_duration, Easing.OutQuint);
return base.OnHover(e); return base.OnHover(e);
} }
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
text.FadeColour(Color4.White, username_fade_duration, Easing.OutQuint); hoverContainer.FadeOut(username_fade_duration, Easing.OutQuint);
underscore.FadeOut(username_fade_duration, Easing.OutQuint);
base.OnHoverLost(e); base.OnHoverLost(e);
} }
} }

View File

@ -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; text.Text = textBold.Text = user.Username;
} }