Skip to content

Commit

Permalink
Apply the base class for the ruby/romaji edit section.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Jan 18, 2023
1 parent 357cc30 commit ee86be3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,7 @@ public partial class RomajiTagEditSection : TextTagEditSection<RomajiTag>
{
protected override LocalisableString Title => "Romaji";

[Resolved]
private ILyricRomajiTagsChangeHandler romajiTagsChangeHandler { get; set; }

protected override IBindableList<RomajiTag> GetBindableTextTags(Lyric lyric)
=> lyric.RomajiTagsBindable;

protected override LabelledTextTagTextBox<RomajiTag> 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));
Expand All @@ -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<RomajiTag> GetItems(Lyric lyric)
=> lyric.RomajiTagsBindable;

protected override LabelledTextTagTextBox<RomajiTag> 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<RomajiTag>
{
[Resolved]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,7 @@ public partial class RubyTagEditSection : TextTagEditSection<RubyTag>
{
protected override LocalisableString Title => "Ruby";

[Resolved]
private ILyricRubyTagsChangeHandler rubyTagsChangeHandler { get; set; }

protected override IBindableList<RubyTag> GetBindableTextTags(Lyric lyric)
=> lyric.RubyTagsBindable;

protected override LabelledTextTagTextBox<RubyTag> 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));
Expand All @@ -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<RubyTag> GetItems(Lyric lyric)
=> lyric.RubyTagsBindable;

protected override LabelledTextTagTextBox<RubyTag> 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<RubyTag>
{
[Resolved]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,72 +13,48 @@

namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Lyrics.Settings.RubyRomaji
{
public abstract partial class TextTagEditSection<TTextTag> : LyricPropertySection where TTextTag : class, ITextTag, new()
public abstract partial class TextTagEditSection<TTextTag> : LyricPropertiesSection<TTextTag> where TTextTag : class, ITextTag, new()
{
protected readonly IBindableList<TTextTag> TextTags = new BindableList<TTextTag>();

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<TTextTag>, 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<TTextTag> CreateLabelledTextTagTextBox(Lyric lyric, TTextTag textTag);

// create new button.
fillFlowContainer?.Insert(int.MaxValue, new CreateNewTextTagButton<TTextTag>
protected override EditorSectionButton CreateCreateNewItemButton()
{
Text = CreateNewTextTagButtonText(),
LabelledTextBoxLabel = CreateNewTextTagTitle(),
LabelledTextBoxDescription = CreateNewTextTagDescription(),
Action = AddTextTag
});
}

protected abstract IBindableList<TTextTag> GetBindableTextTags(Lyric lyric);

protected abstract LabelledTextTagTextBox<TTextTag> CreateLabelledTextTagTextBox(Lyric lyric, TTextTag textTag);
return new CreateNewTextTagButton<TTextTag>
{
Text = CreateNewTextTagButtonText(),
LabelledTextBoxLabel = CreateNewTextTagTitle(),
LabelledTextBoxDescription = CreateNewTextTagDescription(),
Action = AddTextTag
};
}

protected override IBindableList<TTextTag> 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);
}
}
}

0 comments on commit ee86be3

Please sign in to comment.