Patched bug that caused Undoing MoveBounds operations to sometimes move sprite bounds out of range

This commit is contained in:
quinnvoker
2018-12-02 15:13:01 -08:00
parent 07669c2ccb
commit c0c757650c
6 changed files with 96 additions and 73 deletions
@@ -35,7 +35,6 @@ namespace SpriteMapEditor.SpriteMapModifications
}
changes.Add(change);
position = changes.Count - 1;
//Console.WriteLine("Available Undo Steps: " + changes.Count + "; Current Undo Position: " + position);
}
public void Undo()
@@ -51,6 +50,7 @@ namespace SpriteMapEditor.SpriteMapModifications
{
if (CanUndo)
{
Console.Write("Hist.Pos(" + position + "): ");
ModHelper.UndoAndRestoreSelection(changes[position], listBox);
position--;
}
@@ -69,6 +69,7 @@ namespace SpriteMapEditor.SpriteMapModifications
{
if (CanRedo)
{
Console.Write("Hist.Pos(" + position + "): ");
ModHelper.RedoAndRestoreSelection(changes[position + 1], listBox);
position++;
}
@@ -16,18 +16,21 @@ namespace SpriteMapEditor.SpriteMapModifications
mod.SetPreChangeSelection(GetSelectionList(listBox));
mod.Do();
mod.SetPostChangeSelection(GetSelectionList(listBox));
Console.WriteLine("Perform: " + mod);
}
public static void UndoAndRestoreSelection(SpriteMapModifications.ISpriteMapModification mod, ListBox listBox)
{
mod.Undo();
SelectFromList(listBox, mod.GetPreChangeSelection());
Console.WriteLine("Undo: " + mod);
}
public static void RedoAndRestoreSelection(SpriteMapModifications.ISpriteMapModification mod, ListBox listBox)
{
mod.Do();
SelectFromList(listBox, mod.GetPostChangeSelection());
Console.WriteLine("Redo: " + mod);
}
public static List<int> GetSelectionList(ListBox listBox)
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QURO;
using Microsoft.Xna.Framework;
namespace SpriteMapEditor.SpriteMapModifications
{
@@ -13,15 +14,17 @@ namespace SpriteMapEditor.SpriteMapModifications
private readonly int xDiff;
private readonly int yDiff;
private readonly List<Rectangle> oldBoundsList;
private List<int> preChangeSelection;
private List<int> postChangeSelection;
public MoveBounds(List<SpriteMapRegion> spritesToMove, int xDifference, int yDifference)
public MoveBounds(List<SpriteMapRegion> spritesToMove, int xDifference, int yDifference, List<Rectangle> preDragBounds = null)
{
sprites = spritesToMove.ToList();
xDiff = xDifference;
yDiff = yDifference;
oldBoundsList = preDragBounds.ToList();
}
public void Do()
@@ -36,12 +39,22 @@ namespace SpriteMapEditor.SpriteMapModifications
}
public void Undo()
{
foreach (SpriteMapRegion sprite in sprites)
if (oldBoundsList != null)
{
var newBounds = sprite.Bounds;
newBounds.X -= xDiff;
newBounds.Y -= yDiff;
sprite.Bounds = newBounds;
for(int index = 0; index < sprites.Count; index++)
{
sprites[index].Bounds = oldBoundsList[index];
}
}
else
{
foreach (SpriteMapRegion sprite in sprites)
{
var newBounds = sprite.Bounds;
newBounds.X -= xDiff;
newBounds.Y -= yDiff;
sprite.Bounds = newBounds;
}
}
}
@@ -64,7 +77,7 @@ namespace SpriteMapEditor.SpriteMapModifications
public override string ToString()
{
return "Move Sprite Bounds";
return "Move Sprite Bounds: (" + xDiff + ", " + yDiff + "), New Position of "+ sprites[0].Name +": (" + (sprites[0].Bounds.X) + ", " + (sprites[0].Bounds.Y) + ")";
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpriteMapEditor.SpriteMapModifications
{
public enum OriginPreset
{
TopLeft,
Top,
TopRight,
Left,
Center,
Right,
BottomLeft,
Bottom,
BottomRight
}
}