From 954828753e634ee62be3d0ae135c2731abcfa854 Mon Sep 17 00:00:00 2001 From: lunarcleint Date: Sat, 8 Mar 2025 04:42:09 -0700 Subject: [PATCH] atlas dragging + hitboxes --- source/funkin/backend/system/FakeCamera.hx | 3 ++- source/funkin/backend/utils/MatrixUtil.hx | 2 +- .../editors/character/CharacterEditor.hx | 16 +++++++--------- .../funkin/editors/character/CharacterGhost.hx | 6 ++++-- .../editors/character/CharacterGizmos.hx | 18 ++++++++++++------ 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/source/funkin/backend/system/FakeCamera.hx b/source/funkin/backend/system/FakeCamera.hx index b350f4a5..99d0eb1b 100644 --- a/source/funkin/backend/system/FakeCamera.hx +++ b/source/funkin/backend/system/FakeCamera.hx @@ -39,11 +39,12 @@ class FakeCamera extends FlxCamera { class FakeCallCamera extends FakeCamera { public static final instance = new FakeCallCamera(); + public var ignoreDraws:Bool = false; public dynamic function onDraw(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader) { } override function drawPixels(?frame:FlxFrame, ?pixels:BitmapData, matrix:FlxMatrix, ?transform:ColorTransform, ?blend:BlendMode, ?smoothing:Bool = false, ?shader:FlxShader) { - onDraw(frame, pixels, matrix, transform, blend, smoothing, shader); + if (!ignoreDraws) onDraw(frame, pixels, matrix, transform, blend, smoothing, shader); } } \ No newline at end of file diff --git a/source/funkin/backend/utils/MatrixUtil.hx b/source/funkin/backend/utils/MatrixUtil.hx index 68cc7921..851d5dbb 100644 --- a/source/funkin/backend/utils/MatrixUtil.hx +++ b/source/funkin/backend/utils/MatrixUtil.hx @@ -102,7 +102,7 @@ final class MatrixUtil { // points should now contain the corners of the limb - trace("Corners of limb: " + points); + // trace("Corners of limb: " + points); // set the max bounds of each corner of the limb if(topLeft.x < boundsTopLeft.x) boundsTopLeft.x = topLeft.x; diff --git a/source/funkin/editors/character/CharacterEditor.hx b/source/funkin/editors/character/CharacterEditor.hx index 569b69c5..cb9262e4 100644 --- a/source/funkin/editors/character/CharacterEditor.hx +++ b/source/funkin/editors/character/CharacterEditor.hx @@ -382,6 +382,8 @@ class CharacterEditor extends UIState { } animationText.text = '"${characterFakeAnim}"'; + StageEditor.calcSpriteBounds(character); + if (Options.characterDragging) handleMouseOffsets(); @@ -406,15 +408,11 @@ class CharacterEditor extends UIState { } } else { var point = FlxG.mouse.getWorldPosition(charCamera, _point); - if(character.animateAtlas == null) { - StageEditor.calcSpriteBounds(character); - var bounds:FlxRect = cast character.extra.get(StageEditor.exID("bounds")); - trace(bounds); - if (bounds.containsPoint(point)) { - cameraHoverDummy.cursor = #if (mac) DRAG_OPEN; #else CLICK; #end - if (FlxG.mouse.justPressed) - draggingCharacter = true; - } + var bounds:FlxRect = cast character.extra.get(StageEditor.exID("bounds")); + if (bounds.containsPoint(point)) { + cameraHoverDummy.cursor = #if (mac) DRAG_OPEN; #else CLICK; #end + if (FlxG.mouse.justPressed) + draggingCharacter = true; } } } diff --git a/source/funkin/editors/character/CharacterGhost.hx b/source/funkin/editors/character/CharacterGhost.hx index 2cf8bb3e..81c7c5dd 100644 --- a/source/funkin/editors/character/CharacterGhost.hx +++ b/source/funkin/editors/character/CharacterGhost.hx @@ -1,5 +1,6 @@ package funkin.editors.character; +import funkin.backend.system.FakeCamera.FakeCallCamera; import openfl.geom.ColorTransform; import flixel.animation.FlxAnimation; import funkin.game.Character; @@ -14,7 +15,7 @@ typedef AtlasState = { class CharacterGhost extends Character { public var ghosts:Array = []; public override function draw() @:privateAccess { - ghostDraw = true; + ghostDraw = FakeCallCamera.instance.ignoreDraws = true; var wasInvalidFrame:Bool = !colorTransform.__isDefault(false); colorTransform.__identity(); @@ -46,7 +47,7 @@ class CharacterGhost extends Character { if (ghosts.length > 0) frame = frames.frames[animation.frameIndex]; } - ghostDraw = false; + ghostDraw = FakeCallCamera.instance.ignoreDraws = false; alpha = 1; color = 0xFFFFFFFF; if (wasInvalidFrame) { @@ -55,6 +56,7 @@ class CharacterGhost extends Character { colorTransform.color = 0xFFEF0202; } else setAnimOffset(animateAtlas != null ? atlasPlayingAnim : animation.name); + super.draw(); } diff --git a/source/funkin/editors/character/CharacterGizmos.hx b/source/funkin/editors/character/CharacterGizmos.hx index 31dde9e2..acfd6382 100644 --- a/source/funkin/editors/character/CharacterGizmos.hx +++ b/source/funkin/editors/character/CharacterGizmos.hx @@ -1,5 +1,7 @@ package funkin.editors.character; +import funkin.editors.stage.StageEditor; +import flixel.math.FlxRect; import funkin.game.Character; class CharacterGizmos extends FlxSprite { @@ -20,8 +22,11 @@ class CharacterGizmos extends FlxSprite { public function drawHitbox() { for (camera in cameras) { if (character.animateAtlas != null) { - // TODO: ATLAS CALCUATIONS - character._rect.set(); + var bounds:FlxRect = cast character.extra.get(StageEditor.exID("bounds")); + character._rect.copyFrom(bounds.getDefault(FlxRect.weak())); + + character._rect.x -= character.cameras[0].viewX; + character._rect.y -= character.cameras[0].viewY; } else if (character._matrix != null && character.frame != null) { character._rect.set( character._matrix.tx, character._matrix.ty, @@ -32,12 +37,13 @@ class CharacterGizmos extends FlxSprite { if (character._matrix.d < 0) character._rect.y -= character._rect.height; character._rect.offset(-character.cameras[0].viewMarginLeft, -character.cameras[0].viewMarginTop); - character._rect.x *= character.cameras[0].zoom; - character._rect.y *= character.cameras[0].zoom; - character._rect.width *= character.cameras[0].zoom; - character._rect.height *= character.cameras[0].zoom; } + character._rect.x *= character.cameras[0].zoom; + character._rect.y *= character.cameras[0].zoom; + character._rect.width *= character.cameras[0].zoom; + character._rect.height *= character.cameras[0].zoom; + if (DrawUtil.line == null) DrawUtil.createDrawers(); DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.85;