mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-05 06:14:36 +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
|
class SprStage extends FlxSprite
|
||||||
{
|
{
|
||||||
public var layer:Int = 0;
|
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);
|
super(x, y);
|
||||||
|
|
||||||
FlxMouseEventManager.add(this, dragShit, null, function(spr:SprStage)
|
FlxMouseEventManager.add(this, dragShitFunc, null, function(spr:SprStage)
|
||||||
{
|
{
|
||||||
if (isSelected() || StageBuilderState.curTool == SELECT)
|
if (isSelected() || StageBuilderState.curTool == SELECT)
|
||||||
alpha = 0.5;
|
alpha = 0.5;
|
||||||
|
@ -23,7 +26,7 @@ class SprStage extends FlxSprite
|
||||||
}, false, true, true);
|
}, false, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSelected():Bool
|
public function isSelected():Bool
|
||||||
{
|
{
|
||||||
return StageBuilderState.curSelectedSpr == this;
|
return StageBuilderState.curSelectedSpr == this;
|
||||||
}
|
}
|
||||||
|
@ -44,20 +47,4 @@ class SprStage extends FlxSprite
|
||||||
StageBuilderState.changeTool(GRAB);
|
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)
|
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.loadGraphic(Paths.image('stageBuild/stageTempImg'), false, 0, 0, true);
|
||||||
|
|
||||||
awesomeImg.layer = sprGrp.members.length;
|
awesomeImg.layer = sprGrp.members.length;
|
||||||
|
@ -223,6 +223,7 @@ class StageBuilderState extends MusicBeatState
|
||||||
|
|
||||||
if (FlxG.keys.justPressed.Z && actionQueue.length > 0)
|
if (FlxG.keys.justPressed.Z && actionQueue.length > 0)
|
||||||
{
|
{
|
||||||
|
trace('UNDO - QUEUE LENGTH: ' + actionQueue.length);
|
||||||
isUndoRedo = true;
|
isUndoRedo = true;
|
||||||
actionQueue.pop()(posQueue.pop());
|
actionQueue.pop()(posQueue.pop());
|
||||||
}
|
}
|
||||||
|
@ -236,6 +237,7 @@ class StageBuilderState extends MusicBeatState
|
||||||
|
|
||||||
switch (curTool)
|
switch (curTool)
|
||||||
{
|
{
|
||||||
|
// redo this later so it doesn't create brand new FlxSprites into memory or someshit??? this was lazy 3AM way
|
||||||
case SELECT:
|
case SELECT:
|
||||||
FlxG.mouse.load(new FlxSprite().loadGraphic(Paths.image('stageBuild/cursorSelect')).pixels);
|
FlxG.mouse.load(new FlxSprite().loadGraphic(Paths.image('stageBuild/cursorSelect')).pixels);
|
||||||
case GRABBING:
|
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 isUndoRedo:Bool = false;
|
||||||
var actionQueue:Array<Dynamic->Void> = [];
|
var actionQueue:Array<Dynamic->Void> = [];
|
||||||
var posQueue:Array<Dynamic> = [];
|
var posQueue:Array<Dynamic> = [];
|
||||||
|
|
Loading…
Reference in a new issue