diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index cfd2dbb0..b77af211 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -1,5 +1,6 @@ package funkin.editors.charter; +import funkin.editors.charter.CharterStrumline; import funkin.editors.charter.CharterBackdrop.EventBackdrop; import funkin.backend.system.framerate.Framerate; import haxe.Json; @@ -553,8 +554,8 @@ class Charter extends UIState { case DRAG: if (FlxG.mouse.pressed) { selection.loop(function (n:CharterNote) { - n.setPosition(n.id * 40 + (mousePos.x - dragStartPos.x), n.step * 40 + (mousePos.y - dragStartPos.y)); n.snappedToStrumline = false; + n.setPosition(n.id * 40 + (mousePos.x - dragStartPos.x), n.step * 40 + (mousePos.y - dragStartPos.y)); n.cursor = HAND; }, function (e:CharterEvent) { e.y = e.step * 40 + (mousePos.y - dragStartPos.y) - 17; @@ -611,7 +612,7 @@ class Charter extends UIState { } else { if (mouseOnGrid) { var note = new CharterNote(); - note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0); + 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(); @@ -620,7 +621,6 @@ class Charter extends UIState { } } } else if (gridBackdropDummy.hoveredByChild) { - // TODO: NOTE DRAGGING if (FlxG.mouse.pressed && (Math.abs(mousePos.x - dragStartPos.x) > 5 || Math.abs(mousePos.y - dragStartPos.y) > 5)) { var noteHovered:Bool = false; for(n in selection) @@ -741,18 +741,10 @@ class Charter extends UIState { var cStr = new CharterStrumline(strL); strumLines.insert(strumLineID, cStr); - // Push forward notes that are infront of the strumLine - for (note in notesGroup.members) { - if (Std.int(note.id / 4) >= strumLineID) - note.updatePos(note.step, note.id + 4, note.susLength, note.type); - } - - var noteOffset = (strumLines.members.indexOf(cStr)) * 4; - for(note in strL.notes) { var n = new CharterNote(); var t = Conductor.getStepForTime(note.time); - n.updatePos(t, noteOffset + note.id, Conductor.getStepForTime(note.time + note.sLen) - t, note.type); + n.updatePos(t, note.id, Conductor.getStepForTime(note.time + note.sLen) - t, note.type, cStr); notesGroup.add(n); } sortNotes(); @@ -762,45 +754,28 @@ class Charter extends UIState { } public function deleteStrumline(strumLineID:Int, addToUndo:Bool = true) { + var undoNotes:Array = []; removeStrumlineFromSelection(strumLineID); + var i = 0; + while(i < notesGroup.members.length) { + var note = notesGroup.members[i]; + if (note.strumLineID == strumLineID) { + undoNotes.push(buildNote(note)); + deleteSingleSelection(note, false); + } else i++; + } + var strL = strumLines.members[strumLineID].strumLine; strumLines.members[strumLineID].destroy(); strumLines.members.remove(strumLines.members[strumLineID]); - var deletedstrumNotes:Array = []; - // Delete this strums notes - var i = 0; // thanks yosh!!!!! (deleteNote removes a index) - while(i < notesGroup.members.length) { - var note = notesGroup.members[i]; - if (Std.int(note.id / 4) == strumLineID) { // thanks neo lol!!!!! - deletedstrumNotes.push(note); - deleteSingleSelection(note, false); - } else - i++; - } - - // Push back strumline notes that are infront - for (note in notesGroup.members) { - if (Std.int(note.id / 4) > strumLineID) - note.updatePos(note.step, note.id - 4, note.susLength, note.type); - } sortNotes(); - // Undo shit if (addToUndo) { var newStrL = Reflect.copy(strL); - newStrL.notes.clear(); + newStrL.notes = undoNotes; - for (note in deletedstrumNotes) { - var time = Conductor.getTimeForStep(note.step); - newStrL.notes.push({ - type: note.type, - time: time, - sLen: Conductor.getTimeForStep(note.step + note.susLength) - time, - id: note.id % 4 - }); - } undos.addToUndo(CDeleteStrumLine(strumLineID, newStrL)); } } @@ -819,6 +794,8 @@ class Charter extends UIState { })); } + public function orderStrumline() {} + public inline function deleteStrumlineFromData(strL:ChartStrumLine) deleteStrumline(getStrumlineID(strL)); @@ -839,7 +816,7 @@ class Charter extends UIState { while(i < selection.length) { if (selection[i] is CharterNote) { var note = cast (selection[i], CharterNote); - if (Std.int(note.id / 4) == strumLineID) + if (note.strumLineID == strumLineID) selection.remove(note); else i++; } @@ -1021,7 +998,7 @@ class Charter extends UIState { for (s in selection) if (s is CharterNote) { var note:CharterNote = cast(s, CharterNote); - CNote(note.step - minStep, note.id, note.susLength, note.type); + CNote(note.step - minStep, note.id, note.strumLineID, note.susLength, note.type); } else if (s is CharterEvent) { var event = cast(s,CharterEvent); CEvent(event.step - minStep, [for (event in event.events) Reflect.copy(event)]); @@ -1035,13 +1012,13 @@ class Charter extends UIState { var sObjects:Array = []; for(c in clipboard) { switch(c) { - case CNote(step, id, sLen, type): + case CNote(step, id, strumLineID, susLength, type): var note = new CharterNote(); - note.updatePos(minStep + step + 1, id, sLen, type); + note.updatePos(minStep + step, id, susLength, type, strumLines.members[Std.int(FlxMath.bound(strumLineID, 0, strumLines.length-1))]); notesGroup.add(note); sObjects.push(note); case CEvent(step, events): - var event = new CharterEvent(minStep + step + 1, events); + var event = new CharterEvent(minStep + step, events); event.refreshEventIcons(); eventsGroup.add(event); sObjects.push(event); @@ -1064,6 +1041,8 @@ class Charter extends UIState { } function _edit_undo(_) { + if (strumLines.isDragging) return; + selection = []; var undo = undos.undo(); switch(undo) { @@ -1072,6 +1051,8 @@ class Charter extends UIState { createStrumline(strumLineID, strumLine, false); case CCreateStrumLine(strumLineID, strumLine): deleteStrumline(strumLineID, false); + case COrderStrumLine(strumLine, oldID, newID): + strumLines.orderStrumline(strumLine, oldID); case CEditStrumLine(strumLineID, oldStrumLine, newStrumLine): strumLines.members[strumLineID].strumLine = oldStrumLine; strumLines.members[strumLineID].updateInfo(); @@ -1098,6 +1079,8 @@ class Charter extends UIState { } function _edit_redo(_) { + if (strumLines.isDragging) return; + selection = []; var redo = undos.redo(); switch(redo) { @@ -1106,6 +1089,8 @@ class Charter extends UIState { deleteStrumline(strumLineID, false); case CCreateStrumLine(strumLineID, strumLine): createStrumline(strumLineID, strumLine, false); + case COrderStrumLine(strumLine, oldID, newID): + strumLines.orderStrumline(strumLine, newID); case CEditStrumLine(strumLineID, oldStrumLine, newStrumLine): strumLines.members[strumLineID].strumLine = newStrumLine; strumLines.members[strumLineID].updateInfo(); @@ -1236,12 +1221,7 @@ class Charter extends UIState { var n:CharterNote = cast(s, CharterNote); var old:Float = n.susLength; n.updatePos(n.step, n.id, Math.max(n.susLength + change, 0)); - - { - before: old, - after: n.susLength, - note: n - }; + {before: old, after: n.susLength, note: n}; } } ])); @@ -1256,6 +1236,16 @@ class Charter extends UIState { FlxG.switchState(new PlayState()); } + public inline function buildNote(note:CharterNote):ChartNote { + var time = Conductor.getTimeForStep(note.step); + return { + type: note.type, + time: time, + sLen: Conductor.getTimeForStep(note.step + note.susLength) - time, + id: note.id + }; + } + public function buildChart() { PlayState.SONG.strumLines = []; for(s in strumLines) { @@ -1263,16 +1253,8 @@ class Charter extends UIState { PlayState.SONG.strumLines.push(s.strumLine); } for(n in notesGroup.members) { - var strLineID = Std.int(n.id / 4); - if (PlayState.SONG.strumLines[strLineID] != null) { - var time = Conductor.getTimeForStep(n.step); - PlayState.SONG.strumLines[strLineID].notes.push({ - type: n.type, - time: time, - sLen: Conductor.getTimeForStep(n.step + n.susLength) - time, - id: n.id % 4 - }); - } + if (PlayState.SONG.strumLines[n.strumLineID] != null) + PlayState.SONG.strumLines[n.strumLineID].notes.push(buildNote(n)); } buildEvents(); } @@ -1297,23 +1279,24 @@ class Charter extends UIState { } public inline function hitsoundsEnabled(id:Int) - return strumLines.members[Std.int(id / 4)] != null && strumLines.members[Std.int(id / 4)].hitsounds; + return strumLines.members[id] != null && strumLines.members[id].hitsounds; } enum CharterChange { CCreateStrumLine(strumLineID:Int, strumLine:ChartStrumLine); + CEditStrumLine(strumLineID:Int, oldStrumLine:ChartStrumLine, newStrumLine:ChartStrumLine); + COrderStrumLine(strumLine:CharterStrumline, oldID:Int, newID:Int); CDeleteStrumLine(strumLineID:Int, strumLine:ChartStrumLine); 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 { - CNote(step:Float, id:Int, susLength:Float, type:Int); + CNote(step:Float, id:Int, strumLineID:Int, susLength:Float, type:Int); CEvent(step:Float, events:Array); } diff --git a/source/funkin/editors/charter/CharterBackdrop.hx b/source/funkin/editors/charter/CharterBackdrop.hx index dab36825..8b0577a4 100644 --- a/source/funkin/editors/charter/CharterBackdrop.hx +++ b/source/funkin/editors/charter/CharterBackdrop.hx @@ -107,7 +107,7 @@ class CharterBackdrop extends FlxBackdrop { // Draw notes notesGroup.forEach((n) -> { - if(n.exists && n.visible && (Math.floor(n.id/4) == _)) { + if(n.exists && n.visible) { n.cameras = cameras; n.draw(); } diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx index 210bdede..311114dd 100644 --- a/source/funkin/editors/charter/CharterNote.hx +++ b/source/funkin/editors/charter/CharterNote.hx @@ -23,9 +23,6 @@ class CharterNote extends UISprite implements ICharterSelectable { public var selected:Bool = false; public var draggable:Bool = true; - public var snappedToStrumline:Bool = true; - public var strumLine:CharterStrumline = null; - public function new() { super(); antialiasing = true; @@ -51,29 +48,28 @@ class CharterNote extends UISprite implements ICharterSelectable { UIState.state.updateRectButtonHandler(this, __rect, onHovered); } - public var step:Float; + public var id:Int; public var susLength:Float; public var type:Int; - public var realId:Int; - @:isVar public var id(get, set):Int; - function set_id(d:Int) { - strumLine = Charter.instance.strumLines.members[Math.floor(d / 4)]; - if (strumLine != null) - alpha = strumLine.strumLine.visible ? 1 : 0.4; - realId = d; - return id = d % 4; - } + public var strumLine:CharterStrumline; + public var strumLineID(get, never):Int; + public function get_strumLineID():Int + return strumLine == null ? -1 : Charter.instance.strumLines.members.indexOf(strumLine); - function get_id():Int - return id + 4 * Charter.instance.strumLines.members.indexOf(strumLine); + public var snappedToStrumline:Bool = true; - public function updatePos(step:Float, id:Int, susLength:Float = 0, type:Int = 0) { + public var fullID(get, never):Int; // instead of %4 get fullID (for mousepos stuff) + public function get_fullID():Int + return (strumLineID * 4) + id; + + public function updatePos(step:Float, id:Int, susLength:Float = 0, type:Int = 0, ?strumLine:CharterStrumline) { this.step = step; this.id = id; this.susLength = susLength; this.type = type; + this.strumLine = strumLine; y = step * 40; sustainSpr.scale.set(10, (40 * susLength)); @@ -132,8 +128,8 @@ class CharterNote extends UISprite implements ICharterSelectable { sustainSpr.follow(this, 15, 20); if (__passed != (__passed = step < Conductor.curStepFloat)) { - alpha = __passed ? 0.6 : 1; - if (__passed && FlxG.sound.music.playing && Charter.instance.hitsoundsEnabled(id)) + alpha = (__passed ? 0.8 : 1) - (!strumLine.strumLine.visible ? .6 : 0); + if (__passed && FlxG.sound.music.playing && Charter.instance.hitsoundsEnabled(strumLineID)) Charter.instance.hitsound.replay(); } if(sustainSpr.exists) @@ -156,18 +152,15 @@ class CharterNote extends UISprite implements ICharterSelectable { } public function handleDrag(change:FlxPoint) { - var newID:Int = id + Std.int(change.y); + 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; - updatePos(step + change.x, newID, susLength, type); - - Charter.instance.notesGroup.remove(this); - Charter.instance.notesGroup.add(this); + updatePos(step + change.x, newID % 4, susLength, type, Charter.instance.strumLines.members[Std.int(newID/4)]); } public override function draw() { - if (snappedToStrumline) + if (snappedToStrumline) x = (strumLine != null ? strumLine.button.x : 0) + (id % 4) * 40; drawMembers(); diff --git a/source/funkin/editors/charter/CharterStrumLineGroup.hx b/source/funkin/editors/charter/CharterStrumLineGroup.hx index 26bc806d..ec74847c 100644 --- a/source/funkin/editors/charter/CharterStrumLineGroup.hx +++ b/source/funkin/editors/charter/CharterStrumLineGroup.hx @@ -1,5 +1,6 @@ package funkin.editors.charter; +import funkin.backend.chart.ChartData.ChartStrumLine; import funkin.backend.chart.EventsData; import flixel.util.FlxSort; @@ -9,6 +10,9 @@ class CharterStrumLineGroup extends FlxTypedGroup { var draggingOffset:Float = 0; public var draggable:Bool = false; + public var isDragging(get, never):Bool; + public function get_isDragging():Bool + return draggingObj != null; public override function update(elapsed:Float) { var mousePos = FlxG.mouse.getWorldPosition(cameras[0], FlxPoint.get()); @@ -29,7 +33,7 @@ class CharterStrumLineGroup extends FlxTypedGroup { 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.3); + if (!strum.dragging) strum.x = CoolUtil.fpsLerp(strum.x, 160 * i, 0.225); if (Charter.instance.eventsBackdrop != null) Charter.instance.eventsBackdrop.x = members[0].button.x - Charter.instance.eventsBackdrop.width; @@ -42,15 +46,38 @@ class CharterStrumLineGroup extends FlxTypedGroup { finishDrag(); mousePos.put(); - super.update(elapsed); } - inline function finishDrag() { - draggingObj.dragging = false; - draggingObj = null; + public function orderStrumline(strumLine:CharterStrumline, newID:Int) { + __pastStrumlines = members.copy(); - // Fix Events that use strumline param + 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) + draggingObj.dragging = false; + + // Undo + if (addToUndo) { + var oldID = __pastStrumlines.indexOf(draggingObj); + var newID = members.indexOf(draggingObj); + Charter.instance.undos.addToUndo(COrderStrumLine(draggingObj, oldID, newID)); + } + + + draggingObj = null; + fixEvents(); + } + + public inline function fixEvents() { for (i in Charter.instance.eventsGroup.members) { for (j in i.events) { var paramTypes:Array = EventsData.getEventParams(j.name); @@ -60,7 +87,6 @@ class CharterStrumLineGroup extends FlxTypedGroup { } } } - __pastStrumlines = null; }