diff --git a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs index 479124a43d..eda956e6d8 100644 --- a/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs +++ b/osu.Game/Skinning/Components/BeatmapInfoDrawable.cs @@ -27,29 +27,11 @@ namespace osu.Game.Skinning.Components private const BeatmapInfo default_beatmap_info = BeatmapInfo.StarRating; public bool UsesFixedAnchor { get; set; } - [SettingSource("Tracked Beatmap Info/Label", "Which part of the BeatmapInformation should be displayed. Gets overridden by complex changes to ValueFormat")] + [SettingSource("Tracked Beatmap Info/Label", "Which part of the BeatmapInformation should be displayed.")] public Bindable Type { get; } = new Bindable(default_beatmap_info); - [SettingSource("Show Label", "Should a Label be shown, as to which status is currently Displayed?")] - public BindableBool ShowLabel { get; } = new BindableBool(true); - - [SettingSource("Show Value first?", "Should the Value be shown first?")] - public BindableBool ValueBeforeLabel { get; } = new BindableBool(); - - [SettingSource("Label Prefix", "Add something to be shown before the label")] - public Bindable LabelPrefix { get; set; } = new Bindable(""); - - [SettingSource("Show Label Prefix", "Should the Label Prefix be included?")] - public BindableBool ShowLabelPrefix { get; } = new BindableBool(); - - [SettingSource("Label Suffix", "Add something to be shown after the label")] - public Bindable LabelSuffix { get; set; } = new Bindable(": "); - - [SettingSource("Show Label Suffix", "Should the Label Suffix be included?")] - public BindableBool ShowLabelSuffix { get; } = new BindableBool(true); - - [SettingSource("Value Formatting", "Bypass the restriction of 1 Info per element. Format is '{'+Type+'}' to substitue values. e.g. '{Song}' ")] - public Bindable ValueFormat { get; set; } = new Bindable("{" + default_beatmap_info + "}"); + [SettingSource("Template", "Bypass the restriction of 1 Info per element. Format is '{'+Type+'}' to substitue values. e.g. '{Song}' ")] + public Bindable Template { get; set; } = new Bindable("{Label}: {Value}"); [Resolved] private IBindable beatmap { get; set; } = null!; @@ -76,7 +58,7 @@ namespace osu.Game.Skinning.Components [BeatmapInfo.Length] = ArtistStrings.TracklistLength, [BeatmapInfo.Status] = BeatmapDiscussionsStrings.IndexFormBeatmapsetStatusDefault, [BeatmapInfo.BPM] = BeatmapsetsStrings.ShowStatsBpm, - [BeatmapInfo.Custom] = BeatmapInfo.Custom.ToString() + [BeatmapInfo.None] = BeatmapInfo.None.ToString() }.ToImmutableDictionary(); } @@ -99,102 +81,29 @@ namespace osu.Game.Skinning.Components } } - /// - /// This will return the if the format-String contains of a singular replacement of type info, or not. - /// If there is only one one replacement of type info, it will also return the prefix/suffix (or null if no prefix/suffix exists). - /// - /// The format-String to work on - /// The replacement Type to look for - /// (true, prefix, suffix), if there is only one replacement of type info. Else (false, null, null) - private static (bool, string?, string?) isOnlyPrefixedOrSuffixed(string format, BeatmapInfo info) - { - string[] s = format.Split("{" + info + "}"); - - foreach (string si in s) - { - foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) - { - if (si.Contains("{" + type + "}")) return (false, null, null); - } - } - - //Debug.WriteLine($"format:'{format}', type:{info} is only prefixed/suffixed"); - - return (true, - s.Length >= 1 ? s[0] : null, //prefix - s.Length >= 2 ? s[1] : null //suffix - ); - } - protected override void LoadComplete() { base.LoadComplete(); - Type.BindValueChanged(v => - { - string newDefault = "{" + v.NewValue + "}"; - bool custom = v.NewValue == BeatmapInfo.Custom; - - //If the ValueFormat is Default and the user did not change anything we should be able to just swap the strings. - //If it was Default before, it should be default after the Type is changed. - if (ValueFormat.IsDefault && !custom) - ValueFormat.Value = newDefault; - else - { - //In this if statement we decide if the ValueFormat has been trivially changed (so only been prefixed or suffixed) - (bool preOrSuffixed, string? prefix, string? suffix) = isOnlyPrefixedOrSuffixed(ValueFormat.Value, v.OldValue); - if (preOrSuffixed) - //If it has, we can keep the prefix and suffix and just change the thing that would be substituted. - ValueFormat.Value = (prefix ?? "") + newDefault + (suffix ?? ""); - //else we just keep the ValueFormat. I determine here, that the user probably knows what they are doing, and how the ValueFormat works. - } - - //Only if we could preserve the ValueFormat (so nothing was changed except a static prefix/suffix) I want to set the new Default. - ValueFormat.Default = newDefault; - updateLabel(); - }); - ValueFormat.BindValueChanged(f => updateLabel(), true); + Type.BindValueChanged(_ => updateLabel()); + Template.BindValueChanged(f => updateLabel(), true); beatmap.BindValueChanged(b => { UpdateBeatmapContent(b.NewValue); updateLabel(); }, true); - ShowLabel.BindValueChanged(_ => updateLabel()); - ValueBeforeLabel.BindValueChanged(_ => updateLabel()); - LabelPrefix.BindValueChanged(_ => updateLabel()); - ShowLabelPrefix.BindValueChanged(_ => updateLabel()); - LabelSuffix.BindValueChanged(_ => updateLabel()); - ShowLabelSuffix.BindValueChanged(_ => updateLabel()); - } - - private LocalisableString getLabelText() - { - if (!ShowLabel.Value) return new LocalisableString(""); - - return LocalisableString.Format("{0}{1}{2}", - ShowLabelPrefix.Value ? LabelPrefix.Value : "", - label_dictionary[Type.Value], - ShowLabelSuffix.Value ? LabelSuffix.Value : ""); - } - - private LocalisableString getValueText() - { - string value = ValueFormat.Value; - - foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) - { - value = value.Replace("{" + type + "}", valueDictionary[type].ToString()); - } - - return value; } private void updateLabel() { - text.Text = LocalisableString.Format( - ValueBeforeLabel.Value ? "{1}{0}" : "{0}{1}", - getLabelText(), - getValueText() - ); + string newText = Template.Value.Replace("{Label}", label_dictionary[Type.Value].ToString()) + .Replace("{Value}", valueDictionary[Type.Value].ToString()); + + foreach (var type in Enum.GetValues(typeof(BeatmapInfo)).Cast()) + { + newText = newText.Replace("{" + type + "}", valueDictionary[type].ToString()); + } + + text.Text = newText; Width = text.Width; Height = text.Height; } @@ -230,7 +139,7 @@ namespace osu.Game.Skinning.Components valueDictionary[BeatmapInfo.Status] = GetBetmapStatus(workingBeatmap.BeatmapInfo.Status); //update BPM valueDictionary[BeatmapInfo.BPM] = workingBeatmap.BeatmapInfo.BPM.ToString("F2"); - valueDictionary[BeatmapInfo.Custom] = BeatmapInfo.Custom.ToString(); + valueDictionary[BeatmapInfo.None] = string.Empty; } public static LocalisableString GetBetmapStatus(BeatmapOnlineStatus status) @@ -284,6 +193,6 @@ namespace osu.Game.Skinning.Components Length, Status, BPM, - Custom, + None, } }