From 774f70e380ab129f4472a73494e1397e556b0238 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 23 Nov 2022 16:56:40 +0900 Subject: [PATCH] Simplify class structure --- .../Components/BeatmapAttributeText.cs | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/osu.Game/Skinning/Components/BeatmapAttributeText.cs b/osu.Game/Skinning/Components/BeatmapAttributeText.cs index 498ea1d268..572b4ba818 100644 --- a/osu.Game/Skinning/Components/BeatmapAttributeText.cs +++ b/osu.Game/Skinning/Components/BeatmapAttributeText.cs @@ -60,49 +60,32 @@ namespace osu.Game.Skinning.Components public BeatmapAttributeText() { AutoSizeAxes = Axes.Both; + InternalChildren = new Drawable[] { text = new OsuSpriteText { - Text = "BeatInfoDrawable", Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Font = OsuFont.Default.With(size: 40) } }; - - foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) - { - valueDictionary[type] = type.ToString(); - } } protected override void LoadComplete() { base.LoadComplete(); + Attribute.BindValueChanged(_ => updateLabel()); - Template.BindValueChanged(f => updateLabel(), true); + Template.BindValueChanged(_ => updateLabel()); beatmap.BindValueChanged(b => { - UpdateBeatmapContent(b.NewValue); + updateBeatmapContent(b.NewValue); updateLabel(); }, true); } - private void updateLabel() - { - string newText = Template.Value.Replace("{Label}", label_dictionary[Attribute.Value].ToString()) - .Replace("{Value}", valueDictionary[Attribute.Value].ToString()); - - foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) - { - newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); - } - - text.Text = newText; - } - - public void UpdateBeatmapContent(WorkingBeatmap workingBeatmap) + private void updateBeatmapContent(WorkingBeatmap workingBeatmap) { valueDictionary[BeatmapAttribute.Title] = workingBeatmap.BeatmapInfo.Metadata.Title; valueDictionary[BeatmapAttribute.Artist] = workingBeatmap.BeatmapInfo.Metadata.Artist; @@ -117,6 +100,19 @@ namespace osu.Game.Skinning.Components valueDictionary[BeatmapAttribute.ApproachRate] = ((double)workingBeatmap.BeatmapInfo.Difficulty.ApproachRate).ToString(@"F2"); valueDictionary[BeatmapAttribute.StarRating] = workingBeatmap.BeatmapInfo.StarRating.ToString(@"F2"); } + + private void updateLabel() + { + string newText = Template.Value.Replace("{Label}", label_dictionary[Attribute.Value].ToString()) + .Replace("{Value}", valueDictionary[Attribute.Value].ToString()); + + foreach (var type in Enum.GetValues(typeof(BeatmapAttribute)).Cast()) + { + newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); + } + + text.Text = newText; + } } public enum BeatmapAttribute