2022-10-26 05:14:29 +00:00
|
|
|
package funkin.ui.debug.charting;
|
|
|
|
|
2023-06-08 20:48:34 +00:00
|
|
|
import funkin.play.character.CharacterData;
|
|
|
|
import funkin.util.Constants;
|
|
|
|
import funkin.util.SerializerUtil;
|
|
|
|
import funkin.play.song.SongData.SongChartData;
|
|
|
|
import funkin.play.song.SongData.SongMetadata;
|
2022-12-01 22:32:10 +00:00
|
|
|
import flixel.util.FlxTimer;
|
2023-07-19 05:30:43 +00:00
|
|
|
import funkin.util.SortUtil;
|
2022-11-26 01:48:05 +00:00
|
|
|
import funkin.input.Cursor;
|
2022-12-17 20:19:42 +00:00
|
|
|
import funkin.play.character.BaseCharacter;
|
|
|
|
import funkin.play.character.CharacterData.CharacterDataParser;
|
2023-03-01 02:06:09 +00:00
|
|
|
import funkin.play.song.Song;
|
2023-06-08 20:48:34 +00:00
|
|
|
import funkin.play.song.SongMigrator;
|
|
|
|
import funkin.play.song.SongValidator;
|
2022-12-17 20:19:42 +00:00
|
|
|
import funkin.play.song.SongData.SongDataParser;
|
|
|
|
import funkin.play.song.SongData.SongPlayableChar;
|
2022-12-01 22:32:10 +00:00
|
|
|
import funkin.play.song.SongData.SongTimeChange;
|
2023-06-08 20:48:34 +00:00
|
|
|
import funkin.util.FileUtil;
|
2023-03-01 02:06:09 +00:00
|
|
|
import haxe.io.Path;
|
2022-12-01 22:32:10 +00:00
|
|
|
import haxe.ui.components.Button;
|
|
|
|
import haxe.ui.components.DropDown;
|
2022-12-17 20:19:42 +00:00
|
|
|
import haxe.ui.components.Label;
|
2022-11-26 01:48:05 +00:00
|
|
|
import haxe.ui.components.Link;
|
2022-12-01 22:32:10 +00:00
|
|
|
import haxe.ui.components.NumberStepper;
|
|
|
|
import haxe.ui.components.TextField;
|
|
|
|
import haxe.ui.containers.Box;
|
2022-11-25 00:09:47 +00:00
|
|
|
import haxe.ui.containers.dialogs.Dialog;
|
2022-12-01 22:32:10 +00:00
|
|
|
import haxe.ui.containers.dialogs.Dialogs;
|
|
|
|
import haxe.ui.containers.properties.PropertyGrid;
|
|
|
|
import haxe.ui.containers.properties.PropertyGroup;
|
2022-11-25 00:09:47 +00:00
|
|
|
import haxe.ui.containers.VBox;
|
2023-03-01 02:06:09 +00:00
|
|
|
import haxe.ui.core.Component;
|
2022-12-01 22:32:10 +00:00
|
|
|
import haxe.ui.events.UIEvent;
|
2023-03-01 02:06:09 +00:00
|
|
|
import haxe.ui.notifications.NotificationManager;
|
|
|
|
import haxe.ui.notifications.NotificationType;
|
2022-12-01 22:32:10 +00:00
|
|
|
|
|
|
|
using Lambda;
|
2022-11-25 00:09:47 +00:00
|
|
|
|
2023-02-28 18:17:28 +00:00
|
|
|
/**
|
|
|
|
* Handles dialogs for the new Chart Editor.
|
|
|
|
*/
|
2022-10-26 05:14:29 +00:00
|
|
|
class ChartEditorDialogHandler
|
|
|
|
{
|
2023-02-28 18:17:28 +00:00
|
|
|
static final CHART_EDITOR_DIALOG_ABOUT_LAYOUT:String = Paths.ui('chart-editor/dialogs/about');
|
|
|
|
static final CHART_EDITOR_DIALOG_WELCOME_LAYOUT:String = Paths.ui('chart-editor/dialogs/welcome');
|
|
|
|
static final CHART_EDITOR_DIALOG_UPLOAD_INST_LAYOUT:String = Paths.ui('chart-editor/dialogs/upload-inst');
|
|
|
|
static final CHART_EDITOR_DIALOG_SONG_METADATA_LAYOUT:String = Paths.ui('chart-editor/dialogs/song-metadata');
|
|
|
|
static final CHART_EDITOR_DIALOG_SONG_METADATA_CHARGROUP_LAYOUT:String = Paths.ui('chart-editor/dialogs/song-metadata-chargroup');
|
|
|
|
static final CHART_EDITOR_DIALOG_UPLOAD_VOCALS_LAYOUT:String = Paths.ui('chart-editor/dialogs/upload-vocals');
|
|
|
|
static final CHART_EDITOR_DIALOG_UPLOAD_VOCALS_ENTRY_LAYOUT:String = Paths.ui('chart-editor/dialogs/upload-vocals-entry');
|
2023-06-08 20:48:34 +00:00
|
|
|
static final CHART_EDITOR_DIALOG_OPEN_CHART_LAYOUT:String = Paths.ui('chart-editor/dialogs/open-chart');
|
|
|
|
static final CHART_EDITOR_DIALOG_OPEN_CHART_ENTRY_LAYOUT:String = Paths.ui('chart-editor/dialogs/open-chart-entry');
|
|
|
|
static final CHART_EDITOR_DIALOG_IMPORT_CHART_LAYOUT:String = Paths.ui('chart-editor/dialogs/import-chart');
|
2023-02-28 18:17:28 +00:00
|
|
|
static final CHART_EDITOR_DIALOG_USER_GUIDE_LAYOUT:String = Paths.ui('chart-editor/dialogs/user-guide');
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-01 02:06:09 +00:00
|
|
|
* Builds and opens a dialog giving brief credits for the chart editor.
|
|
|
|
* @param state The current chart editor state.
|
|
|
|
* @return The dialog that was opened.
|
2023-01-23 03:25:45 +00:00
|
|
|
*/
|
|
|
|
public static inline function openAboutDialog(state:ChartEditorState):Dialog
|
|
|
|
{
|
|
|
|
return openDialog(state, CHART_EDITOR_DIALOG_ABOUT_LAYOUT, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds and opens a dialog letting the user create a new chart, open a recent chart, or load from a template.
|
2023-03-01 02:06:09 +00:00
|
|
|
* @param state The current chart editor state.
|
|
|
|
* @param closable Whether the dialog can be closed by the user.
|
|
|
|
* @return The dialog that was opened.
|
2023-01-23 03:25:45 +00:00
|
|
|
*/
|
|
|
|
public static function openWelcomeDialog(state:ChartEditorState, closable:Bool = true):Dialog
|
|
|
|
{
|
|
|
|
var dialog:Dialog = openDialog(state, CHART_EDITOR_DIALOG_WELCOME_LAYOUT, true, closable);
|
|
|
|
|
|
|
|
// Add handlers to the "Create From Song" section.
|
|
|
|
var linkCreateBasic:Link = dialog.findComponent('splashCreateFromSongBasic', Link);
|
2023-03-01 02:06:09 +00:00
|
|
|
linkCreateBasic.onClick = function(_event) {
|
|
|
|
// Hide the welcome dialog
|
2023-01-23 03:25:45 +00:00
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
//
|
|
|
|
// Create Song Wizard
|
|
|
|
//
|
2023-06-08 20:48:34 +00:00
|
|
|
openCreateSongWizard(state, false);
|
|
|
|
}
|
2023-03-01 02:06:09 +00:00
|
|
|
|
2023-06-08 20:48:34 +00:00
|
|
|
var linkImportChartLegacy:Link = dialog.findComponent('splashImportChartLegacy', Link);
|
|
|
|
linkImportChartLegacy.onClick = function(_event) {
|
|
|
|
// Hide the welcome dialog
|
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
|
|
|
|
// Open the "Import Chart" dialog
|
|
|
|
openImportChartWizard(state, 'legacy', false);
|
|
|
|
};
|
|
|
|
|
|
|
|
var buttonBrowse:Button = dialog.findComponent('splashBrowse', Button);
|
|
|
|
buttonBrowse.onClick = function(_event) {
|
|
|
|
// Hide the welcome dialog
|
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
|
|
|
|
// Open the "Open Chart" dialog
|
|
|
|
openBrowseWizard(state, false);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var splashTemplateContainer:VBox = dialog.findComponent('splashTemplateContainer', VBox);
|
|
|
|
|
|
|
|
var songList:Array<String> = SongDataParser.listSongIds();
|
2023-08-01 18:08:41 +00:00
|
|
|
songList.sort(SortUtil.alphabetically);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
for (targetSongId in songList)
|
|
|
|
{
|
2023-03-01 02:06:09 +00:00
|
|
|
var songData:Song = SongDataParser.fetchSong(targetSongId);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
if (songData == null) continue;
|
|
|
|
|
2023-08-11 18:00:38 +00:00
|
|
|
var songName:Null<String> = songData.getDifficulty('normal') ?.songName;
|
|
|
|
if (songName == null) songName = songData.getDifficulty() ?.songName;
|
|
|
|
if (songName == null)
|
|
|
|
{
|
|
|
|
trace('[WARN] Could not fetch song name for ${targetSongId}');
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
var linkTemplateSong:Link = new Link();
|
|
|
|
linkTemplateSong.text = songName;
|
2023-03-01 02:06:09 +00:00
|
|
|
linkTemplateSong.onClick = function(_event) {
|
2023-01-23 03:25:45 +00:00
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
|
|
|
|
// Load song from template
|
|
|
|
state.loadSongAsTemplate(targetSongId);
|
|
|
|
}
|
|
|
|
|
|
|
|
splashTemplateContainer.addComponent(linkTemplateSong);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2023-06-08 20:48:34 +00:00
|
|
|
/**
|
|
|
|
* Open the wizard for opening an existing chart from individual files.
|
|
|
|
* @param state
|
|
|
|
* @param closable
|
|
|
|
*/
|
|
|
|
public static function openBrowseWizard(state:ChartEditorState, closable:Bool):Void
|
|
|
|
{
|
|
|
|
// Open the "Open Chart" wizard
|
|
|
|
// Step 1. Open Chart
|
|
|
|
var openChartDialog:Dialog = openChartDialog(state);
|
|
|
|
openChartDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
if (_event.button == DialogButton.APPLY)
|
|
|
|
{
|
|
|
|
// Step 2. Upload instrumental
|
|
|
|
var uploadInstDialog:Dialog = openUploadInstDialog(state, closable);
|
|
|
|
uploadInstDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
if (_event.button == DialogButton.APPLY)
|
|
|
|
{
|
|
|
|
// Step 3. Upload Vocals
|
|
|
|
// NOTE: Uploading vocals is optional, so we don't need to check if the user cancelled the wizard.
|
|
|
|
var uploadVocalsDialog:Dialog = openUploadVocalsDialog(state, closable); // var uploadVocalsDialog:Dialog
|
|
|
|
uploadVocalsDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
state.postLoadInstrumental();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User cancelled the wizard! Back to the welcome dialog.
|
|
|
|
openWelcomeDialog(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User cancelled the wizard! Back to the welcome dialog.
|
|
|
|
openWelcomeDialog(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function openImportChartWizard(state:ChartEditorState, format:String, closable:Bool):Void
|
|
|
|
{
|
|
|
|
// Open the "Open Chart" wizard
|
|
|
|
// Step 1. Open Chart
|
|
|
|
var openChartDialog:Dialog = openImportChartDialog(state, format);
|
|
|
|
openChartDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
if (_event.button == DialogButton.APPLY)
|
|
|
|
{
|
|
|
|
// Step 2. Upload instrumental
|
|
|
|
var uploadInstDialog:Dialog = openUploadInstDialog(state, closable);
|
|
|
|
uploadInstDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
if (_event.button == DialogButton.APPLY)
|
|
|
|
{
|
|
|
|
// Step 3. Upload Vocals
|
|
|
|
// NOTE: Uploading vocals is optional, so we don't need to check if the user cancelled the wizard.
|
|
|
|
var uploadVocalsDialog:Dialog = openUploadVocalsDialog(state, closable); // var uploadVocalsDialog:Dialog
|
|
|
|
uploadVocalsDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
state.postLoadInstrumental();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User cancelled the wizard! Back to the welcome dialog.
|
|
|
|
openWelcomeDialog(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User cancelled the wizard! Back to the welcome dialog.
|
|
|
|
openWelcomeDialog(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function openCreateSongWizard(state:ChartEditorState, closable:Bool):Void
|
|
|
|
{
|
|
|
|
// Step 1. Upload Instrumental
|
|
|
|
var uploadInstDialog:Dialog = openUploadInstDialog(state, closable);
|
|
|
|
uploadInstDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
if (_event.button == DialogButton.APPLY)
|
|
|
|
{
|
|
|
|
// Step 2. Song Metadata
|
|
|
|
var songMetadataDialog:Dialog = openSongMetadataDialog(state);
|
|
|
|
songMetadataDialog.onDialogClosed = function(_event) {
|
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
if (_event.button == DialogButton.APPLY)
|
|
|
|
{
|
|
|
|
// Step 3. Upload Vocals
|
|
|
|
// NOTE: Uploading vocals is optional, so we don't need to check if the user cancelled the wizard.
|
|
|
|
openUploadVocalsDialog(state, false); // var uploadVocalsDialog:Dialog
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User cancelled the wizard! Back to the welcome dialog.
|
|
|
|
openWelcomeDialog(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// User cancelled the wizard! Back to the welcome dialog.
|
|
|
|
openWelcomeDialog(state);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
/**
|
|
|
|
* Builds and opens a dialog where the user uploads an instrumental for the current song.
|
|
|
|
* @param state The current chart editor state.
|
|
|
|
* @param closable Whether the dialog can be closed by the user.
|
|
|
|
* @return The dialog that was opened.
|
|
|
|
*/
|
2023-08-22 08:27:30 +00:00
|
|
|
@:haxe.warning("-WVarInit")
|
2023-08-28 19:03:29 +00:00
|
|
|
public static function openUploadInstDialog(state:ChartEditorState, closable:Bool = true):Dialog
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
var dialog:Dialog = openDialog(state, CHART_EDITOR_DIALOG_UPLOAD_INST_LAYOUT, true, closable);
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var buttonCancel:Button = dialog.findComponent('dialogCancel', Button);
|
|
|
|
|
|
|
|
buttonCancel.onClick = function(_event) {
|
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var instrumentalBox:Box = dialog.findComponent('instrumentalBox', Box);
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
instrumentalBox.onMouseOver = function(_event) {
|
2023-01-23 03:25:45 +00:00
|
|
|
instrumentalBox.swapClass('upload-bg', 'upload-bg-hover');
|
|
|
|
Cursor.cursorMode = Pointer;
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
instrumentalBox.onMouseOut = function(_event) {
|
2023-01-23 03:25:45 +00:00
|
|
|
instrumentalBox.swapClass('upload-bg-hover', 'upload-bg');
|
|
|
|
Cursor.cursorMode = Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
var onDropFile:String->Void;
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
instrumentalBox.onClick = function(_event) {
|
|
|
|
Dialogs.openBinaryFile('Open Instrumental', [
|
|
|
|
{label: 'Audio File (.ogg)', extension: 'ogg'}], function(selectedFile:SelectedFileInfo) {
|
2023-02-28 18:17:28 +00:00
|
|
|
if (selectedFile != null)
|
|
|
|
{
|
2023-03-01 02:06:09 +00:00
|
|
|
if (state.loadInstrumentalFromBytes(selectedFile.bytes))
|
|
|
|
{
|
|
|
|
trace('Selected file: ' + selectedFile.fullPath);
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-03-01 02:06:09 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded instrumental track (${selectedFile.name})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-03-01 02:06:09 +00:00
|
|
|
|
|
|
|
dialog.hideDialog(DialogButton.APPLY);
|
|
|
|
removeDropHandler(onDropFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trace('Failed to load instrumental (${selectedFile.fullPath})');
|
|
|
|
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-03-01 02:06:09 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Failure',
|
|
|
|
body: 'Failed to load instrumental track (${selectedFile.name})',
|
|
|
|
type: NotificationType.Error,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-03-01 02:06:09 +00:00
|
|
|
}
|
2023-02-28 18:17:28 +00:00
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
onDropFile = function(pathStr:String) {
|
|
|
|
var path:Path = new Path(pathStr);
|
|
|
|
trace('Dropped file (${path})');
|
|
|
|
if (state.loadInstrumentalFromPath(path))
|
|
|
|
{
|
|
|
|
// Tell the user the load was successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-03-01 02:06:09 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded instrumental track (${path.file}.${path.ext})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-03-01 02:06:09 +00:00
|
|
|
|
|
|
|
dialog.hideDialog(DialogButton.APPLY);
|
|
|
|
removeDropHandler(onDropFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-08 20:48:34 +00:00
|
|
|
var message:String = if (!ChartEditorState.SUPPORTED_MUSIC_FORMATS.contains(path.ext))
|
|
|
|
{
|
|
|
|
'File format (${path.ext}) not supported for instrumental track (${path.file}.${path.ext})';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
'Failed to load instrumental track (${path.file}.${path.ext})';
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
// Tell the user the load was successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-03-01 02:06:09 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Failure',
|
2023-06-08 20:48:34 +00:00
|
|
|
body: message,
|
2023-03-01 02:06:09 +00:00
|
|
|
type: NotificationType.Error,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-03-01 02:06:09 +00:00
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
};
|
|
|
|
|
2023-02-28 18:17:28 +00:00
|
|
|
addDropHandler(instrumentalBox, onDropFile);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2023-02-28 18:17:28 +00:00
|
|
|
static var dropHandlers:Array<
|
|
|
|
{
|
|
|
|
component:Component,
|
|
|
|
handler:(String->Void)
|
|
|
|
}> = [];
|
|
|
|
|
|
|
|
static function addDropHandler(component:Component, handler:String->Void):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
#if desktop
|
2023-02-28 18:17:28 +00:00
|
|
|
if (!FlxG.stage.window.onDropFile.has(onDropFile)) FlxG.stage.window.onDropFile.add(onDropFile);
|
|
|
|
|
|
|
|
dropHandlers.push(
|
|
|
|
{
|
|
|
|
component: component,
|
|
|
|
handler: handler
|
|
|
|
});
|
2023-01-23 03:25:45 +00:00
|
|
|
#else
|
|
|
|
trace('addDropHandler not implemented for this platform');
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
2023-02-28 18:17:28 +00:00
|
|
|
static function removeDropHandler(handler:String->Void):Void
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
#if desktop
|
|
|
|
FlxG.stage.window.onDropFile.remove(handler);
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
2023-02-28 18:17:28 +00:00
|
|
|
static function clearDropHandlers():Void
|
|
|
|
{
|
|
|
|
#if desktop
|
|
|
|
dropHandlers = [];
|
|
|
|
FlxG.stage.window.onDropFile.remove(onDropFile);
|
|
|
|
#end
|
|
|
|
}
|
|
|
|
|
|
|
|
static function onDropFile(path:String):Void
|
|
|
|
{
|
|
|
|
// a VERY short timer to wait for the mouse position to update
|
|
|
|
new FlxTimer().start(0.01, function(_) {
|
|
|
|
for (handler in dropHandlers)
|
|
|
|
{
|
|
|
|
if (handler.component.hitTest(FlxG.mouse.screenX, FlxG.mouse.screenY))
|
|
|
|
{
|
|
|
|
handler.handler(path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the dialog in the wizard where the user can set song metadata like name and artist and BPM.
|
|
|
|
* @param state The ChartEditorState instance.
|
|
|
|
* @return The dialog to open.
|
|
|
|
*/
|
2023-08-22 08:27:30 +00:00
|
|
|
@:haxe.warning("-WVarInit")
|
2023-01-23 03:25:45 +00:00
|
|
|
public static function openSongMetadataDialog(state:ChartEditorState):Dialog
|
|
|
|
{
|
|
|
|
var dialog:Dialog = openDialog(state, CHART_EDITOR_DIALOG_SONG_METADATA_LAYOUT, true, false);
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var buttonCancel:Button = dialog.findComponent('dialogCancel', Button);
|
|
|
|
|
|
|
|
buttonCancel.onClick = function(_event) {
|
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
var dialogSongName:TextField = dialog.findComponent('dialogSongName', TextField);
|
2023-02-28 18:17:28 +00:00
|
|
|
dialogSongName.onChange = function(event:UIEvent) {
|
|
|
|
var valid:Bool = event.target.text != null && event.target.text != '';
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
dialogSongName.removeClass('invalid-value');
|
|
|
|
state.currentSongMetadata.songName = event.target.text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state.currentSongMetadata.songName = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
state.currentSongMetadata.songName = null;
|
|
|
|
|
|
|
|
var dialogSongArtist:TextField = dialog.findComponent('dialogSongArtist', TextField);
|
2023-02-28 18:17:28 +00:00
|
|
|
dialogSongArtist.onChange = function(event:UIEvent) {
|
|
|
|
var valid:Bool = event.target.text != null && event.target.text != '';
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
if (valid)
|
|
|
|
{
|
|
|
|
dialogSongArtist.removeClass('invalid-value');
|
|
|
|
state.currentSongMetadata.artist = event.target.text;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state.currentSongMetadata.artist = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
state.currentSongMetadata.artist = null;
|
|
|
|
|
|
|
|
var dialogStage:DropDown = dialog.findComponent('dialogStage', DropDown);
|
2023-02-28 18:17:28 +00:00
|
|
|
dialogStage.onChange = function(event:UIEvent) {
|
2023-03-01 02:06:09 +00:00
|
|
|
if (event.data == null && event.data.id == null) return;
|
2023-01-23 03:25:45 +00:00
|
|
|
state.currentSongMetadata.playData.stage = event.data.id;
|
|
|
|
};
|
|
|
|
state.currentSongMetadata.playData.stage = null;
|
|
|
|
|
|
|
|
var dialogNoteSkin:DropDown = dialog.findComponent('dialogNoteSkin', DropDown);
|
2023-03-01 02:06:09 +00:00
|
|
|
dialogNoteSkin.onChange = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
if (event.data.id == null) return;
|
|
|
|
state.currentSongMetadata.playData.noteSkin = event.data.id;
|
|
|
|
};
|
|
|
|
state.currentSongMetadata.playData.noteSkin = null;
|
|
|
|
|
|
|
|
var dialogBPM:NumberStepper = dialog.findComponent('dialogBPM', NumberStepper);
|
2023-03-01 02:06:09 +00:00
|
|
|
dialogBPM.onChange = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
if (event.value == null || event.value <= 0) return;
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var timeChanges:Array<SongTimeChange> = state.currentSongMetadata.timeChanges;
|
2023-01-23 03:25:45 +00:00
|
|
|
if (timeChanges == null || timeChanges.length == 0)
|
|
|
|
{
|
|
|
|
timeChanges = [new SongTimeChange(-1, 0, event.value, 4, 4, [4, 4, 4, 4])];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
timeChanges[0].bpm = event.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
Conductor.forceBPM(event.value);
|
|
|
|
|
|
|
|
state.currentSongMetadata.timeChanges = timeChanges;
|
|
|
|
};
|
|
|
|
|
|
|
|
var dialogCharGrid:PropertyGrid = dialog.findComponent('dialogCharGrid', PropertyGrid);
|
|
|
|
var dialogCharAdd:Button = dialog.findComponent('dialogCharAdd', Button);
|
2023-03-01 02:06:09 +00:00
|
|
|
dialogCharAdd.onClick = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
var charGroup:PropertyGroup;
|
2023-03-01 02:06:09 +00:00
|
|
|
charGroup = buildCharGroup(state, null, () -> dialogCharGrid.removeComponent(charGroup));
|
2023-01-23 03:25:45 +00:00
|
|
|
dialogCharGrid.addComponent(charGroup);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Empty the character list.
|
|
|
|
state.currentSongMetadata.playData.playableChars = {};
|
|
|
|
// Add at least one character group with no Remove button.
|
|
|
|
dialogCharGrid.addComponent(buildCharGroup(state, 'bf', null));
|
|
|
|
|
|
|
|
var dialogContinue:Button = dialog.findComponent('dialogContinue', Button);
|
2023-03-01 02:06:09 +00:00
|
|
|
dialogContinue.onClick = (_event) -> dialog.hideDialog(DialogButton.APPLY);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
static function buildCharGroup(state:ChartEditorState, key:String = null, removeFunc:Void->Void):PropertyGroup
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-03-01 02:06:09 +00:00
|
|
|
var groupKey:String = key;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var getCharData:Void->SongPlayableChar = function() {
|
2023-01-23 03:25:45 +00:00
|
|
|
if (groupKey == null) groupKey = 'newChar${state.currentSongMetadata.playData.playableChars.keys().count()}';
|
|
|
|
|
|
|
|
var result = state.currentSongMetadata.playData.playableChars.get(groupKey);
|
|
|
|
if (result == null)
|
|
|
|
{
|
|
|
|
result = new SongPlayableChar('', 'dad');
|
|
|
|
state.currentSongMetadata.playData.playableChars.set(groupKey, result);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var moveCharGroup:String->Void = function(target:String) {
|
2023-01-23 03:25:45 +00:00
|
|
|
var charData = getCharData();
|
|
|
|
state.currentSongMetadata.playData.playableChars.remove(groupKey);
|
|
|
|
state.currentSongMetadata.playData.playableChars.set(target, charData);
|
|
|
|
groupKey = target;
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var removeGroup:Void->Void = function() {
|
2023-01-23 03:25:45 +00:00
|
|
|
state.currentSongMetadata.playData.playableChars.remove(groupKey);
|
|
|
|
removeFunc();
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var charData:SongPlayableChar = getCharData();
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
var charGroup:PropertyGroup = cast state.buildComponent(CHART_EDITOR_DIALOG_SONG_METADATA_CHARGROUP_LAYOUT);
|
|
|
|
|
|
|
|
var charGroupPlayer:DropDown = charGroup.findComponent('charGroupPlayer', DropDown);
|
2023-03-01 02:06:09 +00:00
|
|
|
charGroupPlayer.onChange = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
charGroup.text = event.data.text;
|
|
|
|
moveCharGroup(event.data.id);
|
|
|
|
};
|
|
|
|
|
|
|
|
var charGroupOpponent:DropDown = charGroup.findComponent('charGroupOpponent', DropDown);
|
2023-03-01 02:06:09 +00:00
|
|
|
charGroupOpponent.onChange = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
charData.opponent = event.data.id;
|
|
|
|
};
|
|
|
|
charGroupOpponent.value = getCharData().opponent;
|
|
|
|
|
|
|
|
var charGroupGirlfriend:DropDown = charGroup.findComponent('charGroupGirlfriend', DropDown);
|
2023-03-01 02:06:09 +00:00
|
|
|
charGroupGirlfriend.onChange = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
charData.girlfriend = event.data.id;
|
|
|
|
};
|
|
|
|
charGroupGirlfriend.value = getCharData().girlfriend;
|
|
|
|
|
|
|
|
var charGroupRemove:Button = charGroup.findComponent('charGroupRemove', Button);
|
2023-03-01 02:06:09 +00:00
|
|
|
charGroupRemove.onClick = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
removeGroup();
|
|
|
|
};
|
|
|
|
|
|
|
|
if (removeFunc == null) charGroupRemove.hidden = true;
|
|
|
|
|
|
|
|
return charGroup;
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
/**
|
|
|
|
* Builds and opens a dialog where the user uploads vocals for the current song.
|
|
|
|
* @param state The current chart editor state.
|
|
|
|
* @param closable Whether the dialog can be closed by the user.
|
|
|
|
* @return The dialog that was opened.
|
|
|
|
*/
|
2023-08-28 19:03:29 +00:00
|
|
|
public static function openUploadVocalsDialog(state:ChartEditorState, closable:Bool = true):Dialog
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
2023-03-01 02:06:09 +00:00
|
|
|
var charIdsForVocals:Array<String> = [];
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
for (charKey in state.currentSongMetadata.playData.playableChars.keys())
|
|
|
|
{
|
2023-03-01 02:06:09 +00:00
|
|
|
var charData:SongPlayableChar = state.currentSongMetadata.playData.playableChars.get(charKey);
|
2023-01-23 03:25:45 +00:00
|
|
|
charIdsForVocals.push(charKey);
|
|
|
|
if (charData.opponent != null) charIdsForVocals.push(charData.opponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
var dialog:Dialog = openDialog(state, CHART_EDITOR_DIALOG_UPLOAD_VOCALS_LAYOUT, true, closable);
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var dialogContainer:Component = dialog.findComponent('vocalContainer');
|
|
|
|
|
|
|
|
var buttonCancel:Button = dialog.findComponent('dialogCancel', Button);
|
|
|
|
buttonCancel.onClick = function(_event) {
|
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-02-28 18:17:28 +00:00
|
|
|
var dialogNoVocals:Button = dialog.findComponent('dialogNoVocals', Button);
|
|
|
|
dialogNoVocals.onClick = function(_event) {
|
|
|
|
// Dismiss
|
|
|
|
dialog.hideDialog(DialogButton.APPLY);
|
|
|
|
};
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
for (charKey in charIdsForVocals)
|
|
|
|
{
|
|
|
|
trace('Adding vocal upload for character ${charKey}');
|
2023-06-08 20:48:34 +00:00
|
|
|
var charMetadata:CharacterData = CharacterDataParser.fetchCharacterData(charKey);
|
2023-06-09 19:28:14 +00:00
|
|
|
var charName:String = charMetadata != null ? charMetadata.name : charKey;
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var vocalsEntry:Component = state.buildComponent(CHART_EDITOR_DIALOG_UPLOAD_VOCALS_ENTRY_LAYOUT);
|
2023-01-23 03:25:45 +00:00
|
|
|
|
|
|
|
var vocalsEntryLabel:Label = vocalsEntry.findComponent('vocalsEntryLabel', Label);
|
2023-03-01 02:06:09 +00:00
|
|
|
vocalsEntryLabel.text = 'Drag and drop vocals for $charName here, or click to browse.';
|
2023-01-23 03:25:45 +00:00
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
var onDropFile:String->Void = function(pathStr:String) {
|
|
|
|
trace('Selected file: $pathStr');
|
|
|
|
var path:Path = new Path(pathStr);
|
2023-02-28 18:17:28 +00:00
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
if (state.loadVocalsFromPath(path, charKey))
|
|
|
|
{
|
|
|
|
// Tell the user the load was successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-03-01 02:06:09 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded vocal track for $charName (${path.file}.${path.ext})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-03-01 02:06:09 +00:00
|
|
|
vocalsEntryLabel.text = 'Vocals for $charName (drag and drop, or click to browse)\nSelected file: ${path.file}.${path.ext}';
|
|
|
|
dialogNoVocals.hidden = true;
|
|
|
|
removeDropHandler(onDropFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-08 20:48:34 +00:00
|
|
|
var message:String = if (!ChartEditorState.SUPPORTED_MUSIC_FORMATS.contains(path.ext))
|
|
|
|
{
|
|
|
|
'File format (${path.ext}) not supported for vocal track (${path.file}.${path.ext})';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
'Failed to load vocal track (${path.file}.${path.ext})';
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
// Vocals failed to load.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-03-01 02:06:09 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Failure',
|
2023-06-08 20:48:34 +00:00
|
|
|
body: message,
|
2023-03-01 02:06:09 +00:00
|
|
|
type: NotificationType.Error,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-03-01 02:06:09 +00:00
|
|
|
|
|
|
|
vocalsEntryLabel.text = 'Drag and drop vocals for $charName here, or click to browse.';
|
|
|
|
}
|
2023-02-28 18:17:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
vocalsEntry.onClick = function(_event) {
|
2023-01-23 03:25:45 +00:00
|
|
|
Dialogs.openBinaryFile('Open $charName Vocals', [
|
2023-02-28 18:17:28 +00:00
|
|
|
{label: 'Audio File (.ogg)', extension: 'ogg'}], function(selectedFile) {
|
|
|
|
if (selectedFile != null)
|
|
|
|
{
|
|
|
|
trace('Selected file: ' + selectedFile.name);
|
|
|
|
vocalsEntryLabel.text = 'Vocals for $charName (click to browse)\n${selectedFile.name}';
|
|
|
|
state.loadVocalsFromBytes(selectedFile.bytes, charKey);
|
|
|
|
dialogNoVocals.hidden = true;
|
|
|
|
removeDropHandler(onDropFile);
|
|
|
|
}
|
2023-01-23 03:25:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-01 02:06:09 +00:00
|
|
|
// onDropFile
|
|
|
|
addDropHandler(vocalsEntry, onDropFile);
|
2023-01-23 03:25:45 +00:00
|
|
|
dialogContainer.addComponent(vocalsEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
var dialogContinue:Button = dialog.findComponent('dialogContinue', Button);
|
2023-02-28 18:17:28 +00:00
|
|
|
dialogContinue.onClick = function(_event) {
|
|
|
|
// Dismiss
|
2023-01-23 03:25:45 +00:00
|
|
|
dialog.hideDialog(DialogButton.APPLY);
|
|
|
|
};
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2023-06-08 20:48:34 +00:00
|
|
|
/**
|
|
|
|
* Builds and opens a dialog where the user upload the JSON files for a song.
|
|
|
|
* @param state The current chart editor state.
|
|
|
|
* @param closable Whether the dialog can be closed by the user.
|
|
|
|
* @return The dialog that was opened.
|
|
|
|
*/
|
|
|
|
@:haxe.warning('-WVarInit')
|
2023-08-28 19:03:29 +00:00
|
|
|
public static function openChartDialog(state:ChartEditorState, closable:Bool = true):Dialog
|
2023-06-08 20:48:34 +00:00
|
|
|
{
|
|
|
|
var dialog:Dialog = openDialog(state, CHART_EDITOR_DIALOG_OPEN_CHART_LAYOUT, true, closable);
|
|
|
|
|
|
|
|
var buttonCancel:Button = dialog.findComponent('dialogCancel', Button);
|
|
|
|
buttonCancel.onClick = function(_event) {
|
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
var chartContainerA:Component = dialog.findComponent('chartContainerA');
|
|
|
|
var chartContainerB:Component = dialog.findComponent('chartContainerB');
|
|
|
|
|
|
|
|
var songMetadata:Map<String, SongMetadata> = [];
|
|
|
|
var songChartData:Map<String, SongChartData> = [];
|
|
|
|
|
|
|
|
var buttonContinue:Button = dialog.findComponent('dialogContinue', Button);
|
|
|
|
buttonContinue.onClick = function(_event) {
|
|
|
|
state.loadSong(songMetadata, songChartData);
|
|
|
|
|
|
|
|
dialog.hideDialog(DialogButton.APPLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
var onDropFileMetadataVariation:String->Label->String->Void;
|
|
|
|
var onClickMetadataVariation:String->Label->UIEvent->Void;
|
|
|
|
var onDropFileChartDataVariation:String->Label->String->Void;
|
|
|
|
var onClickChartDataVariation:String->Label->UIEvent->Void;
|
|
|
|
|
|
|
|
var constructVariationEntries:Array<String>->Void = function(variations:Array<String>) {
|
|
|
|
// Clear the chart container.
|
|
|
|
while (chartContainerB.getComponentAt(0) != null)
|
|
|
|
{
|
|
|
|
chartContainerB.removeComponent(chartContainerB.getComponentAt(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build an entry for -chart.json.
|
|
|
|
var songDefaultChartDataEntry:Component = state.buildComponent(CHART_EDITOR_DIALOG_OPEN_CHART_ENTRY_LAYOUT);
|
|
|
|
var songDefaultChartDataEntryLabel:Label = songDefaultChartDataEntry.findComponent('chartEntryLabel', Label);
|
|
|
|
songDefaultChartDataEntryLabel.text = 'Drag and drop <song>-chart.json file, or click to browse.';
|
|
|
|
|
|
|
|
songDefaultChartDataEntry.onClick = onClickChartDataVariation.bind(Constants.DEFAULT_VARIATION).bind(songDefaultChartDataEntryLabel);
|
|
|
|
addDropHandler(songDefaultChartDataEntry, onDropFileChartDataVariation.bind(Constants.DEFAULT_VARIATION).bind(songDefaultChartDataEntryLabel));
|
|
|
|
chartContainerB.addComponent(songDefaultChartDataEntry);
|
|
|
|
|
|
|
|
for (variation in variations)
|
|
|
|
{
|
|
|
|
// Build entries for -metadata-<variation>.json.
|
|
|
|
var songVariationMetadataEntry:Component = state.buildComponent(CHART_EDITOR_DIALOG_OPEN_CHART_ENTRY_LAYOUT);
|
|
|
|
var songVariationMetadataEntryLabel:Label = songVariationMetadataEntry.findComponent('chartEntryLabel', Label);
|
|
|
|
songVariationMetadataEntryLabel.text = 'Drag and drop <song>-metadata-${variation}.json file, or click to browse.';
|
|
|
|
|
|
|
|
songVariationMetadataEntry.onClick = onClickMetadataVariation.bind(variation).bind(songVariationMetadataEntryLabel);
|
|
|
|
addDropHandler(songVariationMetadataEntry, onDropFileMetadataVariation.bind(variation).bind(songVariationMetadataEntryLabel));
|
|
|
|
chartContainerB.addComponent(songVariationMetadataEntry);
|
|
|
|
|
|
|
|
// Build entries for -chart-<variation>.json.
|
|
|
|
var songVariationChartDataEntry:Component = state.buildComponent(CHART_EDITOR_DIALOG_OPEN_CHART_ENTRY_LAYOUT);
|
|
|
|
var songVariationChartDataEntryLabel:Label = songVariationChartDataEntry.findComponent('chartEntryLabel', Label);
|
|
|
|
songVariationChartDataEntryLabel.text = 'Drag and drop <song>-chart-${variation}.json file, or click to browse.';
|
|
|
|
|
|
|
|
songVariationChartDataEntry.onClick = onClickChartDataVariation.bind(variation).bind(songVariationChartDataEntryLabel);
|
|
|
|
addDropHandler(songVariationChartDataEntry, onDropFileChartDataVariation.bind(variation).bind(songVariationChartDataEntryLabel));
|
|
|
|
chartContainerB.addComponent(songVariationChartDataEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onDropFileMetadataVariation = function(variation:String, label:Label, pathStr:String) {
|
|
|
|
var path:Path = new Path(pathStr);
|
|
|
|
trace('Dropped JSON file (${path})');
|
|
|
|
|
|
|
|
var songMetadataJson:Dynamic = FileUtil.readJSONFromPath(path.toString());
|
|
|
|
var songMetadataVariation:SongMetadata = SongMigrator.migrateSongMetadata(songMetadataJson, 'import');
|
|
|
|
songMetadataVariation = SongValidator.validateSongMetadata(songMetadataVariation, 'import');
|
|
|
|
|
2023-08-28 19:03:29 +00:00
|
|
|
if (songMetadataVariation == null)
|
|
|
|
{
|
|
|
|
// Tell the user the load was not successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-08-28 19:03:29 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Failure',
|
|
|
|
body: 'Could not load metadata file (${path.file}.${path.ext})',
|
|
|
|
type: NotificationType.Error,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-08-28 19:03:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-08 20:48:34 +00:00
|
|
|
songMetadata.set(variation, songMetadataVariation);
|
|
|
|
|
|
|
|
// Tell the user the load was successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-06-08 20:48:34 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded metadata file (${path.file}.${path.ext})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-06-08 20:48:34 +00:00
|
|
|
|
|
|
|
label.text = 'Metadata file (drag and drop, or click to browse)\nSelected file: ${path.file}.${path.ext}';
|
|
|
|
|
|
|
|
if (variation == Constants.DEFAULT_VARIATION) constructVariationEntries(songMetadataVariation.playData.songVariations);
|
|
|
|
};
|
|
|
|
|
|
|
|
onClickMetadataVariation = function(variation:String, label:Label, _event:UIEvent) {
|
|
|
|
Dialogs.openBinaryFile('Open Chart ($variation) Metadata', [
|
|
|
|
{label: 'JSON File (.json)', extension: 'json'}], function(selectedFile) {
|
|
|
|
if (selectedFile != null)
|
|
|
|
{
|
|
|
|
trace('Selected file: ' + selectedFile.name);
|
|
|
|
|
|
|
|
var songMetadataJson:Dynamic = SerializerUtil.fromJSONBytes(selectedFile.bytes);
|
|
|
|
var songMetadataVariation:SongMetadata = SongMigrator.migrateSongMetadata(songMetadataJson, 'import');
|
|
|
|
songMetadataVariation = SongValidator.validateSongMetadata(songMetadataVariation, 'import');
|
|
|
|
songMetadataVariation.variation = variation;
|
|
|
|
|
|
|
|
songMetadata.set(variation, songMetadataVariation);
|
|
|
|
|
|
|
|
// Tell the user the load was successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-06-08 20:48:34 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded metadata file (${selectedFile.name})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-06-08 20:48:34 +00:00
|
|
|
|
|
|
|
label.text = 'Metadata file (drag and drop, or click to browse)\nSelected file: ${selectedFile.name}';
|
|
|
|
|
|
|
|
if (variation == Constants.DEFAULT_VARIATION) constructVariationEntries(songMetadataVariation.playData.songVariations);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDropFileChartDataVariation = function(variation:String, label:Label, pathStr:String) {
|
|
|
|
var path:Path = new Path(pathStr);
|
|
|
|
trace('Dropped JSON file (${path})');
|
|
|
|
|
|
|
|
var songChartDataJson:Dynamic = FileUtil.readJSONFromPath(path.toString());
|
|
|
|
var songChartDataVariation:SongChartData = SongMigrator.migrateSongChartData(songChartDataJson, 'import');
|
|
|
|
songChartDataVariation = SongValidator.validateSongChartData(songChartDataVariation, 'import');
|
|
|
|
|
|
|
|
songChartData.set(variation, songChartDataVariation);
|
|
|
|
|
|
|
|
// Tell the user the load was successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-06-08 20:48:34 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded chart data file (${path.file}.${path.ext})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-06-08 20:48:34 +00:00
|
|
|
|
|
|
|
label.text = 'Chart data file (drag and drop, or click to browse)\nSelected file: ${path.file}.${path.ext}';
|
|
|
|
};
|
|
|
|
|
|
|
|
onClickChartDataVariation = function(variation:String, label:Label, _event:UIEvent) {
|
|
|
|
Dialogs.openBinaryFile('Open Chart ($variation) Metadata', [
|
|
|
|
{label: 'JSON File (.json)', extension: 'json'}], function(selectedFile) {
|
|
|
|
if (selectedFile != null)
|
|
|
|
{
|
|
|
|
trace('Selected file: ' + selectedFile.name);
|
|
|
|
|
|
|
|
var songChartDataJson:Dynamic = SerializerUtil.fromJSONBytes(selectedFile.bytes);
|
|
|
|
var songChartDataVariation:SongChartData = SongMigrator.migrateSongChartData(songChartDataJson, 'import');
|
|
|
|
songChartDataVariation = SongValidator.validateSongChartData(songChartDataVariation, 'import');
|
|
|
|
|
|
|
|
songChartData.set(variation, songChartDataVariation);
|
|
|
|
|
|
|
|
// Tell the user the load was successful.
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-06-08 20:48:34 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded chart data file (${selectedFile.name})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-06-08 20:48:34 +00:00
|
|
|
|
|
|
|
label.text = 'Chart data file (drag and drop, or click to browse)\nSelected file: ${selectedFile.name}';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var metadataEntry:Component = state.buildComponent(CHART_EDITOR_DIALOG_OPEN_CHART_ENTRY_LAYOUT);
|
|
|
|
var metadataEntryLabel:Label = metadataEntry.findComponent('chartEntryLabel', Label);
|
|
|
|
metadataEntryLabel.text = 'Drag and drop <song>-metadata.json file, or click to browse.';
|
|
|
|
|
|
|
|
metadataEntry.onClick = onClickMetadataVariation.bind(Constants.DEFAULT_VARIATION).bind(metadataEntryLabel);
|
|
|
|
addDropHandler(metadataEntry, onDropFileMetadataVariation.bind(Constants.DEFAULT_VARIATION).bind(metadataEntryLabel));
|
|
|
|
|
|
|
|
chartContainerA.addComponent(metadataEntry);
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds and opens a dialog where the user can import a chart from an existing file format.
|
|
|
|
* @param state The current chart editor state.
|
|
|
|
* @param format The format to import from.
|
|
|
|
* @param closable
|
|
|
|
* @return Dialog
|
|
|
|
*/
|
2023-08-28 19:03:29 +00:00
|
|
|
public static function openImportChartDialog(state:ChartEditorState, format:String, closable:Bool = true):Dialog
|
2023-06-08 20:48:34 +00:00
|
|
|
{
|
|
|
|
var dialog:Dialog = openDialog(state, CHART_EDITOR_DIALOG_IMPORT_CHART_LAYOUT, true, closable);
|
|
|
|
|
|
|
|
var prettyFormat:String = switch (format)
|
|
|
|
{
|
|
|
|
case 'legacy': 'FNF Legacy';
|
|
|
|
default: 'Unknown';
|
|
|
|
}
|
|
|
|
|
|
|
|
var fileFilter = switch (format)
|
|
|
|
{
|
|
|
|
case 'legacy': {label: 'JSON Data File (.json)', extension: 'json'};
|
|
|
|
default: null;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.title = 'Import Chart - ${prettyFormat}';
|
|
|
|
|
|
|
|
var buttonCancel:Button = dialog.findComponent('dialogCancel', Button);
|
|
|
|
|
|
|
|
buttonCancel.onClick = function(_event) {
|
|
|
|
dialog.hideDialog(DialogButton.CANCEL);
|
|
|
|
}
|
|
|
|
|
|
|
|
var importBox:Box = dialog.findComponent('importBox', Box);
|
|
|
|
|
|
|
|
importBox.onMouseOver = function(_event) {
|
|
|
|
importBox.swapClass('upload-bg', 'upload-bg-hover');
|
|
|
|
Cursor.cursorMode = Pointer;
|
|
|
|
}
|
|
|
|
|
|
|
|
importBox.onMouseOut = function(_event) {
|
|
|
|
importBox.swapClass('upload-bg-hover', 'upload-bg');
|
|
|
|
Cursor.cursorMode = Default;
|
|
|
|
}
|
|
|
|
|
|
|
|
var onDropFile:String->Void;
|
|
|
|
|
|
|
|
importBox.onClick = function(_event) {
|
|
|
|
Dialogs.openBinaryFile('Import Chart - ${prettyFormat}', [fileFilter], function(selectedFile:SelectedFileInfo) {
|
|
|
|
if (selectedFile != null)
|
|
|
|
{
|
|
|
|
trace('Selected file: ' + selectedFile.fullPath);
|
|
|
|
var selectedFileJson:Dynamic = SerializerUtil.fromJSONBytes(selectedFile.bytes);
|
|
|
|
var songMetadata:SongMetadata = SongMigrator.migrateSongMetadataFromLegacy(selectedFileJson);
|
|
|
|
var songChartData:SongChartData = SongMigrator.migrateSongChartDataFromLegacy(selectedFileJson);
|
|
|
|
|
|
|
|
state.loadSong([Constants.DEFAULT_VARIATION => songMetadata], [Constants.DEFAULT_VARIATION => songChartData]);
|
|
|
|
|
|
|
|
dialog.hideDialog(DialogButton.APPLY);
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-06-08 20:48:34 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded chart file (${selectedFile.name})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-06-08 20:48:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDropFile = function(pathStr:String) {
|
|
|
|
var path:Path = new Path(pathStr);
|
|
|
|
var selectedFileJson:Dynamic = FileUtil.readJSONFromPath(path.toString());
|
|
|
|
var songMetadata:SongMetadata = SongMigrator.migrateSongMetadataFromLegacy(selectedFileJson);
|
|
|
|
var songChartData:SongChartData = SongMigrator.migrateSongChartDataFromLegacy(selectedFileJson);
|
|
|
|
|
|
|
|
state.loadSong([Constants.DEFAULT_VARIATION => songMetadata], [Constants.DEFAULT_VARIATION => songChartData]);
|
|
|
|
|
|
|
|
dialog.hideDialog(DialogButton.APPLY);
|
2023-09-01 03:48:15 +00:00
|
|
|
#if !mac
|
2023-06-08 20:48:34 +00:00
|
|
|
NotificationManager.instance.addNotification(
|
|
|
|
{
|
|
|
|
title: 'Success',
|
|
|
|
body: 'Loaded chart file (${path.file}.${path.ext})',
|
|
|
|
type: NotificationType.Success,
|
|
|
|
expiryMs: ChartEditorState.NOTIFICATION_DISMISS_TIME
|
|
|
|
});
|
2023-09-01 03:48:15 +00:00
|
|
|
#end
|
2023-06-08 20:48:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
addDropHandler(importBox, onDropFile);
|
|
|
|
|
|
|
|
return dialog;
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
/**
|
|
|
|
* Builds and opens a dialog displaying the user guide, providing guidance and help on how to use the chart editor.
|
2023-06-08 20:30:45 +00:00
|
|
|
*
|
2023-03-01 02:06:09 +00:00
|
|
|
* @param state The current chart editor state.
|
|
|
|
* @return The dialog that was opened.
|
2023-01-23 03:25:45 +00:00
|
|
|
*/
|
|
|
|
public static inline function openUserGuideDialog(state:ChartEditorState):Dialog
|
|
|
|
{
|
|
|
|
return openDialog(state, CHART_EDITOR_DIALOG_USER_GUIDE_LAYOUT, true, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds and opens a dialog from a given layout path.
|
|
|
|
* @param modal Makes the background uninteractable while the dialog is open.
|
|
|
|
* @param closable Hides the close button on the dialog, preventing it from being closed unless the user interacts with the dialog.
|
|
|
|
*/
|
|
|
|
static function openDialog(state:ChartEditorState, key:String, modal:Bool = true, closable:Bool = true):Dialog
|
|
|
|
{
|
|
|
|
var dialog:Dialog = cast state.buildComponent(key);
|
2023-06-08 20:48:34 +00:00
|
|
|
if (dialog == null) return null;
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
dialog.destroyOnClose = true;
|
|
|
|
dialog.closable = closable;
|
|
|
|
dialog.showDialog(modal);
|
|
|
|
|
|
|
|
state.isHaxeUIDialogOpen = true;
|
2023-03-01 02:06:09 +00:00
|
|
|
dialog.onDialogClosed = function(event:UIEvent) {
|
2023-01-23 03:25:45 +00:00
|
|
|
state.isHaxeUIDialogOpen = false;
|
|
|
|
};
|
|
|
|
|
2023-07-26 20:52:58 +00:00
|
|
|
dialog.zIndex = 1000;
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
return dialog;
|
|
|
|
}
|
2022-10-26 05:14:29 +00:00
|
|
|
}
|