1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 19:22:56 +08:00

Move star rating display and status pill out of reloadable content

This commit is contained in:
Joseph Madamba 2023-09-05 15:20:20 -07:00
parent 676240928e
commit 3f92dae55c
No known key found for this signature in database
GPG Key ID: 8B746C7BDDF0BD76
2 changed files with 92 additions and 111 deletions

View File

@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddSliderStep("change star difficulty", 0, 11.9, 5.55, v => AddSliderStep("change star difficulty", 0, 11.9, 5.55, v =>
{ {
foreach (var hasCurrentValue in infoWedge.Info.ChildrenOfType<IHasCurrentValue<StarDifficulty>>()) foreach (var hasCurrentValue in infoWedge.ChildrenOfType<IHasCurrentValue<StarDifficulty>>())
hasCurrentValue.Current.Value = new StarDifficulty(v, 0); hasCurrentValue.Current.Value = new StarDifficulty(v, 0);
}); });
} }

View File

@ -39,14 +39,22 @@ namespace osu.Game.Screens.Select
[Resolved] [Resolved]
private OsuColour colours { get; set; } = null!; private OsuColour colours { get; set; } = null!;
[Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
protected Container? DisplayedContent { get; private set; } protected Container? DisplayedContent { get; private set; }
protected WedgeInfoText? Info { get; private set; } protected WedgeInfoText? Info { get; private set; }
private Container difficultyColourBar = null!; private Container difficultyColourBar = null!;
private StarCounter starCounter = null!; private StarCounter starCounter = null!;
private StarRatingDisplay starRatingDisplay = null!;
private BeatmapSetOnlineStatusPill statusPill = null!;
private Container content = null!; private Container content = null!;
private IBindable<StarDifficulty?>? starDifficulty;
private CancellationTokenSource? cancellationSource;
public BeatmapInfoWedgeV2() public BeatmapInfoWedgeV2()
{ {
Height = WEDGE_HEIGHT; Height = WEDGE_HEIGHT;
@ -102,7 +110,38 @@ namespace osu.Game.Screens.Select
Scale = new Vector2(0.35f), Scale = new Vector2(0.35f),
Direction = FillDirection.Vertical Direction = FillDirection.Vertical
} }
} },
new FillFlowContainer
{
Name = "Topright-aligned metadata",
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 3, Right = colour_bar_width + 8 },
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(0, 5),
Depth = float.MinValue,
Children = new Drawable[]
{
starRatingDisplay = new StarRatingDisplay(default, animated: true)
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Shear = -wedged_container_shear,
Alpha = 0,
},
statusPill = new BeatmapSetOnlineStatusPill
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Shear = -wedged_container_shear,
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Alpha = 0,
}
}
},
} }
}; };
} }
@ -112,6 +151,19 @@ namespace osu.Game.Screens.Select
base.LoadComplete(); base.LoadComplete();
ruleset.BindValueChanged(_ => updateDisplay()); ruleset.BindValueChanged(_ => updateDisplay());
starRatingDisplay.Current.BindValueChanged(s =>
{
// use actual stars as star counter has its own animation
starCounter.Current = (float)s.NewValue.Stars;
}, true);
starRatingDisplay.DisplayedStars.BindValueChanged(s =>
{
// sync color with star rating display
starCounter.Colour = s.NewValue >= 6.5 ? colours.Orange1 : Colour4.Black.Opacity(0.75f);
difficultyColourBar.FadeColour(colours.ForStarDifficulty(s.NewValue));
}, true);
} }
private const double animation_duration = 600; private const double animation_duration = 600;
@ -147,6 +199,17 @@ namespace osu.Game.Screens.Select
private void updateDisplay() private void updateDisplay()
{ {
statusPill.Status = beatmap.BeatmapInfo.Status;
starDifficulty = difficultyCache.GetBindableDifficulty(beatmap.BeatmapInfo, (cancellationSource = new CancellationTokenSource()).Token);
starDifficulty.BindValueChanged(s =>
{
starRatingDisplay.Current.Value = s.NewValue ?? default;
starRatingDisplay.FadeIn(transition_duration);
});
Scheduler.AddOnce(() => Scheduler.AddOnce(() =>
{ {
LoadComponentAsync(loadingInfo = new Container LoadComponentAsync(loadingInfo = new Container
@ -174,19 +237,6 @@ namespace osu.Game.Screens.Select
removeOldInfo(); removeOldInfo();
content.Add(DisplayedContent = d); content.Add(DisplayedContent = d);
Info.DisplayedStars.BindValueChanged(s =>
{
starCounter.Colour = s.NewValue >= 6.5 ? colours.Orange1 : Colour4.Black.Opacity(0.75f);
difficultyColourBar.FadeColour(colours.ForStarDifficulty(s.NewValue));
}, true);
Info.ActualStars.BindValueChanged(s =>
{
// use actual stars as star counter has its own animation
starCounter.Current = (float)s.NewValue;
}, true);
}); });
}); });
@ -198,24 +248,20 @@ namespace osu.Game.Screens.Select
} }
} }
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
cancellationSource?.Cancel();
}
public partial class WedgeInfoText : Container public partial class WedgeInfoText : Container
{ {
public OsuSpriteText TitleLabel { get; private set; } = null!; public OsuSpriteText TitleLabel { get; private set; } = null!;
public OsuSpriteText ArtistLabel { get; private set; } = null!; public OsuSpriteText ArtistLabel { get; private set; } = null!;
private StarRatingDisplay starRatingDisplay = null!;
private readonly WorkingBeatmap working; private readonly WorkingBeatmap working;
public IBindable<double> DisplayedStars => starRatingDisplay.DisplayedStars;
public Bindable<double> ActualStars = new Bindable<double>();
[Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
private IBindable<StarDifficulty?>? starDifficulty;
private CancellationTokenSource? cancellationSource;
public WedgeInfoText(WorkingBeatmap working) public WedgeInfoText(WorkingBeatmap working)
{ {
this.working = working; this.working = working;
@ -226,101 +272,36 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
var beatmapInfo = working.BeatmapInfo;
var metadata = working.Metadata; var metadata = working.Metadata;
Children = new Drawable[] Child = new FillFlowContainer
{ {
new FillFlowContainer Name = "Top-left aligned metadata",
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Horizontal = text_margin + shear_width, Top = 12 },
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{ {
Name = "Topright-aligned metadata", TitleLabel = new TruncatingSpriteText
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 3, Right = 8 },
AutoSizeAxes = Axes.Both,
Shear = wedged_container_shear,
Spacing = new Vector2(0f, 5f),
Children = new Drawable[]
{ {
starRatingDisplay = new StarRatingDisplay(default, animated: true) Shadow = true,
{ Text = new RomanisableString(metadata.TitleUnicode, metadata.Title),
Anchor = Anchor.TopRight, Font = OsuFont.TorusAlternate.With(size: 40, weight: FontWeight.SemiBold),
Origin = Anchor.TopRight, RelativeSizeAxes = Axes.X,
Shear = -wedged_container_shear, },
Alpha = 0f, ArtistLabel = new TruncatingSpriteText
},
new BeatmapSetOnlineStatusPill
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Shear = -wedged_container_shear,
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapInfo.Status,
Alpha = string.IsNullOrEmpty(beatmapInfo.DifficultyName) ? 0 : 1
}
}
},
new FillFlowContainer
{
Name = "Top-left aligned metadata",
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Horizontal = text_margin + shear_width, Top = 12 },
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.X,
Children = new Drawable[]
{ {
TitleLabel = new TruncatingSpriteText // TODO : figma design has a diffused shadow, instead of the solid one present here, not possible currently as far as i'm aware.
{ Shadow = true,
Shadow = true, Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
Text = new RomanisableString(metadata.TitleUnicode, metadata.Title), // Not sure if this should be semi bold or medium
Font = OsuFont.TorusAlternate.With(size: 40, weight: FontWeight.SemiBold), Font = OsuFont.Torus.With(size: 20, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
},
ArtistLabel = new TruncatingSpriteText
{
// TODO : figma design has a diffused shadow, instead of the solid one present here, not possible currently as far as i'm aware.
Shadow = true,
Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist),
// Not sure if this should be semi bold or medium
Font = OsuFont.Torus.With(size: 20, weight: FontWeight.SemiBold),
RelativeSizeAxes = Axes.X,
}
} }
} }
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
starDifficulty = difficultyCache.GetBindableDifficulty(working.BeatmapInfo, (cancellationSource = new CancellationTokenSource()).Token);
starDifficulty.BindValueChanged(s =>
{
starRatingDisplay.Current.Value = s.NewValue ?? default;
// Don't roll the counter on initial display (but still allow it to roll on applying mods etc.)
if (!starRatingDisplay.IsPresent)
starRatingDisplay.FinishTransforms(true);
starRatingDisplay.FadeIn(transition_duration);
});
starRatingDisplay.Current.BindValueChanged(s =>
{
ActualStars.Value = s.NewValue.Stars;
});
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
cancellationSource?.Cancel();
}
} }
} }
} }