diff --git a/source/funkin/data/event/SongEventSchema.hx b/source/funkin/data/event/SongEventSchema.hx index 72dac337f97..6a8b94b2502 100644 --- a/source/funkin/data/event/SongEventSchema.hx +++ b/source/funkin/data/event/SongEventSchema.hx @@ -41,6 +41,12 @@ abstract SongEventSchema(SongEventSchemaRaw) return this[k] = v; } + @:arrayAccess + public inline function push(v:SongEventSchemaField) + { + this.push(v); + } + public function stringifyFieldValue(name:String, value:Dynamic, addUnits:Bool = true):String { var field:SongEventSchemaField = getByName(name); diff --git a/source/funkin/data/song/SongData.hx b/source/funkin/data/song/SongData.hx index b5da02d0077..2e8be1f07ce 100644 --- a/source/funkin/data/song/SongData.hx +++ b/source/funkin/data/song/SongData.hx @@ -843,9 +843,27 @@ class SongEventDataRaw implements ICloneable var eventHandler = getHandler(); var eventSchema = getSchema(); - if (eventSchema == null) return 'Unknown Event: ${this.eventKind}'; + var result = 'Unknown Event: ${this.eventKind}'; - var result = '${eventHandler.getTitle()}'; + if (eventSchema == null) + { + // Build a tooltip out of the value map instead. + var valueStruct:haxe.DynamicAccess = valueAsStruct('value'); + + for (pair in valueStruct.keyValueIterator()) + { + var key = pair.key; + var value = pair.value; + + var title = pair.key ?? 'UnknownField'; + + result += '\n- ${title}: ${value}'; + } + + return result; + } + + result = '${eventHandler.getTitle()}'; var defaultKey = eventSchema.getFirstField()?.name; var valueStruct:haxe.DynamicAccess = valueAsStruct(defaultKey); diff --git a/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx b/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx index a878ee6877b..9022186490c 100644 --- a/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/AddEventsCommand.hx @@ -38,6 +38,8 @@ class AddEventsCommand implements ChartEditorCommand state.playSound(Paths.sound('chartingSounds/noteLay')); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; @@ -52,6 +54,8 @@ class AddEventsCommand implements ChartEditorCommand state.currentNoteSelection = []; state.currentEventSelection = []; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; diff --git a/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx b/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx index 6cf674f8097..384eea26cfb 100644 --- a/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/CutItemsCommand.hx @@ -36,6 +36,8 @@ class CutItemsCommand implements ChartEditorCommand state.currentNoteSelection = []; state.currentEventSelection = []; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; @@ -50,6 +52,8 @@ class CutItemsCommand implements ChartEditorCommand state.currentNoteSelection = notes; state.currentEventSelection = events; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; diff --git a/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx b/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx index 5bfef76ccfa..a8dbb5798f8 100644 --- a/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/DeselectAllItemsCommand.hx @@ -23,6 +23,8 @@ class DeselectAllItemsCommand implements ChartEditorCommand state.currentNoteSelection = []; state.currentEventSelection = []; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } @@ -31,6 +33,8 @@ class DeselectAllItemsCommand implements ChartEditorCommand state.currentNoteSelection = previousNoteSelection; state.currentEventSelection = previousEventSelection; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } diff --git a/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx b/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx index 6a115a26a2b..a58cb5311d8 100644 --- a/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/DeselectItemsCommand.hx @@ -25,6 +25,8 @@ class DeselectItemsCommand implements ChartEditorCommand state.currentNoteSelection = SongDataUtils.subtractNotes(state.currentNoteSelection, this.notes); state.currentEventSelection = SongDataUtils.subtractEvents(state.currentEventSelection, this.events); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; state.notePreviewDirty = true; } @@ -41,6 +43,8 @@ class DeselectItemsCommand implements ChartEditorCommand state.currentEventSelection.push(event); } + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; state.notePreviewDirty = true; } diff --git a/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx b/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx index d9a28f46351..7696938f94b 100644 --- a/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/InvertSelectedItemsCommand.hx @@ -25,6 +25,8 @@ class InvertSelectedItemsCommand implements ChartEditorCommand state.currentNoteSelection = SongDataUtils.subtractNotes(state.currentSongChartNoteData, previousNoteSelection); state.currentEventSelection = SongDataUtils.subtractEvents(state.currentSongChartEventData, previousEventSelection); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } @@ -33,6 +35,8 @@ class InvertSelectedItemsCommand implements ChartEditorCommand state.currentNoteSelection = previousNoteSelection; state.currentEventSelection = previousEventSelection; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } diff --git a/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx b/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx index 257db94b45a..8971b21a6e5 100644 --- a/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/PasteItemsCommand.hx @@ -46,6 +46,8 @@ class PasteItemsCommand implements ChartEditorCommand state.currentNoteSelection = addedNotes.copy(); state.currentEventSelection = addedEvents.copy(); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; @@ -64,6 +66,8 @@ class PasteItemsCommand implements ChartEditorCommand state.currentNoteSelection = []; state.currentEventSelection = []; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; diff --git a/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx b/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx index 30f4280d263..0e0da23d043 100644 --- a/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/RemoveEventsCommand.hx @@ -27,6 +27,8 @@ class RemoveEventsCommand implements ChartEditorCommand state.playSound(Paths.sound('chartingSounds/noteErase')); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; @@ -45,6 +47,8 @@ class RemoveEventsCommand implements ChartEditorCommand state.currentEventSelection = events; state.playSound(Paths.sound('chartingSounds/undo')); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; diff --git a/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx b/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx index 1cc61f23334..623a7975607 100644 --- a/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/RemoveItemsCommand.hx @@ -33,6 +33,8 @@ class RemoveItemsCommand implements ChartEditorCommand state.playSound(Paths.sound('chartingSounds/noteErase')); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.saveDataDirty = true; state.noteDisplayDirty = true; state.notePreviewDirty = true; @@ -57,6 +59,8 @@ class RemoveItemsCommand implements ChartEditorCommand state.currentNoteSelection = notes; state.currentEventSelection = events; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.playSound(Paths.sound('chartingSounds/undo')); state.saveDataDirty = true; diff --git a/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx b/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx index f550e044b8c..29b8133d267 100644 --- a/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/SelectAllItemsCommand.hx @@ -30,6 +30,8 @@ class SelectAllItemsCommand implements ChartEditorCommand state.currentNoteSelection = shouldSelectNotes ? state.currentSongChartNoteData : []; state.currentEventSelection = shouldSelectEvents ? state.currentSongChartEventData : []; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } @@ -38,6 +40,8 @@ class SelectAllItemsCommand implements ChartEditorCommand state.currentNoteSelection = previousNoteSelection; state.currentEventSelection = previousEventSelection; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } diff --git a/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx b/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx index 423295f1ab9..ac8c34b94bd 100644 --- a/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx +++ b/source/funkin/ui/debug/charting/commands/SelectItemsCommand.hx @@ -34,7 +34,7 @@ class SelectItemsCommand implements ChartEditorCommand } // If we just selected one or more events (and no notes), then we should make the event data toolbox display the event data for the selected event. - if (this.notes.length == 0 && this.events.length == 1) + if (this.notes.length == 0 && state.currentEventSelection.length == 1) { var eventSelected = this.events[0]; @@ -55,8 +55,6 @@ class SelectItemsCommand implements ChartEditorCommand var eventData = eventSelected.valueAsStruct(defaultKey); state.eventDataToPlace = eventData; - - state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); } // If we just selected one or more notes (and no events), then we should make the note data toolbox display the note data for the selected note. @@ -70,6 +68,8 @@ class SelectItemsCommand implements ChartEditorCommand state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT); } + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; state.notePreviewDirty = true; } @@ -79,6 +79,8 @@ class SelectItemsCommand implements ChartEditorCommand state.currentNoteSelection = SongDataUtils.subtractNotes(state.currentNoteSelection, this.notes); state.currentEventSelection = SongDataUtils.subtractEvents(state.currentEventSelection, this.events); + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; state.notePreviewDirty = true; } diff --git a/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx b/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx index 661c44d85a1..86f7fc68668 100644 --- a/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx +++ b/source/funkin/ui/debug/charting/commands/SetItemSelectionCommand.hx @@ -31,7 +31,7 @@ class SetItemSelectionCommand implements ChartEditorCommand state.currentEventSelection = events; // If we just selected one or more events (and no notes), then we should make the event data toolbox display the event data for the selected event. - if (this.notes.length == 0 && this.events.length == 1) + if (this.notes.length == 0 && this.events.length > 1) { var eventSelected = this.events[0]; @@ -65,8 +65,6 @@ class SetItemSelectionCommand implements ChartEditorCommand { state.eventDataToPlace = eventDataClone; } - - state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); } // IF we just selected one or more notes (and no events), then we should make the note data toolbox display the note data for the selected note. @@ -79,6 +77,8 @@ class SetItemSelectionCommand implements ChartEditorCommand state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_NOTE_DATA_LAYOUT); } + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } @@ -87,6 +87,8 @@ class SetItemSelectionCommand implements ChartEditorCommand state.currentNoteSelection = previousNoteSelection; state.currentEventSelection = previousEventSelection; + state.refreshToolbox(ChartEditorState.CHART_EDITOR_TOOLBOX_EVENT_DATA_LAYOUT); + state.noteDisplayDirty = true; } diff --git a/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx b/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx index 1bdfc227216..14b92fb5559 100644 --- a/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx +++ b/source/funkin/ui/debug/charting/toolboxes/ChartEditorEventDataToolbox.hx @@ -24,16 +24,22 @@ import haxe.ui.containers.Grid; @:build(haxe.ui.ComponentBuilder.build("assets/exclude/data/ui/chart-editor/toolboxes/event-data.xml")) class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox { - var toolboxEventsEventKind:DropDown; + var toolboxEventsModifyAllEvents:CheckBox; var toolboxEventsDataFrame:Frame; + var selectedEventDropdownItemRenderer:haxe.ui.core.ItemRenderer; var toolboxEventsDataGrid:Grid; + var toolboxEventsCustomKindLabel:Label; + var toolboxEventsCustomKind:TextField; var _initializing:Bool = true; + var populateSelectedEventsDropDown:Bool = true; public function new(chartEditorState2:ChartEditorState) { super(chartEditorState2); + selectedEventDropdownItemRenderer = toolboxEventsSelectedEvents.findComponent(haxe.ui.core.ItemRenderer); + initialize(); this.onDialogClosed = onClose; @@ -57,25 +63,31 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox var eventType:String = event.data.id; var sameEvent:Bool = (eventType == chartEditorState.eventKindToPlace); - trace('ChartEditorEventDataToolbox - Event type changed: $eventType'); + if (!sameEvent) trace('ChartEditorEventDataToolbox - Event type changed: $eventType'); // Edit the event data to place. chartEditorState.eventKindToPlace = eventType; var schema:SongEventSchema = SongEventRegistry.getEventSchema(eventType); + if (!sameEvent) chartEditorState.eventDataToPlace = {}; if (schema == null) { - trace('ChartEditorEventDataToolbox - Unknown event kind: $eventType'); - return; + trace('ChartEditorEventDataToolbox - Building useless schema for unknown event'); + toolboxEventsCustomKindLabel.hidden = false; + toolboxEventsCustomKind.hidden = false; + buildEventDataFormFromSchema(toolboxEventsDataGrid, buildSchemaFromEventData(), chartEditorState.eventKindToPlace); + } + else + { + toolboxEventsCustomKindLabel.hidden = true; + toolboxEventsCustomKind.hidden = true; + buildEventDataFormFromSchema(toolboxEventsDataGrid, schema, chartEditorState.eventKindToPlace); } - if (!sameEvent) chartEditorState.eventDataToPlace = {}; - buildEventDataFormFromSchema(toolboxEventsDataGrid, schema, chartEditorState.eventKindToPlace); - - if (!_initializing && chartEditorState.currentEventSelection.length > 0) + if (!_initializing && toolboxEventsModifyAllEvents.selected && chartEditorState.currentEventSelection.length > 0) { - // Edit the event data of any selected events. + // Edit the event data of all selected events. for (event in chartEditorState.currentEventSelection) { event.eventKind = chartEditorState.eventKindToPlace; @@ -84,10 +96,66 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox chartEditorState.saveDataDirty = true; chartEditorState.noteDisplayDirty = true; chartEditorState.notePreviewDirty = true; + chartEditorState.noteTooltipsDirty = true; + } + } + toolboxEventsCustomKind.onChange = function(event:UIEvent) { + var customKind:Null = event?.target?.text; + + if (customKind == null) return; + + var prevEventKindToPlace = chartEditorState.eventKindToPlace; + chartEditorState.eventKindToPlace = customKind; + + if (!_initializing && chartEditorState.currentEventSelection.length > 0) + { + if (toolboxEventsModifyAllEvents.selected) + { + // Edit the event data of any existing events of the same type. + for (event in chartEditorState.currentEventSelection) + { + if (event.eventKind == prevEventKindToPlace) + event.eventKind = chartEditorState.eventKindToPlace; + } + } + else + { + // Find the currently selected event and update it's values. + var event = chartEditorState.currentEventSelection[toolboxEventsSelectedEvents.selectedIndex]; + if (event != null) + { + event.eventKind = chartEditorState.eventKindToPlace; + } + } + chartEditorState.saveDataDirty = true; + chartEditorState.noteDisplayDirty = true; + chartEditorState.notePreviewDirty = true; + chartEditorState.noteTooltipsDirty = true; } } + + toolboxEventsSelectedEvents.onChange = function(event:UIEvent) { + if (event.target.value == null) return; + // Forced to pass event.target.value.id rather than the selectedIndex due to it not getting set at all in refreshSelectedEvents for no reason. + var selectedEvent = chartEditorState.currentEventSelection[Std.parseInt(event.target.value.id)]; + if (selectedEvent != null) + { + chartEditorState.eventKindToPlace = selectedEvent.eventKind; + chartEditorState.eventDataToPlace = selectedEvent.value; + + // This bool prevents the selected event from having it's data overridden (and unnecessary code execution). Look, it works, don't question it. + populateSelectedEventsDropDown = false; + + refresh(); + + populateSelectedEventsDropDown = true; + } + } + toolboxEventsEventKind.pauseEvent(UIEvent.CHANGE, true); + refreshSelectedEvents(); + var startingEventValue = ChartEditorDropdowns.populateDropdownWithSongEvents(toolboxEventsEventKind, chartEditorState.eventKindToPlace); trace('ChartEditorEventDataToolbox - Starting event kind: ${startingEventValue}'); toolboxEventsEventKind.value = startingEventValue; @@ -95,26 +163,49 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox toolboxEventsEventKind.resumeEvent(UIEvent.CHANGE, true, true); } + function refreshSelectedEvents(startingChartEvent:Int = 0):Void + { + var startingSelectedEvent = ChartEditorDropdowns.populateDropdownWithChartEvents(toolboxEventsSelectedEvents, chartEditorState, startingChartEvent); + // Why does this particular selectedIndex refuse to be set more than once?????? + toolboxEventsSelectedEvents.selectedIndex = Std.parseInt(startingSelectedEvent.id); + toolboxEventsSelectedEvents.value = startingSelectedEvent; + selectedEventDropdownItemRenderer.data = startingSelectedEvent; + } + public override function refresh():Void { super.refresh(); toolboxEventsEventKind.pauseEvent(UIEvent.CHANGE, true); + if (populateSelectedEventsDropDown) refreshSelectedEvents(); + var newDropdownElement = ChartEditorDropdowns.findDropdownElement(chartEditorState.eventKindToPlace, toolboxEventsEventKind); if (newDropdownElement == null) { - throw 'ChartEditorEventDataToolbox - Event kind not in dropdown: ${chartEditorState.eventKindToPlace}'; + trace('ChartEditorEventDataToolbox - Event kind not in dropdown: ${chartEditorState.eventKindToPlace}'); + newDropdownElement = ChartEditorDropdowns.findDropdownElement('unknown', toolboxEventsEventKind); + toolboxEventsCustomKindLabel.hidden = false; + toolboxEventsCustomKind.hidden = false; + toolboxEventsCustomKind.value = chartEditorState.eventKindToPlace; } - else if (toolboxEventsEventKind.value != newDropdownElement || lastEventKind != toolboxEventsEventKind.value.id) + else + { + toolboxEventsCustomKindLabel.hidden = true; + toolboxEventsCustomKind.hidden = true; + } + + if (toolboxEventsEventKind.value != newDropdownElement || lastEventKind != toolboxEventsEventKind.value.id) { toolboxEventsEventKind.value = newDropdownElement; var schema:SongEventSchema = SongEventRegistry.getEventSchema(chartEditorState.eventKindToPlace); if (schema == null) { + // Build the event schema using the selected unknown event's value instead. trace('ChartEditorEventDataToolbox - Unknown event kind: ${chartEditorState.eventKindToPlace}'); + buildEventDataFormFromSchema(toolboxEventsDataGrid, buildSchemaFromEventData(), chartEditorState.eventKindToPlace); } else { @@ -163,6 +254,78 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox toolboxEventsEventKind.resumeEvent(UIEvent.CHANGE, true, true); } + function buildSchemaFromEventData():SongEventSchema + { + var schema:SongEventSchema = new SongEventSchema([]); + + for (pair in chartEditorState.eventDataToPlace.keyValueIterator()) + { + var fieldId:String = pair.key; + var value:Null = pair.value; + + switch (value) + { + case Std.isOfType(_, Int) => true: + schema.push( + { + name: '$fieldId', + title: '$fieldId', + defaultValue: value, + step: 1, + type: SongEventFieldType.INTEGER, + }); + case Std.isOfType(_, Float) => true: + schema.push( + { + name: '$fieldId', + title: '$fieldId', + defaultValue: value, + step: 0.1, + type: SongEventFieldType.FLOAT, + }); + case Std.isOfType(_, Bool) => true: + schema.push( + { + name: '$fieldId', + title: '$fieldId', + type: SongEventFieldType.BOOL, + defaultValue: value, + }); + case Std.isOfType(_, String) => true: + schema.push( + { + name: '$fieldId', + title: '$fieldId', + type: SongEventFieldType.STRING, + defaultValue: '$value', + }); + default: + throw 'ChartEditorEventDataToolbox - Field "${fieldId}" is of unknown type "${Type.getClassName(Type.getClass(value))}".'; + } + } + + if (schema.getFirstField() == null) + { + // Fine, here's some useless values for the psychic in you. + schema = new SongEventSchema([ + { + name: 'value1', + title: 'value1', + type: SongEventFieldType.STRING, + defaultValue: '', + }, + { + name: 'value2', + title: 'value2', + type: SongEventFieldType.STRING, + defaultValue: '', + }, + ]); + } + + return schema; + } + var lastEventKind:String = 'unknown'; function buildEventDataFormFromSchema(target:Box, schema:SongEventSchema, eventKind:String):Void @@ -175,6 +338,8 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox // Clear the frame. target.removeAllComponents(); + if (schema == null) return; + for (field in schema) { if (field == null) continue; @@ -288,13 +453,25 @@ class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox chartEditorState.eventDataToPlace.set(event.target.id, value); } - // Edit the event data of any existing events. if (!_initializing && chartEditorState.currentEventSelection.length > 0) { - for (songEvent in chartEditorState.currentEventSelection) + if (toolboxEventsModifyAllEvents.selected) + { + // Edit the event data of any existing events of the same type. + for (event in chartEditorState.currentEventSelection) + { + if (event.eventKind == chartEditorState.eventKindToPlace) event.value = chartEditorState.eventDataToPlace; + } + } + else { - songEvent.eventKind = chartEditorState.eventKindToPlace; - songEvent.value = Reflect.copy(chartEditorState.eventDataToPlace); + // Find the currently selected event and update it's values. + var event = chartEditorState.currentEventSelection[toolboxEventsSelectedEvents.selectedIndex]; + if (event != null) + { + event.eventKind = chartEditorState.eventKindToPlace; + event.value = Reflect.copy(chartEditorState.eventDataToPlace); + } } chartEditorState.saveDataDirty = true; chartEditorState.noteDisplayDirty = true; diff --git a/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx b/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx index 30d2247e095..3f68173f689 100644 --- a/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx +++ b/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx @@ -99,6 +99,47 @@ class ChartEditorDropdowns dropDown.dataSource.sort('text', ASCENDING); + dropDown.dataSource.add({id: 'unknown', text: 'Unknown Event'}); + + return returnValue; + } + + /** + * Populate a dropdown with the current event selection. + */ + public static function populateDropdownWithChartEvents(dropDown:DropDown, state:ChartEditorState, startingChartEvent:Int = 0):DropDownEntry + { + dropDown.dataSource.clear(); + + var events = state.currentEventSelection; + + var returnValue:DropDownEntry = + { + id: "0", + text: (events[0] != null) ? (events[0].time + ' : ' + events[0].buildTooltip()) : ('No Event Selected!') + }; + + for (index in 0...events.length) + { + var value = + { + id: '$index', + text: '${events[index].time} : ${events[index].buildTooltip()}' + }; + if (startingChartEvent == index) returnValue = value; + dropDown.dataSource.add(value); + } + + if (events.length > 0) dropDown.dataSource.add( + { + id: "-1", + text: 'No Selected Event' + }); + else + dropDown.dataSource.add(returnValue); + + dropDown.dataSource.sort('id', ASCENDING); + return returnValue; }