From 7914603009af0cb7d2b5a0a1adbcbef7cb536184 Mon Sep 17 00:00:00 2001 From: TheZoroForce240 <86524550+TheZoroForce240@users.noreply.github.com> Date: Sat, 3 Aug 2024 16:48:29 +0100 Subject: [PATCH] fixed strumline drop down with different zooms --- source/funkin/backend/utils/CoolUtil.hx | 21 +++++++++++++++++++ .../editors/charter/CharterStrumline.hx | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/source/funkin/backend/utils/CoolUtil.hx b/source/funkin/backend/utils/CoolUtil.hx index 996b6bd0..8a518ada 100644 --- a/source/funkin/backend/utils/CoolUtil.hx +++ b/source/funkin/backend/utils/CoolUtil.hx @@ -37,6 +37,7 @@ import haxe.io.Path; import haxe.xml.Access; import lime.utils.Assets; import openfl.geom.ColorTransform; +import flixel.math.FlxPoint; using StringTools; @@ -846,6 +847,26 @@ class CoolUtil return angle - diff; } + /** + * Returns the screen position of an object, while taking the camera zoom into account. + * + * @param object Any `FlxObject` + * @param camera The desired "screen" coordinate space. If `null`, `FlxG.camera` is used. + * @param result Optional arg for the returning point + * @return The screen position of the object. + */ + public static function worldToScreenPosition(object:FlxObject, ?camera:FlxCamera, ?result:FlxPoint) { + if (result == null) + result = FlxPoint.get(); + if (camera == null) + camera = FlxG.camera; + + result.set(object.x, object.y); + result.x = (((result.x - camera.scroll.x * object.scrollFactor.x) * camera.zoom) - ((camera.width * 0.5) * (camera.zoom - camera.initialZoom))); + result.y = (((result.y - camera.scroll.y * object.scrollFactor.y) * camera.zoom) - ((camera.height * 0.5) * (camera.zoom - camera.initialZoom))); + return result; + } + public static function sortAlphabetically(array:Array, ?lowercase:Bool=false) { array.sort(function(a1, a2):Int { if(lowercase) { diff --git a/source/funkin/editors/charter/CharterStrumline.hx b/source/funkin/editors/charter/CharterStrumline.hx index 78bb3156..7b757add 100644 --- a/source/funkin/editors/charter/CharterStrumline.hx +++ b/source/funkin/editors/charter/CharterStrumline.hx @@ -203,6 +203,9 @@ class CharterStrumlineOptions extends UITopMenuButton { contextMenu.insert(1+Charter.waveformHandler.waveformList.length, null); - super.openContextMenu(); + var cam = Charter.instance.charterCamera; + var point = CoolUtil.worldToScreenPosition(this, cam); + curMenu = UIState.state.openContextMenu(contextMenu, null, point.x, point.y + (bHeight*cam.zoom), Std.int(bWidth * cam.zoom)); + point.put(); } } \ No newline at end of file