diff --git a/source/ui/stageBuildShit/SprStage.hx b/source/ui/stageBuildShit/SprStage.hx index d9339c5ff..5860531e7 100644 --- a/source/ui/stageBuildShit/SprStage.hx +++ b/source/ui/stageBuildShit/SprStage.hx @@ -15,7 +15,7 @@ class SprStage extends FlxSprite FlxMouseEventManager.add(this, dragShit, null, function(spr:SprStage) { - if (FlxG.keys.pressed.CONTROL) + if (isSelected() || StageBuilderState.curTool == SELECT) alpha = 0.5; }, function(spr:SprStage) { @@ -23,11 +23,16 @@ class SprStage extends FlxSprite }, false, true, true); } + function isSelected():Bool + { + return StageBuilderState.curSelectedSpr == this; + } + override function update(elapsed:Float) { super.update(elapsed); - if (mousePressing) + if (mousePressing && isSelected()) { this.x = FlxG.mouse.x - mouseOffset.x; this.y = FlxG.mouse.y - mouseOffset.y; @@ -36,6 +41,7 @@ class SprStage extends FlxSprite if (FlxG.mouse.justReleased) { mousePressing = false; + StageBuilderState.changeTool(GRAB); } } @@ -45,11 +51,13 @@ class SprStage extends FlxSprite function dragShit(spr:SprStage) { - if (FlxG.keys.pressed.CONTROL) + if (StageBuilderState.curTool == SELECT) StageBuilderState.curSelectedSpr = this; mousePressing = true; + if (isSelected()) + StageBuilderState.changeTool(GRABBING); 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 573b6e98c..28be7e614 100644 --- a/source/ui/stageBuildShit/StageBuilderState.hx +++ b/source/ui/stageBuildShit/StageBuilderState.hx @@ -142,10 +142,27 @@ class StageBuilderState extends MusicBeatState // trace(); } + public static var curTool:TOOLS = SELECT; + + var tempTool:TOOLS = SELECT; + override function update(elapsed:Float) { - // trace(sndChannel.position); - // trace(snd + if (FlxG.keys.justPressed.CONTROL) + { + tempTool = curTool; + + changeTool(SELECT); + } + if (FlxG.keys.justReleased.CONTROL) + { + changeTool(tempTool); + } + + if (FlxG.keys.justPressed.V) + { + changeTool(SELECT); + } if (FlxG.keys.justPressed.R) { @@ -163,14 +180,15 @@ class StageBuilderState extends MusicBeatState { if (curSelectedSpr != null) { - if (curSelectedSpr.layer != 0) - { - curSelectedSpr.layer -= 1; - sprGrp.members[curSelectedSpr.layer].layer += 1; - } - // NOTE: fix to account if only one layer is in? + moveLayer(1); + } + } - sortSprGrp(); + if (FlxG.keys.justPressed.DOWN) + { + if (curSelectedSpr != null) + { + moveLayer(-1); } } @@ -203,9 +221,56 @@ class StageBuilderState extends MusicBeatState } } + if (FlxG.keys.justPressed.Z && actionQueue.length > 0) + { + isUndoRedo = true; + actionQueue.pop()(posQueue.pop()); + } + super.update(elapsed); } + static public function changeTool(newTool:TOOLS) + { + curTool = newTool; + + switch (curTool) + { + case SELECT: + FlxG.mouse.load(new FlxSprite().loadGraphic(Paths.image('stageBuild/cursorSelect')).pixels); + case GRABBING: + FlxG.mouse.load(new FlxSprite().loadGraphic(Paths.image('stageBuild/cursorGrabbing')).pixels); + case GRAB: + FlxG.mouse.load(new FlxSprite().loadGraphic(Paths.image('stageBuild/cursorGrab')).pixels); + default: + trace('swag'); + } + } + + var isUndoRedo:Bool = false; + var actionQueue:ArrayVoid> = []; + var posQueue:Array = []; + + function moveLayer(layerMovement:Int = 0):Void + { + if (curSelectedSpr.layer == 0 && layerMovement > 0) + return; + + curSelectedSpr.layer -= layerMovement; + sprGrp.members[curSelectedSpr.layer].layer += layerMovement; + // NOTE: fix to account if only one layer is in? + + sortSprGrp(); + + if (!isUndoRedo) + { + actionQueue.push(moveLayer); + posQueue.push(layerMovement * -1); + } + else + isUndoRedo = false; + } + var isShaking:Bool = false; var shakeIntensity:Float = 60; var shakePos:FlxPoint = new FlxPoint(); @@ -231,3 +296,11 @@ class StageBuilderState extends MusicBeatState return FlxSort.byValues(FlxSort.ASCENDING, layer1.layer, layer2.layer); } } + +enum TOOLS +{ + SELECT; + MOVE; + GRAB; + GRABBING; +}