dragging shit

This commit is contained in:
Cameron Taylor 2021-05-27 19:15:03 -04:00
parent be4b35938b
commit 3f53371f30
4 changed files with 122 additions and 3 deletions

View file

@ -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

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}