From 184105d336dcc79e8cd49f3bda330bf8013f9db3 Mon Sep 17 00:00:00 2001 From: MaybeMaru <97055307+MaybeMaru@users.noreply.github.com> Date: Wed, 8 Nov 2023 03:49:30 +0100 Subject: [PATCH] ALMOST done --- source/funkin/states/editors/ChartingState.hx | 10 +-- .../states/editors/chart/ChartGridBase.hx | 16 +++- .../funkin/states/editors/chart/ChartTabs.hx | 75 ++++++++++--------- 3 files changed, 59 insertions(+), 42 deletions(-) diff --git a/source/funkin/states/editors/ChartingState.hx b/source/funkin/states/editors/ChartingState.hx index 2df3062d..dddc8f11 100644 --- a/source/funkin/states/editors/ChartingState.hx +++ b/source/funkin/states/editors/ChartingState.hx @@ -378,6 +378,8 @@ class ChartingState extends MusicBeatState { public var selectedEvent:Array = null; public var selectedEventObject(default, set):ChartEvent = null; + public var eventID:Int = 0; + function set_selectedEventObject(value) { if (value != null && selectedEventObject != null && value != selectedEventObject) { value.blend = ADD; @@ -388,13 +390,11 @@ class ChartingState extends MusicBeatState { return selectedEventObject = value; } - public var eventID:Int = 0; - public function addEvent() { var strumTime:Float = getYtime(noteTile.y + GRID_SIZE) + sectionTime - Conductor.stepCrochet; eventID = 0; - tabs.setCurEvent(ChartTabs.curEvent); // Update values - var event:Array = [strumTime, ChartTabs.curEvent, convertEventValues(ChartTabs.curEventValues)]; + tabs.setCurEvent(ChartTabs.curEventDatas[eventID].name); // Update values + var event:Array = [strumTime, ChartTabs.curEventDatas[eventID].name, convertEventValues(ChartTabs.curEventDatas[eventID].values)]; SONG.notes[sectionIndex].sectionEvents.push(event); selectedEvent = event; selectedEventObject = eventsGrid.drawObject(event); @@ -402,7 +402,7 @@ class ChartingState extends MusicBeatState { public function updateEvent(id:Int = 0, newValue:Dynamic) { if (selectedEvent == null || selectedEventObject == null) return; - var values = selectedEvent[2].copy(); + final values = selectedEvent[2].copy(); values[id] = newValue; selectedEvent[2] = values; selectedEventObject.data[eventID].values = selectedEvent[2].copy(); diff --git a/source/funkin/states/editors/chart/ChartGridBase.hx b/source/funkin/states/editors/chart/ChartGridBase.hx index f63024a5..f970cc6d 100644 --- a/source/funkin/states/editors/chart/ChartGridBase.hx +++ b/source/funkin/states/editors/chart/ChartGridBase.hx @@ -326,6 +326,8 @@ class ChartEventGrid extends ChartGridBase { class ChartEvent extends FlxTypedSpriteGroup { public var data:Array = []; + public var names:Array = []; + public var sprite:FlxSpriteExt; public var text:FunkinText; @@ -380,11 +382,19 @@ class ChartEvent extends FlxTypedSpriteGroup { public function init(strumTime:Float, names:Array, values:Array>, position:FlxPoint) { setPosition(position.x,position.y); this.strumTime = strumTime; + FlxArrayUtil.clearArray(data); - for (i in 0...names.length) { - if (data[i] == null) data.push(new Event(strumTime, names[i], values[i])); - else data[i].set(strumTime, names[i], values[i]); + FlxArrayUtil.clearArray(this.names); + + for (i in 0...values.length) { + if (data[i] == null) data.push(new Event(strumTime, names[i] ?? "NULL", values[i])); + else data[i].set(strumTime, names[i] ?? "NULL", values[i]); } + + for (i in data) { + names.push(i.name); + } + updateText(); loadSettings(); } diff --git a/source/funkin/states/editors/chart/ChartTabs.hx b/source/funkin/states/editors/chart/ChartTabs.hx index da260054..38d9dfac 100644 --- a/source/funkin/states/editors/chart/ChartTabs.hx +++ b/source/funkin/states/editors/chart/ChartTabs.hx @@ -310,34 +310,34 @@ class ChartTabs extends FlxUITabMenu { var eventDescription:FlxText; public var eventValueTab:EventTab = null; - public static var curEvent:String = ''; - public static var curEventValues:Array; + public static var curEventDatas:Array<{name:String, values:Array}> = []; + public static var curEventNames:Array = []; public function setCurEvent(event:String) { - curEvent = event; - curEventValues = eventValueTab == null ? EventUtil.getEventData(event).values.copy() : eventValueTab.getValues().copy(); + curEventNames[eventID()] = event; + curEventDatas[eventID()] = { + name: event, + values: eventValueTab == null ? EventUtil.getEventData(event).values.copy() : eventValueTab.getValues().copy() + } updateEventTxt(); } - var curEvents:Array = [ - "test1", - "test2", - "test3", - "test4" - ]; - var eventListTxt:FlxText; var eventLeft:FlxUIButton; var eventAdd:FlxUIButton; var eventRemove:FlxUIButton; var eventRight:FlxUIButton; - inline function getEventID() { - return ChartingState.instance.eventID; - } + inline function eventID() return ChartingState.instance.eventID; + inline function eventObj() return ChartingState.instance.selectedEventObject; + + var initEvent:String = "NULL_EVENT"; public function updateEventTxt() { - eventListTxt.text = "[ " + (getEventID() + 1) + " / " + curEvents.length + " ] " + (curEvents[getEventID()] ?? "NULL_EVENT"); + eventListTxt.text = "[ " + + (eventID() + 1) + " / " + + (curEventNames.length) + " ] " + + (curEventNames[eventID()] ?? "NULL_EVENT"); } function addEventUI():Void { @@ -349,14 +349,19 @@ class ChartTabs extends FlxUITabMenu { eventListTxt.alignment = RIGHT; eventLeft = new FlxUIButton(10,10, "<", function () { - ChartingState.instance.eventID = FlxMath.wrap(ChartingState.instance.eventID - 1, 0, curEvents.length - 1); + ChartingState.instance.eventID = FlxMath.wrap(ChartingState.instance.eventID - 1, 0, curEventDatas.length - 1); updateEventTxt(); }); eventAdd = new FlxUIButton(eventLeft.x + 25,eventLeft.y, "+", function () { - if (curEvents.length < 16) { - curEvents.push("testNew"); - ChartingState.instance.eventID = curEvents.length - 1; + if (curEventDatas.length < 16) { + final e:String = eventsDropDown.selectedLabel; + curEventNames.push(e); + curEventDatas.push({ + name: e, + values: eventValueTab == null ? EventUtil.getEventData(e).values.copy() : eventValueTab.getValues().copy() + }); + ChartingState.instance.eventID = curEventDatas.length - 1; updateEventTxt(); } }); @@ -364,9 +369,11 @@ class ChartTabs extends FlxUITabMenu { eventAdd.label.color = FlxColor.WHITE; eventRemove = new FlxUIButton(eventLeft.x + (25*2),eventLeft.y, "-", function () { - if (curEvents.length > 1) { - curEvents.remove(curEvents[getEventID()]); - ChartingState.instance.eventID = curEvents.length - 1; + if (curEventDatas.length > 1) { + curEventDatas.remove(curEventDatas[eventID()]); + curEventNames.remove(curEventNames[eventID()]); + + ChartingState.instance.eventID = curEventDatas.length - 1; updateEventTxt(); } }); @@ -374,14 +381,14 @@ class ChartTabs extends FlxUITabMenu { eventRemove.label.color = FlxColor.WHITE; eventRight = new FlxUIButton(eventLeft.x + (25*3),eventLeft.y, ">", function () { - ChartingState.instance.eventID = FlxMath.wrap(getEventID() + 1, 0, curEvents.length - 1); + ChartingState.instance.eventID = FlxMath.wrap(eventID() + 1, 0, curEventDatas.length - 1); updateEventTxt(); }); var types:Array = EventUtil.eventsArray.copy(); eventsDropDown = new FlxUIDropDownMenu(10, 50, FlxUIDropDownMenu.makeStrIdLabelArray(types, true), function(type:String) { var newEvent = types[Std.parseInt(type)]; - if (curEvent != newEvent) { + if (curEventDatas[eventID()].name != newEvent) { var eventData = EventUtil.getEventData(newEvent); var _defValues = eventData.values.copy(); eventDescription.text = eventData.description; @@ -396,26 +403,26 @@ class ChartTabs extends FlxUITabMenu { i.resize(20,20); } tab_group_event.add(eventListTxt); - updateEventTxt(); - eventDescription = new FlxText(eventsDropDown.x,eventsDropDown.y+25,125,"Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + eventDescription = new FlxText(eventsDropDown.x,eventsDropDown.y + 25, 125, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); tab_group_event.add(eventDescription); tab_group_event.add(new FlxText(eventsDropDown.x, eventsDropDown.y - 15, 0, 'Event:')); tab_group_event.add(eventsDropDown); - - var initEvent = types[0]; - if (initEvent != null) { - setCurEvent(initEvent); - eventsDropDown.selectedLabel = initEvent; - eventDescription.text = EventUtil.getEventData(initEvent).description; - } postCreateFuncs.push(function () { - eventValueTab = new EventTab(150, 50, curEventValues); + initEvent = types[0]; + if (initEvent != null) { + setCurEvent(initEvent); + eventsDropDown.selectedLabel = initEvent; + eventDescription.text = EventUtil.getEventData(initEvent).description; + } + + eventValueTab = new EventTab(150, 50, curEventDatas[eventID()].values); eventValueTab.updateFunc = function (id:Int, value:Dynamic) ChartingState.instance.updateEvent(id, value); tab_group_event.add(eventValueTab); + updateEventTxt(); }); addGroup(tab_group_event);