From 2506f14e2ec8d9b4ec885c03f88fdb7e04d78d6d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 25 Jul 2022 01:10:42 +0800 Subject: [PATCH 1/6] Fix wrong config using. --- .../Generator/ReferenceLyric/ReferenceLyricDetectorConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Generator/ReferenceLyric/ReferenceLyricDetectorConfig.cs b/osu.Game.Rulesets.Karaoke/Edit/Generator/ReferenceLyric/ReferenceLyricDetectorConfig.cs index 4d3d46b77..c1b3a5f0d 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Generator/ReferenceLyric/ReferenceLyricDetectorConfig.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Generator/ReferenceLyric/ReferenceLyricDetectorConfig.cs @@ -1,7 +1,7 @@ // Copyright (c) andy840119 . Licensed under the GPL Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Game.Rulesets.Karaoke.Edit.Checks.Configs; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Types; namespace osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric { From 47b1bca25a69a4ed624e356a9b8f74f832c26af3 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 25 Jul 2022 01:06:06 +0800 Subject: [PATCH 2/6] Add the reference lyric detector config into the config manager. --- .../KaraokeRulesetEditGeneratorConfigManager.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs index 00ed5103c..fa83c329b 100644 --- a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs +++ b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs @@ -4,6 +4,7 @@ using osu.Game.Configuration; using osu.Game.Rulesets.Karaoke.Edit.Generator.Language; using osu.Game.Rulesets.Karaoke.Edit.Generator.Notes; +using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric; using osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags.Ja; using osu.Game.Rulesets.Karaoke.Edit.Generator.RubyTags.Ja; using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags.Ja; @@ -18,6 +19,9 @@ protected override void InitialiseDefaults() { base.InitialiseDefaults(); + // Language detection + SetDefault(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig, CreateDefaultConfig()); + // Language detection SetDefault(KaraokeRulesetEditGeneratorSetting.LanguageDetectorConfig, CreateDefaultConfig()); @@ -41,6 +45,9 @@ protected override void InitialiseDefaults() public enum KaraokeRulesetEditGeneratorSetting { + // Reference lyric detection. + ReferenceLyricDetectorConfig, + // Language detection LanguageDetectorConfig, From bcda986a9efab4a27b5310e300ba377f0b4132f0 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 25 Jul 2022 01:08:50 +0800 Subject: [PATCH 3/6] I guess this shit can be removed. --- .../Configuration/KaraokeRulesetEditGeneratorConfigManager.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs index fa83c329b..3b5bbbd9d 100644 --- a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs +++ b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs @@ -51,9 +51,6 @@ public enum KaraokeRulesetEditGeneratorSetting // Language detection LanguageDetectorConfig, - // Layout generator - LayoutGeneratorConfig, - // Note generator NoteGeneratorConfig, From b2bb285bb8260791ea7c383ff8ae14d08521d69d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Mon, 25 Jul 2022 01:06:47 +0800 Subject: [PATCH 4/6] Now it's able to detect or detect the reference lyric in the change handler. --- .../Lyrics/ILyricAutoGenerateChangeHandler.cs | 2 ++ .../Lyrics/LyricAutoGenerateChangeHandler.cs | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricAutoGenerateChangeHandler.cs index de881ae2c..5d7732837 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/ILyricAutoGenerateChangeHandler.cs @@ -19,6 +19,8 @@ public interface ILyricAutoGenerateChangeHandler public enum LyricAutoGenerateProperty { + DetectReferenceLyric, + DetectLanguage, AutoGenerateRubyTags, diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs index 2df9b9ce9..214ec7bfb 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandler.cs @@ -11,6 +11,7 @@ using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Rulesets.Karaoke.Edit.Generator.Language; using osu.Game.Rulesets.Karaoke.Edit.Generator.Notes; +using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric; using osu.Game.Rulesets.Karaoke.Edit.Generator.RomajiTags; using osu.Game.Rulesets.Karaoke.Edit.Generator.RubyTags; using osu.Game.Rulesets.Karaoke.Edit.Generator.TimeTags; @@ -32,6 +33,10 @@ public bool CanGenerate(LyricAutoGenerateProperty autoGenerateProperty) { switch (autoGenerateProperty) { + case LyricAutoGenerateProperty.DetectReferenceLyric: + var referenceLyricDetector = createLyricDetector(); + return canDetect(referenceLyricDetector); + case LyricAutoGenerateProperty.DetectLanguage: var languageDetector = createLyricDetector(); return canDetect(languageDetector); @@ -67,6 +72,10 @@ public IDictionary GetNotGeneratableLyrics(LyricAutoGe { switch (autoGenerateProperty) { + case LyricAutoGenerateProperty.DetectReferenceLyric: + var referenceLyricDetector = createLyricDetector(); + return getInvalidMessageFromDetector(referenceLyricDetector); + case LyricAutoGenerateProperty.DetectLanguage: var languageDetector = createLyricDetector(); return getInvalidMessageFromDetector(languageDetector); @@ -106,6 +115,15 @@ public void AutoGenerate(LyricAutoGenerateProperty autoGenerateProperty) { switch (autoGenerateProperty) { + case LyricAutoGenerateProperty.DetectReferenceLyric: + var referenceLyricDetector = createLyricDetector(); + PerformOnSelection(lyric => + { + var detectedLanguage = referenceLyricDetector.Detect(lyric); + lyric.ReferenceLyric = detectedLanguage; + }); + break; + case LyricAutoGenerateProperty.DetectLanguage: var languageDetector = createLyricDetector(); PerformOnSelection(lyric => @@ -161,9 +179,14 @@ private ILyricPropertyDetector createLyricDetector() { switch (typeof(T)) { + case Type t when t == typeof(Lyric): + var lyrics = beatmap.HitObjects.OfType().ToArray(); + var referenceLyricDetectorConfig = generatorConfigManager.Get(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig); + return (ILyricPropertyDetector)new ReferenceLyricDetector(lyrics, referenceLyricDetectorConfig); + case Type t when t == typeof(CultureInfo): - var config = generatorConfigManager.Get(KaraokeRulesetEditGeneratorSetting.LanguageDetectorConfig); - return (ILyricPropertyDetector)new LanguageDetector(config); + var languageDetectorConfig = generatorConfigManager.Get(KaraokeRulesetEditGeneratorSetting.LanguageDetectorConfig); + return (ILyricPropertyDetector)new LanguageDetector(languageDetectorConfig); default: throw new NotSupportedException(); From 894c57669dca6d479b5b920238987249e77672ab Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 26 Jul 2022 01:27:02 +0800 Subject: [PATCH 5/6] Implement the config popover and dialog for the reference lyric mode. --- .../ReferenceLyric/GenericSection.cs | 32 +++++++++++++++++++ .../ReferenceLyricDetectorConfigDialog.cs | 31 ++++++++++++++++++ .../ReferenceLyricDetectorConfigPopover.cs | 24 ++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/GenericSection.cs create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigDialog.cs create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigPopover.cs diff --git a/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/GenericSection.cs b/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/GenericSection.cs new file mode 100644 index 000000000..6a944dfa7 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/GenericSection.cs @@ -0,0 +1,32 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Game.Graphics.UserInterfaceV2; +using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric; + +namespace osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric +{ + public class GenericSection : GeneratorConfigSection + { + private readonly LabelledSwitchButton ignorePrefixAndPostfixSymbol; + + protected override string Title => "Generic"; + + public GenericSection(Bindable current) + : base(current) + { + Children = new Drawable[] + { + ignorePrefixAndPostfixSymbol = new LabelledSwitchButton + { + Label = "Ruby as Katakana", + Description = "Ruby as Katakana.", + }, + }; + + RegisterConfig(ignorePrefixAndPostfixSymbol.Current, nameof(ReferenceLyricDetectorConfig.IgnorePrefixAndPostfixSymbol)); + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigDialog.cs b/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigDialog.cs new file mode 100644 index 000000000..2a10aaa52 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigDialog.cs @@ -0,0 +1,31 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using osu.Framework.Bindables; +using osu.Game.Overlays; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric; + +namespace osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric +{ + public class ReferenceLyricGeneratorConfigDialog : GeneratorConfigDialog + { + protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.NoteGeneratorConfig; + + protected override OverlayColourScheme OverlayColourScheme => OverlayColourScheme.Green; + + protected override string Title => "Reference lyric config"; + + protected override string Description => "Change config for reference lyric detector."; + + protected override GeneratorConfigSection[] CreateConfigSection(Bindable current) + { + return new GeneratorConfigSection[] + { + new GenericSection(current), + }; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigPopover.cs b/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigPopover.cs new file mode 100644 index 000000000..f501e3c2d --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Configs/Generator/ReferenceLyric/ReferenceLyricDetectorConfigPopover.cs @@ -0,0 +1,24 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using osu.Framework.Bindables; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.Generator.ReferenceLyric; + +namespace osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric +{ + public class ReferenceLyricDetectorConfigPopover : GeneratorConfigPopover + { + protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig; + + protected override GeneratorConfigSection[] CreateConfigSection(Bindable current) + { + return new GeneratorConfigSection[] + { + new GenericSection(current), + }; + } + } +} From 26857d4968565506dd7da74fc9b42398dd55e887 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Tue, 26 Jul 2022 01:30:04 +0800 Subject: [PATCH 6/6] Implement the reference lyric edit mode section. --- .../Extends/Reference/ReferenceExtend.cs | 20 +++++++ .../ReferenceLyricAutoGenerateSection.cs | 55 +++++++++++++++++++ .../Edit/Lyrics/LyricEditor.cs | 2 + 3 files changed, 77 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceExtend.cs create mode 100644 osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricAutoGenerateSection.cs diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceExtend.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceExtend.cs new file mode 100644 index 000000000..a1419ae48 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceExtend.cs @@ -0,0 +1,20 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference +{ + public class ReferenceExtend : EditExtend + { + public override ExtendDirection Direction => ExtendDirection.Right; + + public override float ExtendWidth => 300; + + public ReferenceExtend() + { + Children = new[] + { + new ReferenceLyricAutoGenerateSection(), + }; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricAutoGenerateSection.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricAutoGenerateSection.cs new file mode 100644 index 000000000..2044095c5 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/Extends/Reference/ReferenceLyricAutoGenerateSection.cs @@ -0,0 +1,55 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Localisation; +using osu.Game.Rulesets.Karaoke.Edit.Components.Containers; +using osu.Game.Rulesets.Karaoke.Edit.Configs.Generator.ReferenceLyric; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Components; + +namespace osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference +{ + public class ReferenceLyricAutoGenerateSection : Section + { + protected override LocalisableString Title => "Auto generate"; + + public ReferenceLyricAutoGenerateSection() + { + Children = new[] + { + new ReferenceLyricAutoGenerateSubsection() + }; + } + + private class ReferenceLyricAutoGenerateSubsection : AutoGenerateSubsection + { + public ReferenceLyricAutoGenerateSubsection() + : base(LyricAutoGenerateProperty.DetectReferenceLyric) + { + } + + protected override InvalidLyricAlertTextContainer CreateInvalidLyricAlertTextContainer() + => new InvalidLyricLanguageAlertTextContainer(); + + protected override ConfigButton CreateConfigButton() + => new ReferenceLyricAutoGenerateConfigButton(); + + protected class InvalidLyricLanguageAlertTextContainer : InvalidLyricAlertTextContainer + { + private const string language_mode = "LANGUAGE_MODE"; + + public InvalidLyricLanguageAlertTextContainer() + { + SwitchToEditorMode(language_mode, "edit language mode", LyricEditorMode.Language); + Text = $"Seems some lyric missing language, go to [{language_mode}] to fill the language."; + } + } + + protected class ReferenceLyricAutoGenerateConfigButton : ConfigButton + { + public override Popover GetPopover() + => new ReferenceLyricDetectorConfigPopover(); + } + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs index 38012409b..4a0dd0b0c 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/LyricEditor.cs @@ -18,6 +18,7 @@ using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Languages; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Notes; +using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Reference; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.RubyRomaji; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Singers; using osu.Game.Rulesets.Karaoke.Edit.Lyrics.Extends.Texting; @@ -230,6 +231,7 @@ EditExtend getExtendArea() => Mode switch { LyricEditorMode.Texting => new TextingExtend(), + LyricEditorMode.Reference => new ReferenceExtend(), LyricEditorMode.Language => new LanguageExtend(), LyricEditorMode.EditRuby => new RubyTagExtend(), LyricEditorMode.EditRomaji => new RomajiTagExtend(),