diff --git a/assets/images/editors/charter/drag-strumline.png b/assets/images/editors/charter/drag-strumline.png new file mode 100644 index 00000000..9fb8fa5e Binary files /dev/null and b/assets/images/editors/charter/drag-strumline.png differ diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 8a60889a..1b303fc3 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -53,6 +53,7 @@ class Charter extends UIState { public var strumlineInfoBG:FlxSprite; public var strumlineAddButton:CharterStrumlineExtraButton; + public var strumlineLockButton:CharterStrumlineExtraButton; public var hitsound:FlxSound; public var metronome:FlxSound; @@ -375,10 +376,15 @@ class Charter extends UIState { strumlineInfoBG.y = 23; strumlineInfoBG.scrollFactor.set(); - strumlineAddButton = new CharterStrumlineExtraButton("editors/charter/add-strumline", "Add New"); + strumlineAddButton = new CharterStrumlineExtraButton("editors/charter/add-strumline", "Create New"); strumlineAddButton.onClick = createStrumWithUI; - strumlineAddButton.cameras = [charterCamera]; + strumlineLockButton = new CharterStrumlineExtraButton("editors/charter/add-strumline", "Lock/Unlock"); + strumlineLockButton.onClick = function () { + if (strumLines != null) strumLines.draggable = !strumLines.draggable; + }; + + strumlineAddButton.cameras = strumlineLockButton.cameras = [charterCamera]; strumlineInfoBG.cameras = [charterCamera]; strumLines.cameras = [charterCamera]; @@ -394,6 +400,7 @@ class Charter extends UIState { add(notesGroup); add(selectionBox); add(strumlineInfoBG); + add(strumlineLockButton); add(strumlineAddButton); add(strumLines); // add the top menu last OUT of the ui group so that it stays on top @@ -931,6 +938,9 @@ class Charter extends UIState { strumlineAddButton.x = strumLines.length * (40 * 4); strumlineAddButton.y = strumlineInfoBG.y; + + strumlineLockButton.x = -1 * (40 * 4); + strumlineLockButton.y = strumlineInfoBG.y; } var zoom(default, set):Float = 0; diff --git a/source/funkin/editors/charter/CharterBackdrop.hx b/source/funkin/editors/charter/CharterBackdrop.hx index 1bc937b3..dab36825 100644 --- a/source/funkin/editors/charter/CharterBackdrop.hx +++ b/source/funkin/editors/charter/CharterBackdrop.hx @@ -44,7 +44,7 @@ class CharterBackdrop extends FlxBackdrop { beatSeparator.visible = Options.charterShowBeats; for(sep in [sectionSeparator, beatSeparator]) { - sep.makeGraphic(1, 1, -1); + sep.makeSolid(1, 1, -1); sep.alpha = 0.5; sep.scrollFactor.set(1, 1); sep.scale.set((4 * 40), sep == sectionSeparator ? 4 : 2); @@ -52,14 +52,14 @@ class CharterBackdrop extends FlxBackdrop { } bottomSeparator = new FlxSprite(0,-2); - bottomSeparator.makeGraphic(1, 1, -1); + bottomSeparator.makeSolid(1, 1, -1); bottomSeparator.alpha = 0.5; bottomSeparator.scrollFactor.set(1, 1); bottomSeparator.scale.set(4 * 40, 4); bottomSeparator.updateHitbox(); topSeparator = new FlxSprite(0, -2); - topSeparator.makeGraphic(1, 1, -1); + topSeparator.makeSolid(1, 1, -1); topSeparator.alpha = 0.5; topSeparator.scrollFactor.set(1, 1); topSeparator.scale.set(4 * 40, 4); @@ -67,23 +67,24 @@ class CharterBackdrop extends FlxBackdrop { // Limits topLimit = new FlxSprite(); - topLimit.makeGraphic(1, 1, -1); + topLimit.makeSolid(1, 1, -1); topLimit.color = 0xFF888888; topLimit.blend = MULTIPLY; bottomLimit = new FlxSprite(); - bottomLimit.makeGraphic(1, 1, -1); + bottomLimit.makeSolid(1, 1, -1); bottomLimit.color = 0xFF888888; bottomLimit.blend = MULTIPLY; // Follower - conductorFollowerSpr = new FlxSprite(0, 0).makeGraphic(1, 1, -1); + conductorFollowerSpr = new FlxSprite(0, 0).makeSolid(1, 1, -1); conductorFollowerSpr.scale.set(4 * 40, 4); conductorFollowerSpr.updateHitbox(); } public override function draw() { var ogX:Float = x; + //FlxG.watch.addQuick("gridXs", [for (strum in Charter.instance.strumLines.members) strum.x]); for(_ in 0...strumlinesAmount) { if (Charter.instance.strumLines.members[_] != null) { x = Charter.instance.strumLines.members[_].x; @@ -181,7 +182,7 @@ class EventBackdrop extends FlxBackdrop { eventBeatSeparator.visible = Options.charterShowBeats; for(sep in [eventSecSeparator, eventBeatSeparator]) { - sep.makeGraphic(1, 1, -1); + sep.makeSolid(1, 1, -1); sep.alpha = 0.5; sep.scrollFactor.set(1, 1); } @@ -193,14 +194,14 @@ class EventBackdrop extends FlxBackdrop { eventBeatSeparator.updateHitbox(); bottomSeparator = new FlxSprite(0,-2); - bottomSeparator.makeGraphic(1, 1, -1); + bottomSeparator.makeSolid(1, 1, -1); bottomSeparator.alpha = 0.5; bottomSeparator.scrollFactor.set(1, 1); bottomSeparator.scale.set(20, 4); bottomSeparator.updateHitbox(); topSeparator = new FlxSprite(0, -2); - topSeparator.makeGraphic(1, 1, -1); + topSeparator.makeSolid(1, 1, -1); topSeparator.alpha = 0.5; topSeparator.scrollFactor.set(1, 1); topSeparator.scale.set(20, 4); diff --git a/source/funkin/editors/charter/CharterStrumLineGroup.hx b/source/funkin/editors/charter/CharterStrumLineGroup.hx index 42ee9773..26bc806d 100644 --- a/source/funkin/editors/charter/CharterStrumLineGroup.hx +++ b/source/funkin/editors/charter/CharterStrumLineGroup.hx @@ -8,46 +8,78 @@ class CharterStrumLineGroup extends FlxTypedGroup { 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;