1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 18:52:55 +08:00

Refactored out changes in StarRatingDisplay

This commit is contained in:
Denrage 2021-05-05 13:13:37 +02:00
parent 377af38d94
commit cf6ed7a7cf
3 changed files with 97 additions and 118 deletions

View File

@ -22,22 +22,7 @@ namespace osu.Game.Screens.Ranking.Expanded
/// </summary>
public class StarRatingDisplay : CompositeDrawable
{
[Resolved]
private OsuColour colours { get; set; }
private CircularContainer colorContainer;
private StarDifficulty starDifficulty;
private FillFlowContainer foregroundContainer;
public StarDifficulty StarDifficulty
{
get => starDifficulty;
set
{
starDifficulty = value;
setDifficulty(starDifficulty);
}
}
private readonly StarDifficulty difficulty;
/// <summary>
/// Creates a new <see cref="StarRatingDisplay"/> using an already computed <see cref="StarDifficulty"/>.
@ -45,94 +30,78 @@ namespace osu.Game.Screens.Ranking.Expanded
/// <param name="starDifficulty">The already computed <see cref="StarDifficulty"/> to display the star difficulty of.</param>
public StarRatingDisplay(StarDifficulty starDifficulty)
{
this.starDifficulty = starDifficulty;
}
private void setDifficulty(StarDifficulty difficulty)
{
colorContainer.FadeColour(getDifficultyColour(difficulty), 250);
foregroundContainer.Expire();
foregroundContainer = null;
AddInternal(foregroundContainer = createForegroundContainer(difficulty));
difficulty = starDifficulty;
}
[BackgroundDependencyLoader]
private void load()
private void load(OsuColour colours, BeatmapDifficultyCache difficultyCache)
{
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
colorContainer = new CircularContainer
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Colour = getDifficultyColour(starDifficulty),
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
},
}
},
foregroundContainer = createForegroundContainer(starDifficulty),
};
}
private ColourInfo getDifficultyColour(StarDifficulty difficulty)
{
return difficulty.DifficultyRating == DifficultyRating.ExpertPlus
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959"))
: (ColourInfo)colours.ForDifficultyRating(difficulty.DifficultyRating);
}
private FillFlowContainer createForegroundContainer(StarDifficulty difficulty)
{
var starRatingParts = difficulty.Stars.ToString("0.00", CultureInfo.InvariantCulture).Split('.');
string wholePart = starRatingParts[0];
string fractionPart = starRatingParts[1];
string separator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
return new FillFlowContainer
ColourInfo backgroundColour = difficulty.DifficultyRating == DifficultyRating.ExpertPlus
? ColourInfo.GradientVertical(Color4Extensions.FromHex("#C1C1C1"), Color4Extensions.FromHex("#595959"))
: (ColourInfo)colours.ForDifficultyRating(difficulty.DifficultyRating);
InternalChildren = new Drawable[]
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 8, Vertical = 4 },
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2, 0),
Children = new Drawable[]
new CircularContainer
{
new SpriteIcon
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(7),
Icon = FontAwesome.Solid.Star,
Colour = Color4.Black
},
new OsuTextFlowContainer(s => s.Font = OsuFont.Numeric.With(weight: FontWeight.Black))
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
TextAnchor = Anchor.BottomLeft,
}.With(t =>
{
t.AddText($"{wholePart}", s =>
new Box
{
s.Colour = Color4.Black;
s.Font = s.Font.With(size: 14);
s.UseFullGlyphHeight = false;
});
t.AddText($"{separator}{fractionPart}", s =>
RelativeSizeAxes = Axes.Both,
Colour = backgroundColour
},
}
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 8, Vertical = 4 },
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2, 0),
Children = new Drawable[]
{
new SpriteIcon
{
s.Colour = Color4.Black;
s.Font = s.Font.With(size: 7);
s.UseFullGlyphHeight = false;
});
}),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(7),
Icon = FontAwesome.Solid.Star,
Colour = Color4.Black
},
new OsuTextFlowContainer(s => s.Font = OsuFont.Numeric.With(weight: FontWeight.Black))
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
TextAnchor = Anchor.BottomLeft,
}.With(t =>
{
t.AddText($"{wholePart}", s =>
{
s.Colour = Color4.Black;
s.Font = s.Font.With(size: 14);
s.UseFullGlyphHeight = false;
});
t.AddText($"{separator}{fractionPart}", s =>
{
s.Colour = Color4.Black;
s.Font = s.Font.With(size: 7);
s.UseFullGlyphHeight = false;
});
})
}
}
};
}

