From 282e93e1ffed1664a10440e0ae06d96dde2ab336 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 29 Apr 2022 23:46:41 -0400 Subject: [PATCH] character repositioning proof of concept stuf --- source/funkin/CoolUtil.hx | 32 ++++++-- source/funkin/play/PlayState.hx | 22 +++++- .../ui/stageBuildShit/StageOffsetSubstate.hx | 73 +++++++++++++++++++ 3 files changed, 117 insertions(+), 10 deletions(-) create mode 100644 source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx diff --git a/source/funkin/CoolUtil.hx b/source/funkin/CoolUtil.hx index 60e12f343..207638cc5 100644 --- a/source/funkin/CoolUtil.hx +++ b/source/funkin/CoolUtil.hx @@ -10,13 +10,13 @@ import flixel.math.FlxRect; import flixel.system.FlxAssets.FlxGraphicAsset; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; +import funkin.play.PlayState; +import funkin.shaderslmfao.ScreenWipeShader; import haxe.Json; import haxe.format.JsonParser; import lime.math.Rectangle; import lime.utils.Assets; import openfl.filters.ShaderFilter; -import funkin.play.PlayState; -import funkin.shaderslmfao.ScreenWipeShader; using StringTools; @@ -68,18 +68,34 @@ class CoolUtil static var oldCamPos:FlxPoint = new FlxPoint(); static var oldMousePos:FlxPoint = new FlxPoint(); - public static function mouseCamDrag():Void + /** + * Used to be for general camera middle click dragging, now generalized for any click and drag type shit! + * Listen I don't make the rules here + * @param target what you want to be dragged, defaults to CAMERA SCROLL + * @param jusPres the "justPressed", should be a button of some sort + * @param pressed the "pressed", which should be the same button as `jusPres` + */ + public static function mouseCamDrag(?target:FlxPoint, ?jusPres:Bool, ?pressed:Bool):Void { - if (FlxG.mouse.justPressedMiddle) + if (target == null) + target = FlxG.camera.scroll; + + if (jusPres == null) + jusPres = FlxG.mouse.justPressedMiddle; + + if (pressed == null) + pressed = FlxG.mouse.pressedMiddle; + + if (jusPres) { - oldCamPos.set(FlxG.camera.scroll.x, FlxG.camera.scroll.y); + oldCamPos.set(target.x, target.y); oldMousePos.set(FlxG.mouse.screenX, FlxG.mouse.screenY); } - if (FlxG.mouse.pressedMiddle) + if (pressed) { - FlxG.camera.scroll.x = oldCamPos.x - (FlxG.mouse.screenX - oldMousePos.x); - FlxG.camera.scroll.y = oldCamPos.y - (FlxG.mouse.screenY - oldMousePos.y); + target.x = oldCamPos.x - (FlxG.mouse.screenX - oldMousePos.x); + target.y = oldCamPos.y - (FlxG.mouse.screenY - oldMousePos.y); } } diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 87e8d9e69..b16d9f00a 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -41,6 +41,7 @@ import funkin.play.stage.Stage; import funkin.play.stage.StageData; import funkin.ui.PopUpStuff; import funkin.ui.PreferencesMenu; +import funkin.ui.stageBuildShit.StageOffsetSubstate; import funkin.util.Constants; import funkin.util.SortUtil; import lime.ui.Haptic; @@ -624,6 +625,15 @@ class PlayState extends MusicBeatState implements IHook super.debug_refreshModules(); } + /** + * Pauses music and vocals easily. + */ + public function pauseMusic() + { + FlxG.sound.music.pause(); + vocals.pause(); + } + /** * Loads stage data from cache, assembles the props, * and adds it to the state. @@ -939,6 +949,11 @@ class PlayState extends MusicBeatState implements IHook { super.update(elapsed); + if (FlxG.keys.justPressed.U) + { + openSubState(new StageOffsetSubstate()); + } + updateHealthBar(); updateScoreText(); @@ -1071,7 +1086,7 @@ class PlayState extends MusicBeatState implements IHook changeSection(-1); #end - if (camZooming) + if (camZooming && subState == null) { FlxG.camera.zoom = FlxMath.lerp(defaultCameraZoom, FlxG.camera.zoom, 0.95); camHUD.zoom = FlxMath.lerp(1 * FlxCamera.defaultZoom, camHUD.zoom, 0.95); @@ -1776,6 +1791,8 @@ class PlayState extends MusicBeatState implements IHook // That combo counter that got spoiled that one time. // Comes with NEAT visual and audio effects. + // bruh this var is bonkers i thot it was a function lmfaooo + var shouldShowComboText:Bool = (curBeat % 8 == 7) // End of measure. TODO: Is this always the correct time? && (SongLoad.getSong()[Std.int(curStep / 16)].mustHitSection) // Current section is BF's. && (combo > 5) // Don't want to show on small combos. @@ -1991,9 +2008,10 @@ class PlayState extends MusicBeatState implements IHook /** * Resets the camera's zoom level and focus point. */ - function resetCamera():Void + public function resetCamera():Void { FlxG.camera.follow(cameraFollowPoint, LOCKON, 0.04); + FlxG.camera.targetOffset.set(); FlxG.camera.zoom = defaultCameraZoom; FlxG.camera.focusOn(cameraFollowPoint.getPosition()); } diff --git a/source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx b/source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx new file mode 100644 index 000000000..b642265e2 --- /dev/null +++ b/source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx @@ -0,0 +1,73 @@ +package funkin.ui.stageBuildShit; + +import flixel.math.FlxPoint; +import flixel.ui.FlxButton; +import funkin.play.PlayState; + +class StageOffsetSubstate extends MusicBeatSubstate +{ + public function new() + { + super(); + FlxG.mouse.visible = true; + PlayState.instance.pauseMusic(); + FlxG.camera.target = null; + + var btn:FlxButton = new FlxButton(10, 10, "SAVE COMPILE", function() + { + // put character position data to a file of some sort + }); + btn.scrollFactor.set(); + add(btn); + } + + var mosPosOld:FlxPoint = new FlxPoint(); + var sprOld:FlxPoint = new FlxPoint(); + + override function update(elapsed:Float) + { + super.update(elapsed); + + CoolUtil.mouseCamDrag(); + + if (FlxG.keys.pressed.CONTROL) + CoolUtil.mouseWheelZoom(); + + if (FlxG.mouse.pressed) + { + if (FlxG.mouse.justPressed) + { + sprOld.x = PlayState.instance.currentStage.getBoyfriend().x; + sprOld.y = PlayState.instance.currentStage.getBoyfriend().y; + + mosPosOld.x = FlxG.mouse.x; + mosPosOld.y = FlxG.mouse.y; + } + + PlayState.instance.currentStage.getBoyfriend().x = sprOld.x - (mosPosOld.x - FlxG.mouse.x); + PlayState.instance.currentStage.getBoyfriend().y = sprOld.y - (mosPosOld.y - FlxG.mouse.y); + } + + if (FlxG.mouse.pressedRight) + { + if (FlxG.mouse.justPressedRight) + { + sprOld.x = PlayState.instance.currentStage.getDad().x; + sprOld.y = PlayState.instance.currentStage.getDad().y; + + mosPosOld.x = FlxG.mouse.x; + mosPosOld.y = FlxG.mouse.y; + } + + PlayState.instance.currentStage.getDad().x = sprOld.x - (mosPosOld.x - FlxG.mouse.x); + PlayState.instance.currentStage.getDad().y = sprOld.y - (mosPosOld.y - FlxG.mouse.y); + } + + if (FlxG.keys.justPressed.Y) + { + PlayState.instance.resetCamera(); + FlxG.mouse.visible = false; + close(); + } + } +}