From 16f500ff697a9e6c1efb13ea87c246516b5564f4 Mon Sep 17 00:00:00 2001 From: lunarcleint Date: Mon, 11 Nov 2024 15:16:16 -0700 Subject: [PATCH] radioactive events --- source/funkin/editors/charter/Charter.hx | 90 ++++++++++++++----- .../editors/charter/CharterBackdropGroup.hx | 2 +- .../editors/charter/CharterDeleteAnim.hx | 2 +- source/funkin/editors/charter/CharterEvent.hx | 11 ++- .../funkin/editors/charter/CharterEventAdd.hx | 2 +- .../editors/charter/CharterEventGroup.hx | 5 ++ source/funkin/editors/charter/CharterNote.hx | 4 +- .../editors/charter/CharterNoteHoverer.hx | 2 +- 8 files changed, 89 insertions(+), 29 deletions(-) diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 12582162..ad374e04 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -2,6 +2,7 @@ package funkin.editors.charter; // ! FUCK YOU CHUF (your biggest fan -lunar) <3 //import flixel.FlxLayer; +import funkin.editors.charter.CharterEvent; import funkin.editors.extra.CameraHoverDummy; import flixel.input.keyboard.FlxKey; import flixel.math.FlxPoint; @@ -503,13 +504,13 @@ class Charter extends UIState { // adds grid and notes so that they're ALWAYS behind the UI add(gridBackdrops); - //add(textLayer = new FlxLayer()); add(localEventsBackdrop); - add(localAddEventSpr); - add(localEventsGroup); add(globalEventsBackdrop); + add(localAddEventSpr); add(globalAddEventSpr); + add(localEventsGroup); add(globalEventsGroup); + add(noteHoverer); add(noteDeleteAnims); add(notesGroup); @@ -816,15 +817,18 @@ class Charter extends UIState { if (selectionDragging) { gridBackdrops.draggingObj = null; selection.loop(function (n:CharterNote) { - n.snappedToStrumline = false; + n.snappedToGrid = false; n.setPosition(n.fullID * 40 + (mousePos.x - dragStartPos.x), n.step * 40 + (mousePos.y - dragStartPos.y)); n.y = CoolUtil.bound(n.y, 0, (__endStep*40) - n.height); n.x = CoolUtil.bound(n.x, 0, (strumLines.totalKeyCount-1) * 40); n.cursor = HAND; }, function (e:CharterEvent) { - e.y = e.step * 40 + (mousePos.y - dragStartPos.y) - 17; + e.snappedToGrid = false; + e.setPosition(e.eventsBackdrop.x + (e.global ? 0 : e.eventsBackdrop.width - e.bWidth) + (mousePos.x - dragStartPos.x), e.step * 40 + (mousePos.y - dragStartPos.y) - 17); e.y = CoolUtil.bound(e.y, -17, (__endStep*40)-17); e.cursor = HAND; + + e.displayGlobal = e.x + (e.bWidth/2) > ((strumLines.totalKeyCount*40)/2); }); currentCursor = HAND; } else { @@ -856,18 +860,18 @@ class Charter extends UIState { changePoint.put(); } - if (s is CharterNote) { - var s:CharterNote = cast s; - s.snappedToStrumline = true; - } - if (s is UISprite) { - var s:UISprite = cast s; - s.cursor = CLICK; - } + s.snappedToGrid = true; + + if (s is UISprite) cast(s, UISprite).cursor = CLICK; } + if (!(verticalChange == 0 && horizontalChange == 0)) { - notesGroup.sortNotes(); localEventsGroup.sortEvents(); globalEventsGroup.sortEvents(); - undos.addToUndo(CSelectionDrag(undoDrags)); + notesGroup.sortNotes(); + + undos.addToUndo(CChangeBundle([ + CSelectionDrag(undoDrags), + updateEventsGroups(selection) + ])); } gridActionType = NONE; @@ -1098,6 +1102,26 @@ class Charter extends UIState { return []; } + public function updateEventsGroups(selection:Selection):CharterChange { + if (selection.length <= 0) return CEditEventGroups([]); + var eventsChanged:Array = []; + + selection.loop(function (n:CharterNote) {}, function (e:CharterEvent) { + if (e.displayGlobal != e.global) { + (e.global ? globalEventsGroup : localEventsGroup).remove(e); + (e.displayGlobal ? globalEventsGroup : localEventsGroup).add(e); + + e.global = e.displayGlobal; + eventsChanged.push(e); + } + }, true); + + localEventsGroup.sortEvents(); globalEventsGroup.sortEvents(); + for (e in eventsChanged) e.update(0); // remove little stutter + + return CEditEventGroups(eventsChanged); + } + // STRUMLINE DELETION/CREATION public function createStrumline(strumLineID:Int, strL:ChartStrumLine, addToUndo:Bool = true, ?__createNotes:Bool = true) { var cStr = new CharterStrumline(strL); @@ -1491,11 +1515,7 @@ class Charter extends UIState { selection = deleteSelection(selection, true); } - function _edit_undo(_) { - if (strumLines.isDragging || selectionDragging || (subState != null && !(subState is UIContextMenu))) return; - - selection = []; - var undo = undos.undo(); + function _undo(undo:CharterChange) { switch(undo) { case null: // do nothing case CDeleteStrumLine(strumLineID, strumLine): @@ -1527,6 +1547,10 @@ class Charter extends UIState { event.refreshEventIcons(); Charter.instance.updateBPMEvents(); + case CEditEventGroups(events): + for (event in events) event.displayGlobal = !event.global; + updateEventsGroups(cast events); + case CEditChartData(oldData, newData): PlayState.SONG.stage = oldData.stage; PlayState.SONG.scrollSpeed = oldData.speed; @@ -1535,14 +1559,19 @@ class Charter extends UIState { changeNoteType(null, false); case CEditSpecNotesType(notes, oldTypes, newTypes): for(i=>note in notes) note.updatePos(note.step, note.id, note.susLength, oldTypes[i]); + case CChangeBundle(changes): + for (change in changes) _undo(change); } } - function _edit_redo(_) { + function _edit_undo(_) { if (strumLines.isDragging || selectionDragging || (subState != null && !(subState is UIContextMenu))) return; selection = []; - var redo = undos.redo(); + _undo(undos.undo()); + } + + function _redo(redo:CharterChange) { switch(redo) { case null: // do nothing case CDeleteStrumLine(strumLineID, strumLine): @@ -1573,6 +1602,10 @@ class Charter extends UIState { event.refreshEventIcons(); Charter.instance.updateBPMEvents(); + case CEditEventGroups(events): + for (event in events) event.displayGlobal = !event.global; + updateEventsGroups(cast events); + case CEditChartData(oldData, newData): PlayState.SONG.stage = newData.stage; PlayState.SONG.scrollSpeed = newData.speed; @@ -1581,9 +1614,18 @@ class Charter extends UIState { changeNoteType(null, false); case CEditSpecNotesType(notes, oldTypes, newTypes): for(i=>note in notes) note.updatePos(note.step, note.id, note.susLength, newTypes[i]); + case CChangeBundle(changes): + for (change in changes) _redo(change); } } + function _edit_redo(_) { + if (strumLines.isDragging || selectionDragging || (subState != null && !(subState is UIContextMenu))) return; + + selection = []; + _redo(undos.redo()); + } + inline function _chart_playtest(_) playtestChart(0, false); inline function _chart_playtest_here(_) @@ -2015,9 +2057,12 @@ enum CharterChange { CSelectionDrag(selectionDrags:Array); CEditSustains(notes:Array); CEditEvent(event:CharterEvent, oldEvents:Array, newEvents:Array); + CEditEventGroups(events:Array); CEditChartData(oldData:{stage:String, speed:Float}, newData:{stage:String, speed:Float}); CEditNoteTypes(oldArray:Array, newArray:Array); CEditSpecNotesType(notes:Array, oldNoteTypes:Array, newNoteTypes:Array); + + CChangeBundle(changes:Array); } enum CharterCopyboardObject { @@ -2060,6 +2105,7 @@ interface ICharterSelectable { public var selected:Bool; public var hovered:Bool; public var draggable:Bool; + public var snappedToGrid:Bool; public function handleSelection(selectionBox:UISliceSprite):Bool; public function handleDrag(change:FlxPoint):Void; diff --git a/source/funkin/editors/charter/CharterBackdropGroup.hx b/source/funkin/editors/charter/CharterBackdropGroup.hx index a6ba36d6..3741f9b2 100644 --- a/source/funkin/editors/charter/CharterBackdropGroup.hx +++ b/source/funkin/editors/charter/CharterBackdropGroup.hx @@ -88,7 +88,7 @@ class CharterBackdropGroup extends FlxTypedGroup { grid.notesGroup.clear(); notesGroup.forEach((n) -> { if(n.exists && n.visible) { - var onStr:Bool = (n.snappedToStrumline ? n.strumLineID : CoolUtil.boundInt(Std.int((n.x+n.width)/(40*strumLine.keyCount)), 0, strumLineGroup.members.length-1)) == i; + var onStr:Bool = (n.snappedToGrid ? n.strumLineID : CoolUtil.boundInt(Std.int((n.x+n.width)/(40*strumLine.keyCount)), 0, strumLineGroup.members.length-1)) == i; if(onStr) grid.notesGroup.add(n); } diff --git a/source/funkin/editors/charter/CharterDeleteAnim.hx b/source/funkin/editors/charter/CharterDeleteAnim.hx index 6175bf9b..2e23d38a 100644 --- a/source/funkin/editors/charter/CharterDeleteAnim.hx +++ b/source/funkin/editors/charter/CharterDeleteAnim.hx @@ -11,7 +11,7 @@ class CharterDeleteAnim extends CharterNote { super(); sustainSpr.color = 0xFF630000; color = 0xFF605A5A; - snappedToStrumline = selectable = autoAlpha = false; + snappedToGrid = selectable = autoAlpha = false; @:privateAccess __animSpeed = 1.25; garbageIcon = new FlxSprite().loadGraphic(Paths.image("editors/deleter")); diff --git a/source/funkin/editors/charter/CharterEvent.hx b/source/funkin/editors/charter/CharterEvent.hx index a93c90a0..ed3458a9 100644 --- a/source/funkin/editors/charter/CharterEvent.hx +++ b/source/funkin/editors/charter/CharterEvent.hx @@ -17,17 +17,22 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable { public var eventsBackdrop:EventBackdrop; public var snappedToGrid:Bool = true; + public var global:Bool = false; + public var displayGlobal:Bool = false; public function new(step:Float, ?events:Array, ?global:Bool = false) { super(-100, (step * 40) - 17, 100, 34, 'editors/charter/event-spr'); this.step = step; this.events = events.getDefault([]); - this.global = this.flipX = global; + + this.global = displayGlobal = global; + __redOffset = global ? 20 : 0; cursor = CLICK; } + var __redOffset:Float = 0; public override function update(elapsed:Float) { super.update(elapsed); @@ -46,6 +51,10 @@ class CharterEvent extends UISliceSprite implements ICharterSelectable { for (sprite in icons) sprite.colorTransform = colorTransform; + + flipX = displayGlobal; + __redOffset = FlxMath.lerp(__redOffset, displayGlobal ? 200 : 0, elapsed*3); + colorTransform.greenOffset += __redOffset; } private static function generateDefaultIcon(name:String) { diff --git a/source/funkin/editors/charter/CharterEventAdd.hx b/source/funkin/editors/charter/CharterEventAdd.hx index a286edf7..e7238e4f 100644 --- a/source/funkin/editors/charter/CharterEventAdd.hx +++ b/source/funkin/editors/charter/CharterEventAdd.hx @@ -22,7 +22,7 @@ class CharterEventAdd extends UISliceSprite { public override function onHovered() { super.onHovered(); - if (FlxG.mouse.justReleased) { + if (FlxG.mouse.justPressed) { if (curCharterEvent != null) Charter.instance.openSubState(new CharterEventScreen(step, global, curCharterEvent)); else diff --git a/source/funkin/editors/charter/CharterEventGroup.hx b/source/funkin/editors/charter/CharterEventGroup.hx index 5b71c47c..e1d01c55 100644 --- a/source/funkin/editors/charter/CharterEventGroup.hx +++ b/source/funkin/editors/charter/CharterEventGroup.hx @@ -37,11 +37,16 @@ class CharterEventGroup extends FlxTypedGroup { return FlxSort.byValues(FlxSort.ASCENDING, e1.step, e2.step); }); updateEventsIDs(); + updateEventsBackdrop(); } public inline function updateEventsIDs() for (i => n in members) n.ID = i; + public inline function updateEventsBackdrop() + for (event in members) + event.eventsBackdrop = eventsBackdrop; + public inline function filterEvents() { for (event in members) if (event.events.length == 0) { diff --git a/source/funkin/editors/charter/CharterNote.hx b/source/funkin/editors/charter/CharterNote.hx index 13948728..ffc901dd 100644 --- a/source/funkin/editors/charter/CharterNote.hx +++ b/source/funkin/editors/charter/CharterNote.hx @@ -81,7 +81,7 @@ class CharterNote extends UISprite implements ICharterSelectable { public function get_strumLineID():Int return strumLineID = (strumLine == null ? strumLineID : Charter.instance.strumLines.members.indexOf(strumLine)); - public var snappedToStrumline:Bool = true; + public var snappedToGrid:Bool = true; public var fullID(get, never):Int; // instead of %4 get fullID (for mousepos stuff) public function get_fullID():Int @@ -196,7 +196,7 @@ class CharterNote extends UISprite implements ICharterSelectable { } public override function draw() { - if (snappedToStrumline) + if (snappedToGrid) x = (strumLine != null ? strumLine.x : 0) + (id % (strumLine != null ? strumLine.keyCount : 4)) * 40; drawMembers(); diff --git a/source/funkin/editors/charter/CharterNoteHoverer.hx b/source/funkin/editors/charter/CharterNoteHoverer.hx index 729110bb..809a6f9f 100644 --- a/source/funkin/editors/charter/CharterNoteHoverer.hx +++ b/source/funkin/editors/charter/CharterNoteHoverer.hx @@ -6,7 +6,7 @@ class CharterNoteHoverer extends CharterNote { public function new() { super(); - snappedToStrumline = selectable = autoAlpha = false; visible = sustainSpr.visible = false; + snappedToGrid = selectable = autoAlpha = false; visible = sustainSpr.visible = false; @:privateAccess __animSpeed = 1.25; typeVisible = false; alpha = 0.4; }