mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-08-20 15:35:13 +00:00
undo/redo selections
This commit is contained in:
parent
65d187f511
commit
1f91c3bdef
|
@ -8,12 +8,15 @@ import flixel.math.FlxPoint;
|
|||
class SprStage extends FlxSprite
|
||||
{
|
||||
public var layer:Int = 0;
|
||||
public var mousePressing:Bool = false;
|
||||
|
||||
public function new(?x:Float = 0, ?y:Float = 0)
|
||||
public var mouseOffset:FlxPoint = FlxPoint.get(0, 0);
|
||||
|
||||
public function new(?x:Float = 0, ?y:Float = 0, dragShitFunc:SprStage->Void)
|
||||
{
|
||||
super(x, y);
|
||||
|
||||
FlxMouseEventManager.add(this, dragShit, null, function(spr:SprStage)
|
||||
FlxMouseEventManager.add(this, dragShitFunc, null, function(spr:SprStage)
|
||||
{
|
||||
if (isSelected() || StageBuilderState.curTool == SELECT)
|
||||
alpha = 0.5;
|
||||
|
@ -23,7 +26,7 @@ class SprStage extends FlxSprite
|
|||
}, false, true, true);
|
||||
}
|
||||
|
||||
function isSelected():Bool
|
||||
public function isSelected():Bool
|
||||
{
|
||||
return StageBuilderState.curSelectedSpr == this;
|
||||
}
|
||||
|
@ -44,20 +47,4 @@ class SprStage extends FlxSprite
|
|||
StageBuilderState.changeTool(GRAB);
|
||||
}
|
||||
}
|
||||
|
||||
public var mousePressing:Bool = false;
|
||||
|
||||
private var mouseOffset:FlxPoint = FlxPoint.get(0, 0);
|
||||
|
||||
function dragShit(spr:SprStage)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ class StageBuilderState extends MusicBeatState
|
|||
|
||||
new FlxTimer().start(0.2, function(tmr)
|
||||
{
|
||||
var awesomeImg:SprStage = new SprStage(FlxG.mouse.x, FlxG.mouse.y);
|
||||
var awesomeImg:SprStage = new SprStage(FlxG.mouse.x, FlxG.mouse.y, sprDragShitFunc);
|
||||
awesomeImg.loadGraphic(Paths.image('stageBuild/stageTempImg'), false, 0, 0, true);
|
||||
|
||||
awesomeImg.layer = sprGrp.members.length;
|
||||
|
@ -223,6 +223,7 @@ class StageBuilderState extends MusicBeatState
|
|||
|
||||
if (FlxG.keys.justPressed.Z && actionQueue.length > 0)
|
||||
{
|
||||
trace('UNDO - QUEUE LENGTH: ' + actionQueue.length);
|
||||
isUndoRedo = true;
|
||||
actionQueue.pop()(posQueue.pop());
|
||||
}
|
||||
|
@ -236,6 +237,7 @@ class StageBuilderState extends MusicBeatState
|
|||
|
||||
switch (curTool)
|
||||
{
|
||||
// redo this later so it doesn't create brand new FlxSprites into memory or someshit??? this was lazy 3AM way
|
||||
case SELECT:
|
||||
FlxG.mouse.load(new FlxSprite().loadGraphic(Paths.image('stageBuild/cursorSelect')).pixels);
|
||||
case GRABBING:
|
||||
|
@ -247,6 +249,34 @@ class StageBuilderState extends MusicBeatState
|
|||
}
|
||||
}
|
||||
|
||||
function changeCurSelected(spr:SprStage)
|
||||
{
|
||||
if (!isUndoRedo)
|
||||
{
|
||||
actionQueue.push(changeCurSelected);
|
||||
posQueue.push(curSelectedSpr);
|
||||
}
|
||||
else
|
||||
isUndoRedo = false;
|
||||
|
||||
curSelectedSpr = spr;
|
||||
}
|
||||
|
||||
function sprDragShitFunc(spr:SprStage)
|
||||
{
|
||||
if (curTool == SELECT)
|
||||
changeCurSelected(spr);
|
||||
|
||||
spr.mousePressing = true;
|
||||
|
||||
if (spr.isSelected())
|
||||
changeTool(GRABBING);
|
||||
spr.mouseOffset.set(FlxG.mouse.x - spr.x, FlxG.mouse.y - spr.y);
|
||||
}
|
||||
|
||||
// make function for changing cur selection
|
||||
function moveSprPos(xDiff:Float, yDiff:Float) {}
|
||||
|
||||
var isUndoRedo:Bool = false;
|
||||
var actionQueue:Array<Dynamic->Void> = [];
|
||||
var posQueue:Array<Dynamic> = [];
|
||||
|
|
Loading…
Reference in a new issue