From 1c9f8c2f59802d34439dd4aa3ce2a50a83adebd4 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Tue, 29 Aug 2023 17:16:53 -0700 Subject: [PATCH] bug fixes/lock --- .../images/editors/charter/drag-strumline.png | Bin 0 -> 129 bytes source/funkin/editors/charter/Charter.hx | 14 +++- .../funkin/editors/charter/CharterBackdrop.hx | 19 ++--- .../editors/charter/CharterStrumLineGroup.hx | 72 +++++++++++++----- .../editors/charter/CharterStrumline.hx | 46 +++++++++-- .../charter/CharterStrumlineExtraButton.hx | 5 +- source/funkin/editors/ui/UIState.hx | 7 ++ 7 files changed, 120 insertions(+), 43 deletions(-) create mode 100644 assets/images/editors/charter/drag-strumline.png diff --git a/assets/images/editors/charter/drag-strumline.png b/assets/images/editors/charter/drag-strumline.png new file mode 100644 index 0000000000000000000000000000000000000000..9fb8fa5ef1208549c02d90da164a002241fadafc GIT binary patch literal 129 zcmeAS@N?(olHy`uVBq!ia0vp^20+Zi!3HE%cG(32DaPU;cPEB*=VV?2Io6&ojv*eM z$q5pA59~#FObgv+C~Q)4b33M}e6Ho)VMT5>?@0>bH6lC~5;>kpTSTOa5;mxC79DNZ aVPFtEYA { var draggingObj:CharterStrumline = null; var draggingOffset:Float = 0; - public override function update(elapsed:Float) { - super.update(elapsed); + public var draggable:Bool = false; + public override function update(elapsed:Float) { + var mousePos = FlxG.mouse.getWorldPosition(cameras[0], FlxPoint.get()); for (strumLine in members) { - if (FlxG.mouse.overlaps(strumLine.healthIcon) && FlxG.mouse.justPressed) { + strumLine.draggable = draggable; + if (draggable && UIState.state.isOverlapping(strumLine.draggingSprite, @:privateAccess strumLine.draggingSprite.__rect) && FlxG.mouse.justPressed) { draggingObj = strumLine; strumLine.dragging = true; - draggingOffset = FlxG.mouse.x - strumLine.button.x; + draggingOffset = mousePos.x - strumLine.button.x; __pastStrumlines = members.copy(); break; } } if (draggingObj != null) - draggingObj.x = FlxG.mouse.x - draggingOffset; - + draggingObj.x = mousePos.x - draggingOffset; 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); - Charter.instance.eventsBackdrop.x = members[0].button.x - Charter.instance.eventsBackdrop.width; + if (Charter.instance.eventsBackdrop != null) + Charter.instance.eventsBackdrop.x = members[0].button.x - Charter.instance.eventsBackdrop.width; + if (Charter.instance.strumlineLockButton != null) + Charter.instance.strumlineLockButton.x = members[0].x - (40*4); + if (Charter.instance.strumlineAddButton != null) + Charter.instance.strumlineAddButton.x = members[members.length-1].x + (40*4); - if (FlxG.mouse.justReleased && draggingObj != null) { - draggingObj.dragging = false; - draggingObj = null; + if ((FlxG.mouse.justReleased || !draggable) && draggingObj != null) + finishDrag(); - // Fix Events that use strumline param - for (i in Charter.instance.eventsGroup.members) { - for (j in i.events) { - var paramTypes:Array = EventsData.getEventParams(j.name); - for (i => param in paramTypes) { - if (param.type != TStrumLine) continue; - j.params[i] = Charter.instance.strumLines.members.indexOf(__pastStrumlines[j.params[i]]); - } + mousePos.put(); + + super.update(elapsed); + } + + inline function finishDrag() { + draggingObj.dragging = false; + draggingObj = null; + + // Fix Events that use strumline param + for (i in Charter.instance.eventsGroup.members) { + for (j in i.events) { + var paramTypes:Array = EventsData.getEventParams(j.name); + for (i => param in paramTypes) { + if (param.type != TStrumLine) continue; + j.params[i] = members.indexOf(__pastStrumlines[j.params[i]]); } } - - __pastStrumlines = null; } + + __pastStrumlines = null; + } + + override function draw() @:privateAccess { + var i:Int = 0; + var basic:FlxBasic = null; + + var oldDefaultCameras = FlxCamera._defaultCameras; + if (cameras != null) + FlxCamera._defaultCameras = cameras; + + while (i < length) + { + basic = members[i++]; + if (basic != null && basic != draggingObj && basic.exists && basic.visible) + basic.draw(); + } + if (draggingObj != null) draggingObj.draw(); + + FlxCamera._defaultCameras = oldDefaultCameras; } } \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterStrumline.hx b/source/funkin/editors/charter/CharterStrumline.hx index 90f0fe05..31636780 100644 --- a/source/funkin/editors/charter/CharterStrumline.hx +++ b/source/funkin/editors/charter/CharterStrumline.hx @@ -9,11 +9,13 @@ import funkin.backend.chart.ChartData.ChartStrumLine; class CharterStrumline extends UISprite { public var strumLine:ChartStrumLine; - public var hitsounds:Bool = true; + public var draggingSprite:UISprite; public var healthIcon:HealthIcon; public var button:CharterStrumlineButton; + + public var draggable:Bool = false; public var dragging:Bool = false; public var curMenu:UIContextMenu = null; @@ -28,22 +30,48 @@ class CharterStrumline extends UISprite { var icon = Character.getIconFromCharName(strumLine.characters != null ? strumLine.characters[0] : null); healthIcon = new HealthIcon(icon); - healthIcon.scale.set(80 / 150, 80 / 150); + healthIcon.scale.set((80 - (draggable ? 21 : 0)) / 150, (80 - (draggable ? 21 : 0)) / 150); healthIcon.updateHitbox(); - if(strumLine.visible == null) - strumLine.visible = true; + healthIcon.y = draggable ? 29 : 7; + + if(strumLine.visible == null) strumLine.visible = true; healthIcon.alpha = strumLine.visible ? 1 : 0.4; members.push(healthIcon); + draggingSprite = new UISprite(); + draggingSprite.loadGraphic(Paths.image("editors/charter/drag-strumline")); + draggingSprite.alpha = 0.4; + draggingSprite.y = 9; + draggingSprite.antialiasing = true; + draggingSprite.cursor = BUTTON; + members.push(draggingSprite); + button = new CharterStrumlineButton(this); members.push(button); } public override function update(elapsed:Float) { - if (healthIcon != null) - healthIcon.follow(this, ((40 * 4) - healthIcon.width) / 2, 50); + if (FlxG.keys.justPressed.K) draggable = !draggable; + if (healthIcon != null) { + var healthScale:Float = FlxMath.lerp(healthIcon.scale.x, (80 - (draggable ? 21 : 0)) / 150, 1/20); + healthIcon.scale.set(healthScale, healthScale); + healthIcon.updateHitbox(); + + healthIcon.follow(this, ((40 * 4) - healthIcon.width) / 2, FlxMath.lerp(healthIcon.y - y, draggable ? 29 : 7, 1/20)); + } + + var dragScale:Float = FlxMath.lerp(draggingSprite.scale.x, draggable ? 1 : 0.8, 1/16); + draggingSprite.scale.set(dragScale, dragScale); + draggingSprite.updateHitbox(); + + draggingSprite.follow(this, (160/2) - (draggingSprite.width/2), FlxMath.lerp(draggingSprite.y - y, draggable ? 9 : 6, 1/12)); + draggingSprite.alpha = FlxMath.lerp(draggingSprite.alpha, draggable ? 0.4 : 0, 1/12); button.follow(this, 0, 95); + + draggingSprite.selectable = draggable; + + UIState.state.updateSpriteRect(draggingSprite); super.update(elapsed); } @@ -54,8 +82,10 @@ class CharterStrumline extends UISprite { var icon = Character.getIconFromCharName(strumLine.characters != null ? strumLine.characters[0] : null); healthIcon = new HealthIcon(icon); - healthIcon.scale.set(80 / 150, 80 / 150); + healthIcon.scale.set((80 - (draggable ? 21 : 0)) / 150, (80 - (draggable ? 21 : 0)) / 150); healthIcon.updateHitbox(); + healthIcon.y = draggable ? 29 : 7; + healthIcon.alpha = strumLine.visible ? 1 : 0.4; members.push(healthIcon); } @@ -72,7 +102,7 @@ class CharterStrumlineButton extends UITopMenuButton { public override function update(elapsed:Float) { super.update(elapsed); - alpha = FlxMath.lerp(1/3, 1, alpha); // so that instead of 0% it is 33% visible + alpha = FlxMath.lerp(1/20, 1, alpha); // so that instead of 0% it is 33% visible } public override function openContextMenu() { diff --git a/source/funkin/editors/charter/CharterStrumlineExtraButton.hx b/source/funkin/editors/charter/CharterStrumlineExtraButton.hx index f19e4c30..471aebe5 100644 --- a/source/funkin/editors/charter/CharterStrumlineExtraButton.hx +++ b/source/funkin/editors/charter/CharterStrumlineExtraButton.hx @@ -35,10 +35,7 @@ class CharterStrumlineExtraButton extends UISprite { super.update(elapsed); - button.__rect.x = button.x; - button.__rect.y = button.y; - button.__rect.width = button.width; - button.__rect.height = button.height; + UIState.state.updateSpriteRect(button); if(UIState.state.isOverlapping(button, button.__rect)) { buttonScale.set(0.85, 0.85); if (FlxG.mouse.justReleased && onClick != null) onClick(); diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index 9aa8cac3..4987d8fb 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -59,6 +59,13 @@ class UIState extends MusicBeatState { currentFocus.onTextEdit(str, start, end); } + public inline function updateSpriteRect(spr:UISprite) { + spr.__rect.x = spr.x; + spr.__rect.y = spr.y; + spr.__rect.width = spr.width; + spr.__rect.height = spr.height; + } + public function updateButtonHandler(spr:UISprite, buttonHandler:Void->Void) { spr.__rect.x = spr.x; spr.__rect.y = spr.y;