From bf475d9bd3b07eb2d207678c4bbf7410b7d35213 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Mon, 21 Aug 2023 21:00:55 -0700 Subject: [PATCH] adsgfasdg --- .../funkin/editors/charter/ChartHoverNote.hx | 66 +++++++++++++++++++ source/funkin/editors/charter/Charter.hx | 20 ++++-- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 source/funkin/editors/charter/ChartHoverNote.hx diff --git a/source/funkin/editors/charter/ChartHoverNote.hx b/source/funkin/editors/charter/ChartHoverNote.hx new file mode 100644 index 00000000..d3eee237 --- /dev/null +++ b/source/funkin/editors/charter/ChartHoverNote.hx @@ -0,0 +1,66 @@ +package funkin.editors.charter; + +import flixel.tweens.misc.VarTween; +import flixel.tweens.FlxTween; + +class ChartHoverNote extends UISprite { + public var angleTween:FlxTween; + + public var onGrid:Bool = false; + public var id:Int = 0; + public var nextID:Int = 0; + + public function new() { + super(); + antialiasing = true; + loadGraphic(Paths.image('editors/charter/note'), true, 157, 154); + animation.add("note", [for(i in 0...frames.frames.length) i], 0, true); + animation.play("note"); + this.setUnstretchedGraphicSize(40, 40, false); + + moves = selectable = false; + colorTransform.color = 0xFFFFFF; + } + + public override function update(elapsed:Float) { + super.update(elapsed); + + var mousePos = FlxG.mouse.getWorldPosition(__lastDrawCameras[0]); + alpha = FlxMath.lerp(alpha, onGrid ? 0.2 : 0, 1/8); + id = Math.floor(x / 40); + + if (onGrid) { + Charter.instance.gridBackdropDummy.cursor = BUTTON; + x = (nextID = Math.floor(mousePos.x / 40)) * 40; + y = (FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40)) * 40; + + if (id != nextID) { + if (angleTween != null) angleTween.cancel(); + + angle = switch(id % 4) { + case 0: -90; + case 1: 180; + case 2: 0; + case 3: 90; + default: 0; // how is that even possible + }; + + var destAngle = switch((nextID % 4)) { + case 0: -90; + case 1: 180; + case 2: 0; + case 3: 90; + default: 0; // how is that even possible + }; + + angleTween = FlxTween.tween(this, {angle: destAngle}, 2/3, {ease: function(t) { + return ((Math.sin(t * Math.PI) * 0.35) * 3 * t * Math.sqrt(1 - t)) + t; + }, onComplete: function (t) {angleTween = null;}}); + } + } else if (alpha > 0) { + Charter.instance.gridBackdropDummy.cursor = ARROW; + x = mousePos.x - 20; y = mousePos.y -20; + } + mousePos.put(); + } +} \ No newline at end of file diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 20c8c05d..13f909f6 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -55,6 +55,7 @@ class Charter extends UIState { public var topLimit:FlxSprite; public var bottomLimit:FlxSprite; public var bottomSeparator:FlxSprite; + public var hoverNote:ChartHoverNote; public var strumlineInfoBG:FlxSprite; public var strumlineAddButton:CharterStrumlineExtraButton; @@ -342,6 +343,9 @@ class Charter extends UIState { eventsBackdrop.cameras = [charterCamera]; add(eventsBackdrop); + hoverNote = new ChartHoverNote(); + hoverNote.cameras = [charterCamera]; + add(gridBackdropDummy = new CharterBackdropDummy(gridBackdrop)); sectionSeparator = new FlxBackdrop(null, Y, 0, 0); sectionSeparator.x = -20; @@ -421,6 +425,7 @@ class Charter extends UIState { // adds grid and notes so that they're ALWAYS behind the UI add(gridBackdrop); + add(hoverNote); add(sectionSeparator); add(beatSeparator); add(addEventSpr); @@ -549,6 +554,7 @@ class Charter extends UIState { if (!gridBackdropDummy.hoveredByChild && !FlxG.mouse.pressed) gridActionType = NONE; selectionBox.visible = false; + hoverNote.onGrid = false; switch(gridActionType) { case BOX: if (gridBackdropDummy.hoveredByChild) { @@ -625,19 +631,25 @@ class Charter extends UIState { case NONE: if (FlxG.mouse.justPressed) - FlxG.mouse.getWorldPosition(charterCamera, dragStartPos); + FlxG.mouse.getWorldPosition(charterCamera, dragStartPos); + + hoverNote.visible = hoveredSprite != null ? hoveredSprite is CharterNote : true; + if (gridBackdropDummy.hovered) { // AUTO DETECT if (FlxG.mouse.pressed && (Math.abs(mousePos.x - dragStartPos.x) > 20 || Math.abs(mousePos.y - dragStartPos.y) > 20)) gridActionType = BOX; + var id = Math.floor(mousePos.x / 40); + var mouseOnGrid = id >= 0 && id < 4 * gridBackdrop.strumlinesAmount && mousePos.y >= 0; + + hoverNote.onGrid = mouseOnGrid; + if (FlxG.mouse.justReleased) { if (selection.length > 1) { selection = []; // clear selection } else { - // place note - var id = Math.floor(mousePos.x / 40); - if (id >= 0 && id < 4 * gridBackdrop.strumlinesAmount && mousePos.y >= 0) { + if (mouseOnGrid) { var note = new CharterNote(); note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0); notesGroup.add(note);