From c486d1cd898640be8b9fb4444dc44c2d9a17db0a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 4 Sep 2022 17:33:15 +0800 Subject: [PATCH 1/4] Rename the component. --- ...LyricSelector.cs => LabelledReferenceLyricSelector.cs} | 4 ++-- .../Lyrics/Extends/Reference/ReferenceLyricSection.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) rename osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/{LabelledLyricSelector.cs => LabelledReferenceLyricSelector.cs} (96%) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledLyricSelector.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs similarity index 96% rename from osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledLyricSelector.cs rename to osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs index c2dad451e..31d3ab075 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledLyricSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs @@ -21,9 +21,9 @@ namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference { - public class LabelledLyricSelector : LabelledComponent + public class LabelledReferenceLyricSelector : LabelledComponent { - public LabelledLyricSelector() + public LabelledReferenceLyricSelector() : base(true) { } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs index ba4538810..7a896bda8 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs @@ -16,20 +16,20 @@ public class ReferenceLyricSection : LyricPropertySection [Resolved, AllowNull] private ILyricReferenceChangeHandler lyricReferenceChangeHandler { get; set; } - private readonly LabelledLyricSelector labelledLyricSelector; + private readonly LabelledReferenceLyricSelector labelledReferenceLyricSelector; public ReferenceLyricSection() { Children = new[] { - labelledLyricSelector = new LabelledLyricSelector + labelledReferenceLyricSelector = new LabelledReferenceLyricSelector { Label = "Referenced lyric", Description = "Select the similar lyric that want to reference or sync the property." } }; - labelledLyricSelector.Current.BindValueChanged(x => + labelledReferenceLyricSelector.Current.BindValueChanged(x => { if (!IsRebinding) lyricReferenceChangeHandler.UpdateReferenceLyric(x.NewValue); @@ -41,7 +41,7 @@ protected override void OnLyricChanged(Lyric? lyric) if (lyric == null) return; - labelledLyricSelector.Current = lyric.ReferenceLyricBindable; + labelledReferenceLyricSelector.Current = lyric.ReferenceLyricBindable; } } } From 208f98bb24706a6a8563fb1bc917df308e4eccea Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 4 Sep 2022 22:18:09 +0800 Subject: [PATCH 2/4] Should disable select the same lyric as reference lyric. --- .../LabelledReferenceLyricSelector.cs | 29 +++++++++++++++---- .../Reference/ReferenceLyricSection.cs | 1 + 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs index 31d3ab075..6fdf2d99d 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs @@ -34,6 +34,12 @@ protected override SelectLyricButton CreateComponent() RelativeSizeAxes = Axes.X }; + public Lyric? IgnoredLyric + { + get => Component.IgnoredLyric; + set => Component.IgnoredLyric = value; + } + public class SelectLyricButton : OsuButton, IHasCurrentValue, IHasPopover { private readonly BindableWithCurrent current = new(); @@ -44,6 +50,8 @@ public Bindable Current set => current.Current = value; } + public Lyric? IgnoredLyric { get; set; } + public SelectLyricButton() { Action = this.ShowPopover; @@ -57,15 +65,20 @@ public SelectLyricButton() } public Popover GetPopover() - => new LyricSelectorPopover(Current); + => new LyricSelectorPopover(Current, IgnoredLyric); } private class LyricSelectorPopover : OsuPopover { private readonly ReferenceLyricSelector lyricSelector; - public LyricSelectorPopover(Bindable bindable) + [Cached] + private readonly Lyric? ignoreLyric; + + public LyricSelectorPopover(Bindable bindable, Lyric? ignoreLyric) { + this.ignoreLyric = ignoreLyric; + Child = lyricSelector = new ReferenceLyricSelector { Width = 400, @@ -100,6 +113,9 @@ protected class DrawableReferenceLyricListItem : DrawableLyricListItem [Resolved, AllowNull] private EditorBeatmap editorBeatmap { get; set; } + [Resolved] + private Lyric? ignoredLyric { get; set; } + public DrawableReferenceLyricListItem(Lyric? item) : base(item) { @@ -118,14 +134,14 @@ protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContai { base.CreateDisplayContent(textFlowContainer, model); - // should have disable style if lyric is not selectable. - textFlowContainer.Alpha = selectable(model) ? 1 : 0.5f; - if (model == null) return; Schedule(() => { + // should have disable style if lyric is not selectable. + textFlowContainer.Alpha = selectable(model) ? 1 : 0.5f; + // add reference text at the end of the text. int referenceLyricsAmount = EditorBeatmapUtils.GetAllReferenceLyrics(editorBeatmap, model).Count(); @@ -136,7 +152,8 @@ protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContai }); } - private static bool selectable(Lyric? lyric) => lyric?.ReferenceLyric == null; + private bool selectable(Lyric? lyric) + => lyric != ignoredLyric && lyric?.ReferenceLyric == null; } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs index 7a896bda8..c1be3b8dc 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricSection.cs @@ -42,6 +42,7 @@ protected override void OnLyricChanged(Lyric? lyric) return; labelledReferenceLyricSelector.Current = lyric.ReferenceLyricBindable; + labelledReferenceLyricSelector.IgnoredLyric = lyric; } } } From 1f20dd334120d1abb0f94607669f7c9c896744c5 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 4 Sep 2022 22:22:49 +0800 Subject: [PATCH 3/4] Should not enable the select reference lyric button if lyric has being referenced. --- .../Reference/LabelledReferenceLyricSelector.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs index 6fdf2d99d..3d14ce860 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs @@ -42,6 +42,9 @@ public Lyric? IgnoredLyric public class SelectLyricButton : OsuButton, IHasCurrentValue, IHasPopover { + [Resolved, AllowNull] + private EditorBeatmap editorBeatmap { get; set; } + private readonly BindableWithCurrent current = new(); public Bindable Current @@ -50,7 +53,19 @@ public Bindable Current set => current.Current = value; } - public Lyric? IgnoredLyric { get; set; } + private Lyric? ignoredLyric; + + public Lyric? IgnoredLyric + { + get => ignoredLyric; + set + { + ignoredLyric = value; + + // should not enable the selection if current lyric is being referenced. + Enabled.Value = ignoredLyric != null && !EditorBeatmapUtils.GetAllReferenceLyrics(editorBeatmap, ignoredLyric).Any(); + } + } public SelectLyricButton() { From 9c1917a72f94cd049cbcf4c12c5d74410e361eb6 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 4 Sep 2022 22:26:09 +0800 Subject: [PATCH 4/4] Will start fill the text after BDL loaded, so there's no need to add schedule in the child class. --- .../UserInterfaceV2/LyricSelector.cs | 17 ++++++-------- .../LabelledReferenceLyricSelector.cs | 21 ++++++++--------- .../RearrangeableTextFlowListContainer.cs | 9 +++++++- .../Graphics/UserInterfaceV2/FontSelector.cs | 23 ++++++++----------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Components/UserInterfaceV2/LyricSelector.cs b/osu.Game.Rulesets.Karaoke/Edit/Components/UserInterfaceV2/LyricSelector.cs index 6ddd46ff8..81f11bf1c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Components/UserInterfaceV2/LyricSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Components/UserInterfaceV2/LyricSelector.cs @@ -129,16 +129,13 @@ protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContai } else { - Schedule(() => - { - // display the lyric order. - textFlowContainer.AddText($"#{model.Order}", x => x.Colour = colours.Yellow); - textFlowContainer.AddText(" "); - - // main text - textFlowContainer.AddText(model.Text); - textFlowContainer.AddText(" "); - }); + // display the lyric order. + textFlowContainer.AddText($"#{model.Order}", x => x.Colour = colours.Yellow); + textFlowContainer.AddText(" "); + + // main text + textFlowContainer.AddText(model.Text); + textFlowContainer.AddText(" "); } } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs index 3d14ce860..7e0651abf 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/LabelledReferenceLyricSelector.cs @@ -147,24 +147,21 @@ protected override bool OnClick(ClickEvent e) protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, Lyric? model) { + // should have disable style if lyric is not selectable. + textFlowContainer.Alpha = selectable(model) ? 1 : 0.5f; + base.CreateDisplayContent(textFlowContainer, model); if (model == null) return; - Schedule(() => - { - // should have disable style if lyric is not selectable. - textFlowContainer.Alpha = selectable(model) ? 1 : 0.5f; - - // add reference text at the end of the text. - int referenceLyricsAmount = EditorBeatmapUtils.GetAllReferenceLyrics(editorBeatmap, model).Count(); + // add reference text at the end of the text. + int referenceLyricsAmount = EditorBeatmapUtils.GetAllReferenceLyrics(editorBeatmap, model).Count(); - if (referenceLyricsAmount > 0) - { - textFlowContainer.AddText($"({referenceLyricsAmount} reference)", x => x.Colour = colours.Red); - } - }); + if (referenceLyricsAmount > 0) + { + textFlowContainer.AddText($"({referenceLyricsAmount} reference)", x => x.Colour = colours.Red); + } } private bool selectable(Lyric? lyric) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs index 2a2033907..0a3548725 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/RearrangeableTextFlowListContainer.cs @@ -95,7 +95,14 @@ protected override void LoadComplete() { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - }.With(x => CreateDisplayContent(x, Model)); + }.With(x => + { + Schedule(() => + { + // should create the text after BDL loaded. + CreateDisplayContent(x, Model); + }); + }); protected override bool OnClick(ClickEvent e) { diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs index fe1a3b9d5..316fdea7b 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs @@ -271,21 +271,18 @@ public DrawableFontFamilyListItem(string item) protected override void CreateDisplayContent(OsuTextFlowContainer textFlowContainer, string model) { textFlowContainer.TextAnchor = Anchor.BottomLeft; - Schedule(() => - { - textFlowContainer.AddText(model); + textFlowContainer.AddText(model); - var matchedFormat = fontManager.Fonts - .Where(x => x.Family == Model).Select(x => x.FontFormat) - .Distinct() - .ToArray(); + var matchedFormat = fontManager.Fonts + .Where(x => x.Family == Model).Select(x => x.FontFormat) + .Distinct() + .ToArray(); - foreach (var format in matchedFormat) - { - textFlowContainer.AddText(" "); - textFlowContainer.AddArbitraryDrawable(new FontFormatBadge(format)); - } - }); + foreach (var format in matchedFormat) + { + textFlowContainer.AddText(" "); + textFlowContainer.AddArbitraryDrawable(new FontFormatBadge(format)); + } } } }