diff --git a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/TestKaraokeBeatmap.cs b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/TestKaraokeBeatmap.cs index 6ce4da355..d2126232e 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/TestKaraokeBeatmap.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Beatmaps/TestKaraokeBeatmap.cs @@ -34,6 +34,7 @@ public TestKaraokeBeatmap(RulesetInfo ruleset) List = "https://assets.ppy.sh/beatmaps/163112/covers/list.jpg" } }; + BeatmapInfo.BeatmapSet.Files = new List(); } private static Beatmap createTestBeatmap() diff --git a/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneLyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneLyricEditorScreen.cs index fe6db77a9..421f45a34 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneLyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Edit/TestSceneLyricEditorScreen.cs @@ -3,20 +3,31 @@ using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Framework.Timing; +using osu.Game.Overlays; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; using osu.Game.Rulesets.Karaoke.Edit.LyricEditor; using osu.Game.Rulesets.Karaoke.Tests.Beatmaps; +using osu.Game.Rulesets.Karaoke.Tests.Resources; using osu.Game.Screens.Edit; using osu.Game.Tests.Visual; +using System.IO; namespace osu.Game.Rulesets.Karaoke.Tests.Edit { [TestFixture] - [Ignore("Will fail if run multiple tests. No idea how to fix that.")] + [Ignore("This test case run failed in appveyor : (")] public class TestSceneLyricEditorScreen : EditorClockTestScene { + protected override Container Content { get; } = new Container { RelativeSizeAxes = Axes.Both }; + + private DialogOverlay dialogOverlay; + + private LyricEditorScreen screen; + public TestSceneLyricEditorScreen() { // It's a tricky to let osu! to read karaoke testing beatmap @@ -40,7 +51,29 @@ private void load() Dependencies.CacheAs(editorBeatmap); Dependencies.CacheAs(editorBeatmap); - Child = new LyricEditorScreen(); + base.Content.AddRange(new Drawable[] + { + Content, + dialogOverlay = new DialogOverlay() + }); + + Dependencies.Cache(dialogOverlay); + } + + [SetUp] + public void SetUp() => Schedule(() => + { + Child = screen = new LyricEditorScreen(); + }); + + [Test] + public void TestImportLyricFile() + { + AddAssert($"Import lrc file.", () => + { + var temp = TestResources.GetTestLrcForImport("default"); + return screen.ImportLyricFile(new FileInfo(temp)); + }); } } } diff --git a/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs b/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs index af6536730..209dcd5d6 100644 --- a/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs +++ b/osu.Game.Rulesets.Karaoke.Tests/Resources/TestResources.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.IO; +using NUnit.Framework; using osu.Framework.Audio; using osu.Framework.Audio.Track; using osu.Framework.IO.Stores; @@ -20,6 +21,18 @@ public static class TestResources public static Stream OpenLrcResource(string name) => OpenResource($"Testing/Lrc/{name}.lrc"); + public static string GetTestLrcForImport(string name) + { + var tempPath = Path.GetTempFileName() + ".lrc"; + + using (var stream = OpenLrcResource(name)) + using (var newFile = File.Create(tempPath)) + stream.CopyTo(newFile); + + Assert.IsTrue(File.Exists(tempPath)); + return tempPath; + } + public static Stream OpenNicoKaraResource(string name) => OpenResource($"Testing/NicoKara/{name}.nkmproj"); public static Stream OpenTrackResource(string name) => OpenResource($"Testing/Track/{name}.mp3"); diff --git a/osu.Game.Rulesets.Karaoke/Edit/LyricEditor/ImportLyricDialog.cs b/osu.Game.Rulesets.Karaoke/Edit/LyricEditor/ImportLyricDialog.cs new file mode 100644 index 000000000..af8d6f1b8 --- /dev/null +++ b/osu.Game.Rulesets.Karaoke/Edit/LyricEditor/ImportLyricDialog.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.Graphics.Sprites; +using osu.Game.Overlays.Dialog; +using System; + +namespace osu.Game.Rulesets.Karaoke.Edit.LyricEditor +{ + public class ImportLyricDialog : PopupDialog + { + public ImportLyricDialog(Action resetAction) + { + BodyText = "Import lyric file will clean-up all exist lyric."; + + Icon = FontAwesome.Regular.TrashAlt; + HeaderText = @"Confirm import lyric file?"; + Buttons = new PopupDialogButton[] + { + new PopupDialogOkButton + { + Text = @"Yes. Go for it.", + Action = resetAction + }, + new PopupDialogCancelButton + { + Text = @"No! Abort mission!", + }, + }; + } + } +} diff --git a/osu.Game.Rulesets.Karaoke/Edit/LyricEditor/LyricEditorScreen.cs b/osu.Game.Rulesets.Karaoke/Edit/LyricEditor/LyricEditorScreen.cs index b7d9e102a..a33477500 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/LyricEditor/LyricEditorScreen.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/LyricEditor/LyricEditorScreen.cs @@ -5,30 +5,98 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.UserInterface; +using osu.Game.Beatmaps; +using osu.Game.Database; using osu.Game.Graphics.UserInterface; +using osu.Game.Overlays; +using osu.Game.Overlays.Dialog; +using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; using osu.Game.Rulesets.Karaoke.Edit.Timelines; using osu.Game.Rulesets.Karaoke.Objects; using osu.Game.Rulesets.Objects; using osu.Game.Screens.Edit; using osu.Game.Skinning; using osuTK; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; namespace osu.Game.Rulesets.Karaoke.Edit.LyricEditor { - public class LyricEditorScreen : EditorScreenWithTimeline + public class LyricEditorScreen : EditorScreenWithTimeline, ICanAcceptFiles { + private const string backup_lrc_name = "backup.lrc"; + private KaraokeLyricEditorSkin skin; private FillFlowContainer