Added SpriteMapModifications for use in Form1
This commit is contained in:
@@ -13,6 +13,7 @@ using Microsoft.Xna;
|
||||
using System.IO;
|
||||
using QURO;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;
|
||||
using SpriteMapEditor.SpriteMapModifications;
|
||||
|
||||
|
||||
namespace SpriteMapEditor
|
||||
@@ -23,7 +24,6 @@ namespace SpriteMapEditor
|
||||
private List<SpriteMapRegion> selectedSprites;
|
||||
|
||||
private bool highlight = false;
|
||||
//private SpriteMapRegion currentSprite { get { return sprites[spriteList.SelectedIndices[0]]; } }
|
||||
private int zoomLevel = 3;
|
||||
|
||||
private bool loadingSprite = false;
|
||||
|
||||
@@ -58,11 +58,18 @@
|
||||
<Compile Include="Form1.Designer.cs">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="SpriteMapModifications\AddSprite.cs" />
|
||||
<Compile Include="SpriteMapModifications\ISpriteModification.cs" />
|
||||
<Compile Include="SpriteMapModifications\ModifyBounds.cs" />
|
||||
<Compile Include="PictureBoxWithInterpolationMode.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SpriteMapModifications\ModifyOrigin.cs" />
|
||||
<Compile Include="SpriteMapModifications\MoveBounds.cs" />
|
||||
<Compile Include="SpriteMapModifications\MoveSpriteListEntry.cs" />
|
||||
<Compile Include="SpriteMapModifications\RemoveSprite.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using QURO;
|
||||
|
||||
namespace SpriteMapEditor.SpriteMapModifications
|
||||
{
|
||||
class AddSprite : ISpriteMapModification
|
||||
{
|
||||
private readonly BindingList<SpriteMapRegion> allSprites;
|
||||
|
||||
private readonly SpriteMapRegion selectedSprite;
|
||||
|
||||
public AddSprite(BindingList<SpriteMapRegion> spriteList, SpriteMapRegion selected = null)
|
||||
{
|
||||
allSprites = spriteList;
|
||||
selectedSprite = selected;
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
if (selectedSprite != null)
|
||||
allSprites.Add(new SpriteMapRegion(selectedSprite.Name, selectedSprite.Bounds, selectedSprite.Origin));
|
||||
else
|
||||
allSprites.Add(new SpriteMapRegion());
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
allSprites.RemoveAt(allSprites.Count - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SpriteMapEditor.SpriteMapModifications
|
||||
{
|
||||
interface ISpriteMapModification
|
||||
{
|
||||
void Do();
|
||||
void Undo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using QURO;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace SpriteMapEditor.SpriteMapModifications
|
||||
{
|
||||
class ModifyBounds : ISpriteMapModification
|
||||
{
|
||||
private readonly List<SpriteMapRegion> sprites;
|
||||
|
||||
private readonly int newXPosition;
|
||||
private readonly int newYPosition;
|
||||
private readonly int newWidth;
|
||||
private readonly int newHeight;
|
||||
|
||||
private readonly List<Rectangle> oldBounds;
|
||||
|
||||
public ModifyBounds(List<SpriteMapRegion> spritesToModify, int x = -1, int y = -1, int width = -1, int height = -1)
|
||||
{
|
||||
sprites = spritesToModify;
|
||||
newXPosition = x;
|
||||
newYPosition = y;
|
||||
newWidth = width;
|
||||
newHeight = height;
|
||||
|
||||
oldBounds = new List<Rectangle>();
|
||||
|
||||
for(int index = 0; index < sprites.Count; index++)
|
||||
{
|
||||
oldBounds.Add(sprites[index].Bounds);
|
||||
}
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
for (int index = 0; index < sprites.Count; index++)
|
||||
{
|
||||
Rectangle newBounds = sprites[index].Bounds;
|
||||
|
||||
if (newXPosition > -1)
|
||||
newBounds.X = newXPosition;
|
||||
if (newYPosition > -1)
|
||||
newBounds.Y = newYPosition;
|
||||
if (newWidth > -1)
|
||||
newBounds.Width = newWidth;
|
||||
if (newHeight > -1)
|
||||
newBounds.Height = newHeight;
|
||||
|
||||
sprites[index].Bounds = newBounds;
|
||||
}
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
for (int index = 0; index < sprites.Count; index++)
|
||||
{
|
||||
sprites[index].Bounds = oldBounds[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using QURO;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace SpriteMapEditor.SpriteMapModifications
|
||||
{
|
||||
class ModifyOrigin : ISpriteMapModification
|
||||
{
|
||||
private readonly List<SpriteMapRegion> sprites;
|
||||
|
||||
private readonly int newOriginX;
|
||||
private readonly int newOriginY;
|
||||
|
||||
private readonly List<Vector2> oldOrigins;
|
||||
|
||||
public ModifyOrigin(List<SpriteMapRegion> spritesToEditOrigin, int x = -1, int y = -1)
|
||||
{
|
||||
sprites = spritesToEditOrigin;
|
||||
newOriginX = x;
|
||||
newOriginY = y;
|
||||
|
||||
oldOrigins = new List<Vector2>();
|
||||
for(int index = 0; index < sprites.Count; index++)
|
||||
{
|
||||
oldOrigins.Add(sprites[index].Origin);
|
||||
}
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
for (int index = 0; index < sprites.Count; index++)
|
||||
{
|
||||
var newOrigin = sprites[index].Origin;
|
||||
|
||||
if (newOriginX > -1)
|
||||
newOrigin.X = newOriginX;
|
||||
if (newOriginY > -1)
|
||||
newOrigin.Y = newOriginY;
|
||||
|
||||
sprites[index].Origin = newOrigin;
|
||||
}
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
for (int index = 0; index < sprites.Count; index++)
|
||||
{
|
||||
sprites[index].Origin = oldOrigins[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using QURO;
|
||||
|
||||
namespace SpriteMapEditor.SpriteMapModifications
|
||||
{
|
||||
class MoveBounds : ISpriteMapModification
|
||||
{
|
||||
private readonly List<SpriteMapRegion> sprites;
|
||||
|
||||
private readonly int xDiff;
|
||||
private readonly int yDiff;
|
||||
|
||||
public MoveBounds(List<SpriteMapRegion> spritesToMove, int xDifference, int yDifference)
|
||||
{
|
||||
sprites = spritesToMove;
|
||||
xDiff = xDifference;
|
||||
yDiff = yDifference;
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
foreach (SpriteMapRegion sprite in sprites)
|
||||
{
|
||||
var newBounds = sprite.Bounds;
|
||||
newBounds.X += xDiff;
|
||||
newBounds.Y += yDiff;
|
||||
sprite.Bounds = newBounds;
|
||||
}
|
||||
}
|
||||
public void Undo()
|
||||
{
|
||||
foreach (SpriteMapRegion sprite in sprites)
|
||||
{
|
||||
var newBounds = sprite.Bounds;
|
||||
newBounds.X -= xDiff;
|
||||
newBounds.Y -= yDiff;
|
||||
sprite.Bounds = newBounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using QURO;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SpriteMapEditor.SpriteMapModifications
|
||||
{
|
||||
class MoveSpriteListEntry : ISpriteMapModification
|
||||
{
|
||||
private readonly BindingList<SpriteMapRegion> allSprites;
|
||||
|
||||
private readonly int selectedIndex;
|
||||
private readonly int dir;
|
||||
|
||||
public MoveSpriteListEntry(BindingList<SpriteMapRegion> spriteList, int selection, int direction)
|
||||
{
|
||||
allSprites = spriteList;
|
||||
selectedIndex = selection;
|
||||
dir = Math.Sign(direction);
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
var movingSprite = allSprites[selectedIndex];
|
||||
allSprites.RemoveAt(selectedIndex);
|
||||
allSprites.Insert(selectedIndex + dir, movingSprite);
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
var movingSprite = allSprites[selectedIndex + dir];
|
||||
allSprites.RemoveAt(selectedIndex + dir);
|
||||
allSprites.Insert(selectedIndex, movingSprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using QURO;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SpriteMapEditor.SpriteMapModifications
|
||||
{
|
||||
class RemoveSprite : ISpriteMapModification
|
||||
{
|
||||
private readonly BindingList<SpriteMapRegion> allSprites;
|
||||
|
||||
private readonly int index;
|
||||
|
||||
private readonly SpriteMapRegion removedSprite;
|
||||
|
||||
public RemoveSprite(BindingList<SpriteMapRegion> spriteList, int indexToRemove)
|
||||
{
|
||||
allSprites = spriteList;
|
||||
index = indexToRemove;
|
||||
removedSprite = allSprites[index];
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
allSprites.RemoveAt(index);
|
||||
}
|
||||
|
||||
public void Undo()
|
||||
{
|
||||
allSprites.Insert(index, removedSprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user