-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. Move dialog and handle some exception message. 3. Create ok dialog to show message only. 4. Add ImportManager into injection in test case.
- Loading branch information
1 parent
438bfcd
commit 72ad04b
Showing
6 changed files
with
187 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
osu.Game.Rulesets.Karaoke/Edit/Import/ImportLyricDialog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Game.Overlays; | ||
using osu.Game.Overlays.Dialog; | ||
using System; | ||
using System.IO; | ||
using osu.Game.Rulesets.Karaoke.Graphics.Overlays.Dialog; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Import | ||
{ | ||
public class ImportLyricDialog : PopupDialog | ||
{ | ||
[Resolved] | ||
private ImportManager importManager { get; set; } | ||
|
||
[Resolved] | ||
private DialogOverlay dialogOverlay { get; set; } | ||
|
||
public ImportLyricDialog(FileInfo info, Action<bool> resetAction = null) | ||
{ | ||
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 = () => { | ||
var success = processImport(info); | ||
resetAction?.Invoke(true); | ||
} | ||
}, | ||
new PopupDialogCancelButton | ||
{ | ||
Text = @"No! Abort mission!", | ||
}, | ||
}; | ||
} | ||
|
||
private bool processImport(FileInfo info) | ||
{ | ||
try | ||
{ | ||
importManager.ImportLrcFile(info); | ||
dialogOverlay.Push(new OkPopupDialog | ||
{ | ||
Icon = FontAwesome.Regular.CheckCircle, | ||
HeaderText = @"Import success", | ||
BodyText = "Lyrics has been imported." | ||
}); | ||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
switch (ex) | ||
{ | ||
case FileNotFoundException fileNotFoundException: | ||
dialogOverlay.Push(new OkPopupDialog | ||
{ | ||
Icon = FontAwesome.Regular.QuestionCircle, | ||
HeaderText = @"File not found", | ||
BodyText = fileNotFoundException.Message, | ||
}); | ||
break; | ||
case FileLoadException loadException: | ||
dialogOverlay.Push(new OkPopupDialog | ||
{ | ||
Icon = FontAwesome.Regular.QuestionCircle, | ||
HeaderText = @"File not found", | ||
BodyText = loadException.Message, | ||
}); | ||
break; | ||
} | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Game.Beatmaps; | ||
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats; | ||
using osu.Game.Screens.Edit; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Edit.Import | ||
{ | ||
public class ImportManager : Component | ||
{ | ||
public static string[] LyricFotmatExtensions { get; } = { ".lrc", ".kar" }; | ||
public static string[] NicokaraSkinFotmatExtensions { get; } = { ".nkmproj" }; | ||
|
||
private const string backup_lrc_name = "backup.lrc"; | ||
|
||
[Resolved] | ||
private EditorBeatmap editorBeatmap { get; set; } | ||
|
||
[Resolved] | ||
private IBindable<WorkingBeatmap> beatmap { get; set; } | ||
|
||
public void ImportLrcFile(FileInfo info) | ||
{ | ||
if (!info.Exists) | ||
throw new FileNotFoundException("Lyric file does not found!"); | ||
|
||
var isFormatMatch = LyricFotmatExtensions.Contains(info.Extension); | ||
if (!isFormatMatch) | ||
throw new FileLoadException("Only .lrc or .kar karaoke file is supported now"); | ||
|
||
var set = beatmap.Value.BeatmapSetInfo; | ||
var oldFile = set.Files?.FirstOrDefault(f => f.Filename == backup_lrc_name); | ||
using (var stream = info.OpenRead()) | ||
{ | ||
// todo : make a backup if has new lyric file. | ||
/* | ||
if (oldFile != null) | ||
beatmaps.ReplaceFile(set, oldFile, stream, backup_lrc_name); | ||
else | ||
beatmaps.AddFile(set, stream, backup_lrc_name); | ||
*/ | ||
|
||
// Import and replace all the file. | ||
using (var reader = new IO.LineBufferedReader(stream)) | ||
{ | ||
var decoder = new LrcDecoder(); | ||
var lrcBeatmap = decoder.Decode(reader); | ||
|
||
// todo : remove all notes and lyric | ||
// or just clear all beatmap because not really sure is singer should be removed also? | ||
|
||
// then re-add the lyric. | ||
} | ||
} | ||
} | ||
|
||
public void ImportNicokaraSkinFile(FileInfo info) | ||
{ | ||
if (!info.Exists) | ||
throw new FileNotFoundException("Nicokara file does not found!"); | ||
|
||
var isFormatMatch = NicokaraSkinFotmatExtensions.Contains(info.Extension); | ||
if (isFormatMatch) | ||
throw new FileLoadException("Nicokara's skin extension should be .nkmproj"); | ||
} | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
osu.Game.Rulesets.Karaoke/Edit/LyricEditor/ImportLyricDialog.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
osu.Game.Rulesets.Karaoke/Graphics/Overlays/Dialog/OkPopupDialog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Game.Overlays.Dialog; | ||
|
||
namespace osu.Game.Rulesets.Karaoke.Graphics.Overlays.Dialog | ||
{ | ||
public class OkPopupDialog : PopupDialog | ||
{ | ||
public OkPopupDialog() | ||
{ | ||
Buttons = new PopupDialogButton[] | ||
{ | ||
new PopupDialogCancelButton | ||
{ | ||
Text = @"OK", | ||
}, | ||
}; | ||
} | ||
} | ||
} |