diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 9f0a9983a..31e9dd0eb 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -1149,6 +1149,22 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState */ var commandHistoryDirty:Bool = true; + /** + * Whether the selection has changed and the edit buttons need to be updated. + */ + var editButtonsDirty:Bool = true; + + /** + * Whether the clipboard has changed and the paste buttons need to be updated. + */ + var clipboardDirty:Bool = true; + + /** + * Whether the clipboard is valid and contains a json of notes and events. + */ + var clipboardValid:Bool = true; + + /** * If true, we are currently in the process of quitting the chart editor. * Skip any update functions as most of them will call a crash. @@ -3524,6 +3540,8 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState function copySelection():Void { + clipboardDirty = true; + clipboardValid = true; // Doesn't use a command because it's not undoable. // Calculate a single time offset for all the notes and events. @@ -7112,6 +7130,50 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState menubarItemRedo.text = 'Redo ${redoHistory[redoHistory.length - 1].toString()}'; } } + if (clipboardDirty) + { + clipboardDirty = false; + + if (funkin.util.ClipboardUtil.getClipboard() == null || !clipboardValid) + { + menubarItemPaste.disabled = true; + menubarItemPasteUnsnapped.disabled = true; + clipboardValid = false; + } + else if (clipboardValid) + { + menubarItemPaste.disabled = false; + menubarItemPasteUnsnapped.disabled = false; + } + } + + if (editButtonsDirty) + { + editButtonsDirty = false; + + if (currentEventSelection.length > 0 || currentNoteSelection.length > 0) + { + menubarItemCopy.disabled = false; + menubarItemCut.disabled = false; + menubarItemDelete.disabled = false; + menubarItemSelectNone.disabled = false; + } + else + { + menubarItemCopy.disabled = true; + menubarItemCut.disabled = true; + menubarItemDelete.disabled = true; + menubarItemSelectNone.disabled = true; + } + if (currentNoteSelection.length > 0) + { + menubarItemFlipNotes.disabled = false; + } + else + { + menubarItemFlipNotes.disabled = true; + } + } } /** diff --git a/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx b/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx index 51a59f3d8..9fa1635df 100644 --- a/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx @@ -42,6 +42,7 @@ class AddEventsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } @@ -57,6 +58,7 @@ class AddEventsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } diff --git a/source/funkin/ui/debug/charting/commands/AddNotesCommand.hx b/source/funkin/ui/debug/charting/commands/AddNotesCommand.hx index c5d39f7f9..dd4465fdf 100644 --- a/source/funkin/ui/debug/charting/commands/AddNotesCommand.hx +++ b/source/funkin/ui/debug/charting/commands/AddNotesCommand.hx @@ -42,6 +42,7 @@ class AddNotesCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } @@ -56,6 +57,7 @@ class AddNotesCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } diff --git a/source/funkin/ui/debug/charting/commands/CopyItemsCommand.hx b/source/funkin/ui/debug/charting/commands/CopyItemsCommand.hx index fcf0794da..7a10d109c 100644 --- a/source/funkin/ui/debug/charting/commands/CopyItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/CopyItemsCommand.hx @@ -42,6 +42,8 @@ class CopyItemsCommand implements ChartEditorCommand }); performVisuals(state); + state.clipboardDirty = true; + state.clipboardValid = true; } function performVisuals(state:ChartEditorState):Void diff --git a/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx b/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx index e21932619..ae193effd 100644 --- a/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx @@ -39,6 +39,9 @@ class CutItemsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; + state.clipboardDirty = true; + state.clipboardValid = true; state.sortChartData(); } @@ -53,6 +56,7 @@ class CutItemsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } diff --git a/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx b/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx index af09ed8de..44e42483a 100644 --- a/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx @@ -27,6 +27,7 @@ class DeselectAllItemsCommand implements ChartEditorCommand state.currentEventSelection = []; state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function undo(state:ChartEditorState):Void @@ -35,6 +36,7 @@ class DeselectAllItemsCommand implements ChartEditorCommand state.currentEventSelection = previousEventSelection; state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function shouldAddToHistory(state:ChartEditorState):Bool diff --git a/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx b/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx index 8b1401d07..98993ab84 100644 --- a/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx @@ -28,6 +28,7 @@ class DeselectItemsCommand implements ChartEditorCommand state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; } public function undo(state:ChartEditorState):Void @@ -44,6 +45,7 @@ class DeselectItemsCommand implements ChartEditorCommand state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; } public function shouldAddToHistory(state:ChartEditorState):Bool diff --git a/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx b/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx index 7f464a901..2492b8eb0 100644 --- a/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx @@ -29,6 +29,7 @@ class InvertSelectedItemsCommand implements ChartEditorCommand state.currentEventSelection = SongDataUtils.subtractEvents(state.currentSongChartEventData, previousEventSelection); state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function undo(state:ChartEditorState):Void @@ -37,6 +38,7 @@ class InvertSelectedItemsCommand implements ChartEditorCommand state.currentEventSelection = previousEventSelection; state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function shouldAddToHistory(state:ChartEditorState):Bool diff --git a/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx b/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx index 1bda21f1c..d85ae2887 100644 --- a/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx @@ -22,18 +22,27 @@ class PasteItemsCommand implements ChartEditorCommand var removedNotes:Array = []; var isRedo:Bool = false; + var currentClipboard:SongClipboardItems = + { + valid: false, + notes: [], + events: [] + }; + public function new(targetTimestamp:Float) { this.targetTimestamp = targetTimestamp; + // Doing this here so that clearing or changing the clipboard doesn't break the redo and string. + this.currentClipboard = SongDataUtils.readItemsFromClipboard(); } public function execute(state:ChartEditorState):Void { - var currentClipboard:SongClipboardItems = SongDataUtils.readItemsFromClipboard(); - if (currentClipboard.valid != true) { state.error('Failed to Paste', 'Could not parse clipboard contents.'); + state.clipboardDirty = true; + state.clipboardValid = false; return; } @@ -57,6 +66,7 @@ class PasteItemsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); @@ -93,6 +103,7 @@ class PasteItemsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); @@ -107,8 +118,6 @@ class PasteItemsCommand implements ChartEditorCommand public function toString():String { - var currentClipboard:SongClipboardItems = SongDataUtils.readItemsFromClipboard(); - var len:Int = currentClipboard.notes.length + currentClipboard.events.length; if (currentClipboard.notes.length == 0) return 'Paste $len Events'; diff --git a/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx b/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx index 2cefc7698..ea1b06a3e 100644 --- a/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx @@ -31,6 +31,7 @@ class RemoveEventsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } @@ -49,6 +50,7 @@ class RemoveEventsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } diff --git a/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx b/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx index c6939b1ad..f02198ab1 100644 --- a/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx @@ -37,6 +37,7 @@ class RemoveItemsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } @@ -63,6 +64,7 @@ class RemoveItemsCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } diff --git a/source/funkin/ui/debug/charting/commands/RemoveNotesCommand.hx b/source/funkin/ui/debug/charting/commands/RemoveNotesCommand.hx index aadeeaac7..d1f797efc 100644 --- a/source/funkin/ui/debug/charting/commands/RemoveNotesCommand.hx +++ b/source/funkin/ui/debug/charting/commands/RemoveNotesCommand.hx @@ -32,6 +32,7 @@ class RemoveNotesCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } @@ -51,6 +52,7 @@ class RemoveNotesCommand implements ChartEditorCommand state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; state.sortChartData(); } diff --git a/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx b/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx index b6e90db6f..a4c89c27d 100644 --- a/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx @@ -32,6 +32,7 @@ class SelectAllItemsCommand implements ChartEditorCommand state.currentEventSelection = shouldSelectEvents ? state.currentSongChartEventData : []; state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function undo(state:ChartEditorState):Void @@ -40,6 +41,7 @@ class SelectAllItemsCommand implements ChartEditorCommand state.currentEventSelection = previousEventSelection; state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function shouldAddToHistory(state:ChartEditorState):Bool diff --git a/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx b/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx index adb6ee1d1..07fd55602 100644 --- a/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx @@ -73,6 +73,7 @@ class SelectItemsCommand implements ChartEditorCommand state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; } public function undo(state:ChartEditorState):Void @@ -82,6 +83,7 @@ class SelectItemsCommand implements ChartEditorCommand state.noteDisplayDirty = true; state.notePreviewDirty = true; + state.editButtonsDirty = true; } public function shouldAddToHistory(state:ChartEditorState):Bool diff --git a/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx b/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx index 18d3796a2..d27b4af81 100644 --- a/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx +++ b/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx @@ -81,6 +81,7 @@ class SetItemSelectionCommand implements ChartEditorCommand } state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function undo(state:ChartEditorState):Void @@ -89,6 +90,7 @@ class SetItemSelectionCommand implements ChartEditorCommand state.currentEventSelection = previousEventSelection; state.noteDisplayDirty = true; + state.editButtonsDirty = true; } public function shouldAddToHistory(state:ChartEditorState):Bool