diff --git a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs index 00ed5103c..3b5bbbd9d 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,12 +45,12 @@ protected override void InitialiseDefaults() public enum KaraokeRulesetEditGeneratorSetting { + // Reference lyric detection. + ReferenceLyricDetectorConfig, + // Language detection LanguageDetectorConfig, - // Layout generator - LayoutGeneratorConfig, - // Note generator NoteGeneratorConfig, 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(); 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), + }; + } + } +} 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 { 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(),