Ensure selected field is correct in updateSelectionState()

Co-Authored-By: Bartłomiej Dach <dach.bartlomiej@gmail.com>
This commit is contained in:
Joseph Madamba 2023-04-19 18:34:35 -07:00
parent eaef5ff2a3
commit 776c4cfaad
No known key found for this signature in database
GPG Key ID: 8B746C7BDDF0BD76

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(true); titlePart.DrawablePartsRecreated += _ => updateSelectionState(SelectedSet.Value, instant: 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,25 +66,22 @@ namespace osu.Game.Overlays.Music
sprite.Padding = new MarginPadding { Top = 1 }; sprite.Padding = new MarginPadding { Top = 1 };
}); });
SelectedSet.BindValueChanged(set => SelectedSet.BindValueChanged(set => updateSelectionState(set.NewValue, instant: false));
{ updateSelectionState(SelectedSet.Value, instant: true);
bool newSelected = set.NewValue?.Equals(Model) == true;
if (newSelected == selected)
return;
selected = newSelected;
updateSelectionState(false);
}, true);
updateSelectionState(true);
}); });
} }
private bool selected; private bool selected;
private void updateSelectionState(bool instant) private void updateSelectionState(Live<BeatmapSetInfo> selectedSet, bool instant)
{ {
bool newSelected = selectedSet?.Equals(Model) == true;
if (newSelected == selected && !instant) // instant updates should forcibly set correct state regardless of previous state.
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, instant ? 0 : FADE_DURATION);
} }