From b814011d73f2da0d5205ab70d85ade6603269937 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Sat, 16 Sep 2023 23:54:52 -0700 Subject: [PATCH] sorry i went afk for 3987 hours --- source/funkin/editors/charter/Charter.hx | 47 ++++++++++++++----- source/funkin/editors/charter/CharterEvent.hx | 6 ++- source/funkin/editors/charter/CharterNote.hx | 4 +- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 2e42977b..e0bfeac4 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -561,6 +561,7 @@ class Charter extends UIState { n.snappedToStrumline = false; n.setPosition(n.fullID * 40 + (mousePos.x - dragStartPos.x), n.step * 40 + (mousePos.y - dragStartPos.y)); n.y = FlxMath.bound(n.y, 0, (__endStep*40) - n.height); + n.x = FlxMath.bound(n.x, 0, ((strumLines.members.length * 4)-1) * 40); n.cursor = HAND; }, function (e:CharterEvent) { e.y = e.step * 40 + (mousePos.y - dragStartPos.y) - 17; @@ -581,14 +582,30 @@ class Charter extends UIState { : CoolUtil.floorInt((mousePos.y - dragStartPos.y) / 40); var horizontalChange:Int = CoolUtil.floorInt((mousePos.x - dragStartPos.x) / 40); var changePoint:FlxPoint = FlxPoint.get(verticalChange, horizontalChange); + var undoDrags:Array = []; for (s in selection) { - if (!s.draggable) continue; - s.handleDrag(changePoint); + if (s.draggable) { + var boundedChange:FlxPoint = changePoint.clone(); + + // Some maths, so cool bro -lunar (i dont know why i quopte my self here) + if (s.step + changePoint.x < 0) boundedChange.x += Math.abs(s.step + changePoint.x); + if (s.step + changePoint.x > Charter.instance.__endStep-1) boundedChange.x -= (s.step + changePoint.x) - (Charter.instance.__endStep-1); + + if (s is CharterNote) { + var note:CharterNote = cast (s, CharterNote); + if (note.fullID + changePoint.y < 0) boundedChange.y += Math.abs(note.fullID + changePoint.y); + if (note.fullID + changePoint.y > (strumLines.members.length*4)-1) boundedChange.y -= (note.fullID + changePoint.y) - ((strumLines.members.length*4)-1); + } + + s.handleDrag(changePoint); + undoDrags.push({selectable:s, change: boundedChange}); + } + if (s is CharterNote) cast(s, CharterNote).snappedToStrumline = true; if (s is UISprite) cast(s, UISprite).cursor = BUTTON; } - undos.addToUndo(CSelectionDrag(selection, changePoint.clone())); + if (!(changePoint.x == 0 && changePoint.y == 0)) undos.addToUndo(CSelectionDrag(undoDrags)); changePoint.put(); hoverOffset.put(); @@ -1045,10 +1062,11 @@ class Charter extends UIState { deleteSelection(selection, false); case CDeleteSelection(selection): createSelection(selection, false); - case CSelectionDrag(selection, change): - for (s in selection) - if (s.draggable) s.handleDrag(change * -1); - this.selection = selection; + case CSelectionDrag(selectionDrags): + for (s in selectionDrags) + if (s.selectable.draggable) s.selectable.handleDrag(s.change * -1); + + this.selection = [for (s in selectionDrags) s.selectable]; case CEditSustains(changes): for(n in changes) n.note.updatePos(n.note.step, n.note.id, n.before, n.note.type); @@ -1085,10 +1103,10 @@ class Charter extends UIState { createSelection(selection, false); case CDeleteSelection(selection): deleteSelection(selection, false); - case CSelectionDrag(selection, change): - for (s in selection) - if (s.draggable) s.handleDrag(change); - this.selection = selection; + case CSelectionDrag(selectionDrags): + for (s in selectionDrags) + if (s.selectable.draggable) s.selectable.handleDrag(s.change); + //this.selection = selection; case CEditSustains(changes): for(n in changes) n.note.updatePos(n.note.step, n.note.id, n.after, n.note.type); @@ -1276,7 +1294,7 @@ enum CharterChange { CDeleteStrumLine(strumLineID:Int, strumLine:ChartStrumLine); CCreateSelection(selection:Selection); CDeleteSelection(selection:Selection); - CSelectionDrag(selection:Selection, change:FlxPoint); + CSelectionDrag(selectionDrags:Array); CEditSustains(notes:Array); CEditEvent(event:CharterEvent, oldEvents:Array, newEvents:Array); CEditChartData(oldData:{stage:String, speed:Float}, newData:{stage:String, speed:Float}); @@ -1293,6 +1311,11 @@ typedef NoteSustainChange = { var after:Float; } +typedef SelectionDragChange = { + var selectable:ICharterSelectable; + var change:FlxPoint; +} + @:forward abstract Selection(Array) from Array to Array { public inline function new(?array:Array) this = array == null ? [] : array; diff --git a/source/funkin/editors/charter/CharterEvent.hx b/source/funkin/editors/charter/CharterEvent.hx index 7eb5a157..7fe4fff6 100644 --- a/source/funkin/editors/charter/CharterEvent.hx +++ b/source/funkin/editors/charter/CharterEvent.hx @@ -84,8 +84,10 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable { return (selectionBox.x + selectionBox.bWidth > x) && (selectionBox.x < x + bWidth) && (selectionBox.y + selectionBox.bHeight > y) && (selectionBox.y < y + bHeight); } - public function handleDrag(change:FlxPoint) - y = ((step += change.x) * 40) - 17; + public function handleDrag(change:FlxPoint) { + var newStep:Float = FlxMath.bound(step + change.x, 0, Charter.instance.__endStep-1); + y = ((step = newStep) * 40) - 17; + } public function refreshEventIcons() { while(icons.length > 0) { diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx index 95bfa53d..0b2fd10e 100644 --- a/source/funkin/editors/charter/CharterNote.hx +++ b/source/funkin/editors/charter/CharterNote.hx @@ -153,9 +153,7 @@ class CharterNote extends UISprite implements ICharterSelectable { public function handleDrag(change:FlxPoint) { var newStep = FlxMath.bound(step + change.x, 0, Charter.instance.__endStep-1); - var newID:Int = fullID + Std.int(change.y); - if (newID > ((Charter.instance.strumLines.members.length*4)-1)) newID %= 4; - else if (newID < 0) newID = (Charter.instance.strumLines.members.length*4) + newID % 4; + var newID:Int = Std.int(FlxMath.bound(fullID + Std.int(change.y), 0, (Charter.instance.strumLines.members.length*4)-1)); updatePos(newStep, newID % 4, susLength, type, Charter.instance.strumLines.members[Std.int(newID/4)]); }