1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:02:55 +08:00

Refactor slightly for readability

This commit is contained in:
Dean Herbert 2023-05-02 14:11:16 +09:00
parent 776c4cfaad
commit 736be6a73b

View File

@ -56,7 +56,7 @@ namespace osu.Game.Overlays.Music
var artist = new RomanisableString(metadata.ArtistUnicode, metadata.Artist); var artist = new RomanisableString(metadata.ArtistUnicode, metadata.Artist);
titlePart = text.AddText(title, sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)); titlePart = text.AddText(title, sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular));
titlePart.DrawablePartsRecreated += _ => updateSelectionState(SelectedSet.Value, instant: true); titlePart.DrawablePartsRecreated += _ => updateSelectionState(SelectedSet.Value, applyImmediately: true);
text.AddText(@" "); // to separate the title from the artist. text.AddText(@" "); // to separate the title from the artist.
text.AddText(artist, sprite => text.AddText(artist, sprite =>
@ -66,24 +66,25 @@ namespace osu.Game.Overlays.Music
sprite.Padding = new MarginPadding { Top = 1 }; sprite.Padding = new MarginPadding { Top = 1 };
}); });
SelectedSet.BindValueChanged(set => updateSelectionState(set.NewValue, instant: false)); SelectedSet.BindValueChanged(set => updateSelectionState(set.NewValue));
updateSelectionState(SelectedSet.Value, instant: true); updateSelectionState(SelectedSet.Value, applyImmediately: true);
}); });
} }
private bool selected; private bool selected;
private void updateSelectionState(Live<BeatmapSetInfo> selectedSet, bool instant) private void updateSelectionState(Live<BeatmapSetInfo> selectedSet, bool applyImmediately = false)
{ {
bool newSelected = selectedSet?.Equals(Model) == true; bool wasSelected = selected;
selected = selectedSet?.Equals(Model) == true;
if (newSelected == selected && !instant) // instant updates should forcibly set correct state regardless of previous state. // Immediate updates should forcibly set correct state regardless of previous state.
// This ensures that the initial state is correctly applied.
if (wasSelected == selected && !applyImmediately)
return; return;
selected = newSelected;
foreach (Drawable s in titlePart.Drawables) foreach (Drawable s in titlePart.Drawables)
s.FadeColour(selected ? colours.Yellow : Color4.White, instant ? 0 : FADE_DURATION); s.FadeColour(selected ? colours.Yellow : Color4.White, applyImmediately ? 0 : FADE_DURATION);
} }
protected override Drawable CreateContent() => new DelayedLoadWrapper(text = new OsuTextFlowContainer protected override Drawable CreateContent() => new DelayedLoadWrapper(text = new OsuTextFlowContainer