1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 04:02:57 +08:00

Fix potential resource leak

This commit is contained in:
C0D3 M4513R 2022-11-03 08:05:26 +01:00
parent 49427fe8b7
commit 502bfa950e
No known key found for this signature in database
GPG Key ID: 3FF32B5F41A39834

View File

@ -83,17 +83,18 @@ namespace osu.Game.Skinning.Components
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
Type.BindValueChanged(update, true); Type.BindValueChanged(_ => updateBeatmapContent());
ShowLabel.BindValueChanged(ignored => updateLabel()); beatmap.BindValueChanged(_ => updateBeatmapContent(), true);
ValueBeforeLabel.BindValueChanged(ignored => updateLabel()); ShowLabel.BindValueChanged(_ => updateLabel());
LabelPrefix.BindValueChanged(ignored => updateLabel()); ValueBeforeLabel.BindValueChanged(_ => updateLabel());
ShowLabelPrefix.BindValueChanged(ignored => updateLabel()); LabelPrefix.BindValueChanged(_ => updateLabel());
LabelSuffix.BindValueChanged(ignored => updateLabel()); ShowLabelPrefix.BindValueChanged(_ => updateLabel());
ShowLabelSuffix.BindValueChanged(ignored => updateLabel()); LabelSuffix.BindValueChanged(_ => updateLabel());
ValuePrefix.BindValueChanged(ignored => updateLabel()); ShowLabelSuffix.BindValueChanged(_ => updateLabel());
ShowValuePrefix.BindValueChanged(ignored => updateLabel()); ValuePrefix.BindValueChanged(_ => updateLabel());
ValueSuffix.BindValueChanged(ignored => updateLabel()); ShowValuePrefix.BindValueChanged(_ => updateLabel());
ShowValueSuffix.BindValueChanged(ignored => updateLabel()); ValueSuffix.BindValueChanged(_ => updateLabel());
ShowValueSuffix.BindValueChanged(_ => updateLabel());
} }
private LocalisableString getLabelText() private LocalisableString getLabelText()
@ -125,126 +126,80 @@ namespace osu.Game.Skinning.Components
Height = text.Height; Height = text.Height;
} }
private void update(ValueChangedEvent<BeatmapInfo> type) private void updateBeatmapContent()
{ {
switch (type.NewValue) switch (Type.Value)
{ {
case BeatmapInfo.CircleSize: case BeatmapInfo.CircleSize:
beatmap.BindValueChanged(bm => double cs = beatmap.Value.BeatmapInfo.Difficulty.CircleSize;
{
double cs = bm.NewValue.BeatmapInfo.Difficulty.CircleSize;
labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs; labelText = TooltipText = BeatmapsetsStrings.ShowStatsCs;
value = cs.ToString("F2"); value = cs.ToString("F2");
updateLabel();
}, true);
break; break;
case BeatmapInfo.HPDrain: case BeatmapInfo.HPDrain:
beatmap.BindValueChanged(bm => double hp = beatmap.Value.BeatmapInfo.Difficulty.DrainRate;
{
double hp = bm.NewValue.BeatmapInfo.Difficulty.DrainRate;
labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain; labelText = TooltipText = BeatmapsetsStrings.ShowStatsDrain;
value = hp.ToString("F2"); value = hp.ToString("F2");
updateLabel();
}, true);
break; break;
case BeatmapInfo.Accuracy: case BeatmapInfo.Accuracy:
beatmap.BindValueChanged(bm => double od = beatmap.Value.BeatmapInfo.Difficulty.OverallDifficulty;
{
double od = bm.NewValue.BeatmapInfo.Difficulty.OverallDifficulty;
labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy; labelText = TooltipText = BeatmapsetsStrings.ShowStatsAccuracy;
value = od.ToString("F2"); value = od.ToString("F2");
updateLabel();
}, true);
break; break;
case BeatmapInfo.ApproachRate: case BeatmapInfo.ApproachRate:
beatmap.BindValueChanged(bm => double ar = beatmap.Value.BeatmapInfo.Difficulty.ApproachRate;
{
double ar = bm.NewValue.BeatmapInfo.Difficulty.ApproachRate;
labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr; labelText = TooltipText = BeatmapsetsStrings.ShowStatsAr;
value = ar.ToString("F2"); value = ar.ToString("F2");
updateLabel();
}, true);
break; break;
case BeatmapInfo.StarRating: case BeatmapInfo.StarRating:
beatmap.BindValueChanged(bm => double sr = beatmap.Value.BeatmapInfo.StarRating;
{
double sr = bm.NewValue.BeatmapInfo.StarRating;
labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars; labelText = TooltipText = BeatmapsetsStrings.ShowStatsStars;
value = sr.ToString("F2"); value = sr.ToString("F2");
updateLabel();
}, true);
break; break;
case BeatmapInfo.Song: case BeatmapInfo.Song:
beatmap.BindValueChanged(bm => string title = beatmap.Value.BeatmapInfo.Metadata.Title;
{
string title = bm.NewValue.BeatmapInfo.Metadata.Title;
//todo: no Song Title localisation?
labelText = TooltipText = EditorSetupStrings.Title; labelText = TooltipText = EditorSetupStrings.Title;
value = title; value = title;
updateLabel();
}, true);
break; break;
case BeatmapInfo.Artist: case BeatmapInfo.Artist:
beatmap.BindValueChanged(bm => string artist = beatmap.Value.BeatmapInfo.Metadata.Artist;
{
string artist = bm.NewValue.BeatmapInfo.Metadata.Artist;
labelText = EditorSetupStrings.Artist; labelText = EditorSetupStrings.Artist;
TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist); TooltipText = BeatmapsetsStrings.ShowDetailsByArtist(artist);
value = artist; value = artist;
updateLabel();
}, true);
break; break;
case BeatmapInfo.Difficulty: case BeatmapInfo.Difficulty:
beatmap.BindValueChanged(bm => string diff = beatmap.Value.BeatmapInfo.DifficultyName;
{
string diff = bm.NewValue.BeatmapInfo.DifficultyName;
labelText = TooltipText = EditorSetupStrings.DifficultyHeader; labelText = TooltipText = EditorSetupStrings.DifficultyHeader;
text.Current.Value = diff; text.Current.Value = diff;
updateLabel();
}, true);
break; break;
case BeatmapInfo.Mapper: case BeatmapInfo.Mapper:
beatmap.BindValueChanged(bm => string mapper = beatmap.Value.BeatmapInfo.Metadata.Author.Username;
{ //todo: is there a good alternative, to NotificationsOptionsMapping?
string mapper = bm.NewValue.BeatmapInfo.Metadata.Author.Username;
//todo: is there a good alternative, to ShowDetailsMappedBy?
labelText = AccountsStrings.NotificationsOptionsMapping; labelText = AccountsStrings.NotificationsOptionsMapping;
TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper); TooltipText = BeatmapsetsStrings.ShowDetailsMappedBy(mapper);
value = mapper; value = mapper;
updateLabel();
}, true);
break; break;
case BeatmapInfo.Length: case BeatmapInfo.Length:
beatmap.BindValueChanged(bm =>
{
labelText = TooltipText = ArtistStrings.TracklistLength; labelText = TooltipText = ArtistStrings.TracklistLength;
value = TimeSpan.FromMilliseconds(bm.NewValue.BeatmapInfo.Length).ToFormattedDuration(); value = TimeSpan.FromMilliseconds(beatmap.Value.BeatmapInfo.Length).ToFormattedDuration();
updateLabel();
}, true);
break; break;
case BeatmapInfo.Status: case BeatmapInfo.Status:
beatmap.BindValueChanged(bm => BeatmapOnlineStatus status = beatmap.Value.BeatmapInfo.Status;
{ TooltipText = labelText = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault;
BeatmapOnlineStatus status = bm.NewValue.BeatmapInfo.Status;
//todo: no Localizasion for None Beatmap Online Status
labelText = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault;
switch (status) switch (status)
{ {
case BeatmapOnlineStatus.Approved: case BeatmapOnlineStatus.Approved:
value = BeatmapsetsStrings.ShowStatusApproved; value = BeatmapsetsStrings.ShowStatusApproved;
//todo: is this correct?
TooltipText = BeatmapsetsStrings.ShowDetailsDateApproved(bm.NewValue.BeatmapSetInfo.DateRanked.ToString());
break; break;
case BeatmapOnlineStatus.Graveyard: case BeatmapOnlineStatus.Graveyard:
@ -280,19 +235,15 @@ namespace osu.Game.Skinning.Components
break; break;
} }
updateLabel();
}, true);
break; break;
case BeatmapInfo.BPM: case BeatmapInfo.BPM:
beatmap.BindValueChanged(bm =>
{
labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm; labelText = TooltipText = BeatmapsetsStrings.ShowStatsBpm;
value = bm.NewValue.BeatmapInfo.BPM.ToString("F2"); value = beatmap.Value.BeatmapInfo.BPM.ToString("F2");
updateLabel();
}, true);
break; break;
} }
updateLabel();
} }
} }