From 3f53371f30680a09fc3430dbbc93c0cf55bc1974 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Thu, 27 May 2021 19:15:03 -0400 Subject: [PATCH] dragging shit --- source/CoolUtil.hx | 6 ++ source/DebugBoundingState.hx | 64 ++++++++++++++++++- source/ui/stageBuildShit/SprStage.hx | 37 +++++++++++ source/ui/stageBuildShit/StageBuilderState.hx | 18 +++++- 4 files changed, 122 insertions(+), 3 deletions(-) diff --git a/source/CoolUtil.hx b/source/CoolUtil.hx index 648724d8e..4d76c9231 100644 --- a/source/CoolUtil.hx +++ b/source/CoolUtil.hx @@ -62,6 +62,12 @@ class CoolUtil } } + public static function mouseWheelZoom():Void + { + if (FlxG.mouse.wheel != 0) + FlxG.camera.zoom += FlxG.mouse.wheel * (0.1 * FlxG.camera.zoom); + } + /** Lerps camera, but accountsfor framerate shit? Right now it's simply for use to change the followLerp variable of a camera during update diff --git a/source/DebugBoundingState.hx b/source/DebugBoundingState.hx index ef89d3300..7a8a1bef7 100644 --- a/source/DebugBoundingState.hx +++ b/source/DebugBoundingState.hx @@ -1,18 +1,37 @@ package; +import flixel.FlxCamera; import flixel.FlxG; import flixel.FlxSprite; import flixel.FlxState; import flixel.addons.display.FlxGridOverlay; import flixel.graphics.frames.FlxAtlasFrames; +import flixel.group.FlxGroup; +import flixel.text.FlxText; +import flixel.util.FlxColor; +import flixel.util.FlxSpriteUtil; import openfl.Assets; import sys.io.File; +using flixel.util.FlxSpriteUtil; + class DebugBoundingState extends FlxState { + var bg:FlxSprite; + var fileInfo:FlxText; + + var txtGrp:FlxGroup; + + var hudCam:FlxCamera; + override function create() { - var bg:FlxSprite = FlxGridOverlay.create(10, 10); + hudCam = new FlxCamera(); + hudCam.bgColor.alpha = 0; + + FlxG.cameras.add(hudCam, false); + + bg = FlxGridOverlay.create(10, 10); bg.scrollFactor.set(); add(bg); @@ -24,6 +43,32 @@ class DebugBoundingState extends FlxState bf.loadGraphic(tex.parent); add(bf); + var swagGraphic:FlxSprite = new FlxSprite().makeGraphic(tex.parent.width, tex.parent.height, FlxColor.TRANSPARENT); + + for (i in tex.frames) + { + var lineStyle:LineStyle = {color: FlxColor.RED, thickness: 2}; + + var uvW:Float = (i.uv.width * i.parent.width) - (i.uv.x * i.parent.width); + var uvH:Float = (i.uv.height * i.parent.height) - (i.uv.y * i.parent.height); + + // trace(Std.int(i.uv.width * i.parent.width)); + swagGraphic.drawRect(i.uv.x * i.parent.width, i.uv.y * i.parent.height, uvW, uvH, FlxColor.TRANSPARENT, lineStyle); + // swagGraphic.setPosition(, ); + // trace(uvH); + } + + txtGrp = new FlxGroup(); + txtGrp.cameras = [hudCam]; + add(txtGrp); + + addInfo('boyfriend.xml', ""); + addInfo('Width', bf.width); + addInfo('Height', bf.height); + + swagGraphic.antialiasing = true; + add(swagGraphic); + FlxG.stage.window.onDropFile.add(function(path:String) { trace("DROPPED FILE FROM: " + Std.string(path)); @@ -44,9 +89,26 @@ class DebugBoundingState extends FlxState super.create(); } + function addInfo(str:String, value:Dynamic) + { + var swagText:FlxText = new FlxText(10, 10 + (28 * txtGrp.length)); + swagText.setFormat(Paths.font("vcr.ttf"), 26, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK); + swagText.scrollFactor.set(); + txtGrp.add(swagText); + + swagText.text = str + ": " + Std.string(value); + } + override function update(elapsed:Float) { CoolUtil.mouseCamDrag(); + CoolUtil.mouseWheelZoom(); + + // bg.scale.x = FlxG.camera.zoom; + // bg.scale.y = FlxG.camera.zoom; + + bg.setGraphicSize(Std.int(bg.width / FlxG.camera.zoom)); + super.update(elapsed); } } diff --git a/source/ui/stageBuildShit/SprStage.hx b/source/ui/stageBuildShit/SprStage.hx index 9cc961650..4f46805c6 100644 --- a/source/ui/stageBuildShit/SprStage.hx +++ b/source/ui/stageBuildShit/SprStage.hx @@ -1,11 +1,48 @@ package ui.stageBuildShit; +import flixel.FlxG; import flixel.FlxSprite; +import flixel.input.mouse.FlxMouseEventManager; +import flixel.math.FlxPoint; class SprStage extends FlxSprite { public function new(?x:Float = 0, ?y:Float = 0) { super(x, y); + + FlxMouseEventManager.add(this, dragShit, null, function(spr:SprStage) + { + alpha = 0.5; + }, function(spr:SprStage) + { + alpha = 1; + }, false, true, true); + } + + override function update(elapsed:Float) + { + super.update(elapsed); + + if (mousePressing) + { + this.x = FlxG.mouse.x - mouseOffset.x; + this.y = FlxG.mouse.y - mouseOffset.y; + } + + if (FlxG.mouse.justReleased) + { + mousePressing = false; + } + } + + public var mousePressing:Bool = false; + + private var mouseOffset:FlxPoint = FlxPoint.get(0, 0); + + function dragShit(spr:SprStage) + { + mousePressing = true; + mouseOffset.set(FlxG.mouse.x - this.x, FlxG.mouse.y - this.y); } } diff --git a/source/ui/stageBuildShit/StageBuilderState.hx b/source/ui/stageBuildShit/StageBuilderState.hx index d0c00edf7..d757625c2 100644 --- a/source/ui/stageBuildShit/StageBuilderState.hx +++ b/source/ui/stageBuildShit/StageBuilderState.hx @@ -4,6 +4,8 @@ import flixel.FlxG; import flixel.FlxSprite; import flixel.addons.display.FlxGridOverlay; import flixel.group.FlxGroup; +import flixel.input.mouse.FlxMouseButton.FlxMouseButtonID; +import flixel.input.mouse.FlxMouseEventManager; import flixel.math.FlxPoint; import flixel.ui.FlxButton; import flixel.util.FlxTimer; @@ -75,6 +77,8 @@ class StageBuilderState extends MusicBeatState var saveSceneBtn:FlxButton = new FlxButton(20, 50, "Save Scene", saveScene); hudGrp.add(saveSceneBtn); + FlxMouseEventManager.init(); + #if desktop FlxG.stage.window.onDropFile.add(function(path:String) { @@ -95,12 +99,14 @@ class StageBuilderState extends MusicBeatState fo.write(sys.io.File.getBytes(path)); - new FlxTimer().start(1, function(tmr) + new FlxTimer().start(0.2, function(tmr) { - var awesomeImg:SprStage = new SprStage(); + var awesomeImg:SprStage = new SprStage(FlxG.mouse.x, FlxG.mouse.y); awesomeImg.loadGraphic(Paths.image('stageBuild/stageTempImg'), false, 0, 0, true); sprGrp.add(awesomeImg); + + // FlxMouseEventManager.add(awesomeImg, swagMousePress, null, null, null, false, true, false, [FlxMouseButtonID.LEFT, FlxMouseButtonID.RIGHT]); }); // Load the image shit by @@ -121,6 +127,11 @@ class StageBuilderState extends MusicBeatState #end } + function swagMousePress(spr:SprStage) + { + // spr.setPosition(FlxG.mouse.x, FlxG.mouse.y); + } + function loadImage():Void { var img:FlxSprite = new FlxSprite().loadGraphic(Paths.image('newgrounds_logo')); @@ -140,6 +151,9 @@ class StageBuilderState extends MusicBeatState CoolUtil.mouseCamDrag(); + if (FlxG.keys.pressed.CONTROL) + CoolUtil.mouseWheelZoom(); + super.update(elapsed); } }