diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagEditSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagEditSection.cs index 4b91191fa..35ef0e568 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagEditSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RomajiTagEditSection.cs @@ -20,26 +20,7 @@ public partial class RomajiTagEditSection : TextTagEditSection { protected override LocalisableString Title => "Romaji"; - [Resolved] - private ILyricRomajiTagsChangeHandler romajiTagsChangeHandler { get; set; } - - protected override IBindableList GetBindableTextTags(Lyric lyric) - => lyric.RomajiTagsBindable; - - protected override LabelledTextTagTextBox CreateLabelledTextTagTextBox(Lyric lyric, RomajiTag textTag) - => new LabelledRomajiTagTextBox(lyric, textTag); - - protected override void AddTextTag(RomajiTag textTag) - => romajiTagsChangeHandler.Add(textTag); - - protected override LocalisableString CreateNewTextTagButtonText() - => "Create new romaji"; - - protected override LocalisableString CreateNewTextTagTitle() - => "Romaji"; - - protected override LocalisableString CreateNewTextTagDescription() - => "Please enter the romaji."; + protected override LyricPropertiesEditor CreateLyricPropertiesEditor() => new RomajiTagsEditor(); protected override LockLyricPropertyBy? IsWriteLyricPropertyLocked(Lyric lyric) => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.RomajiTags)); @@ -60,6 +41,30 @@ protected override LocalisableString GetWriteLyricPropertyLockedTooltip(LockLyri _ => throw new ArgumentOutOfRangeException(nameof(lockLyricPropertyBy), lockLyricPropertyBy, null) }; + private partial class RomajiTagsEditor : TextTagsEditor + { + [Resolved] + private ILyricRomajiTagsChangeHandler romajiTagsChangeHandler { get; set; } + + protected override IBindableList GetItems(Lyric lyric) + => lyric.RomajiTagsBindable; + + protected override LabelledTextTagTextBox CreateLabelledTextTagTextBox(Lyric lyric, RomajiTag textTag) + => new LabelledRomajiTagTextBox(lyric, textTag); + + protected override void AddTextTag(RomajiTag textTag) + => romajiTagsChangeHandler.Add(textTag); + + protected override LocalisableString CreateNewTextTagButtonText() + => "Create new romaji"; + + protected override LocalisableString CreateNewTextTagTitle() + => "Romaji"; + + protected override LocalisableString CreateNewTextTagDescription() + => "Please enter the romaji."; + } + protected partial class LabelledRomajiTagTextBox : LabelledTextTagTextBox { [Resolved] diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagEditSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagEditSection.cs index f078c7e4a..13722735e 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagEditSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/RubyTagEditSection.cs @@ -20,26 +20,7 @@ public partial class RubyTagEditSection : TextTagEditSection { protected override LocalisableString Title => "Ruby"; - [Resolved] - private ILyricRubyTagsChangeHandler rubyTagsChangeHandler { get; set; } - - protected override IBindableList GetBindableTextTags(Lyric lyric) - => lyric.RubyTagsBindable; - - protected override LabelledTextTagTextBox CreateLabelledTextTagTextBox(Lyric lyric, RubyTag textTag) - => new LabelledRubyTagTextBox(lyric, textTag); - - protected override void AddTextTag(RubyTag textTag) - => rubyTagsChangeHandler.Add(textTag); - - protected override LocalisableString CreateNewTextTagButtonText() - => "Create new ruby"; - - protected override LocalisableString CreateNewTextTagTitle() - => "Ruby"; - - protected override LocalisableString CreateNewTextTagDescription() - => "Please enter the ruby."; + protected override LyricPropertiesEditor CreateLyricPropertiesEditor() => new RubyTagsEditor(); protected override LockLyricPropertyBy? IsWriteLyricPropertyLocked(Lyric lyric) => HitObjectWritableUtils.GetLyricPropertyLockedBy(lyric, nameof(Lyric.RubyTags)); @@ -60,6 +41,30 @@ protected override LocalisableString GetWriteLyricPropertyLockedTooltip(LockLyri _ => throw new ArgumentOutOfRangeException(nameof(lockLyricPropertyBy), lockLyricPropertyBy, null) }; + private partial class RubyTagsEditor : TextTagsEditor + { + [Resolved] + private ILyricRubyTagsChangeHandler rubyTagsChangeHandler { get; set; } + + protected override IBindableList GetItems(Lyric lyric) + => lyric.RubyTagsBindable; + + protected override LabelledTextTagTextBox CreateLabelledTextTagTextBox(Lyric lyric, RubyTag textTag) + => new LabelledRubyTagTextBox(lyric, textTag); + + protected override void AddTextTag(RubyTag textTag) + => rubyTagsChangeHandler.Add(textTag); + + protected override LocalisableString CreateNewTextTagButtonText() + => "Create new ruby"; + + protected override LocalisableString CreateNewTextTagTitle() + => "Ruby"; + + protected override LocalisableString CreateNewTextTagDescription() + => "Please enter the ruby."; + } + protected partial class LabelledRubyTagTextBox : LabelledTextTagTextBox { [Resolved] diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditSection.cs index 6a4c28045..0ba911e6b 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Lyrics/Settings/RubyRomaji/TextTagEditSection.cs @@ -3,10 +3,8 @@ #nullable disable -using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; using osu.Framework.Localisation; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Karaoke.Objects.Types; @@ -15,72 +13,48 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.RubyRomaji { - public abstract partial class TextTagEditSection : LyricPropertySection where TTextTag : class, ITextTag, new() + public abstract partial class TextTagEditSection : LyricPropertiesSection where TTextTag : class, ITextTag, new() { - protected readonly IBindableList TextTags = new BindableList(); - - private Lyric lyric; - - protected TextTagEditSection() + protected abstract partial class TextTagsEditor : LyricPropertiesEditor { - // add create button. - addCreateButton(); - - // create list of text-tag text-box if bindable changed. - TextTags.BindCollectionChanged((_, _) => + protected sealed override Drawable CreateDrawable(TTextTag item) { - RemoveAll(x => x is LabelledTextTagTextBox, true); - AddRange(TextTags.Select(x => - { - string relativeToLyricText = TextTagUtils.GetTextFromLyric(x, lyric.Text); - string range = TextTagUtils.PositionFormattedString(x); - - return CreateLabelledTextTagTextBox(lyric, x).With(t => - { - t.Label = relativeToLyricText; - t.Description = range; - t.TabbableContentContainer = this; - }); - })); - }); - } - - protected override void OnLyricChanged(Lyric lyric) - { - TextTags.UnbindBindings(); - - if (lyric == null) - return; - - this.lyric = lyric; + string relativeToLyricText = TextTagUtils.GetTextFromLyric(item, CurrentLyric.Text); + string range = TextTagUtils.PositionFormattedString(item); - TextTags.BindTo(GetBindableTextTags(lyric)); - } + return CreateLabelledTextTagTextBox(CurrentLyric, item).With(t => + { + t.Label = relativeToLyricText; + t.Description = range; + t.TabbableContentContainer = this; + }); + } - private void addCreateButton() - { - var fillFlowContainer = Content as FillFlowContainer; + protected abstract LabelledTextTagTextBox CreateLabelledTextTagTextBox(Lyric lyric, TTextTag textTag); - // create new button. - fillFlowContainer?.Insert(int.MaxValue, new CreateNewTextTagButton + protected override EditorSectionButton CreateCreateNewItemButton() { - Text = CreateNewTextTagButtonText(), - LabelledTextBoxLabel = CreateNewTextTagTitle(), - LabelledTextBoxDescription = CreateNewTextTagDescription(), - Action = AddTextTag - }); - } - - protected abstract IBindableList GetBindableTextTags(Lyric lyric); - - protected abstract LabelledTextTagTextBox CreateLabelledTextTagTextBox(Lyric lyric, TTextTag textTag); + return new CreateNewTextTagButton + { + Text = CreateNewTextTagButtonText(), + LabelledTextBoxLabel = CreateNewTextTagTitle(), + LabelledTextBoxDescription = CreateNewTextTagDescription(), + Action = AddTextTag + }; + } + + protected override IBindableList GetItems(Lyric lyric) + { + throw new System.NotImplementedException(); + } - protected abstract void AddTextTag(TTextTag textTag); + protected abstract LocalisableString CreateNewTextTagButtonText(); - protected abstract LocalisableString CreateNewTextTagButtonText(); + protected abstract LocalisableString CreateNewTextTagTitle(); - protected abstract LocalisableString CreateNewTextTagTitle(); + protected abstract LocalisableString CreateNewTextTagDescription(); - protected abstract LocalisableString CreateNewTextTagDescription(); + protected abstract void AddTextTag(TTextTag textTag); + } } }