From df78635efc6160ea199849b950183202a8a396e1 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Fri, 23 Dec 2022 23:21:52 +0800 Subject: [PATCH 1/7] Add config for beatmap page generator. --- .../KaraokeRulesetEditGeneratorConfigManager.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs index 00cc89df0..9e3535533 100644 --- a/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs +++ b/osu.Game.Rulesets.Karaoke/Configuration/KaraokeRulesetEditGeneratorConfigManager.cs @@ -3,6 +3,7 @@ using osu.Game.Configuration; using osu.Game.Rulesets.Karaoke.Edit.Generator; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Language; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.Notes; using osu.Game.Rulesets.Karaoke.Edit.Generator.Lyrics.ReferenceLyric; @@ -19,6 +20,9 @@ protected override void InitialiseDefaults() { base.InitialiseDefaults(); + // Beatmap page + SetDefault(KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig, CreateDefaultConfig()); + // Language detection SetDefault(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig, CreateDefaultConfig()); @@ -37,6 +41,9 @@ protected override void InitialiseDefaults() // Time tag generator SetDefault(KaraokeRulesetEditGeneratorSetting.JaTimeTagGeneratorConfig, CreateDefaultConfig()); SetDefault(KaraokeRulesetEditGeneratorSetting.ZhTimeTagGeneratorConfig, CreateDefaultConfig()); + + // Language detection + SetDefault(KaraokeRulesetEditGeneratorSetting.ReferenceLyricDetectorConfig, CreateDefaultConfig()); } protected static T CreateDefaultConfig() where T : IHasConfig, new() @@ -45,6 +52,9 @@ protected override void InitialiseDefaults() public enum KaraokeRulesetEditGeneratorSetting { + // Beatmap + BeatmapPageGeneratorConfig, + // Reference lyric detection. ReferenceLyricDetectorConfig, From c7c54d001fdce2b3a7abaafd0aa50c0daf2ef11e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Fri, 23 Dec 2022 23:43:28 +0800 Subject: [PATCH 2/7] Move the injection logic into the base class because might have more change handler with auto-generator logic inside. --- .../ChangeHandlers/BaseChangeHandlerTest.cs | 15 +++++++++++++++ .../Lyrics/LyricAutoGenerateChangeHandlerTest.cs | 8 +------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseChangeHandlerTest.cs index f437e81c4..7616a1a34 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/BaseChangeHandlerTest.cs @@ -10,6 +10,7 @@ using osu.Framework.Testing; using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas; +using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Rulesets.Objects; using osu.Game.Screens.Edit; using osu.Game.Tests.Visual; @@ -71,6 +72,20 @@ public virtual void SetUp() }); } + protected virtual bool IncludeAutoGenerator => false; + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + if (!IncludeAutoGenerator) + { + return base.CreateChildDependencies(parent); + } + + var baseDependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + baseDependencies.Cache(new KaraokeRulesetEditGeneratorConfigManager()); + return baseDependencies; + } + protected void SetUpEditorBeatmap(Action action) { AddStep("Prepare testing beatmap", () => diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandlerTest.cs index b5eb433ab..e80d7e774 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Lyrics/LyricAutoGenerateChangeHandlerTest.cs @@ -6,7 +6,6 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; -using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Lyrics; using osu.Game.Rulesets.Karaoke.Edit.Generator; using osu.Game.Rulesets.Karaoke.Edit.Utils; @@ -18,12 +17,7 @@ namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Lyrics { public partial class LyricAutoGenerateChangeHandlerTest : LyricPropertyChangeHandlerTest { - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - { - var baseDependencies = new DependencyContainer(base.CreateChildDependencies(parent)); - baseDependencies.Cache(new KaraokeRulesetEditGeneratorConfigManager()); - return baseDependencies; - } + protected override bool IncludeAutoGenerator => true; #region Reference lyric From ba21a268dd9b2cbbe4cf2cfa061c360fe96ba92e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Fri, 23 Dec 2022 23:55:52 +0800 Subject: [PATCH 3/7] Add the auto-generator logic in the page change handler. --- .../Beatmaps/BeatmapPagesChangeHandlerTest.cs | 32 ++++++++++++++++++ .../Beatmaps/BeatmapPagesChangeHandler.cs | 33 +++++++++++++++++++ .../Beatmaps/IBeatmapPagesChangeHandler.cs | 5 +++ 3 files changed, 70 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandlerTest.cs b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandlerTest.cs index bafbad161..3b670b709 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandlerTest.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Editor/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandlerTest.cs @@ -4,11 +4,43 @@ using NUnit.Framework; using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas; using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; +using osu.Game.Rulesets.Karaoke.Edit.Generator; +using osu.Game.Rulesets.Karaoke.Objects; +using osu.Game.Rulesets.Karaoke.Tests.Helper; namespace osu.Game.Rulesets.Karaoke.Tests.Editor.ChangeHandlers.Beatmaps; public partial class BeatmapPagesChangeHandlerTest : BaseChangeHandlerTest { + protected override bool IncludeAutoGenerator => true; + + [Test] + public void TestGeneratePage() + { + PrepareHitObject(TestCaseTagHelper.ParseLyric("[1000,3000]:karaoke"), false); + + TriggerHandlerChanged(c => c.AutoGenerate()); + + AssertKaraokeBeatmap(karaokeBeatmap => + { + var pages = karaokeBeatmap.PageInfo.SortedPages; + + Assert.AreEqual(2, pages.Count); + + Assert.AreEqual(1000, pages[0].Time); + Assert.AreEqual(3000, pages[1].Time); + }); + } + + [Test] + public void TestGeneratePageWithInvalidCase() + { + // there's no time-info inside. + PrepareHitObject(new Lyric(), false); + + TriggerHandlerChangedWithException(c => c.AutoGenerate()); + } + [Test] public void TestAdd() { diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandler.cs index eae765a6d..4f2061819 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/BeatmapPagesChangeHandler.cs @@ -3,13 +3,46 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; +using osu.Framework.Allocation; +using osu.Framework.Localisation; using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages; namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; public partial class BeatmapPagesChangeHandler : BeatmapPropertyChangeHandler, IBeatmapPagesChangeHandler { + [Resolved, AllowNull] + private KaraokeRulesetEditGeneratorConfigManager generatorConfigManager { get; set; } + + public LocalisableString? GetNotGeneratableMessage() + { + var config = getGeneratorConfig(); + var generator = new PageGenerator(config); + return generator.GetInvalidMessage(KaraokeBeatmap); + } + + public void AutoGenerate() + { + var config = getGeneratorConfig(); + var generator = new PageGenerator(config); + var pages = generator.Generate(KaraokeBeatmap); + + performPageInfoChanged(pageInfo => + { + if (config.ClearExistPages) + pageInfo.Pages.Clear(); + + pageInfo.Pages.AddRange(pages); + }); + } + + private PageGeneratorConfig getGeneratorConfig() + => generatorConfigManager.Get(KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig); + public void Add(Page page) { performPageInfoChanged(pageInfo => diff --git a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/IBeatmapPagesChangeHandler.cs b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/IBeatmapPagesChangeHandler.cs index c073db7e9..a313d26d0 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/IBeatmapPagesChangeHandler.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/ChangeHandlers/Beatmaps/IBeatmapPagesChangeHandler.cs @@ -2,12 +2,17 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using osu.Framework.Localisation; using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas; namespace osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; public interface IBeatmapPagesChangeHandler { + LocalisableString? GetNotGeneratableMessage(); + + void AutoGenerate(); + void Add(Page page); void Remove(Page page); From 9c36b31778946885ac6b2d0ff41bc13f1727a326 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 24 Dec 2022 23:04:05 +0800 Subject: [PATCH 4/7] Implement the modal and popover for able to adjust the page generator. --- .../TestSceneBeatmapGeneratorConfigDialog.cs | 36 ++++++++++++ .../Beatmaps/Pages/GenericSection.cs | 58 +++++++++++++++++++ .../Pages/PageGeneratorConfigDialog.cs | 29 ++++++++++ .../Pages/PageGeneratorConfigPopover.cs | 22 +++++++ 4 files changed, 145 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Configs/TestSceneBeatmapGeneratorConfigDialog.cs create mode 100644 osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/GenericSection.cs create mode 100644 osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigDialog.cs create mode 100644 osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigPopover.cs diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Configs/TestSceneBeatmapGeneratorConfigDialog.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Configs/TestSceneBeatmapGeneratorConfigDialog.cs new file mode 100644 index 000000000..d2a597fe5 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/Configs/TestSceneBeatmapGeneratorConfigDialog.cs @@ -0,0 +1,36 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages; +using osu.Game.Tests.Visual; + +namespace osu.Game.Rulesets.Karaoke.Tests.Screens.Edit.Beatmap.Configs; + +[TestFixture] +public partial class TestSceneBeatmapGeneratorConfigDialog : OsuTestScene +{ + [BackgroundDependencyLoader] + private void load() + { + var config = new KaraokeRulesetEditGeneratorConfigManager(); + Dependencies.Cache(config); + } + + [TestCase(typeof(PageGeneratorConfigDialog), TestName = nameof(PageGeneratorConfigDialog))] + public void TestGenerate(Type configType) + { + AddStep("Show dialog", () => + { + Schedule(() => + { + Child = Activator.CreateInstance(configType) as Drawable; + Child?.Show(); + }); + }); + } +} diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/GenericSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/GenericSection.cs new file mode 100644 index 000000000..71b3ab5a2 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/GenericSection.cs @@ -0,0 +1,58 @@ +// 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.Checks; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages; + +namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages; + +public partial class GenericSection : GeneratorConfigSection +{ + private readonly LabelledSliderBar minTimeTextBox; + private readonly LabelledSliderBar maxTimeTextButton; + private readonly LabelledSwitchButton clearExistPagesSwitchButton; + + protected override string Title => "Generic"; + + public GenericSection(Bindable current) + : base(current) + { + Children = new Drawable[] + { + minTimeTextBox = new LabelledSliderBar + { + Label = "Min time", + Description = "Min interval between pages.", + Current = new BindableDouble + { + MinValue = CheckBeatmapPageInfo.MIN_INTERVAL, + MaxValue = CheckBeatmapPageInfo.MAX_INTERVAL, + Precision = 0.1f, + } + }, + maxTimeTextButton = new LabelledSliderBar + { + Label = "Max time", + Description = "Max interval between pages.", + Current = new BindableDouble + { + MinValue = CheckBeatmapPageInfo.MIN_INTERVAL, + MaxValue = CheckBeatmapPageInfo.MAX_INTERVAL, + Precision = 0.1f, + } + }, + clearExistPagesSwitchButton = new LabelledSwitchButton + { + Label = "Clear the exist page.", + Description = "Clear the exist page after generated.", + }, + }; + + RegisterConfig(minTimeTextBox.Current, nameof(PageGeneratorConfig.MinTime)); + RegisterConfig(maxTimeTextButton.Current, nameof(PageGeneratorConfig.MaxTime)); + RegisterConfig(clearExistPagesSwitchButton.Current, nameof(PageGeneratorConfig.ClearExistPages)); + } +} diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigDialog.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigDialog.cs new file mode 100644 index 000000000..2b655b45c --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigDialog.cs @@ -0,0 +1,29 @@ +// 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.Game.Overlays; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages; + +namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages +{ + public partial class PageGeneratorConfigDialog : GeneratorConfigDialog + { + protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig; + + protected override OverlayColourScheme OverlayColourScheme => OverlayColourScheme.Green; + + protected override string Title => "Page generator config."; + + protected override string Description => "Change config for page generator."; + + protected override GeneratorConfigSection[] CreateConfigSection(Bindable current) + { + return new GeneratorConfigSection[] + { + new GenericSection(current), + }; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigPopover.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigPopover.cs new file mode 100644 index 000000000..ea102af22 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Configs/Generator/Beatmaps/Pages/PageGeneratorConfigPopover.cs @@ -0,0 +1,22 @@ +// 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.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages; + +namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages +{ + public partial class PageGeneratorConfigPopover : GeneratorConfigPopover + { + protected override KaraokeRulesetEditGeneratorSetting Config => KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig; + + protected override GeneratorConfigSection[] CreateConfigSection(Bindable current) + { + return new GeneratorConfigSection[] + { + new GenericSection(current), + }; + } + } +} From 6078ddf25e5b28e2716a697ca85832ce3867acbb Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 24 Dec 2022 22:26:48 +0800 Subject: [PATCH 5/7] Create the generate section and confirm generate dialog. --- .../Settings/ConfirmReGeneratePageDialog.cs | 31 +++++++ .../Pages/Settings/PageAutoGenerateSection.cs | 93 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/ConfirmReGeneratePageDialog.cs create mode 100644 osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageAutoGenerateSection.cs diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/ConfirmReGeneratePageDialog.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/ConfirmReGeneratePageDialog.cs new file mode 100644 index 000000000..d96025d15 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/ConfirmReGeneratePageDialog.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. + +using System; +using osu.Framework.Graphics.Sprites; +using osu.Game.Overlays.Dialog; + +namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Pages.Settings; + +public partial class ConfirmReGeneratePageDialog : PopupDialog +{ + public ConfirmReGeneratePageDialog(Action okAction) + { + Icon = FontAwesome.Solid.Trash; + HeaderText = "Are you sure re-generate the pages? It will delete all the pages in the beatmap."; + BodyText = "page"; + Buttons = new PopupDialogButton[] + { + new PopupDialogOkButton + { + Text = @"Yes. Go for it.", + Action = () => okAction.Invoke(true), + }, + new PopupDialogCancelButton + { + Text = @"No! Abort mission!", + Action = () => okAction.Invoke(false), + }, + }; + } +} diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageAutoGenerateSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageAutoGenerateSection.cs new file mode 100644 index 000000000..f7be7f906 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageAutoGenerateSection.cs @@ -0,0 +1,93 @@ +// Copyright (c) andy840119 . Licensed under the GPL Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Diagnostics.CodeAnalysis; +using osu.Framework.Allocation; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Game.Overlays; +using osu.Game.Rulesets.Karaoke.Configuration; +using osu.Game.Rulesets.Karaoke.Edit.ChangeHandlers.Beatmaps; +using osu.Game.Rulesets.Karaoke.Edit.Generator.Beatmaps.Pages; +using osu.Game.Rulesets.Karaoke.Graphics.Overlays.Dialog; +using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Configs.Generator.Beatmaps.Pages; +using osu.Game.Rulesets.Karaoke.Screens.Edit.Components.Markdown; + +namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Pages.Settings; + +public partial class PageAutoGenerateSection : AutoGenerateSection +{ + protected override AutoGenerateSubsection CreateAutoGenerateSubsection() + => new PageAutoGenerateSubsection(); + + private partial class PageAutoGenerateSubsection : AutoGenerateSubsection + { + protected override EditorSectionButton CreateGenerateButton() + => new PageAutoGenerateButton(); + + protected override DescriptionFormat CreateInvalidDescriptionFormat() + => new() + { + Text = "Seems have some time-related issues in the lyrics. Go to lyric editor to fix them." + }; + + protected override ConfigButton CreateConfigButton() + => new PageAutoGenerateConfigButton(); + + protected partial class PageAutoGenerateConfigButton : ConfigButton + { + public override Popover GetPopover() + => new PageGeneratorConfigPopover(); + } + + private partial class PageAutoGenerateButton : EditorSectionButton + { + [Resolved, AllowNull] + private KaraokeRulesetEditGeneratorConfigManager generatorConfigManager { get; set; } + + [Resolved, AllowNull] + private IDialogOverlay dialogOverlay { get; set; } + + [Resolved, AllowNull] + private IBeatmapPagesChangeHandler beatmapPagesChangeHandler { get; set; } + + public PageAutoGenerateButton() + { + Text = "Generate"; + Action = () => + { + var invalidMessage = beatmapPagesChangeHandler.GetNotGeneratableMessage(); + + if (invalidMessage != null) + { + dialogOverlay.Push(new OkPopupDialog + { + Icon = FontAwesome.Solid.ExclamationTriangle, + HeaderText = "Seems still have some issues need to be fixed.", + BodyText = invalidMessage.Value, + }); + return; + } + + bool clearPagesAfterGenerated = clearExistPagesAfterGenerated(); + + if (clearPagesAfterGenerated) + { + dialogOverlay.Push(new ConfirmReGeneratePageDialog(isOk => + { + if (isOk) + beatmapPagesChangeHandler.AutoGenerate(); + })); + } + else + { + beatmapPagesChangeHandler.AutoGenerate(); + } + }; + } + + private bool clearExistPagesAfterGenerated() + => generatorConfigManager.Get(KaraokeRulesetEditGeneratorSetting.BeatmapPageGeneratorConfig).ClearExistPages; + } + } +} From 907f7a56b695f34f574b4707359736f441ad358e Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 24 Dec 2022 14:40:56 +0800 Subject: [PATCH 6/7] Create new section for generate the page. --- .../Screens/Edit/Beatmaps/Pages/PageEditorEditMode.cs | 2 ++ .../Pages/Settings/PageEditorEditModeSection.cs | 10 +++++++--- .../Edit/Beatmaps/Pages/Settings/PageSettings.cs | 5 +++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/PageEditorEditMode.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/PageEditorEditMode.cs index 0f0eecd0a..dae735a3d 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/PageEditorEditMode.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/PageEditorEditMode.cs @@ -5,6 +5,8 @@ namespace osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Pages; public enum PageEditorEditMode { + Generate, + Edit, Verify diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageEditorEditModeSection.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageEditorEditModeSection.cs index 72591228a..913af5c32 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageEditorEditModeSection.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageEditorEditModeSection.cs @@ -33,6 +33,7 @@ protected override OverlayColourScheme CreateColourScheme() protected override Selection CreateSelection(PageEditorEditMode mode) => mode switch { + PageEditorEditMode.Generate => new Selection(), PageEditorEditMode.Edit => new Selection(), PageEditorEditMode.Verify => new PageEditorVerifySelection(), _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null) @@ -41,7 +42,8 @@ protected override Selection CreateSelection(PageEditorEditMode mode) => protected override LocalisableString GetSelectionText(PageEditorEditMode mode) => mode switch { - PageEditorEditMode.Edit => "Generate", + PageEditorEditMode.Generate => "Generate", + PageEditorEditMode.Edit => "Edit", PageEditorEditMode.Verify => "Verify", _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null) }; @@ -49,7 +51,8 @@ protected override LocalisableString GetSelectionText(PageEditorEditMode mode) = protected override Color4 GetSelectionColour(OsuColour colours, PageEditorEditMode mode, bool active) => mode switch { - PageEditorEditMode.Edit => active ? colours.Blue : colours.BlueDarker, + PageEditorEditMode.Generate => active ? colours.Blue : colours.BlueDarker, + PageEditorEditMode.Edit => active ? colours.Red : colours.RedDarker, PageEditorEditMode.Verify => active ? colours.Yellow : colours.YellowDarker, _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null) }; @@ -57,7 +60,8 @@ protected override Color4 GetSelectionColour(OsuColour colours, PageEditorEditMo protected override DescriptionFormat GetSelectionDescription(PageEditorEditMode mode) => mode switch { - PageEditorEditMode.Edit => "Edit the page.", + PageEditorEditMode.Generate => "Generate the pages by lyric.", + PageEditorEditMode.Edit => "Batch edit page in here.", PageEditorEditMode.Verify => "Check if have any page issues.", _ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null) }; diff --git a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageSettings.cs b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageSettings.cs index bbde5f742..a2a940578 100644 --- a/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageSettings.cs +++ b/osu.Game.Rulesets.Karaoke/Screens/Edit/Beatmaps/Pages/Settings/PageSettings.cs @@ -29,6 +29,11 @@ private void load(OverlayColourProvider colourProvider, IPageStateProvider pageS protected override IReadOnlyList CreateSections() => bindableMode.Value switch { + PageEditorEditMode.Generate => new Drawable[] + { + new PageEditorEditModeSection(), + new PageAutoGenerateSection(), + }, PageEditorEditMode.Edit => new Drawable[] { new PageEditorEditModeSection(), From 775ca745e6c48ebba2fa00eecb1545d8cb4fb88a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sun, 25 Dec 2022 00:23:53 +0800 Subject: [PATCH 7/7] Add missing injection. --- .../Screens/Edit/Beatmap/TestScenePageScreen.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestScenePageScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestScenePageScreen.cs index a9a0c545e..8260f029a 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestScenePageScreen.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Screens/Edit/Beatmap/TestScenePageScreen.cs @@ -8,6 +8,7 @@ using osu.Game.Overlays; using osu.Game.Rulesets.Karaoke.Beatmaps; using osu.Game.Rulesets.Karaoke.Beatmaps.Metadatas; +using osu.Game.Rulesets.Karaoke.Configuration; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps; using osu.Game.Rulesets.Karaoke.Screens.Edit.Beatmaps.Pages; @@ -58,6 +59,7 @@ private void load() Dependencies.CacheAs(dialogOverlay); Dependencies.CacheAs(lyricsProvider); + Dependencies.Cache(new KaraokeRulesetEditGeneratorConfigManager()); } } }