Merge pull request #17923 from peppy/fix-difficulty-tooltip-visibility

Fix high star ratings not being easily visible on tooltips
This commit is contained in:
Dan Balasescu 2022-04-22 16:49:32 +09:00 committed by GitHub
commit ca6c292a08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor; using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK; using osuTK;
@ -16,11 +15,11 @@ namespace osu.Game.Beatmaps.Drawables
{ {
internal class DifficultyIconTooltip : VisibilityContainer, ITooltip<DifficultyIconTooltipContent> internal class DifficultyIconTooltip : VisibilityContainer, ITooltip<DifficultyIconTooltipContent>
{ {
private readonly OsuSpriteText difficultyName, starRating; private OsuSpriteText difficultyName;
private readonly Box background; private StarRatingDisplay starRating;
private readonly FillFlowContainer difficultyFlow;
public DifficultyIconTooltip() [BackgroundDependencyLoader]
private void load(OsuColour colours)
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Masking = true; Masking = true;
@ -28,9 +27,10 @@ namespace osu.Game.Beatmaps.Drawables
Children = new Drawable[] Children = new Drawable[]
{ {
background = new Box new Box
{ {
Alpha = 0.9f, Alpha = 0.9f,
Colour = colours.Gray3,
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}, },
new FillFlowContainer new FillFlowContainer
@ -40,6 +40,7 @@ namespace osu.Game.Beatmaps.Drawables
AutoSizeEasing = Easing.OutQuint, AutoSizeEasing = Easing.OutQuint,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Padding = new MarginPadding(10), Padding = new MarginPadding(10),
Spacing = new Vector2(5),
Children = new Drawable[] Children = new Drawable[]
{ {
difficultyName = new OsuSpriteText difficultyName = new OsuSpriteText
@ -48,57 +49,27 @@ namespace osu.Game.Beatmaps.Drawables
Origin = Anchor.Centre, Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold), Font = OsuFont.GetFont(size: 16, weight: FontWeight.Bold),
}, },
difficultyFlow = new FillFlowContainer starRating = new StarRatingDisplay(default, StarRatingDisplaySize.Small)
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
starRating = new OsuSpriteText
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Margin = new MarginPadding { Left = 4 },
Icon = FontAwesome.Solid.Star,
Size = new Vector2(12),
},
}
} }
} }
} }
}; };
} }
[Resolved] private DifficultyIconTooltipContent displayedContent;
private OsuColour colours { get; set; }
[BackgroundDependencyLoader]
private void load()
{
background.Colour = colours.Gray3;
}
private readonly IBindable<StarDifficulty> starDifficulty = new Bindable<StarDifficulty>();
public void SetContent(DifficultyIconTooltipContent content) public void SetContent(DifficultyIconTooltipContent content)
{ {
difficultyName.Text = content.BeatmapInfo.DifficultyName; if (displayedContent != null)
starRating.Current.UnbindFrom(displayedContent.Difficulty);
starDifficulty.UnbindAll(); displayedContent = content;
starDifficulty.BindTo(content.Difficulty);
starDifficulty.BindValueChanged(difficulty => starRating.Current.BindTarget = displayedContent.Difficulty;
{ difficultyName.Text = displayedContent.BeatmapInfo.DifficultyName;
starRating.Text = $"{difficulty.NewValue.Stars:0.##}";
difficultyFlow.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars);
}, true);
} }
public void Move(Vector2 pos) => Position = pos; public void Move(Vector2 pos) => Position = pos;