From abcec3c5f6bfa78444845235cb4992da4375d27a Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Mon, 11 Sep 2023 19:42:10 -0400 Subject: [PATCH] Render a ghost hold note when dragging to place (plus fix for hold notes on different note quants) --- .../charting/ChartEditorHoldNoteSprite.hx | 5 +-- .../ui/debug/charting/ChartEditorState.hx | 31 +++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx b/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx index 5805874f6..3045cb623 100644 --- a/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx +++ b/source/funkin/ui/debug/charting/ChartEditorHoldNoteSprite.hx @@ -139,8 +139,9 @@ class ChartEditorHoldNoteSprite extends SustainTrail { // noteData.stepTime is a calculated value which accounts for BPM changes var stepTime:Float = this.noteData.stepTime; - var roundedStepTime:Float = Math.floor(stepTime + 0.01); // Add epsilon to fix rounding issues - this.y = roundedStepTime * ChartEditorState.GRID_SIZE; + // Add epsilon to fix rounding issues? + // var roundedStepTime:Float = Math.floor((stepTime + 0.01) / noteSnapRatio) * noteSnapRatio; + this.y = stepTime * ChartEditorState.GRID_SIZE; } this.x += ChartEditorState.GRID_SIZE / 2; diff --git a/source/funkin/ui/debug/charting/ChartEditorState.hx b/source/funkin/ui/debug/charting/ChartEditorState.hx index 52468070d..86dc0ec60 100644 --- a/source/funkin/ui/debug/charting/ChartEditorState.hx +++ b/source/funkin/ui/debug/charting/ChartEditorState.hx @@ -1121,6 +1121,11 @@ class ChartEditorState extends HaxeUIState */ var gridGhostNote:Null = null; + /** + * A sprite used to indicate the note that will be placed on click. + */ + var gridGhostHoldNote:Null = null; + /** * A sprite used to indicate the event that will be placed on click. */ @@ -1294,6 +1299,13 @@ class ChartEditorState extends HaxeUIState add(gridGhostNote); gridGhostNote.zIndex = 11; + gridGhostHoldNote = new ChartEditorHoldNoteSprite(this); + gridGhostHoldNote.alpha = 0.6; + gridGhostHoldNote.noteData = new SongNoteData(0, 0, 0, ""); + gridGhostHoldNote.visible = false; + add(gridGhostHoldNote); + gridGhostHoldNote.zIndex = 11; + gridGhostEvent = new ChartEditorEventSprite(this); gridGhostEvent.alpha = 0.6; gridGhostEvent.eventData = new SongEventData(-1, '', {}); @@ -2286,6 +2298,8 @@ class ChartEditorState extends HaxeUIState } else { + // Clicking and dragging. + // Scroll the screen if the mouse is above or below the grid. if (FlxG.mouse.screenY < MENU_BAR_HEIGHT) { @@ -2413,15 +2427,17 @@ class ChartEditorState extends HaxeUIState { // Handle extending the note as you drag. - // TODO: This should be beat snapped? var dragLengthSteps:Float = Conductor.getTimeInSteps(cursorSnappedMs) - currentPlaceNoteData.stepTime; + var dragLengthMs:Float = dragLengthSteps * Conductor.stepLengthMs; + var dragLengthPixels:Float = dragLengthSteps * GRID_SIZE; - // Without this, the newly placed note feels too short compared to the user's input. - var INCREMENT:Float = 1.0; - // TODO: Make this not busted with BPM changes - var dragLengthMs:Float = Math.floor(dragLengthSteps + INCREMENT) * Conductor.stepLengthMs; + gridGhostHoldNote.visible = true; + gridGhostHoldNote.noteData = gridGhostNote.noteData; + gridGhostHoldNote.noteDirection = gridGhostNote.noteData.getDirection(); - // TODO: Add and update some sort of preview? + gridGhostHoldNote.setHeightDirectly(dragLengthPixels); + + gridGhostHoldNote.updateHoldNotePosition(renderedHoldNotes); if (FlxG.mouse.justReleased) { @@ -2577,6 +2593,7 @@ class ChartEditorState extends HaxeUIState if (cursorColumn == eventColumn) { if (gridGhostNote != null) gridGhostNote.visible = false; + gridGhostHoldNote.visible = false; if (gridGhostEvent == null) throw "ERROR: Tried to handle cursor, but gridGhostEvent is null! Check ChartEditorState.buildGrid()"; @@ -2621,6 +2638,7 @@ class ChartEditorState extends HaxeUIState else { if (gridGhostNote != null) gridGhostNote.visible = false; + if (gridGhostHoldNote != null) gridGhostHoldNote.visible = false; if (gridGhostEvent != null) gridGhostEvent.visible = false; Cursor.cursorMode = Default; } @@ -2629,6 +2647,7 @@ class ChartEditorState extends HaxeUIState else { if (gridGhostNote != null) gridGhostNote.visible = false; + if (gridGhostHoldNote != null) gridGhostHoldNote.visible = false; if (gridGhostEvent != null) gridGhostEvent.visible = false; }