diff --git a/libs.xml b/libs.xml index e1653aed..42e11b13 100644 --- a/libs.xml +++ b/libs.xml @@ -17,6 +17,7 @@ + diff --git a/project.xml b/project.xml index 5b737d6f..ca912ab7 100644 --- a/project.xml +++ b/project.xml @@ -105,6 +105,9 @@ + + + @@ -185,6 +188,14 @@ +
+ + + + + +
+
diff --git a/source/funkin/backend/utils/CoolUtil.hx b/source/funkin/backend/utils/CoolUtil.hx index d3c040c2..29dd6272 100644 --- a/source/funkin/backend/utils/CoolUtil.hx +++ b/source/funkin/backend/utils/CoolUtil.hx @@ -914,6 +914,28 @@ final class CoolUtil return result; } + /** + * Returns the screen position of an point, 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 pointToScreenPosition(object:FlxPoint, ?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) * camera.zoom) - ((camera.width * 0.5) * (camera.zoom - camera.initialZoom))); + result.y = (((result.y - camera.scroll.y) * camera.zoom) - ((camera.height * 0.5) * (camera.zoom - camera.initialZoom))); + + object.putWeak(); + return result; + } + /** * Sorts an array alphabetically. * @param array Array to sort diff --git a/source/funkin/backend/utils/DrawUtil.hx b/source/funkin/backend/utils/DrawUtil.hx index 8b3976e7..0e70b745 100644 --- a/source/funkin/backend/utils/DrawUtil.hx +++ b/source/funkin/backend/utils/DrawUtil.hx @@ -1,5 +1,6 @@ package funkin.backend.utils; +import flixel.math.FlxRect; import flixel.util.FlxColor; import flixel.math.FlxAngle; import flixel.math.FlxPoint; @@ -18,7 +19,7 @@ final class DrawUtil { dot.draw(); } - public static inline function drawLine(point1:FlxPoint, point2:FlxPoint, sizeModify:Float = 1, ?color:Null) { + public static inline function drawLine(point1:FlxPoint, point2:FlxPoint, thickness:Float = 1, ?color:Null) { if (line == null) createDrawers(); var dx:Float = point2.x - point1.x; @@ -27,11 +28,12 @@ final class DrawUtil { var angle:Float = Math.atan2(dy, dx); var distance:Float = Math.sqrt(dx * dx + dy * dy); - line.setPosition(point1.x, point1.y); + // Math.ceil to prevent flickering + line.setPosition(Math.ceil(point1.x), Math.ceil(point1.y)); line.angle = angle * FlxAngle.TO_DEG; line.origin.set(0, line.frameHeight / 2); line.scale.x = distance / line.frameWidth; - line.scale.y = 0.20/line.cameras[0].zoom * sizeModify; + line.scale.y = thickness; line.y -= line.height / 2; if (color != null) line.color = color; line.draw(); @@ -39,6 +41,15 @@ final class DrawUtil { line.angle = 0; line.scale.x = line.scale.y = 1; line.updateHitbox(); + + point1.putWeak(); point2.putWeak(); + } + + public static inline function drawRect(rect:FlxRect, thickness:Float = 1, ?color:Null) { + DrawUtil.drawLine(FlxPoint.weak(rect.x, rect.y), FlxPoint.weak(rect.x + rect.width, rect.y), thickness, color); + DrawUtil.drawLine(FlxPoint.weak(rect.x, rect.y), FlxPoint.weak(rect.x, rect.y + rect.height), thickness, color); + DrawUtil.drawLine(FlxPoint.weak(rect.x + rect.width, rect.y), FlxPoint.weak(rect.x + rect.width, rect.y + rect.height), thickness, color); + DrawUtil.drawLine(FlxPoint.weak(rect.x, rect.y + rect.height), FlxPoint.weak(rect.x + rect.width, rect.y + rect.height), thickness, color); } public static inline function createDrawers() { @@ -50,7 +61,7 @@ final class DrawUtil { dot.camera = FlxG.camera; dot.forceIsOnScreen = true; - line = new FlxSprite().makeGraphic(30, 30, FlxColor.WHITE); + line = new FlxSprite().makeGraphic(1, 1, FlxColor.WHITE); line.camera = FlxG.camera; line.forceIsOnScreen = true; } diff --git a/source/funkin/editors/character/CharacterEditor.hx b/source/funkin/editors/character/CharacterEditor.hx index 1c004e32..ce2c85e4 100644 --- a/source/funkin/editors/character/CharacterEditor.hx +++ b/source/funkin/editors/character/CharacterEditor.hx @@ -1,5 +1,6 @@ package funkin.editors.character; +import funkin.editors.extra.AxisGizmo; import flixel.math.FlxRect; import funkin.editors.stage.StageEditor; import funkin.game.Stage; @@ -14,7 +15,6 @@ import funkin.editors.ui.UIContextMenu.UIContextMenuOptionSpr; import funkin.game.Character; import haxe.xml.Access; import haxe.xml.Printer; -import funkin.editors.extra.DrawAxis; class CharacterEditor extends UIState { static var __character:String; @@ -33,7 +33,8 @@ class CharacterEditor extends UIState { // public var dragOffsetsCheckbox:UICheckbox; // public var lockCameraCheckbox:UICheckbox; - public var drawAxis:DrawAxis; + public var axisGizmo:AxisGizmo; + public var characterGizmo:CharacterGizmos; public var uiGroup:FlxTypedGroup = new FlxTypedGroup(); public var cameraHoverDummy:CameraHoverDummy; @@ -42,6 +43,7 @@ class CharacterEditor extends UIState { public var characterAnimsWindow:CharacterAnimsWindow; public var charCamera:FlxCamera; + public var gizmosCamera:FlxCamera; public var uiCamera:FlxCamera; public var animationText:UIText; @@ -255,6 +257,20 @@ class CharacterEditor extends UIState { charCamera = FlxG.camera; + gizmosCamera = new FlxCamera(); + gizmosCamera.bgColor = 0; + FlxG.cameras.add(gizmosCamera); + + axisGizmo = new AxisGizmo(); + axisGizmo.cameras = [gizmosCamera]; + add(axisGizmo); + + characterGizmo = new CharacterGizmos(); + characterGizmo.boxGizmo = Options.characterHitbox; + characterGizmo.cameraGizmo = Options.characterCamera; + characterGizmo.cameras = [gizmosCamera]; + add(characterGizmo); + uiCamera = new FlxCamera(); uiCamera.bgColor = 0; @@ -264,17 +280,12 @@ class CharacterEditor extends UIState { character.debugMode = true; character.cameras = [charCamera]; - character.debugHitbox = Options.characterHitbox; - character.debugCamera = Options.characterCamera; + characterGizmo.character = character; changeCharacterIsPlayer(character.playerOffsets); add(character); - drawAxis = new DrawAxis(); - drawAxis.cameras = [charCamera]; - add(drawAxis); - uiGroup.cameras = [uiCamera]; add(cameraHoverDummy = new CameraHoverDummy(uiGroup, FlxPoint.weak(0, 0))); @@ -627,17 +638,17 @@ class CharacterEditor extends UIState { function _view_character_show_hitbox(t) { t.icon = (Options.characterHitbox = !Options.characterHitbox) ? 1 : 0; - character.debugHitbox = Options.characterHitbox; + characterGizmo.boxGizmo = Options.characterHitbox; } function _view_character_show_camera(t) { t.icon = (Options.characterCamera = !Options.characterCamera) ? 1 : 0; - character.debugCamera = Options.characterCamera; + characterGizmo.cameraGizmo = Options.characterCamera; } function _view_character_show_axis(t) { t.icon = (Options.characterAxis = !Options.characterAxis) ? 1 : 0; - drawAxis.visible = Options.characterAxis; + axisGizmo.visible = Options.characterAxis; } function _view_focus_character(_) { diff --git a/source/funkin/editors/character/CharacterGizmos.hx b/source/funkin/editors/character/CharacterGizmos.hx new file mode 100644 index 00000000..ed3c8887 --- /dev/null +++ b/source/funkin/editors/character/CharacterGizmos.hx @@ -0,0 +1,79 @@ +package funkin.editors.character; + +import funkin.game.Character; + +class CharacterGizmos extends FlxSprite { + public var character:Character; + + public var boxGizmo:Bool = true; + public var cameraGizmo:Bool = true; + + public override function draw() { + super.draw(); + + if (character == null) return; + + if (boxGizmo) drawHitbox(); + if (cameraGizmo) drawCamera(); + } + + public function drawHitbox() { + // TODO: ATLAS VESION OF THIS CODE + if (character._matrix == null || character.frame == null) return; + + for (camera in cameras) { + character._rect.set(character._matrix.tx, character._matrix.ty, character.frame.frame.width * character._matrix.a, character.frame.frame.height * character._matrix.d); + @:privateAccess character._rect = FlxG.camera.transformRect(character._rect); + trace(character._rect); + + if (DrawUtil.line == null) DrawUtil.createDrawers(); + DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.75; + + DrawUtil.drawRect(character._rect, 1, 0xFF8F8A00); + // yes i made a drawRect function for this purpose, no im not using it >:D + DrawUtil.drawLine( + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y), FlxG.camera, FlxPoint.weak()), + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y), FlxG.camera, FlxPoint.weak()), + 1, 0xFF007B8F + ); + DrawUtil.drawLine( + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y), FlxG.camera, FlxPoint.weak()), + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), + 1, 0xFF007B8F + ); + DrawUtil.drawLine( + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y), FlxG.camera, FlxPoint.weak()), + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), + 1, 0xFF007B8F + ); + DrawUtil.drawLine( + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), + CoolUtil.pointToScreenPosition(FlxPoint.weak(character._rect.x + character._rect.width, character._rect.y + character._rect.height), FlxG.camera, FlxPoint.weak()), + 1, 0xFF007B8F + ); + } + } + + public function drawCamera() { + for (camera in cameras) { + var camPos:FlxPoint = character.getCameraPosition(); + camPos -= camera.scroll; + + if (DrawUtil.line == null) DrawUtil.createDrawers(); + DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.75; + + DrawUtil.drawLine( + CoolUtil.pointToScreenPosition(FlxPoint.weak(camPos.x - 8, camPos.y), FlxG.camera, FlxPoint.weak()), + CoolUtil.pointToScreenPosition(FlxPoint.weak(camPos.x + 8, camPos.y), FlxG.camera, FlxPoint.weak()), + 1, 0xFF00A0B9); + + DrawUtil.drawLine( + CoolUtil.pointToScreenPosition(FlxPoint.weak(camPos.x, camPos.y - 8), FlxG.camera, FlxPoint.weak()), + CoolUtil.pointToScreenPosition(FlxPoint.weak(camPos.x, camPos.y + 8), FlxG.camera, FlxPoint.weak()), + 1, 0xFF00A0B9); + + camPos.put(); + + } + } +} \ No newline at end of file diff --git a/source/funkin/editors/extra/AxisGizmo.hx b/source/funkin/editors/extra/AxisGizmo.hx new file mode 100644 index 00000000..a66ece95 --- /dev/null +++ b/source/funkin/editors/extra/AxisGizmo.hx @@ -0,0 +1,31 @@ +package funkin.editors.extra; + +class AxisGizmo extends FlxObject { + var _worldPos:FlxPoint = FlxPoint.get(); + + public override function draw() { + super.draw(); + + for (camera in cameras) { + if (DrawUtil.line == null) DrawUtil.createDrawers(); + DrawUtil.line.camera = camera; DrawUtil.line.alpha = 0.75; + + CoolUtil.pointToScreenPosition(FlxPoint.weak(), FlxG.camera, _worldPos); + // Stole these colors directly from godot >:D -luanr + DrawUtil.drawLine( + FlxPoint.weak(_worldPos.x, 0), + FlxPoint.weak(_worldPos.x, camera.height), + 1, 0xFF76BC02); + + DrawUtil.drawLine( + FlxPoint.weak(0, _worldPos.y), + FlxPoint.weak(camera.width, _worldPos.y), + 1, 0xFFD72C47); + } + } + + public override function destroy() { + super.destroy(); + _worldPos.put(); + } +} \ No newline at end of file diff --git a/source/funkin/editors/extra/DrawAxis.hx b/source/funkin/editors/extra/DrawAxis.hx deleted file mode 100644 index c3e2a0d9..00000000 --- a/source/funkin/editors/extra/DrawAxis.hx +++ /dev/null @@ -1,33 +0,0 @@ -package funkin.editors.extra; - -import openfl.display.Graphics; -import flixel.util.FlxSpriteUtil; - -class DrawAxis extends FlxObject { - public override function draw() { - super.draw(); - - /* - for (camera in cameras) { - var gfx:Graphics = FlxG.renderBlit ? { - FlxSpriteUtil.flashGfx.clear(); - FlxSpriteUtil.flashGfx; - } : camera.debugLayer.graphics; - - // Stole these colors directly from godot - gfx.lineStyle(2, 0xFF76BC02, 1); - - gfx.moveTo(-camera.scroll.x, camera.viewMarginTop); - gfx.lineTo(-camera.scroll.x, camera.viewMarginBottom); - - gfx.lineStyle(2, 0xFFD72C47, 1); - - gfx.moveTo(camera.viewMarginLeft, -camera.scroll.y); - gfx.lineTo(camera.viewMarginRight, -camera.scroll.y); - - if (FlxG.renderBlit) - camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); - } - */ - } -} \ No newline at end of file diff --git a/source/funkin/editors/stage/StageEditor.hx b/source/funkin/editors/stage/StageEditor.hx index f715d8e0..b596eb7a 100644 --- a/source/funkin/editors/stage/StageEditor.hx +++ b/source/funkin/editors/stage/StageEditor.hx @@ -427,7 +427,6 @@ class StageEditor extends UIState { override function destroy() { super.destroy(); nextScroll = FlxDestroyUtil.destroy(nextScroll); - DrawUtil.destroyDrawers(); if(Framerate.isLoaded) { Framerate.fpsCounter.alpha = 1; Framerate.memoryCounter.alpha = 1; diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index 34a9fc63..fb578b61 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -132,6 +132,7 @@ class UIState extends MusicBeatState { super.destroy(); __mousePos.put(); + DrawUtil.destroyDrawers(); WindowUtils.resetAffixes(); SaveWarning.reset(); diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index 07963143..c69ac57f 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -247,66 +247,9 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset super.draw(); postDraw(); - if (!ghostDraw) { - if (debugHitbox) drawHitbox(); - if (debugCamera) drawCamera(); - } - script.call("postDraw", [e]); } - public var debugHitbox:Bool = false; - public var debugCamera:Bool = false; - - public function drawHitbox() { - if (_matrix == null || frame == null) return; - - /* - for (camera in cameras) { - var gfx:Graphics = FlxG.renderBlit ? { - FlxSpriteUtil.flashGfx.clear(); - FlxSpriteUtil.flashGfx; - } : camera.debugLayer.graphics; - - _rect.set(_matrix.tx, _matrix.ty, frame.frame.width * _matrix.a, frame.frame.height * _matrix.d); - @:privateAccess _rect = camera.transformRect(_rect); - - gfx.lineStyle(2, 0xFF007B8F, 1); - gfx.drawRect(_rect.x, _rect.y, _rect.width, _rect.height); - - if (FlxG.renderBlit) - camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); - } - */ - } - - public function drawCamera() { - /* - for (camera in cameras) { - var gfx:Graphics = FlxG.renderBlit ? { - FlxSpriteUtil.flashGfx.clear(); - FlxSpriteUtil.flashGfx; - } : camera.debugLayer.graphics; - - var camPos:FlxPoint = getCameraPosition(); - camPos -= camera.scroll; - - gfx.lineStyle(2, 0xFF00A0B9, 1); - - gfx.moveTo(camPos.x - 8, camPos.y); - gfx.lineTo(camPos.x + 8, camPos.y); - - gfx.moveTo(camPos.x, camPos.y - 8); - gfx.lineTo(camPos.x, camPos.y + 8); - - camPos.put(); - - if (FlxG.renderBlit) - camera.buffer.draw(FlxSpriteUtil.flashGfxSprite); - } - */ - } - public var singAnims = ["singLEFT", "singDOWN", "singUP", "singRIGHT"]; public inline function getSingAnim(direction:Int, suffix:String = ""):String return singAnims[direction % singAnims.length] + suffix; diff --git a/source/funkin/options/Options.hx b/source/funkin/options/Options.hx index 054f3506..5ec8a90b 100644 --- a/source/funkin/options/Options.hx +++ b/source/funkin/options/Options.hx @@ -39,6 +39,9 @@ class Options public static var songOffset:Float = 0; public static var framerate:Int = 120; public static var gpuOnlyBitmaps:Bool = #if (mac || web) false #else true #end; // causes issues on mac and web + #if MODCHARTING_FEATURES + public static var modchartingHoldSubdivisions:Int = 4; + #end public static var lastLoadedMod:String = null; diff --git a/source/lime/_internal/backend/native/NativeApplication.hx b/source/lime/_internal/backend/native/NativeApplication.hx index 63466a42..ac8ab467 100644 --- a/source/lime/_internal/backend/native/NativeApplication.hx +++ b/source/lime/_internal/backend/native/NativeApplication.hx @@ -226,9 +226,7 @@ class NativeApplication var joystick = Joystick.devices.get(joystickEventInfo.id); if (joystick != null) joystick.onHatMove.dispatch(joystickEventInfo.index, joystickEventInfo.eventValue); - case TRACKBALL_MOVE: - var joystick = Joystick.devices.get(joystickEventInfo.id); - if (joystick != null) joystick.onTrackballMove.dispatch(joystickEventInfo.index, joystickEventInfo.x, joystickEventInfo.y); + case TRACKBALL_MOVE: // I guess this was just removed ?? case BUTTON_DOWN: var joystick = Joystick.devices.get(joystickEventInfo.id);