From 9a0310c721331dc9dca3bd3bf77c40252cdfe242 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Fri, 1 Sep 2023 23:31:57 -0700 Subject: [PATCH] change sorting blah blah blah --- source/funkin/editors/charter/Charter.hx | 16 ---------------- source/funkin/editors/charter/CharterBackdrop.hx | 1 - .../funkin/editors/charter/CharterEventGroup.hx | 16 ++++++++++++++++ source/funkin/editors/charter/CharterNote.hx | 2 +- .../funkin/editors/charter/CharterNoteGroup.hx | 15 ++++++++++++++- .../editors/charter/CharterStrumLineGroup.hx | 13 +++++-------- 6 files changed, 36 insertions(+), 27 deletions(-) diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index b77af211..03c9503b 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -583,7 +583,6 @@ class Charter extends UIState { if (s is CharterNote) cast(s, CharterNote).snappedToStrumline = true; if (s is UISprite) cast(s, UISprite).cursor = BUTTON; } - sortNotes(); undos.addToUndo(CSelectionDrag(selection, changePoint.clone())); changePoint.put(); @@ -615,7 +614,6 @@ class Charter extends UIState { note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id % 4, 0, 0, strumLines.members[Std.int(id/4)]); notesGroup.add(note); selection = [note]; - sortNotes(); undos.addToUndo(CCreateSelection([note])); } } @@ -678,7 +676,6 @@ class Charter extends UIState { eventsGroup.remove(event, true); event.kill(); } - sortNotes(); if (addToUndo) undos.addToUndo(CDeleteSelection([selected])); @@ -697,7 +694,6 @@ class Charter extends UIState { e.revive(); e.refreshEventIcons(); }, false); - sortNotes(); for (s in selection) if (s is CharterEvent) { @@ -723,7 +719,6 @@ class Charter extends UIState { else member++; } } - sortNotes(); for (s in selection) if (s is CharterEvent) { @@ -747,7 +742,6 @@ class Charter extends UIState { n.updatePos(t, note.id, Conductor.getStepForTime(note.time + note.sLen) - t, note.type, cStr); notesGroup.add(n); } - sortNotes(); if (addToUndo) undos.addToUndo(CCreateStrumLine(strumLineID, strL)); @@ -770,8 +764,6 @@ class Charter extends UIState { strumLines.members[strumLineID].destroy(); strumLines.members.remove(strumLines.members[strumLineID]); - sortNotes(); - if (addToUndo) { var newStrL = Reflect.copy(strL); newStrL.notes = undoNotes; @@ -822,14 +814,6 @@ class Charter extends UIState { } } } - - public inline function sortNotes() { - notesGroup.sort(function(i, n1, n2) { - if (n1.step == n2.step) - return FlxSort.byValues(FlxSort.ASCENDING, n1.id, n2.id); - return FlxSort.byValues(FlxSort.ASCENDING, n1.step, n2.step); - }); - } #end var __crochet:Float; diff --git a/source/funkin/editors/charter/CharterBackdrop.hx b/source/funkin/editors/charter/CharterBackdrop.hx index 8b0577a4..7b440d30 100644 --- a/source/funkin/editors/charter/CharterBackdrop.hx +++ b/source/funkin/editors/charter/CharterBackdrop.hx @@ -105,7 +105,6 @@ class CharterBackdrop extends FlxBackdrop { topLimit.x = this.x; topLimit.cameras = this.cameras; - // Draw notes notesGroup.forEach((n) -> { if(n.exists && n.visible) { n.cameras = cameras; diff --git a/source/funkin/editors/charter/CharterEventGroup.hx b/source/funkin/editors/charter/CharterEventGroup.hx index e28ac29a..cef8913c 100644 --- a/source/funkin/editors/charter/CharterEventGroup.hx +++ b/source/funkin/editors/charter/CharterEventGroup.hx @@ -1,9 +1,18 @@ package funkin.editors.charter; import funkin.editors.charter.CharterBackdrop.EventBackdrop; +import flixel.util.FlxSort; class CharterEventGroup extends FlxTypedGroup { public var eventsBackdrop:EventBackdrop; + var __lastSort:Int = 0; + + public override function update(elapsed:Float) { + if (length != __lastSort) + sortEvents(); + + super.update(elapsed); + } public override function draw() { for (event in members) { @@ -12,4 +21,11 @@ class CharterEventGroup extends FlxTypedGroup { } super.draw(); } + + public function sortEvents() { + __lastSort = length; + this.sort(function(i, e1, e2) { + return FlxSort.byValues(FlxSort.ASCENDING, e1.step, e2.step); + }); + } } \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx index 311114dd..85f7f961 100644 --- a/source/funkin/editors/charter/CharterNote.hx +++ b/source/funkin/editors/charter/CharterNote.hx @@ -128,7 +128,7 @@ class CharterNote extends UISprite implements ICharterSelectable { sustainSpr.follow(this, 15, 20); if (__passed != (__passed = step < Conductor.curStepFloat)) { - alpha = (__passed ? 0.8 : 1) - (!strumLine.strumLine.visible ? .6 : 0); + alpha = (__passed ? 0.6 : 1); if (__passed && FlxG.sound.music.playing && Charter.instance.hitsoundsEnabled(strumLineID)) Charter.instance.hitsound.replay(); } diff --git a/source/funkin/editors/charter/CharterNoteGroup.hx b/source/funkin/editors/charter/CharterNoteGroup.hx index 60dd393f..4051545f 100644 --- a/source/funkin/editors/charter/CharterNoteGroup.hx +++ b/source/funkin/editors/charter/CharterNoteGroup.hx @@ -1,5 +1,6 @@ package funkin.editors.charter; +import flixel.util.FlxSort; import funkin.backend.system.Conductor; class CharterNoteGroup extends FlxTypedGroup { @@ -8,6 +9,7 @@ class CharterNoteGroup extends FlxTypedGroup { var max:Float = 0; var __currentlyLooping:Bool = false; var __autoDraw:Bool = false; + var __lastSort:Int = 0; public override function forEach(noteFunc:CharterNote->Void, recursive:Bool = false) { __loopSprite = null; @@ -62,7 +64,6 @@ class CharterNoteGroup extends FlxTypedGroup { }); } - @:privateAccess FlxCamera._defaultCameras = oldDefaultCameras; } @@ -70,6 +71,9 @@ class CharterNoteGroup extends FlxTypedGroup { @:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras; @:privateAccess if (cameras != null) FlxCamera._defaultCameras = cameras; + if (length != __lastSort) + sortNotes(); + forEach((n) -> { if(n.exists && n.active) n.update(elapsed); @@ -77,4 +81,13 @@ class CharterNoteGroup extends FlxTypedGroup { @:privateAccess FlxCamera._defaultCameras = oldDefaultCameras; } + + public function sortNotes() { + __lastSort = length; + this.sort(function(i, n1, n2) { + if (n1.step == n2.step) + return FlxSort.byValues(FlxSort.ASCENDING, n1.fullID, n2.fullID); + return FlxSort.byValues(FlxSort.ASCENDING, n1.step, n2.step); + }); + } } \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterStrumLineGroup.hx b/source/funkin/editors/charter/CharterStrumLineGroup.hx index ec74847c..fd7156f5 100644 --- a/source/funkin/editors/charter/CharterStrumLineGroup.hx +++ b/source/funkin/editors/charter/CharterStrumLineGroup.hx @@ -28,10 +28,11 @@ class CharterStrumLineGroup extends FlxTypedGroup { } } - if (draggingObj != null) + if (isDragging) { draggingObj.x = mousePos.x - draggingOffset; + this.sort(function(o, a, b) return FlxSort.byValues(o, a.x, b.x), -1); + } - this.sort(function(o, a, b) return FlxSort.byValues(o, a.x, b.x), -1); for (i=>strum in members) if (!strum.dragging) strum.x = CoolUtil.fpsLerp(strum.x, 160 * i, 0.225); @@ -42,7 +43,7 @@ class CharterStrumLineGroup extends FlxTypedGroup { if (Charter.instance.strumlineAddButton != null) Charter.instance.strumlineAddButton.x = members[members.length-1].x + (40*4); - if ((FlxG.mouse.justReleased || !draggable) && draggingObj != null) + if ((FlxG.mouse.justReleased || !draggable) && isDragging) finishDrag(); mousePos.put(); @@ -55,14 +56,11 @@ class CharterStrumLineGroup extends FlxTypedGroup { members.remove(strumLine); members.insert(newID, strumLine); - for (i=>strum in members) - strum.x = 160 * i; - finishDrag(false); } public function finishDrag(?addToUndo:Bool = true) { - if (draggingObj != null) + if (isDragging) draggingObj.dragging = false; // Undo @@ -72,7 +70,6 @@ class CharterStrumLineGroup extends FlxTypedGroup { Charter.instance.undos.addToUndo(COrderStrumLine(draggingObj, oldID, newID)); } - draggingObj = null; fixEvents(); }