From 30a6db615b8bc4fbafaf00179740f5129df55961 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sun, 16 May 2021 19:17:58 -0400 Subject: [PATCH] middle click drag --- Project.xml | 8 +-- source/TitleState.hx | 3 + source/ui/StageBuilderState.hx | 20 ------ source/ui/stageBuildShit/StageBuilderState.hx | 61 +++++++++++++++++++ 4 files changed, 68 insertions(+), 24 deletions(-) delete mode 100644 source/ui/StageBuilderState.hx create mode 100644 source/ui/stageBuildShit/StageBuilderState.hx diff --git a/Project.xml b/Project.xml index 2a8392335..d5ee2d3a4 100644 --- a/Project.xml +++ b/Project.xml @@ -124,13 +124,13 @@ - + - - - + + + diff --git a/source/TitleState.hx b/source/TitleState.hx index 122422f10..97764574d 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -34,6 +34,7 @@ import shaderslmfao.BuildingShaders.BuildingShader; import shaderslmfao.BuildingShaders; import shaderslmfao.ColorSwap; import ui.PreferencesMenu; +import ui.stageBuildShit.StageBuilderState; using StringTools; @@ -152,6 +153,8 @@ class TitleState extends MusicBeatState */ // netConnection.addEventListener(MouseEvent.MOUSE_DOWN, overlay_onMouseDown); + #elseif STAGEBUILD + FlxG.switchState(new StageBuilderState()); #else new FlxTimer().start(1, function(tmr:FlxTimer) { diff --git a/source/ui/StageBuilderState.hx b/source/ui/StageBuilderState.hx deleted file mode 100644 index 35acf8125..000000000 --- a/source/ui/StageBuilderState.hx +++ /dev/null @@ -1,20 +0,0 @@ -package ui; - -import flixel.FlxSprite; -import flixel.addons.display.FlxGridOverlay; - -class StageBuilderState extends MusicBeatState -{ - public function new() - { - super(); - } - - override function create() - { - super.create(); - - var bg:FlxSprite = FlxGridOverlay.create(10, 10); - add(bg); - } -} diff --git a/source/ui/stageBuildShit/StageBuilderState.hx b/source/ui/stageBuildShit/StageBuilderState.hx new file mode 100644 index 000000000..413717f15 --- /dev/null +++ b/source/ui/stageBuildShit/StageBuilderState.hx @@ -0,0 +1,61 @@ +package ui.stageBuildShit; + +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.addons.display.FlxGridOverlay; +import flixel.group.FlxGroup; +import flixel.math.FlxPoint; +import flixel.ui.FlxButton; + +class StageBuilderState extends MusicBeatState +{ + private var hudGrp:FlxGroup; + + private var sprGrp:FlxGroup; + + override function create() + { + super.create(); + + FlxG.mouse.visible = true; + + var bg:FlxSprite = FlxGridOverlay.create(10, 10); + add(bg); + + sprGrp = new FlxGroup(); + add(sprGrp); + + hudGrp = new FlxGroup(); + add(hudGrp); + + var imgBtn:FlxButton = new FlxButton(20, 20, "Load Image", loadImage); + hudGrp.add(imgBtn); + } + + function loadImage():Void + { + var img:FlxSprite = new FlxSprite().loadGraphic(Paths.image('newgrounds_logo')); + img.scrollFactor.set(0.5, 2); + sprGrp.add(img); + } + + var oldCamPos:FlxPoint = new FlxPoint(); + var oldMousePos:FlxPoint = new FlxPoint(); + + override function update(elapsed:Float) + { + if (FlxG.mouse.justPressedMiddle) + { + oldCamPos.set(FlxG.camera.scroll.x, FlxG.camera.scroll.y); + oldMousePos.set(FlxG.mouse.screenX, FlxG.mouse.screenY); + } + + if (FlxG.mouse.pressedMiddle) + { + FlxG.camera.scroll.x = oldCamPos.x + (FlxG.mouse.screenX - oldMousePos.x); + FlxG.camera.scroll.y = oldCamPos.y + (FlxG.mouse.screenY - oldMousePos.y); + } + + super.update(elapsed); + } +}