From 67bc6ee9b9385074e5823d0e9cc8d0e633c9cf4e Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Wed, 23 Aug 2023 15:41:54 -0700 Subject: [PATCH] add undos to all actions in chart editor --- .../funkin/editors/charter/ChartDataScreen.hx | 9 ++++++--- source/funkin/editors/charter/Charter.hx | 19 ++++++++++++++++++- .../editors/charter/CharterEventScreen.hx | 6 ++---- .../editors/charter/CharterStrumlineScreen.hx | 6 +++--- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/source/funkin/editors/charter/ChartDataScreen.hx b/source/funkin/editors/charter/ChartDataScreen.hx index 846fd4bc..3e6078d9 100644 --- a/source/funkin/editors/charter/ChartDataScreen.hx +++ b/source/funkin/editors/charter/ChartDataScreen.hx @@ -34,11 +34,11 @@ class ChartDataScreen extends UISubstateWindow { var title:UIText; add(title = new UIText(windowSpr.x + 20, windowSpr.y + 30 + 16, 0, "Edit Chart Data", 28)); - stageTextBox = new UITextBox(title.x, title.y + title.height + 38, PlayState.SONG.stage, 160); + stageTextBox = new UITextBox(title.x, title.y + title.height + 38, PlayState.SONG.stage, 200); add(stageTextBox); addLabelOn(stageTextBox, "Stage"); - scrollSpeedStepper = new UINumericStepper(stageTextBox.x + 160 + 26, stageTextBox.y, data.scrollSpeed, 0.1, 2, 0, 10, 82); + scrollSpeedStepper = new UINumericStepper(stageTextBox.x + 200 + 26, stageTextBox.y, data.scrollSpeed, 0.1, 2, 0, 10, 82); add(scrollSpeedStepper); addLabelOn(scrollSpeedStepper, "Scroll Speed"); @@ -60,8 +60,11 @@ class ChartDataScreen extends UISubstateWindow { { @:privateAccess scrollSpeedStepper.__onChange(scrollSpeedStepper.label.text); + var oldData:{stage:String, speed:Float} = {stage: PlayState.SONG.stage, speed: PlayState.SONG.scrollSpeed}; + PlayState.SONG.stage = stageTextBox.label.text; PlayState.SONG.scrollSpeed = scrollSpeedStepper.value; - } + Charter.instance.addToUndo(CEditChartData(oldData, {stage: stageTextBox.label.text, speed: scrollSpeedStepper.value})); + } } \ No newline at end of file diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 4f9ade4f..3071f19a 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -863,9 +863,13 @@ class Charter extends UIState { public inline function editStrumline(strL:ChartStrumLine) { var strID = getStrumlineID(strL); + var oldData:ChartStrumLine = Reflect.copy(strL); + FlxG.state.openSubState(new CharterStrumlineScreen(strID, strL, (_) -> { strumLines.members[strID].strumLine = _; strumLines.members[strID].updateInfo(); + + this.addToUndo(CEditStrumLine(strID, oldData, _)); })); } @@ -878,7 +882,6 @@ class Charter extends UIState { selection.remove(note); else i++; } - } } @@ -1117,6 +1120,9 @@ class Charter extends UIState { createStrumline(strumLineID, strumLine, false); case CCreateStrumLine(strumLineID, strumLine): deleteStrumline(strumLineID, false); + case CEditStrumLine(strumLineID, oldStrumLine, newStrumLine): + strumLines.members[strumLineID].strumLine = oldStrumLine; + strumLines.members[strumLineID].updateInfo(); case CCreateSelection(selection): deleteSelection(selection, false); case CDeleteSelection(selection): @@ -1133,6 +1139,9 @@ class Charter extends UIState { event.refreshEventIcons(); Charter.instance.updateBPMEvents(); + case CEditChartData(oldData, newData): + PlayState.SONG.stage = oldData.stage; + PlayState.SONG.scrollSpeed = oldData.speed; } if (v != null) redoList.insert(0, v); @@ -1160,6 +1169,9 @@ class Charter extends UIState { deleteStrumline(strumLineID, false); case CCreateStrumLine(strumLineID, strumLine): createStrumline(strumLineID, strumLine, false); + case CEditStrumLine(strumLineID, oldStrumLine, newStrumLine): + strumLines.members[strumLineID].strumLine = newStrumLine; + strumLines.members[strumLineID].updateInfo(); case CCreateSelection(selection): createSelection(selection, false); case CDeleteSelection(selection): @@ -1176,6 +1188,9 @@ class Charter extends UIState { event.refreshEventIcons(); Charter.instance.updateBPMEvents(); + case CEditChartData(oldData, newData): + PlayState.SONG.stage = newData.stage; + PlayState.SONG.scrollSpeed = newData.speed; } if (v != null) undoList.insert(0, v); @@ -1333,8 +1348,10 @@ enum CharterChange { CCreateSelection(selection:Selection); CDeleteSelection(selection:Selection); CSelectionDrag(selection:Selection, change:FlxPoint); + CEditStrumLine(strumLineID:Int, oldStrumLine:ChartStrumLine, newStrumLine:ChartStrumLine); CEditSustains(notes:Array); CEditEvent(event:CharterEvent, oldEvents:Array, newEvents:Array); + CEditChartData(oldData:{stage:String, speed:Float}, newData:{stage:String, speed:Float}); } enum CharterCopyboardObject { diff --git a/source/funkin/editors/charter/CharterEventScreen.hx b/source/funkin/editors/charter/CharterEventScreen.hx index f7d40c06..e8ab4024 100644 --- a/source/funkin/editors/charter/CharterEventScreen.hx +++ b/source/funkin/editors/charter/CharterEventScreen.hx @@ -77,12 +77,10 @@ class CharterEventScreen extends UISubstateWindow { if (creatingEvent && events.length > 0) Charter.instance.createSelection([chartEvent]); else { - chartEvent.events = [ - for (i in eventsList.buttons.members) i.event - ]; + chartEvent.events = [for (i in eventsList.buttons.members) i.event]; chartEvent.refreshEventIcons(); - Charter.instance.addToUndo(CEditEvent(chartEvent, oldEvents, events.copy())); + Charter.instance.addToUndo(CEditEvent(chartEvent, oldEvents, [for (event in events) Reflect.copy(event)])); } } diff --git a/source/funkin/editors/charter/CharterStrumlineScreen.hx b/source/funkin/editors/charter/CharterStrumlineScreen.hx index 0f2341a9..da7e369c 100644 --- a/source/funkin/editors/charter/CharterStrumlineScreen.hx +++ b/source/funkin/editors/charter/CharterStrumlineScreen.hx @@ -139,7 +139,7 @@ class CharterStrumlineScreen extends UISubstateWindow { for (stepper in [hudXStepper, hudYStepper, hudScaleStepper]) @:privateAccess stepper.__onChange(stepper.label.text); - strumLine = { + var newStrumLine:ChartStrumLine = { characters: [ for (char in charactersList.buttons.members) char.textBox.label.text.trim() @@ -151,8 +151,8 @@ class CharterStrumlineScreen extends UISubstateWindow { strumPos: [hudXStepper.value, hudYStepper.value], strumScale: hudScaleStepper.value }; - if(!usesChartscrollSpeed.checked) strumLine.scrollSpeed = scrollSpeedStepper.value; - if (onSave != null) onSave(strumLine); + if(!usesChartscrollSpeed.checked) newStrumLine.scrollSpeed = scrollSpeedStepper.value; + if (onSave != null) onSave(newStrumLine); } }