2024-01-04 00:53:17 +00:00
|
|
|
package funkin.ui.debug.charting.toolboxes;
|
|
|
|
|
|
|
|
import funkin.play.character.BaseCharacter.CharacterType;
|
|
|
|
import funkin.play.character.CharacterData;
|
2024-01-16 21:49:15 +00:00
|
|
|
import funkin.data.stage.StageData;
|
2024-01-04 00:53:17 +00:00
|
|
|
import funkin.play.event.SongEvent;
|
2024-01-04 02:10:14 +00:00
|
|
|
import funkin.data.event.SongEventSchema;
|
2024-01-04 00:53:17 +00:00
|
|
|
import funkin.ui.debug.charting.commands.ChangeStartingBPMCommand;
|
|
|
|
import funkin.ui.debug.charting.util.ChartEditorDropdowns;
|
|
|
|
import haxe.ui.components.Button;
|
|
|
|
import haxe.ui.components.CheckBox;
|
|
|
|
import haxe.ui.components.DropDown;
|
|
|
|
import haxe.ui.components.HorizontalSlider;
|
|
|
|
import haxe.ui.components.Label;
|
|
|
|
import haxe.ui.components.NumberStepper;
|
|
|
|
import haxe.ui.components.Slider;
|
|
|
|
import haxe.ui.core.Component;
|
2024-01-04 02:10:14 +00:00
|
|
|
import funkin.data.event.SongEventRegistry;
|
2024-01-04 00:53:17 +00:00
|
|
|
import haxe.ui.components.TextField;
|
|
|
|
import haxe.ui.containers.Box;
|
2024-01-27 01:30:41 +00:00
|
|
|
import haxe.ui.containers.HBox;
|
2024-01-04 00:53:17 +00:00
|
|
|
import haxe.ui.containers.Frame;
|
|
|
|
import haxe.ui.events.UIEvent;
|
|
|
|
import haxe.ui.data.ArrayDataSource;
|
|
|
|
import haxe.ui.containers.Grid;
|
|
|
|
import haxe.ui.components.DropDown;
|
|
|
|
import haxe.ui.containers.Frame;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The toolbox which allows modifying information like Song Title, Scroll Speed, Characters/Stages, and starting BPM.
|
|
|
|
*/
|
|
|
|
// @:nullSafety // TODO: Fix null safety when used with HaxeUI build macros.
|
|
|
|
@:access(funkin.ui.debug.charting.ChartEditorState)
|
|
|
|
@:build(haxe.ui.ComponentBuilder.build("assets/exclude/data/ui/chart-editor/toolboxes/event-data.xml"))
|
|
|
|
class ChartEditorEventDataToolbox extends ChartEditorBaseToolbox
|
|
|
|
{
|
|
|
|
var toolboxEventsEventKind:DropDown;
|
|
|
|
var toolboxEventsDataFrame:Frame;
|
|
|
|
var toolboxEventsDataGrid:Grid;
|
|
|
|
|
|
|
|
var _initializing:Bool = true;
|
|
|
|
|
|
|
|
public function new(chartEditorState2:ChartEditorState)
|
|
|
|
{
|
|
|
|
super(chartEditorState2);
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
|
|
|
this.onDialogClosed = onClose;
|
|
|
|
|
|
|
|
this._initializing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClose(event:UIEvent)
|
|
|
|
{
|
|
|
|
chartEditorState.menubarItemToggleToolboxEventData.selected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function initialize():Void
|
|
|
|
{
|
|
|
|
toolboxEventsEventKind.onChange = function(event:UIEvent) {
|
2024-06-05 23:25:53 +00:00
|
|
|
var eventType:String = event.data.id;
|
2024-01-04 00:53:17 +00:00
|
|
|
|
|
|
|
trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event type changed: $eventType');
|
|
|
|
|
|
|
|
// Edit the event data to place.
|
|
|
|
chartEditorState.eventKindToPlace = eventType;
|
|
|
|
|
2024-01-04 02:10:14 +00:00
|
|
|
var schema:SongEventSchema = SongEventRegistry.getEventSchema(eventType);
|
2024-01-04 00:53:17 +00:00
|
|
|
|
|
|
|
if (schema == null)
|
|
|
|
{
|
|
|
|
trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Unknown event kind: $eventType');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-05 23:25:53 +00:00
|
|
|
buildEventDataFormFromSchema(toolboxEventsDataGrid, schema, chartEditorState.eventKindToPlace);
|
2024-01-04 00:53:17 +00:00
|
|
|
|
|
|
|
if (!_initializing && chartEditorState.currentEventSelection.length > 0)
|
|
|
|
{
|
|
|
|
// Edit the event data of any selected events.
|
|
|
|
for (event in chartEditorState.currentEventSelection)
|
|
|
|
{
|
2024-02-18 08:02:36 +00:00
|
|
|
event.eventKind = chartEditorState.eventKindToPlace;
|
2024-01-04 00:53:17 +00:00
|
|
|
event.value = chartEditorState.eventDataToPlace;
|
|
|
|
}
|
|
|
|
chartEditorState.saveDataDirty = true;
|
|
|
|
chartEditorState.noteDisplayDirty = true;
|
|
|
|
chartEditorState.notePreviewDirty = true;
|
|
|
|
}
|
|
|
|
}
|
2024-06-05 23:25:53 +00:00
|
|
|
var startingEventValue = ChartEditorDropdowns.populateDropdownWithSongEvents(toolboxEventsEventKind, chartEditorState.eventKindToPlace);
|
2024-06-06 20:44:47 +00:00
|
|
|
trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Starting event kind: ${startingEventValue}');
|
2024-06-05 23:25:53 +00:00
|
|
|
toolboxEventsEventKind.value = startingEventValue;
|
2024-01-04 00:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override function refresh():Void
|
|
|
|
{
|
|
|
|
super.refresh();
|
|
|
|
|
2024-06-05 23:25:53 +00:00
|
|
|
var newDropdownElement = ChartEditorDropdowns.findDropdownElement(chartEditorState.eventKindToPlace, toolboxEventsEventKind);
|
|
|
|
|
|
|
|
if (newDropdownElement == null)
|
|
|
|
{
|
|
|
|
throw 'ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event kind not in dropdown: ${chartEditorState.eventKindToPlace}';
|
|
|
|
}
|
2024-06-06 20:44:47 +00:00
|
|
|
else if (toolboxEventsEventKind.value != newDropdownElement || lastEventKind != toolboxEventsEventKind.value.id)
|
2024-06-05 23:25:53 +00:00
|
|
|
{
|
|
|
|
toolboxEventsEventKind.value = newDropdownElement;
|
|
|
|
|
|
|
|
var schema:SongEventSchema = SongEventRegistry.getEventSchema(chartEditorState.eventKindToPlace);
|
|
|
|
if (schema == null)
|
|
|
|
{
|
|
|
|
trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Unknown event kind: ${chartEditorState.eventKindToPlace}');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-06 20:44:47 +00:00
|
|
|
trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event kind changed: ${toolboxEventsEventKind.value.id} != ${newDropdownElement.id} != ${lastEventKind}, rebuilding form');
|
2024-06-05 23:25:53 +00:00
|
|
|
buildEventDataFormFromSchema(toolboxEventsDataGrid, schema, chartEditorState.eventKindToPlace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-06-06 20:44:47 +00:00
|
|
|
trace('ChartEditorToolboxHandler.buildToolboxEventDataLayout() - Event kind not changed: ${toolboxEventsEventKind.value} == ${newDropdownElement} == ${lastEventKind}');
|
2024-06-05 23:25:53 +00:00
|
|
|
}
|
2024-01-04 00:53:17 +00:00
|
|
|
|
|
|
|
for (pair in chartEditorState.eventDataToPlace.keyValueIterator())
|
|
|
|
{
|
|
|
|
var fieldId:String = pair.key;
|
|
|
|
var value:Null<Dynamic> = pair.value;
|
|
|
|
|
|
|
|
var field:Component = toolboxEventsDataGrid.findComponent(fieldId);
|
|
|
|
|
|
|
|
if (field == null)
|
|
|
|
{
|
2024-06-05 23:25:53 +00:00
|
|
|
throw 'ChartEditorToolboxHandler.refresh() - Field "${fieldId}" does not exist in the event data form for kind ${lastEventKind}.';
|
2024-01-04 00:53:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (field)
|
|
|
|
{
|
|
|
|
case Std.isOfType(_, NumberStepper) => true:
|
|
|
|
var numberStepper:NumberStepper = cast field;
|
|
|
|
numberStepper.value = value;
|
|
|
|
case Std.isOfType(_, CheckBox) => true:
|
|
|
|
var checkBox:CheckBox = cast field;
|
|
|
|
checkBox.selected = value;
|
|
|
|
case Std.isOfType(_, DropDown) => true:
|
|
|
|
var dropDown:DropDown = cast field;
|
|
|
|
dropDown.value = value;
|
|
|
|
case Std.isOfType(_, TextField) => true:
|
|
|
|
var textField:TextField = cast field;
|
|
|
|
textField.text = value;
|
|
|
|
default:
|
|
|
|
throw 'ChartEditorToolboxHandler.refresh() - Field "${fieldId}" is of unknown type "${Type.getClassName(Type.getClass(field))}".';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-05 23:25:53 +00:00
|
|
|
var lastEventKind:String = 'unknown';
|
|
|
|
|
|
|
|
function buildEventDataFormFromSchema(target:Box, schema:SongEventSchema, eventKind:String):Void
|
2024-01-04 00:53:17 +00:00
|
|
|
{
|
2024-06-05 23:25:53 +00:00
|
|
|
trace('Building event data form from schema for event kind: ${eventKind}');
|
|
|
|
// trace(schema);
|
|
|
|
|
|
|
|
lastEventKind = eventKind ?? 'unknown';
|
|
|
|
|
2024-01-04 00:53:17 +00:00
|
|
|
// Clear the frame.
|
|
|
|
target.removeAllComponents();
|
|
|
|
|
|
|
|
chartEditorState.eventDataToPlace = {};
|
|
|
|
|
|
|
|
for (field in schema)
|
|
|
|
{
|
|
|
|
if (field == null) continue;
|
|
|
|
|
|
|
|
// Add a label for the data field.
|
|
|
|
var label:Label = new Label();
|
|
|
|
label.text = field.title;
|
|
|
|
label.verticalAlign = "center";
|
|
|
|
target.addComponent(label);
|
|
|
|
|
|
|
|
// Add an input field for the data field.
|
|
|
|
var input:Component;
|
|
|
|
switch (field.type)
|
|
|
|
{
|
|
|
|
case INTEGER:
|
|
|
|
var numberStepper:NumberStepper = new NumberStepper();
|
|
|
|
numberStepper.id = field.name;
|
|
|
|
numberStepper.step = field.step ?? 1.0;
|
|
|
|
numberStepper.min = field.min ?? 0.0;
|
|
|
|
numberStepper.max = field.max ?? 10.0;
|
|
|
|
if (field.defaultValue != null) numberStepper.value = field.defaultValue;
|
|
|
|
input = numberStepper;
|
|
|
|
case FLOAT:
|
|
|
|
var numberStepper:NumberStepper = new NumberStepper();
|
|
|
|
numberStepper.id = field.name;
|
|
|
|
numberStepper.step = field.step ?? 0.1;
|
|
|
|
if (field.min != null) numberStepper.min = field.min;
|
|
|
|
if (field.max != null) numberStepper.max = field.max;
|
|
|
|
if (field.defaultValue != null) numberStepper.value = field.defaultValue;
|
|
|
|
input = numberStepper;
|
|
|
|
case BOOL:
|
|
|
|
var checkBox:CheckBox = new CheckBox();
|
|
|
|
checkBox.id = field.name;
|
|
|
|
if (field.defaultValue != null) checkBox.selected = field.defaultValue;
|
|
|
|
input = checkBox;
|
|
|
|
case ENUM:
|
|
|
|
var dropDown:DropDown = new DropDown();
|
|
|
|
dropDown.id = field.name;
|
|
|
|
dropDown.width = 200.0;
|
2024-06-06 00:09:26 +00:00
|
|
|
dropDown.dropdownSize = 10;
|
|
|
|
dropDown.dropdownWidth = 300;
|
|
|
|
dropDown.searchable = true;
|
2024-01-04 00:53:17 +00:00
|
|
|
dropDown.dataSource = new ArrayDataSource();
|
|
|
|
|
|
|
|
if (field.keys == null) throw 'Field "${field.name}" is of Enum type but has no keys.';
|
|
|
|
|
|
|
|
// Add entries to the dropdown.
|
|
|
|
|
|
|
|
for (optionName in field.keys.keys())
|
|
|
|
{
|
|
|
|
var optionValue:Null<Dynamic> = field.keys.get(optionName);
|
2024-06-05 23:25:53 +00:00
|
|
|
// trace('$optionName : $optionValue');
|
2024-01-04 00:53:17 +00:00
|
|
|
dropDown.dataSource.add({value: optionValue, text: optionName});
|
|
|
|
}
|
|
|
|
|
|
|
|
dropDown.value = field.defaultValue;
|
|
|
|
|
2024-06-05 23:25:53 +00:00
|
|
|
// TODO: Add an option to customize sort.
|
|
|
|
dropDown.dataSource.sort('text', ASCENDING);
|
|
|
|
|
2024-01-04 00:53:17 +00:00
|
|
|
input = dropDown;
|
|
|
|
case STRING:
|
|
|
|
input = new TextField();
|
|
|
|
input.id = field.name;
|
|
|
|
if (field.defaultValue != null) input.text = field.defaultValue;
|
|
|
|
default:
|
|
|
|
// Unknown type. Display a label that proclaims the type so we can debug it.
|
|
|
|
input = new Label();
|
|
|
|
input.id = field.name;
|
|
|
|
input.text = field.type;
|
|
|
|
}
|
|
|
|
|
2024-01-27 01:30:41 +00:00
|
|
|
// Putting in a box so we can add a unit label easily if there is one.
|
|
|
|
var inputBox:HBox = new HBox();
|
|
|
|
inputBox.addComponent(input);
|
2024-01-04 00:53:17 +00:00
|
|
|
|
2024-01-27 01:30:41 +00:00
|
|
|
// Add a unit label if applicable.
|
2024-01-25 03:31:25 +00:00
|
|
|
if (field.units != null && field.units != "")
|
|
|
|
{
|
|
|
|
var units:Label = new Label();
|
|
|
|
units.text = field.units;
|
|
|
|
units.verticalAlign = "center";
|
2024-01-27 01:30:41 +00:00
|
|
|
inputBox.addComponent(units);
|
2024-01-25 03:31:25 +00:00
|
|
|
}
|
|
|
|
|
2024-01-27 01:30:41 +00:00
|
|
|
target.addComponent(inputBox);
|
|
|
|
|
2024-01-04 00:53:17 +00:00
|
|
|
// Update the value of the event data.
|
|
|
|
input.onChange = function(event:UIEvent) {
|
|
|
|
var value = event.target.value;
|
|
|
|
if (field.type == ENUM)
|
|
|
|
{
|
|
|
|
value = event.target.value.value;
|
|
|
|
}
|
2024-03-05 03:57:21 +00:00
|
|
|
else if (field.type == BOOL)
|
|
|
|
{
|
|
|
|
var chk:CheckBox = cast event.target;
|
|
|
|
value = cast(chk.selected, Null<Bool>); // Need to cast to nullable bool or the compiler will get mad.
|
|
|
|
}
|
2024-01-04 00:53:17 +00:00
|
|
|
|
|
|
|
trace('ChartEditorToolboxHandler.buildEventDataFormFromSchema() - ${event.target.id} = ${value}');
|
|
|
|
|
|
|
|
// Edit the event data to place.
|
|
|
|
if (value == null)
|
|
|
|
{
|
|
|
|
chartEditorState.eventDataToPlace.remove(event.target.id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
chartEditorState.eventDataToPlace.set(event.target.id, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edit the event data of any existing events.
|
|
|
|
if (!_initializing && chartEditorState.currentEventSelection.length > 0)
|
|
|
|
{
|
2024-03-22 03:57:26 +00:00
|
|
|
for (songEvent in chartEditorState.currentEventSelection)
|
2024-01-04 00:53:17 +00:00
|
|
|
{
|
2024-03-22 03:57:26 +00:00
|
|
|
songEvent.eventKind = chartEditorState.eventKindToPlace;
|
|
|
|
songEvent.value = Reflect.copy(chartEditorState.eventDataToPlace);
|
2024-01-04 00:53:17 +00:00
|
|
|
}
|
|
|
|
chartEditorState.saveDataDirty = true;
|
|
|
|
chartEditorState.noteDisplayDirty = true;
|
|
|
|
chartEditorState.notePreviewDirty = true;
|
2024-03-22 03:57:26 +00:00
|
|
|
chartEditorState.noteTooltipsDirty = true;
|
2024-01-04 00:53:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function build(chartEditorState:ChartEditorState):ChartEditorEventDataToolbox
|
|
|
|
{
|
|
|
|
return new ChartEditorEventDataToolbox(chartEditorState);
|
|
|
|
}
|
|
|
|
}
|