Restruct: QURO << QURO.Animation; SpriteMapRegion -> Sprite: Now can draw itself
This commit is contained in:
@@ -152,10 +152,6 @@
|
|||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\QURO.AnimationLibrary\QURO.AnimationLibrary.csproj">
|
|
||||||
<Project>{69dadc27-fbeb-4625-9212-6eb5bed5102a}</Project>
|
|
||||||
<Name>QURO.AnimationLibrary</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
<ProjectReference Include="..\QURO\QURO.csproj">
|
<ProjectReference Include="..\QURO\QURO.csproj">
|
||||||
<Project>{4581e0c8-b14a-454d-9a7b-52d37535e7e9}</Project>
|
<Project>{4581e0c8-b14a-454d-9a7b-52d37535e7e9}</Project>
|
||||||
<Name>QURO</Name>
|
<Name>QURO</Name>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MonoGame.Forms.Controls;
|
using MonoGame.Forms.Controls;
|
||||||
using QURO.AnimationLibrary;
|
using QURO.Animation;
|
||||||
|
|
||||||
namespace AnimationEditor
|
namespace AnimationEditor
|
||||||
{
|
{
|
||||||
|
|||||||
+14
-14
@@ -11,7 +11,7 @@ using System.IO;
|
|||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using QURO.AnimationLibrary;
|
using QURO.Animation;
|
||||||
using QURO;
|
using QURO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;
|
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;
|
||||||
@@ -23,9 +23,9 @@ namespace AnimationEditor
|
|||||||
private Texture2D spriteSheet;
|
private Texture2D spriteSheet;
|
||||||
private int frameRate;
|
private int frameRate;
|
||||||
|
|
||||||
private BindingList<SpriteMapRegion> sprites;
|
private BindingList<Sprite> sprites;
|
||||||
private BindingList<Frame> frames;
|
private BindingList<Frame> frames;
|
||||||
private BindingList<SpriteMapRegion> subSprites;
|
private BindingList<Sprite> subSprites;
|
||||||
private BindingList<Animation> animations;
|
private BindingList<Animation> animations;
|
||||||
|
|
||||||
private Animation currentAnimation;
|
private Animation currentAnimation;
|
||||||
@@ -82,7 +82,7 @@ namespace AnimationEditor
|
|||||||
{
|
{
|
||||||
if (spriteListBox.SelectedItem != null)
|
if (spriteListBox.SelectedItem != null)
|
||||||
{
|
{
|
||||||
AddFrame(new Frame((SpriteMapRegion)spriteListBox.SelectedItem, importDelay));
|
AddFrame(new Frame((Sprite)spriteListBox.SelectedItem, importDelay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ namespace AnimationEditor
|
|||||||
{
|
{
|
||||||
if (spriteListBox.SelectedItem != null)
|
if (spriteListBox.SelectedItem != null)
|
||||||
{
|
{
|
||||||
var currentSprite = (SpriteMapRegion)spriteListBox.SelectedItem;
|
var currentSprite = (Sprite)spriteListBox.SelectedItem;
|
||||||
Stream texture2DToImageStream = new MemoryStream();
|
Stream texture2DToImageStream = new MemoryStream();
|
||||||
Texture2DRegionExtractor.GetTexture2DFromRegion(spriteSheet, spriteSheet.GraphicsDevice, currentSprite.Bounds)
|
Texture2DRegionExtractor.GetTexture2DFromRegion(spriteSheet, spriteSheet.GraphicsDevice, currentSprite.Bounds)
|
||||||
.SaveAsPng(texture2DToImageStream, currentSprite.Bounds.Width, currentSprite.Bounds.Height);
|
.SaveAsPng(texture2DToImageStream, currentSprite.Bounds.Width, currentSprite.Bounds.Height);
|
||||||
@@ -177,9 +177,9 @@ namespace AnimationEditor
|
|||||||
}
|
}
|
||||||
subSpritePanel.Enabled = true;
|
subSpritePanel.Enabled = true;
|
||||||
if (currentFrame.SubSprites != null)
|
if (currentFrame.SubSprites != null)
|
||||||
subSprites = new BindingList<SpriteMapRegion>(currentFrame.SubSprites);
|
subSprites = new BindingList<Sprite>(currentFrame.SubSprites);
|
||||||
else
|
else
|
||||||
subSprites = new BindingList<SpriteMapRegion>();
|
subSprites = new BindingList<Sprite>();
|
||||||
subSpriteListBox.DataSource = subSprites;
|
subSpriteListBox.DataSource = subSprites;
|
||||||
subSpriteListBox.DisplayMember = "Name";
|
subSpriteListBox.DisplayMember = "Name";
|
||||||
UpdateFrameInformation();
|
UpdateFrameInformation();
|
||||||
@@ -221,18 +221,18 @@ namespace AnimationEditor
|
|||||||
LoadSpriteMapFromFile();
|
LoadSpriteMapFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<string, SpriteMapRegion> LoadSpriteMapFromFile()
|
private Dictionary<string, Sprite> LoadSpriteMapFromFile()
|
||||||
{
|
{
|
||||||
if (loadSpriteMapDialog.ShowDialog() == DialogResult.OK)
|
if (loadSpriteMapDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
Dictionary<string, SpriteMapRegion> loadedSpriteMap;
|
Dictionary<string, Sprite> loadedSpriteMap;
|
||||||
using (XmlReader xmlRead = XmlReader.Create(loadSpriteMapDialog.FileName))
|
using (XmlReader xmlRead = XmlReader.Create(loadSpriteMapDialog.FileName))
|
||||||
{
|
{
|
||||||
loadedSpriteMap = IntermediateSerializer.Deserialize<Dictionary<string, SpriteMapRegion>>(xmlRead, null);
|
loadedSpriteMap = IntermediateSerializer.Deserialize<Dictionary<string, Sprite>>(xmlRead, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprites = new BindingList<SpriteMapRegion>();
|
sprites = new BindingList<Sprite>();
|
||||||
foreach (KeyValuePair<string, SpriteMapRegion> sprite in loadedSpriteMap)
|
foreach (KeyValuePair<string, Sprite> sprite in loadedSpriteMap)
|
||||||
{
|
{
|
||||||
sprites.Add(sprite.Value);
|
sprites.Add(sprite.Value);
|
||||||
}
|
}
|
||||||
@@ -491,7 +491,7 @@ namespace AnimationEditor
|
|||||||
|
|
||||||
using(XmlReader xmlRead = XmlReader.Create(loadSpriteMapDialog.FileName))
|
using(XmlReader xmlRead = XmlReader.Create(loadSpriteMapDialog.FileName))
|
||||||
{
|
{
|
||||||
loadedSpriteMap = IntermediateSerializer.Deserialize<Dictionary<string, SpriteMapRegion>>(xmlRead, null);
|
loadedSpriteMap = IntermediateSerializer.Deserialize<Dictionary<string, Sprite>>(xmlRead, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
int updateCounter = 0;
|
int updateCounter = 0;
|
||||||
@@ -563,7 +563,7 @@ namespace AnimationEditor
|
|||||||
currentFrame.SubSpritePositions = new List<Vector2>();
|
currentFrame.SubSpritePositions = new List<Vector2>();
|
||||||
currentFrame.SubSpritePositions.Add(Vector2.Zero);
|
currentFrame.SubSpritePositions.Add(Vector2.Zero);
|
||||||
if (currentFrame.SubSprites == null)
|
if (currentFrame.SubSprites == null)
|
||||||
currentFrame.SubSprites = new List<SpriteMapRegion>();
|
currentFrame.SubSprites = new List<Sprite>();
|
||||||
currentFrame.SubSprites.Add(spriteToAdd);
|
currentFrame.SubSprites.Add(spriteToAdd);
|
||||||
subSprites.Add(spriteToAdd);
|
subSprites.Add(spriteToAdd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ VisualStudioVersion = 15.0.27703.2047
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuzzSwap", "PuzzSwap\PuzzSwap.csproj", "{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PuzzSwap", "PuzzSwap\PuzzSwap.csproj", "{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QURO.AnimationLibrary", "QURO.AnimationLibrary\QURO.AnimationLibrary.csproj", "{69DADC27-FBEB-4625-9212-6EB5BED5102A}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QURO", "QURO\QURO.csproj", "{4581E0C8-B14A-454D-9A7B-52D37535E7E9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QURO", "QURO\QURO.csproj", "{4581E0C8-B14A-454D-9A7B-52D37535E7E9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpriteMapEditor", "SpriteMapEditor\SpriteMapEditor.csproj", "{2AF6999F-93F0-4096-9BC1-863CEE5E7791}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpriteMapEditor", "SpriteMapEditor\SpriteMapEditor.csproj", "{2AF6999F-93F0-4096-9BC1-863CEE5E7791}"
|
||||||
@@ -23,10 +21,6 @@ Global
|
|||||||
{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}.Release|Any CPU.Build.0 = Release|Any CPU
|
{CD753795-0CB4-4F05-A0E7-2D2EFC968D82}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{69DADC27-FBEB-4625-9212-6EB5BED5102A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{69DADC27-FBEB-4625-9212-6EB5BED5102A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{69DADC27-FBEB-4625-9212-6EB5BED5102A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{69DADC27-FBEB-4625-9212-6EB5BED5102A}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{4581E0C8-B14A-454D-9A7B-52D37535E7E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{4581E0C8-B14A-454D-9A7B-52D37535E7E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{4581E0C8-B14A-454D-9A7B-52D37535E7E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4581E0C8-B14A-454D-9A7B-52D37535E7E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4581E0C8-B14A-454D-9A7B-52D37535E7E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4581E0C8-B14A-454D-9A7B-52D37535E7E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|||||||
@@ -1,112 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
|
||||||
using QURO;
|
|
||||||
|
|
||||||
namespace QURO.AnimationLibrary
|
|
||||||
{
|
|
||||||
public class AnimatedSprite
|
|
||||||
{
|
|
||||||
public Texture2D SpriteSheet { get; set; }
|
|
||||||
private Animation currentAnimation;
|
|
||||||
public Animation CurrentAnimation
|
|
||||||
{
|
|
||||||
get { return currentAnimation; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
currentAnimation = value;
|
|
||||||
finishedPlaying = false;
|
|
||||||
CurrentFrameIndex = 0;
|
|
||||||
timer = CurrentFrame.Delay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int CurrentFrameIndex { get; set; }
|
|
||||||
public Frame CurrentFrame => CurrentAnimation.Frames[CurrentFrameIndex];
|
|
||||||
|
|
||||||
private float timer;
|
|
||||||
private bool finishedPlaying;
|
|
||||||
|
|
||||||
public AnimatedSprite() { }
|
|
||||||
|
|
||||||
public AnimatedSprite(Texture2D spriteSheet, Animation startingAnimation)
|
|
||||||
{
|
|
||||||
SpriteSheet = spriteSheet;
|
|
||||||
CurrentAnimation = startingAnimation;
|
|
||||||
timer = CurrentFrame.Delay;
|
|
||||||
finishedPlaying = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
CurrentFrameIndex = 0;
|
|
||||||
finishedPlaying = false;
|
|
||||||
timer = CurrentFrame.Delay;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(GameTime gameTime)
|
|
||||||
{
|
|
||||||
if (!CurrentAnimation.IsStillImage && !finishedPlaying)
|
|
||||||
{
|
|
||||||
if (timer <= 0)
|
|
||||||
{
|
|
||||||
if (CurrentFrameIndex < CurrentAnimation.Frames.Length - 1)
|
|
||||||
{
|
|
||||||
CurrentFrameIndex++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (CurrentAnimation.IsLooping)
|
|
||||||
{
|
|
||||||
CurrentFrameIndex = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
finishedPlaying = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timer = CurrentFrame.Delay;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
timer -= (float)gameTime.ElapsedGameTime.TotalSeconds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color tint)
|
|
||||||
{
|
|
||||||
spriteBatch.Draw(SpriteSheet, position - CurrentFrame.Origin, CurrentFrame.Bounds, tint);
|
|
||||||
if (CurrentFrame.SubSprites != null)
|
|
||||||
DrawSubSprites(spriteBatch, position, tint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Vector2 spriteMapOffset, Color tint, bool offsetSubSprites = false)
|
|
||||||
{
|
|
||||||
Rectangle sourceRect = CurrentFrame.Bounds;
|
|
||||||
sourceRect.Offset(spriteMapOffset);
|
|
||||||
|
|
||||||
spriteBatch.Draw(SpriteSheet, position, sourceRect, tint);
|
|
||||||
if (CurrentFrame.SubSprites != null)
|
|
||||||
DrawSubSprites(spriteBatch, position, tint, offsetSubSprites? (Vector2?)spriteMapOffset : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DrawSubSprites(SpriteBatch spriteBatch, Vector2 position, Color tint, Vector2? spriteMapOffset = null)
|
|
||||||
{
|
|
||||||
if (CurrentFrame.SubSprites.Count != CurrentFrame.SubSpritePositions.Count)
|
|
||||||
{
|
|
||||||
System.Console.WriteLine("SubSpriteCount and SubSpritePositionCount are not equal! Skipping subsprites...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int index = 0; index < CurrentFrame.SubSprites.Count; index++)
|
|
||||||
{
|
|
||||||
var subSprite = CurrentFrame.SubSprites[index];
|
|
||||||
|
|
||||||
Rectangle sourceRect = subSprite.Bounds;
|
|
||||||
|
|
||||||
if (spriteMapOffset != null)
|
|
||||||
sourceRect.Offset((Vector2)spriteMapOffset);
|
|
||||||
|
|
||||||
spriteBatch.Draw(SpriteSheet, position - subSprite.Origin + CurrentFrame.SubSpritePositions[index], sourceRect, tint);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
using Microsoft.Xna.Framework;
|
|
||||||
|
|
||||||
namespace QURO.AnimationLibrary
|
|
||||||
{
|
|
||||||
public class Animation
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
public bool IsLooping { get; set; }
|
|
||||||
|
|
||||||
public Frame[] Frames { get; set; }
|
|
||||||
|
|
||||||
public bool IsStillImage => Frames.Length <= 1;
|
|
||||||
|
|
||||||
public Animation() : this("unnamed", new Frame[] { new Frame() }, false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Animation(string name, Frame[] frames, bool loop)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
Frames = frames;
|
|
||||||
IsLooping = loop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace QURO.AnimationLibrary
|
|
||||||
{
|
|
||||||
public class AnimationSet
|
|
||||||
{
|
|
||||||
public Dictionary<string, Animation> Anims;
|
|
||||||
|
|
||||||
public AnimationSet()
|
|
||||||
{
|
|
||||||
Anims = new Dictionary<string, Animation>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(Animation anim)
|
|
||||||
{
|
|
||||||
Anims.Add(anim.Name, anim);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove(Animation anim)
|
|
||||||
{
|
|
||||||
Anims.Remove(anim.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove(string animName)
|
|
||||||
{
|
|
||||||
Anims.Remove(animName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using QURO;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.Xna.Framework;
|
|
||||||
|
|
||||||
namespace QURO.AnimationLibrary
|
|
||||||
{
|
|
||||||
public class Frame
|
|
||||||
{
|
|
||||||
public SpriteMapRegion Sprite { get; set; }
|
|
||||||
public List<SpriteMapRegion> SubSprites { get; set; }
|
|
||||||
public List<Vector2> SubSpritePositions { get; set; }
|
|
||||||
|
|
||||||
public float Delay { get; set; }
|
|
||||||
|
|
||||||
public string Name { get { return Sprite.Name; } }
|
|
||||||
public Rectangle Bounds { get { return Sprite.Bounds; } }
|
|
||||||
public Vector2 Origin { get { return Sprite.Origin; } }
|
|
||||||
|
|
||||||
|
|
||||||
public Frame() : this(new SpriteMapRegion(), 0, null, null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Frame(SpriteMapRegion sprite, float delay) : this(sprite, delay, null, null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public Frame(SpriteMapRegion sprite, float delay, List<SpriteMapRegion> subSprites, List<Vector2> subSpritePositons)
|
|
||||||
{
|
|
||||||
Sprite = sprite;
|
|
||||||
Delay = delay;
|
|
||||||
SubSprites = subSprites;
|
|
||||||
SubSpritePositions = subSpritePositons;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+22
-22
@@ -23,8 +23,8 @@ namespace SpriteMapEditor
|
|||||||
{
|
{
|
||||||
private History undoHistory;
|
private History undoHistory;
|
||||||
|
|
||||||
private BindingList<SpriteMapRegion> sprites;
|
private BindingList<Sprite> sprites;
|
||||||
private List<SpriteMapRegion> selectedSprites;
|
private List<Sprite> selectedSprites;
|
||||||
|
|
||||||
private bool highlight = false;
|
private bool highlight = false;
|
||||||
private int zoomLevel = 3;
|
private int zoomLevel = 3;
|
||||||
@@ -96,8 +96,8 @@ namespace SpriteMapEditor
|
|||||||
spriteSheetViewer.Width = 1;
|
spriteSheetViewer.Width = 1;
|
||||||
spriteSheetViewer.Height = 1;
|
spriteSheetViewer.Height = 1;
|
||||||
|
|
||||||
sprites = new BindingList<SpriteMapRegion> { new SpriteMapRegion() };
|
sprites = new BindingList<Sprite> { new Sprite() };
|
||||||
selectedSprites = new List<SpriteMapRegion>();
|
selectedSprites = new List<Sprite>();
|
||||||
|
|
||||||
spriteList.DataSource = sprites;
|
spriteList.DataSource = sprites;
|
||||||
spriteList.DisplayMember = "Name";
|
spriteList.DisplayMember = "Name";
|
||||||
@@ -123,7 +123,7 @@ namespace SpriteMapEditor
|
|||||||
CurrentSpriteMapFileLocation = null;
|
CurrentSpriteMapFileLocation = null;
|
||||||
CurrentSpriteSheetFileLocation = null;
|
CurrentSpriteSheetFileLocation = null;
|
||||||
|
|
||||||
sprites = new BindingList<SpriteMapRegion>() { new SpriteMapRegion() };
|
sprites = new BindingList<Sprite>() { new Sprite() };
|
||||||
LoadSpriteSheet();
|
LoadSpriteSheet();
|
||||||
if (spriteSheet == null)
|
if (spriteSheet == null)
|
||||||
return;
|
return;
|
||||||
@@ -152,14 +152,14 @@ namespace SpriteMapEditor
|
|||||||
{
|
{
|
||||||
CurrentSpriteMapFileLocation = loadMapDialog.FileName;
|
CurrentSpriteMapFileLocation = loadMapDialog.FileName;
|
||||||
|
|
||||||
Dictionary<string, SpriteMapRegion> loadedSpriteMap;
|
Dictionary<string, Sprite> loadedSpriteMap;
|
||||||
using (XmlReader xmlRead = XmlReader.Create(CurrentSpriteMapFileLocation))
|
using (XmlReader xmlRead = XmlReader.Create(CurrentSpriteMapFileLocation))
|
||||||
{
|
{
|
||||||
loadedSpriteMap = IntermediateSerializer.Deserialize<Dictionary<string, SpriteMapRegion>>(xmlRead, null);
|
loadedSpriteMap = IntermediateSerializer.Deserialize<Dictionary<string, Sprite>>(xmlRead, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprites = new BindingList<SpriteMapRegion>();
|
sprites = new BindingList<Sprite>();
|
||||||
foreach (KeyValuePair<string, SpriteMapRegion> sprite in loadedSpriteMap)
|
foreach (KeyValuePair<string, Sprite> sprite in loadedSpriteMap)
|
||||||
{
|
{
|
||||||
sprites.Add(sprite.Value);
|
sprites.Add(sprite.Value);
|
||||||
}
|
}
|
||||||
@@ -210,7 +210,7 @@ namespace SpriteMapEditor
|
|||||||
|
|
||||||
importSpriteSheetToolStripMenuItem.Text = "Replace Sprite Sheet...";
|
importSpriteSheetToolStripMenuItem.Text = "Replace Sprite Sheet...";
|
||||||
|
|
||||||
sprites = new BindingList<SpriteMapRegion>(loadedProject.SpriteMap);
|
sprites = new BindingList<Sprite>(loadedProject.SpriteMap);
|
||||||
spriteList.DataSource = sprites;
|
spriteList.DataSource = sprites;
|
||||||
|
|
||||||
saveProjectToolStripMenuItem.Enabled = true;
|
saveProjectToolStripMenuItem.Enabled = true;
|
||||||
@@ -240,7 +240,7 @@ namespace SpriteMapEditor
|
|||||||
e.Graphics.DrawImage(highlightMask.Bitmap, highlightBounds);
|
e.Graphics.DrawImage(highlightMask.Bitmap, highlightBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (SpriteMapRegion currentSprite in selectedSprites)
|
foreach (Sprite currentSprite in selectedSprites)
|
||||||
{
|
{
|
||||||
DrawHighContrastOutline(GetDrawingRect(currentSprite.Bounds), e.Graphics);
|
DrawHighContrastOutline(GetDrawingRect(currentSprite.Bounds), e.Graphics);
|
||||||
DrawOriginPoint(currentSprite, e.Graphics);
|
DrawOriginPoint(currentSprite, e.Graphics);
|
||||||
@@ -265,7 +265,7 @@ namespace SpriteMapEditor
|
|||||||
}
|
}
|
||||||
else if(spriteList.SelectedIndices.Count > 0)
|
else if(spriteList.SelectedIndices.Count > 0)
|
||||||
{
|
{
|
||||||
SpriteMapRegion currentSprite = selectedSprites[0];
|
Sprite currentSprite = selectedSprites[0];
|
||||||
spriteNameBox.Text = currentSprite.Name;
|
spriteNameBox.Text = currentSprite.Name;
|
||||||
spriteXPosBox.Value = currentSprite.Bounds.X;
|
spriteXPosBox.Value = currentSprite.Bounds.X;
|
||||||
spriteXPosBox.Text = currentSprite.Bounds.X.ToString();
|
spriteXPosBox.Text = currentSprite.Bounds.X.ToString();
|
||||||
@@ -298,7 +298,7 @@ namespace SpriteMapEditor
|
|||||||
return drawingRect;
|
return drawingRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Point GetOriginDrawingPoint(SpriteMapRegion sprite)
|
private Point GetOriginDrawingPoint(Sprite sprite)
|
||||||
{
|
{
|
||||||
var drawingPoint = new Point(sprite.Bounds.X, sprite.Bounds.Y);
|
var drawingPoint = new Point(sprite.Bounds.X, sprite.Bounds.Y);
|
||||||
drawingPoint.X = drawingPoint.X * zoomLevel;
|
drawingPoint.X = drawingPoint.X * zoomLevel;
|
||||||
@@ -308,7 +308,7 @@ namespace SpriteMapEditor
|
|||||||
return drawingPoint;
|
return drawingPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawOriginPoint(SpriteMapRegion sprite, Graphics graphics)
|
private void DrawOriginPoint(Sprite sprite, Graphics graphics)
|
||||||
{
|
{
|
||||||
if (editingOrigin)
|
if (editingOrigin)
|
||||||
{
|
{
|
||||||
@@ -335,7 +335,7 @@ namespace SpriteMapEditor
|
|||||||
if (highlight)
|
if (highlight)
|
||||||
{
|
{
|
||||||
InitializeMask();
|
InitializeMask();
|
||||||
foreach (SpriteMapRegion currentSprite in selectedSprites)
|
foreach (Sprite currentSprite in selectedSprites)
|
||||||
{
|
{
|
||||||
var highlightRect = currentSprite.Bounds;
|
var highlightRect = currentSprite.Bounds;
|
||||||
|
|
||||||
@@ -518,7 +518,7 @@ namespace SpriteMapEditor
|
|||||||
Microsoft.Xna.Framework.Rectangle rightMost = selectedSprites[0].Bounds;
|
Microsoft.Xna.Framework.Rectangle rightMost = selectedSprites[0].Bounds;
|
||||||
Microsoft.Xna.Framework.Rectangle bottomMost = selectedSprites[0].Bounds;
|
Microsoft.Xna.Framework.Rectangle bottomMost = selectedSprites[0].Bounds;
|
||||||
|
|
||||||
foreach (SpriteMapRegion currentSprite in selectedSprites)
|
foreach (Sprite currentSprite in selectedSprites)
|
||||||
{
|
{
|
||||||
if (currentSprite.Bounds.X < leftMost.X)
|
if (currentSprite.Bounds.X < leftMost.X)
|
||||||
leftMost = currentSprite.Bounds;
|
leftMost = currentSprite.Bounds;
|
||||||
@@ -537,8 +537,8 @@ namespace SpriteMapEditor
|
|||||||
|
|
||||||
private void exportMapToolStripMenuItem_Click(object sender, EventArgs e)
|
private void exportMapToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var exportDict = new Dictionary<string, SpriteMapRegion>();
|
var exportDict = new Dictionary<string, Sprite>();
|
||||||
foreach (SpriteMapRegion sprite in sprites)
|
foreach (Sprite sprite in sprites)
|
||||||
{
|
{
|
||||||
if (exportDict.ContainsKey(sprite.Name))
|
if (exportDict.ContainsKey(sprite.Name))
|
||||||
{
|
{
|
||||||
@@ -577,7 +577,7 @@ namespace SpriteMapEditor
|
|||||||
|
|
||||||
bool hovering = false;
|
bool hovering = false;
|
||||||
|
|
||||||
foreach (SpriteMapRegion currentSprite in selectedSprites)
|
foreach (Sprite currentSprite in selectedSprites)
|
||||||
{
|
{
|
||||||
if (GetDrawingRect(currentSprite.Bounds).Contains(mousePosition))
|
if (GetDrawingRect(currentSprite.Bounds).Contains(mousePosition))
|
||||||
{
|
{
|
||||||
@@ -602,7 +602,7 @@ namespace SpriteMapEditor
|
|||||||
groupRect.Y + groupRect.Height + differenceY > spriteSheet.Height)
|
groupRect.Y + groupRect.Height + differenceY > spriteSheet.Height)
|
||||||
differenceY = 0;
|
differenceY = 0;
|
||||||
|
|
||||||
foreach (SpriteMapRegion spriteToMove in selectedSprites)
|
foreach (Sprite spriteToMove in selectedSprites)
|
||||||
{
|
{
|
||||||
var newBounds = spriteToMove.Bounds;
|
var newBounds = spriteToMove.Bounds;
|
||||||
newBounds.X += differenceX;
|
newBounds.X += differenceX;
|
||||||
@@ -626,13 +626,13 @@ namespace SpriteMapEditor
|
|||||||
|
|
||||||
Point mousePosition = new Point(e.X, e.Y);
|
Point mousePosition = new Point(e.X, e.Y);
|
||||||
|
|
||||||
foreach (SpriteMapRegion currentSprite in selectedSprites)
|
foreach (Sprite currentSprite in selectedSprites)
|
||||||
{
|
{
|
||||||
if (GetDrawingRect(currentSprite.Bounds).Contains(mousePosition))
|
if (GetDrawingRect(currentSprite.Bounds).Contains(mousePosition))
|
||||||
{
|
{
|
||||||
movingWithMouse = true;
|
movingWithMouse = true;
|
||||||
preDragBounds = new List<Microsoft.Xna.Framework.Rectangle>();
|
preDragBounds = new List<Microsoft.Xna.Framework.Rectangle>();
|
||||||
foreach (SpriteMapRegion sprite in selectedSprites)
|
foreach (Sprite sprite in selectedSprites)
|
||||||
{
|
{
|
||||||
preDragBounds.Add(sprite.Bounds);
|
preDragBounds.Add(sprite.Bounds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class AddSprite : ISpriteMapModification
|
class AddSprite : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly BindingList<SpriteMapRegion> allSprites;
|
private readonly BindingList<Sprite> allSprites;
|
||||||
|
|
||||||
private readonly SpriteMapRegion selectedSprite;
|
private readonly Sprite selectedSprite;
|
||||||
|
|
||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public AddSprite(BindingList<SpriteMapRegion> spriteList, SpriteMapRegion selected = null)
|
public AddSprite(BindingList<Sprite> spriteList, Sprite selected = null)
|
||||||
{
|
{
|
||||||
allSprites = spriteList;
|
allSprites = spriteList;
|
||||||
|
|
||||||
@@ -28,9 +28,9 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
public void Do()
|
public void Do()
|
||||||
{
|
{
|
||||||
if (selectedSprite != null)
|
if (selectedSprite != null)
|
||||||
allSprites.Add(new SpriteMapRegion(selectedSprite.Name, selectedSprite.Bounds, selectedSprite.Origin));
|
allSprites.Add(new Sprite(selectedSprite.Name, selectedSprite.Bounds, selectedSprite.Origin));
|
||||||
else
|
else
|
||||||
allSprites.Add(new SpriteMapRegion());
|
allSprites.Add(new Sprite());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Undo()
|
public void Undo()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class ApplyOriginPreset : ISpriteMapModification
|
class ApplyOriginPreset : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly List<SpriteMapRegion> sprites;
|
private readonly List<Sprite> sprites;
|
||||||
|
|
||||||
private readonly OriginPreset preset;
|
private readonly OriginPreset preset;
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public ApplyOriginPreset(List<SpriteMapRegion> spritesToEditOrigin, OriginPreset presetToApply)
|
public ApplyOriginPreset(List<Sprite> spritesToEditOrigin, OriginPreset presetToApply)
|
||||||
{
|
{
|
||||||
sprites = spritesToEditOrigin.ToList();
|
sprites = spritesToEditOrigin.ToList();
|
||||||
preset = presetToApply;
|
preset = presetToApply;
|
||||||
@@ -33,7 +33,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
|
|
||||||
public void Do()
|
public void Do()
|
||||||
{
|
{
|
||||||
foreach(SpriteMapRegion sprite in sprites)
|
foreach(Sprite sprite in sprites)
|
||||||
{
|
{
|
||||||
Vector2 newOrigin = sprite.Origin;
|
Vector2 newOrigin = sprite.Origin;
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
public static void SelectFromList(ListBox listBox, List<int> newSelection)
|
public static void SelectFromList(ListBox listBox, List<int> newSelection)
|
||||||
{
|
{
|
||||||
listBox.SelectedIndices.Clear();
|
listBox.SelectedIndices.Clear();
|
||||||
var source = (BindingList<SpriteMapRegion>)listBox.DataSource;
|
var source = (BindingList<Sprite>)listBox.DataSource;
|
||||||
foreach (int currentIndex in newSelection)
|
foreach (int currentIndex in newSelection)
|
||||||
{
|
{
|
||||||
if(currentIndex < source.Count)
|
if(currentIndex < source.Count)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class ModifyBounds : ISpriteMapModification
|
class ModifyBounds : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly List<SpriteMapRegion> sprites;
|
private readonly List<Sprite> sprites;
|
||||||
|
|
||||||
private readonly int newXPosition;
|
private readonly int newXPosition;
|
||||||
private readonly int newYPosition;
|
private readonly int newYPosition;
|
||||||
@@ -23,7 +23,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public ModifyBounds(List<SpriteMapRegion> spritesToModify, int x = -1, int y = -1, int width = -1, int height = -1)
|
public ModifyBounds(List<Sprite> spritesToModify, int x = -1, int y = -1, int width = -1, int height = -1)
|
||||||
{
|
{
|
||||||
sprites = spritesToModify.ToList();
|
sprites = spritesToModify.ToList();
|
||||||
newXPosition = x;
|
newXPosition = x;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class ModifyOrigin : ISpriteMapModification
|
class ModifyOrigin : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly List<SpriteMapRegion> sprites;
|
private readonly List<Sprite> sprites;
|
||||||
|
|
||||||
private readonly int newOriginX;
|
private readonly int newOriginX;
|
||||||
private readonly int newOriginY;
|
private readonly int newOriginY;
|
||||||
@@ -20,7 +20,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public ModifyOrigin(List<SpriteMapRegion> spritesToEditOrigin, int x = -1, int y = -1)
|
public ModifyOrigin(List<Sprite> spritesToEditOrigin, int x = -1, int y = -1)
|
||||||
{
|
{
|
||||||
sprites = spritesToEditOrigin.ToList();
|
sprites = spritesToEditOrigin.ToList();
|
||||||
newOriginX = x;
|
newOriginX = x;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class MoveBounds : ISpriteMapModification
|
class MoveBounds : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly List<SpriteMapRegion> sprites;
|
private readonly List<Sprite> sprites;
|
||||||
|
|
||||||
private readonly int xDiff;
|
private readonly int xDiff;
|
||||||
private readonly int yDiff;
|
private readonly int yDiff;
|
||||||
@@ -19,7 +19,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public MoveBounds(List<SpriteMapRegion> spritesToMove, int xDifference, int yDifference, List<Rectangle> preDragBounds = null)
|
public MoveBounds(List<Sprite> spritesToMove, int xDifference, int yDifference, List<Rectangle> preDragBounds = null)
|
||||||
{
|
{
|
||||||
sprites = spritesToMove.ToList();
|
sprites = spritesToMove.ToList();
|
||||||
xDiff = xDifference;
|
xDiff = xDifference;
|
||||||
@@ -29,7 +29,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
|
|
||||||
public void Do()
|
public void Do()
|
||||||
{
|
{
|
||||||
foreach (SpriteMapRegion sprite in sprites)
|
foreach (Sprite sprite in sprites)
|
||||||
{
|
{
|
||||||
var newBounds = sprite.Bounds;
|
var newBounds = sprite.Bounds;
|
||||||
newBounds.X += xDiff;
|
newBounds.X += xDiff;
|
||||||
@@ -48,7 +48,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (SpriteMapRegion sprite in sprites)
|
foreach (Sprite sprite in sprites)
|
||||||
{
|
{
|
||||||
var newBounds = sprite.Bounds;
|
var newBounds = sprite.Bounds;
|
||||||
newBounds.X -= xDiff;
|
newBounds.X -= xDiff;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class MoveSpriteListEntry : ISpriteMapModification
|
class MoveSpriteListEntry : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly BindingList<SpriteMapRegion> allSprites;
|
private readonly BindingList<Sprite> allSprites;
|
||||||
|
|
||||||
private readonly int selectedIndex;
|
private readonly int selectedIndex;
|
||||||
private readonly int dir;
|
private readonly int dir;
|
||||||
@@ -18,7 +18,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public MoveSpriteListEntry(BindingList<SpriteMapRegion> spriteList, int selection, int direction)
|
public MoveSpriteListEntry(BindingList<Sprite> spriteList, int selection, int direction)
|
||||||
{
|
{
|
||||||
allSprites = spriteList;
|
allSprites = spriteList;
|
||||||
selectedIndex = selection;
|
selectedIndex = selection;
|
||||||
|
|||||||
@@ -10,16 +10,16 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class RemoveSprite : ISpriteMapModification
|
class RemoveSprite : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly BindingList<SpriteMapRegion> allSprites;
|
private readonly BindingList<Sprite> allSprites;
|
||||||
|
|
||||||
private readonly int index;
|
private readonly int index;
|
||||||
|
|
||||||
private readonly SpriteMapRegion removedSprite;
|
private readonly Sprite removedSprite;
|
||||||
|
|
||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public RemoveSprite(BindingList<SpriteMapRegion> spriteList, int indexToRemove)
|
public RemoveSprite(BindingList<Sprite> spriteList, int indexToRemove)
|
||||||
{
|
{
|
||||||
allSprites = spriteList;
|
allSprites = spriteList;
|
||||||
index = indexToRemove;
|
index = indexToRemove;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
{
|
{
|
||||||
class RenameSprite : ISpriteMapModification
|
class RenameSprite : ISpriteMapModification
|
||||||
{
|
{
|
||||||
private readonly SpriteMapRegion sprite;
|
private readonly Sprite sprite;
|
||||||
|
|
||||||
private readonly string newName;
|
private readonly string newName;
|
||||||
private readonly string oldName;
|
private readonly string oldName;
|
||||||
@@ -17,7 +17,7 @@ namespace SpriteMapEditor.SpriteMapModifications
|
|||||||
private List<int> preChangeSelection;
|
private List<int> preChangeSelection;
|
||||||
private List<int> postChangeSelection;
|
private List<int> postChangeSelection;
|
||||||
|
|
||||||
public RenameSprite(SpriteMapRegion spriteToRename, string name)
|
public RenameSprite(Sprite spriteToRename, string name)
|
||||||
{
|
{
|
||||||
sprite = spriteToRename;
|
sprite = spriteToRename;
|
||||||
newName = name;
|
newName = name;
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ namespace SpriteMapEditor
|
|||||||
public class SpriteMapProject
|
public class SpriteMapProject
|
||||||
{
|
{
|
||||||
public string SpriteSheetFileLocation { get; set; }
|
public string SpriteSheetFileLocation { get; set; }
|
||||||
public List<SpriteMapRegion> SpriteMap { get; set; }
|
public List<Sprite> SpriteMap { get; set; }
|
||||||
|
|
||||||
public SpriteMapProject()
|
public SpriteMapProject()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpriteMapProject(string spriteSheetLocation, List<SpriteMapRegion> spriteMap)
|
public SpriteMapProject(string spriteSheetLocation, List<Sprite> spriteMap)
|
||||||
{
|
{
|
||||||
SpriteSheetFileLocation = spriteSheetLocation;
|
SpriteSheetFileLocation = spriteSheetLocation;
|
||||||
SpriteMap = spriteMap;
|
SpriteMap = spriteMap;
|
||||||
|
|||||||
Reference in New Issue
Block a user