1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-08-20 07:25:59 +00:00

Move notification handling into its own class.

This commit is contained in:
EliteMasterEric 2023-11-22 19:16:38 -05:00
parent 27234ddd67
commit 780220c2d4
6 changed files with 191 additions and 371 deletions

View file

@ -99,8 +99,6 @@ import haxe.ui.core.Screen;
import haxe.ui.events.DragEvent;
import haxe.ui.events.UIEvent;
import haxe.ui.focus.FocusManager;
import haxe.ui.notifications.NotificationManager;
import haxe.ui.notifications.NotificationType;
import openfl.display.BitmapData;
import funkin.util.FileUtil;
@ -1527,27 +1525,18 @@ class ChartEditorState extends HaxeUIState
var result:Null<Array<String>> = this.loadFromFNFCPath(params.fnfcTargetPath);
if (result != null)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: result.length == 0 ? 'Loaded chart (${params.fnfcTargetPath})' : 'Loaded chart (${params.fnfcTargetPath})\n${result.join("\n")}',
type: result.length == 0 ? NotificationType.Success : NotificationType.Warning,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
if (result.length == 0)
{
this.success('Loaded Chart', 'Loaded chart (${params.fnfcTargetPath})');
}
else
{
this.warning('Loaded Chart', 'Loaded chart with issues (${params.fnfcTargetPath})\n${result.join("\n")}');
}
}
else
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load chart (${params.fnfcTargetPath})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
this.error('Failure', 'Failed to load chart (${params.fnfcTargetPath})');
// Song failed to load, open the Welcome dialog so we aren't in a broken state.
this.openWelcomeDialog(false);
@ -1559,7 +1548,11 @@ class ChartEditorState extends HaxeUIState
}
else
{
this.openWelcomeDialog(false);
var welcomeDialog = this.openWelcomeDialog(false);
if (shouldShowBackupAvailableDialog)
{
this.openBackupAvailableDialog(welcomeDialog);
}
}
}
@ -1642,27 +1635,18 @@ class ChartEditorState extends HaxeUIState
var result:Null<Array<String>> = this.loadFromFNFCPath(chartPath);
if (result != null)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: result.length == 0 ? 'Loaded chart (${chartPath.toString()})' : 'Loaded chart (${chartPath.toString()})\n${result.join("\n")}',
type: result.length == 0 ? NotificationType.Success : NotificationType.Warning,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
if (result.length == 0)
{
this.success('Loaded Chart', 'Loaded chart (${chartPath.toString()})');
}
else
{
this.warning('Loaded Chart', 'Loaded chart with issues (${chartPath.toString()})\n${result.join("\n")}');
}
}
else
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load chart (${chartPath.toString()})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
this.error('Failure', 'Failed to load chart (${params.fnfcTargetPath})');
}
}
@ -2002,9 +1986,7 @@ class ChartEditorState extends HaxeUIState
if (menubar == null) throw "Could not find menubar!";
if (!Preferences.debugDisplay) menubar.paddingLeft = null;
// Setup notifications.
@:privateAccess
NotificationManager.GUTTER_SIZE = 20;
this.setupNotifications();
}
/**
@ -4530,15 +4512,7 @@ class ChartEditorState extends HaxeUIState
}
}
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Switch Difficulty',
body: 'Switched difficulty to ${selectedDifficulty.toTitleCase()}',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
this.success('Switch Difficulty', 'Switched difficulty to ${selectedDifficulty.toTitleCase()}');
}
/**
@ -4803,9 +4777,6 @@ class ChartEditorState extends HaxeUIState
*/
// ====================
/**
* Dismiss any existing HaxeUI notifications, if there are any.
*/
function handleNotePreview():Void
{
if (notePreviewDirty && notePreview != null)
@ -5006,14 +4977,6 @@ class ChartEditorState extends HaxeUIState
ChartEditorNoteSprite.noteFrameCollection = null;
}
/**
* Dismiss any existing notifications, if there are any.
*/
function dismissNotifications():Void
{
NotificationManager.instance.clearNotifications();
}
function applyCanQuickSave():Void
{
if (menubarItemSaveChart == null) return;

View file

@ -4,8 +4,6 @@ import funkin.data.song.SongData.SongEventData;
import funkin.data.song.SongData.SongNoteData;
import funkin.data.song.SongDataUtils;
import funkin.data.song.SongDataUtils.SongClipboardItems;
import haxe.ui.notifications.NotificationManager;
import haxe.ui.notifications.NotificationType;
/**
* A command which inserts the contents of the clipboard into the chart editor.
@ -30,15 +28,7 @@ class PasteItemsCommand implements ChartEditorCommand
if (currentClipboard.valid != true)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failed to Paste',
body: 'Could not parse clipboard contents.',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Paste', 'Could not parse clipboard contents.');
return;
}
@ -58,15 +48,7 @@ class PasteItemsCommand implements ChartEditorCommand
state.sortChartData();
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Paste Successful',
body: 'Successfully pasted clipboard contents.',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Paste Successful', 'Successfully pasted clipboard contents.');
}
public function undo(state:ChartEditorState):Void

View file

@ -36,8 +36,6 @@ import haxe.ui.containers.Form;
import haxe.ui.containers.VBox;
import haxe.ui.core.Component;
import haxe.ui.events.UIEvent;
import haxe.ui.notifications.NotificationManager;
import haxe.ui.notifications.NotificationType;
import thx.semver.Version;
using Lambda;
@ -110,27 +108,20 @@ class ChartEditorDialogHandler
var result:Null<Array<String>> = ChartEditorImportExportHandler.loadFromFNFCPath(state, chartPath);
if (result != null)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: result.length == 0 ? 'Loaded chart (${chartPath.toString()})' : 'Loaded chart (${chartPath.toString()})\n${result.join("\n")}',
type: result.length == 0 ? NotificationType.Success : NotificationType.Warning,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
if (result.length == 0)
{
// No warnings.
state.success('Loaded Chart', 'Loaded chart (${chartPath.toString()})');
}
else
{
// One or more warnings.
state.warning('Loaded Chart', 'Loaded chart (${chartPath.toString()})\n${result.join("\n")}');
}
}
else
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load chart (${chartPath.toString()})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Chart', 'Failed to load chart (${chartPath.toString()})');
}
}
@ -334,15 +325,14 @@ class ChartEditorDialogHandler
var result:Null<Array<String>> = ChartEditorImportExportHandler.loadFromFNFC(state, selectedFile.bytes);
if (result != null)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded chart (${selectedFile.name})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
if (result.length == 0)
{
state.success('Loaded Chart', 'Loaded chart (${selectedFile.name})');
}
else
{
state.warning('Loaded Chart', 'Loaded chart (${selectedFile.name})\n${result.join("\n")}');
}
if (selectedFile.fullPath != null) state.currentWorkingFilePath = selectedFile.fullPath;
dialog.hideDialog(DialogButton.APPLY);
@ -351,15 +341,7 @@ class ChartEditorDialogHandler
}
catch (err)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load chart (${selectedFile.name}): ${err}',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Chart', 'Failed to load chart (${selectedFile.name}): ${err}');
}
}
});
@ -374,42 +356,26 @@ class ChartEditorDialogHandler
var result:Null<Array<String>> = ChartEditorImportExportHandler.loadFromFNFCPath(state, path.toString());
if (result != null)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: result.length == 0 ? 'Loaded chart (${path.toString()})' : 'Loaded chart (${path.toString()})\n${result.join("\n")}',
type: result.length == 0 ? NotificationType.Success : NotificationType.Warning,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
if (result.length == 0)
{
state.success('Loaded Chart', 'Loaded chart (${path.file}.${path.ext})');
}
else
{
state.warning('Loaded Chart', 'Loaded chart (${path.file}.${path.ext})\n${result.join("\n")}');
}
dialog.hideDialog(DialogButton.APPLY);
removeDropHandler(onDropFile);
}
else
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load chart (${path.toString()})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Chart', 'Failed to load chart (${path.file}.${path.ext})');
}
}
catch (err)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load chart (${path.toString()}): ${err}',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Chart', 'Failed to load chart (${path.file}.${path.ext})');
}
};
@ -699,15 +665,7 @@ class ChartEditorDialogHandler
{
if (state.loadInstFromBytes(selectedFile.bytes, instId))
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded instrumental track (${selectedFile.name}) for variation (${state.selectedVariation})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Instrumental', 'Loaded instrumental track (${selectedFile.name}) for variation (${state.selectedVariation})');
state.switchToCurrentInstrumental();
dialog.hideDialog(DialogButton.APPLY);
@ -715,15 +673,7 @@ class ChartEditorDialogHandler
}
else
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load instrumental track (${selectedFile.name}) for variation (${state.selectedVariation})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Instrumental', 'Failed to load instrumental track (${selectedFile.name}) for variation (${state.selectedVariation})');
}
}
});
@ -735,15 +685,7 @@ class ChartEditorDialogHandler
if (state.loadInstFromPath(path, instId))
{
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded instrumental track (${path.file}.${path.ext}) for variation (${state.selectedVariation})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Instrumental', 'Loaded instrumental track (${path.file}.${path.ext}) for variation (${state.selectedVariation})');
state.switchToCurrentInstrumental();
dialog.hideDialog(DialogButton.APPLY);
@ -761,15 +703,7 @@ class ChartEditorDialogHandler
}
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: message,
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Instrumental', message);
}
};
@ -991,15 +925,7 @@ class ChartEditorDialogHandler
if (state.loadVocalsFromPath(path, charKey, instId))
{
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded vocals for $charName (${path.file}.${path.ext}), variation ${state.selectedVariation}',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Vocals', 'Loaded vocals for $charName (${path.file}.${path.ext}), variation ${state.selectedVariation}');
#if FILE_DROP_SUPPORTED
vocalsEntryLabel.text = 'Voices for $charName (drag and drop, or click to browse)\nSelected file: ${path.file}.${path.ext}';
#else
@ -1013,16 +939,7 @@ class ChartEditorDialogHandler
{
trace('Failed to load vocal track (${path.file}.${path.ext})');
// Vocals failed to load.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load vocal track (${path.file}.${path.ext}) for variation (${state.selectedVariation})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Vocals', 'Failed to load vocal track (${path.file}.${path.ext}) for variation (${state.selectedVariation})');
#if FILE_DROP_SUPPORTED
vocalsEntryLabel.text = 'Drag and drop vocals for $charName here, or click to browse.';
@ -1046,15 +963,8 @@ class ChartEditorDialogHandler
if (state.loadVocalsFromBytes(selectedFile.bytes, charKey, instId))
{
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded vocals for $charName (${selectedFile.name}), variation ${state.selectedVariation}',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Vocals', 'Loaded vocals for $charName (${selectedFile.name}), variation ${state.selectedVariation}');
#if FILE_DROP_SUPPORTED
vocalsEntryLabel.text = 'Voices for $charName (drag and drop, or click to browse)\nSelected file: ${selectedFile.name}';
#else
@ -1067,15 +977,7 @@ class ChartEditorDialogHandler
{
trace('Failed to load vocal track (${selectedFile.fullPath})');
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load vocal track (${selectedFile.name}) for variation (${state.selectedVariation})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failed to Load Vocals', 'Failed to load vocal track (${selectedFile.name}) for variation (${state.selectedVariation})');
#if FILE_DROP_SUPPORTED
vocalsEntryLabel.text = 'Drag and drop vocals for $charName here, or click to browse.';
@ -1226,15 +1128,7 @@ class ChartEditorDialogHandler
if (songMetadataVersion == null)
{
// Tell the user the load was not successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Could not parse metadata file version (${path.file}.${path.ext})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Could not parse metadata file version (${path.file}.${path.ext})');
return;
}
@ -1244,30 +1138,14 @@ class ChartEditorDialogHandler
if (songMetadataVariation == null)
{
// Tell the user the load was not successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Could not load metadata file (${path.file}.${path.ext})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Could not load metadata file (${path.file}.${path.ext})');
return;
}
songMetadata.set(variation, songMetadataVariation);
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded metadata file (${path.file}.${path.ext})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Metadata', 'Loaded metadata file (${path.file}.${path.ext})');
#if FILE_DROP_SUPPORTED
label.text = 'Metadata file (drag and drop, or click to browse)\nSelected file: ${path.file}.${path.ext}';
@ -1291,15 +1169,7 @@ class ChartEditorDialogHandler
if (songMetadataVersion == null)
{
// Tell the user the load was not successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Could not parse metadata file version (${selectedFile.name})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Could not parse metadata file version (${selectedFile.name})');
return;
}
@ -1311,15 +1181,7 @@ class ChartEditorDialogHandler
songMetadata.set(variation, songMetadataVariation);
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded metadata file (${selectedFile.name})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Metadata', 'Loaded metadata file (${selectedFile.name})');
#if FILE_DROP_SUPPORTED
label.text = 'Metadata file (drag and drop, or click to browse)\nSelected file: ${selectedFile.name}';
@ -1332,15 +1194,7 @@ class ChartEditorDialogHandler
else
{
// Tell the user the load was unsuccessful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load metadata file (${selectedFile.name})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Failed to load metadata file (${selectedFile.name})');
}
}
});
@ -1356,15 +1210,7 @@ class ChartEditorDialogHandler
if (songChartDataVersion == null)
{
// Tell the user the load was not successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Could not parse chart data file version (${path.file}.${path.ext})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Could not parse chart data file version (${path.file}.${path.ext})');
return;
}
@ -1379,15 +1225,7 @@ class ChartEditorDialogHandler
state.noteDisplayDirty = true;
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded chart data file (${path.file}.${path.ext})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Chart Data', 'Loaded chart data file (${path.file}.${path.ext})');
#if FILE_DROP_SUPPORTED
label.text = 'Chart data file (drag and drop, or click to browse)\nSelected file: ${path.file}.${path.ext}';
@ -1398,15 +1236,7 @@ class ChartEditorDialogHandler
else
{
// Tell the user the load was unsuccessful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to load chart data file (${path.file}.${path.ext})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Failed to load chart data file (${path.file}.${path.ext})');
}
};
@ -1423,15 +1253,7 @@ class ChartEditorDialogHandler
if (songChartDataVersion == null)
{
// Tell the user the load was not successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Could not parse chart data file version (${selectedFile.name})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Could not parse chart data file version (${selectedFile.name})');
return;
}
@ -1446,15 +1268,7 @@ class ChartEditorDialogHandler
state.noteDisplayDirty = true;
// Tell the user the load was successful.
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded chart data file (${selectedFile.name})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Loaded Chart Data', 'Loaded chart data file (${selectedFile.name})');
#if FILE_DROP_SUPPORTED
label.text = 'Chart data file (drag and drop, or click to browse)\nSelected file: ${selectedFile.name}';
@ -1551,15 +1365,7 @@ class ChartEditorDialogHandler
if (fnfLegacyData == null)
{
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Failure',
body: 'Failed to parse FNF chart file (${selectedFile.name})',
type: NotificationType.Error,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.error('Failure', 'Failed to parse FNF chart file (${selectedFile.name})');
return;
}
@ -1569,15 +1375,7 @@ class ChartEditorDialogHandler
state.loadSong([Constants.DEFAULT_VARIATION => songMetadata], [Constants.DEFAULT_VARIATION => songChartData]);
dialog.hideDialog(DialogButton.APPLY);
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded chart file (${selectedFile.name})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Success', 'Loaded chart file (${selectedFile.name})');
}
});
}
@ -1592,15 +1390,7 @@ class ChartEditorDialogHandler
state.loadSong([Constants.DEFAULT_VARIATION => songMetadata], [Constants.DEFAULT_VARIATION => songChartData]);
dialog.hideDialog(DialogButton.APPLY);
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded chart file (${path.file}.${path.ext})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Success', 'Loaded chart file (${path.file}.${path.ext})');
};
addDropHandler(importBox, onDropFile);
@ -1700,14 +1490,9 @@ class ChartEditorDialogHandler
state.songMetadata.set(pendingVariation.variation, pendingVariation);
state.difficultySelectDirty = true; // Force the Difficulty toolbox to update.
#if !mac
NotificationManager.instance.addNotification(
{
title: "Add Variation",
body: 'Added new variation "${pendingVariation.variation}"',
type: NotificationType.Success
});
#end
state.success('Add Variation', 'Added new variation "${pendingVariation.variation}"');
dialog.hideDialog(DialogButton.APPLY);
}
@ -1764,14 +1549,8 @@ class ChartEditorDialogHandler
state.createDifficulty(dialogVariation.value.id, dialogDifficultyName.text.toLowerCase(), inputScrollSpeed.value ?? 1.0);
#if !mac
NotificationManager.instance.addNotification(
{
title: "Add Difficulty",
body: 'Added new difficulty "${dialogDifficultyName.text.toLowerCase()}"',
type: NotificationType.Success
});
#end
state.success('Add Difficulty', 'Added new difficulty "${dialogDifficultyName.text.toLowerCase()}"');
dialog.hideDialog(DialogButton.APPLY);
}

View file

@ -100,15 +100,7 @@ class ChartEditorImportExportHandler
state.refreshMetadataToolbox();
#if !mac
NotificationManager.instance.addNotification(
{
title: 'Success',
body: 'Loaded song (${rawSongMetadata[0].songName})',
type: NotificationType.Success,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#end
state.success('Success', 'Loaded song (${rawSongMetadata[0].songName})');
}
/**

View file

@ -0,0 +1,103 @@
package funkin.ui.debug.charting.handlers;
import haxe.ui.notifications.Notification;
import haxe.ui.notifications.NotificationManager;
import haxe.ui.notifications.NotificationType;
class ChartEditorNotificationHandler
{
public static function setupNotifications(state:ChartEditorState):Void
{
// Setup notifications.
@:privateAccess
NotificationManager.GUTTER_SIZE = 20;
}
/**
* Send a notification with a checkmark indicating success.
* @param state The current state of the chart editor.
*/
public static function success(state:ChartEditorState, title:String, body:String):Notification
{
return sendNotification(title, body, NotificationType.Success);
}
/**
* Send a notification with a warning icon.
* @param state The current state of the chart editor.
*/
public static function warning(state:ChartEditorState, title:String, body:String):Notification
{
return sendNotification(title, body, NotificationType.Warning);
}
/**
* Send a notification with a warning icon.
* @param state The current state of the chart editor.
*/
public static inline function warn(state:ChartEditorState, title:String, body:String):Notification
{
return warning(state, title, body);
}
/**
* Send a notification with a cross indicating an error.
* @param state The current state of the chart editor.
*/
public static function error(state:ChartEditorState, title:String, body:String):Notification
{
return sendNotification(title, body, NotificationType.Error);
}
/**
* Send a notification with a cross indicating failure.
* @param state The current state of the chart editor.
*/
public static inline function failure(state:ChartEditorState, title:String, body:String):Notification
{
return error(state, title, body);
}
/**
* Send a notification with an info icon.
* @param state The current state of the chart editor.
*/
public static function info(state:ChartEditorState, title:String, body:String):Notification
{
return sendNotification(title, body, NotificationType.Info);
}
/**
* Clear all active notifications.
* @param state The current state of the chart editor.
*/
public static function clearNotifications(state:ChartEditorState):Void
{
NotificationManager.instance.clearNotifications();
}
/**
* Clear a specific notification.
* @param state The current state of the chart editor.
* @param notif The notification to clear.
*/
public static function clearNotification(state:ChartEditorState, notif:Notification):Void
{
NotificationManager.instance.removeNotification(notif);
}
static function sendNotification(title:String, body:String, ?type:NotificationType):Notification
{
#if !mac
return NotificationManager.instance.addNotification(
{
title: title,
body: body,
type: type ?? NotificationType.Default,
expiryMs: Constants.NOTIFICATION_DISMISS_TIME
});
#else
trace('WARNING: Notifications are not supported on Mac OS.');
#end
}
}

View file

@ -5,6 +5,7 @@ package funkin.ui.debug.charting;
using funkin.ui.debug.charting.handlers.ChartEditorAudioHandler;
using funkin.ui.debug.charting.handlers.ChartEditorDialogHandler;
using funkin.ui.debug.charting.handlers.ChartEditorImportExportHandler;
using funkin.ui.debug.charting.handlers.ChartEditorNotificationHandler;
using funkin.ui.debug.charting.handlers.ChartEditorShortcutHandler;
using funkin.ui.debug.charting.handlers.ChartEditorThemeHandler;
using funkin.ui.debug.charting.handlers.ChartEditorToolboxHandler;