View File

@ -173,7 +173,7 @@ namespace osu.Game.Screens.Select
private ILocalisedBindableString titleBinding;
private ILocalisedBindableString artistBinding;
private FillFlowContainer infoLabelContainer;
private StarRatingDisplay starRatingDisplay;
private Container topRightMetadataContainer;
private Container bpmLabelContainer;
private ModSettingChangeTracker settingChangeTracker;
private CancellationTokenSource cancellationTokenSource;
@ -232,34 +232,15 @@ namespace osu.Game.Screens.Select
},
}
},
new FillFlowContainer
topRightMetadataContainer = new Container
{
Name = "Topright-aligned metadata",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 14, Right = shear_width / 2 },
AutoSizeAxes = Axes.Both,
Shear = wedged_container_shear,
Children = new Drawable[]
{
starRatingDisplay = new StarRatingDisplay(starDifficulty.Value ?? new StarDifficulty())
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Shear = -wedged_container_shear,
Margin = new MarginPadding { Bottom = 5 }
},
StatusPill = new BeatmapSetOnlineStatusPill
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Shear = -wedged_container_shear,
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapInfo.Status,
}
}
Child = createTopRightMetadataContainer(beatmapInfo, starDifficulty.Value ?? new StarDifficulty())
},
new FillFlowContainer
{
@ -306,21 +287,50 @@ namespace osu.Game.Screens.Select
titleBinding.BindValueChanged(_ => setMetadata(metadata.Source));
artistBinding.BindValueChanged(_ => setMetadata(metadata.Source), true);
starDifficulty.BindValueChanged(updateStarRatingDisplay, true);
starDifficulty.BindValueChanged(updateTopRightMetadata, true);
// no difficulty means it can't have a status to show
if (beatmapInfo.Version == null)
StatusPill.Hide();
}
private void updateStarRatingDisplay(ValueChangedEvent<StarDifficulty?> valueChanged)
private void updateTopRightMetadata(ValueChangedEvent<StarDifficulty?> valueChanged)
{
if (valueChanged.NewValue.HasValue && valueChanged.NewValue.Value.Stars > 0)
starRatingDisplay.Show();
else
starRatingDisplay.Hide();
topRightMetadataContainer.Child.FadeOut(250);
topRightMetadataContainer.Child.Expire();
topRightMetadataContainer.Child = createTopRightMetadataContainer(beatmap.BeatmapInfo, valueChanged.NewValue ?? new StarDifficulty());
}
starRatingDisplay.StarDifficulty = valueChanged.NewValue ?? new StarDifficulty();
private FillFlowContainer createTopRightMetadataContainer(BeatmapInfo beatmapInfo, StarDifficulty difficulty)
{
var container = new FillFlowContainer
{
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
};
if (difficulty.Stars > 0)
{
container.Add(new StarRatingDisplay(difficulty)
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Shear = -wedged_container_shear,
Margin = new MarginPadding { Bottom = 5 }
});
}
container.Add(StatusPill = new BeatmapSetOnlineStatusPill
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Shear = -wedged_container_shear,
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapInfo.Status,
});
return container;
}
private void refreshModInformation(ValueChangedEvent<IReadOnlyList<Mod>> modsChangedEvent)

View File

@ -27,7 +27,7 @@ namespace osu.Game.Screens.Select
{
RelativeSizeAxes = Axes.Both;
InternalChild = new BufferedContainer()
InternalChild = new BufferedContainer
{
CacheDrawnFrameBuffer = true,
RelativeSizeAxes = Axes.Both,