SpriteMapEditor Rework
-Renamed Sprite to SpriteMapRegion -Updated Frame code in QURO.AnimationLibrary to use SpriteMapRegions instead of Rectangles -Replaced Drag and drop sprite rearrangement behaviour in Editor with simpler, less buggy up/down button system -Changed Editor's save/load format to be a MonoGame compatible Dictionary<string, SpriteMapRegion> rather than a List
This commit is contained in:
@@ -71,7 +71,6 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sprite.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -103,6 +102,10 @@
|
||||
<Project>{69dadc27-fbeb-4625-9212-6eb5bed5102a}</Project>
|
||||
<Name>QURO.AnimationLibrary</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\QURO\QURO.csproj">
|
||||
<Project>{4581e0c8-b14a-454d-9a7b-52d37535e7e9}</Project>
|
||||
<Name>QURO</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Generated
+21
-22
@@ -32,9 +32,9 @@
|
||||
this.loadSpriteSheetDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.loadSpriteMapButton = new System.Windows.Forms.Button();
|
||||
this.loadSpriteMapDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.spritesListBox = new System.Windows.Forms.ListBox();
|
||||
this.spriteListBox = new System.Windows.Forms.ListBox();
|
||||
this.animationPreview = new AnimationEditor.AnimationPreview();
|
||||
this.listBox1 = new System.Windows.Forms.ListBox();
|
||||
this.frameListBox = new System.Windows.Forms.ListBox();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// loadSpriteSheetButton
|
||||
@@ -70,41 +70,40 @@
|
||||
this.loadSpriteMapDialog.FileName = "openFileDialog1";
|
||||
this.loadSpriteMapDialog.Filter = "Xml Files|*.xml";
|
||||
//
|
||||
// spritesListBox
|
||||
// spriteListBox
|
||||
//
|
||||
this.spritesListBox.FormattingEnabled = true;
|
||||
this.spritesListBox.Location = new System.Drawing.Point(28, 104);
|
||||
this.spritesListBox.Name = "spritesListBox";
|
||||
this.spritesListBox.Size = new System.Drawing.Size(119, 264);
|
||||
this.spritesListBox.TabIndex = 3;
|
||||
this.spriteListBox.FormattingEnabled = true;
|
||||
this.spriteListBox.Location = new System.Drawing.Point(28, 104);
|
||||
this.spriteListBox.Name = "spriteListBox";
|
||||
this.spriteListBox.Size = new System.Drawing.Size(119, 264);
|
||||
this.spriteListBox.TabIndex = 3;
|
||||
this.spriteListBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.spriteListBox_MouseDown);
|
||||
//
|
||||
// animationPreview
|
||||
//
|
||||
this.animationPreview.CurrentAnimation = null;
|
||||
this.animationPreview.Location = new System.Drawing.Point(351, 73);
|
||||
this.animationPreview.Location = new System.Drawing.Point(413, 74);
|
||||
this.animationPreview.Name = "animationPreview";
|
||||
this.animationPreview.PreviewSprite = null;
|
||||
this.animationPreview.Size = new System.Drawing.Size(253, 198);
|
||||
this.animationPreview.SpriteSheet = null;
|
||||
this.animationPreview.TabIndex = 0;
|
||||
this.animationPreview.Text = "animationPreview1";
|
||||
//
|
||||
// listBox1
|
||||
// frameListBox
|
||||
//
|
||||
this.listBox1.AllowDrop = true;
|
||||
this.listBox1.FormattingEnabled = true;
|
||||
this.listBox1.Location = new System.Drawing.Point(166, 104);
|
||||
this.listBox1.Name = "listBox1";
|
||||
this.listBox1.Size = new System.Drawing.Size(120, 264);
|
||||
this.listBox1.TabIndex = 4;
|
||||
this.frameListBox.AllowDrop = true;
|
||||
this.frameListBox.FormattingEnabled = true;
|
||||
this.frameListBox.Location = new System.Drawing.Point(166, 104);
|
||||
this.frameListBox.Name = "frameListBox";
|
||||
this.frameListBox.Size = new System.Drawing.Size(120, 264);
|
||||
this.frameListBox.TabIndex = 4;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.listBox1);
|
||||
this.Controls.Add(this.spritesListBox);
|
||||
this.Controls.Add(this.frameListBox);
|
||||
this.Controls.Add(this.spriteListBox);
|
||||
this.Controls.Add(this.loadSpriteMapButton);
|
||||
this.Controls.Add(this.loadSpriteSheetButton);
|
||||
this.Controls.Add(this.animationPreview);
|
||||
@@ -121,8 +120,8 @@
|
||||
private System.Windows.Forms.OpenFileDialog loadSpriteSheetDialog;
|
||||
private System.Windows.Forms.Button loadSpriteMapButton;
|
||||
private System.Windows.Forms.OpenFileDialog loadSpriteMapDialog;
|
||||
private System.Windows.Forms.ListBox spritesListBox;
|
||||
private System.Windows.Forms.ListBox listBox1;
|
||||
private System.Windows.Forms.ListBox spriteListBox;
|
||||
private System.Windows.Forms.ListBox frameListBox;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,14 @@ using System.Xml.Serialization;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using QURO.AnimationLibrary;
|
||||
using QURO;
|
||||
|
||||
namespace AnimationEditor
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public BindingList<Sprite> Sprites { get; set; }
|
||||
private SpriteMapRegion draggedSprite;
|
||||
public BindingList<SpriteMapRegion> Sprites { get; set; }
|
||||
|
||||
public Form1()
|
||||
{
|
||||
@@ -39,18 +41,26 @@ namespace AnimationEditor
|
||||
if (loadSpriteMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
|
||||
XmlSerializer mapSerializer = new XmlSerializer(typeof(List<Sprite>));
|
||||
XmlSerializer mapSerializer = new XmlSerializer(typeof(List<SpriteMapRegion>));
|
||||
TextReader mapReader = new StreamReader(loadSpriteMapDialog.FileName);
|
||||
|
||||
Sprites = new BindingList<Sprite>((List<Sprite>)mapSerializer.Deserialize(mapReader));
|
||||
spritesListBox.DataSource = Sprites;
|
||||
spritesListBox.DisplayMember = "Name";
|
||||
spritesListBox.ValueMember = "Bounds";
|
||||
Sprites = new BindingList<SpriteMapRegion>((List<SpriteMapRegion>)mapSerializer.Deserialize(mapReader));
|
||||
spriteListBox.DataSource = Sprites;
|
||||
spriteListBox.DisplayMember = "Name";
|
||||
spriteListBox.ValueMember = "Bounds";
|
||||
Rectangle[] frames = new Rectangle[] { Sprites[0].Bounds, Sprites[1].Bounds, Sprites[2].Bounds };
|
||||
animationPreview.CurrentAnimation = new Animation("Test", frames, 1f / 60f, true);
|
||||
animationPreview.PreviewSprite = new AnimatedSprite(animationPreview.SpriteSheet, animationPreview.CurrentAnimation);
|
||||
mapReader.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void spriteListBox_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (spriteListBox.SelectedItem == null)
|
||||
return;
|
||||
spriteListBox.DoDragDrop(spriteListBox.SelectedItem, DragDropEffects.Copy);
|
||||
draggedSprite = (SpriteMapRegion)spriteListBox.SelectedItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace AnimationEditor
|
||||
{
|
||||
public class Sprite
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Rectangle Bounds { get; set; }
|
||||
|
||||
public Sprite()
|
||||
{
|
||||
Name = "unnamed";
|
||||
Bounds = new Rectangle(1, 1, 8, 8);
|
||||
}
|
||||
|
||||
public Sprite(string name, Rectangle bounds)
|
||||
{
|
||||
Name = name;
|
||||
Bounds = bounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,12 +74,12 @@ namespace QURO.AnimationLibrary
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Color tint)
|
||||
{
|
||||
spriteBatch.Draw(SpriteSheet, position, CurrentFrame.SourceRect, tint);
|
||||
spriteBatch.Draw(SpriteSheet, position, CurrentFrame.Bounds, tint);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch, Vector2 position, Vector2 spriteOffset, Color tint)
|
||||
{
|
||||
Rectangle sourceRect = CurrentFrame.SourceRect;
|
||||
Rectangle sourceRect = CurrentFrame.Bounds;
|
||||
sourceRect.Offset(spriteOffset);
|
||||
|
||||
spriteBatch.Draw(SpriteSheet, position, sourceRect, tint);
|
||||
|
||||
@@ -1,17 +1,49 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using QURO;
|
||||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace QURO.AnimationLibrary
|
||||
{
|
||||
public class Frame
|
||||
public class Frame : SpriteMapRegion
|
||||
{
|
||||
public Rectangle SourceRect { get; set; }
|
||||
public float Delay { get; set; }
|
||||
|
||||
public Frame() { }
|
||||
|
||||
public Frame(Rectangle sourceRectangle, float delay)
|
||||
public Frame()
|
||||
{
|
||||
SourceRect = sourceRectangle;
|
||||
Name = "unnamed";
|
||||
Bounds = new Rectangle(0, 0, 8, 8);
|
||||
Origin = Vector2.Zero;
|
||||
Delay = 0;
|
||||
}
|
||||
|
||||
public Frame(SpriteMapRegion sprite, float delay)
|
||||
{
|
||||
Name = sprite.Name;
|
||||
Bounds = sprite.Bounds;
|
||||
Origin = sprite.Origin;
|
||||
Delay = delay;
|
||||
}
|
||||
|
||||
public Frame(string name, Rectangle bounds, float delay, Vector2 origin)
|
||||
{
|
||||
Name = name;
|
||||
Bounds = bounds;
|
||||
Origin = origin;
|
||||
Delay = delay;
|
||||
}
|
||||
|
||||
public Frame(Rectangle bounds, float delay, Vector2 origin)
|
||||
{
|
||||
Name = "unnamed";
|
||||
Bounds = bounds;
|
||||
Origin = origin;
|
||||
Delay = delay;
|
||||
}
|
||||
|
||||
public Frame(Rectangle bounds, float delay)
|
||||
{
|
||||
Name = "unnamed";
|
||||
Bounds = bounds;
|
||||
Origin = Vector2.Zero;
|
||||
Delay = delay;
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+109
-41
@@ -39,6 +39,10 @@
|
||||
this.spriteListPanel = new System.Windows.Forms.Panel();
|
||||
this.spritesLabel = new System.Windows.Forms.Label();
|
||||
this.spritePanel = new System.Windows.Forms.Panel();
|
||||
this.originYPosBox = new System.Windows.Forms.NumericUpDown();
|
||||
this.originXPosBox = new System.Windows.Forms.NumericUpDown();
|
||||
this.originYPosLabel = new System.Windows.Forms.Label();
|
||||
this.originXPosLabel = new System.Windows.Forms.Label();
|
||||
this.spriteHeightBox = new System.Windows.Forms.NumericUpDown();
|
||||
this.spriteWidthBox = new System.Windows.Forms.NumericUpDown();
|
||||
this.spriteYPosBox = new System.Windows.Forms.NumericUpDown();
|
||||
@@ -55,14 +59,17 @@
|
||||
this.saveMapDialogue = new System.Windows.Forms.SaveFileDialog();
|
||||
this.fillButton = new System.Windows.Forms.Button();
|
||||
this.spriteViewerPanel = new System.Windows.Forms.Panel();
|
||||
this.spriteSheetViewer = new SpriteMapEditor.PictureBoxWithInterpolationMode();
|
||||
this.zoomInButton = new System.Windows.Forms.Button();
|
||||
this.zoomOutButton = new System.Windows.Forms.Button();
|
||||
this.zoomLabel = new System.Windows.Forms.Label();
|
||||
this.spriteSheetViewer = new SpriteMapEditor.PictureBoxWithInterpolationMode();
|
||||
this.rearrangeCheckBox = new System.Windows.Forms.CheckBox();
|
||||
this.moveDownButton = new System.Windows.Forms.Button();
|
||||
this.moveUpButton = new System.Windows.Forms.Button();
|
||||
this.filePanel.SuspendLayout();
|
||||
this.spriteListPanel.SuspendLayout();
|
||||
this.spritePanel.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.originYPosBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.originXPosBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.spriteHeightBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.spriteWidthBox)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.spriteYPosBox)).BeginInit();
|
||||
@@ -74,18 +81,12 @@
|
||||
// spriteList
|
||||
//
|
||||
this.spriteList.AllowDrop = true;
|
||||
this.spriteList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.spriteList.FormattingEnabled = true;
|
||||
this.spriteList.Location = new System.Drawing.Point(3, 32);
|
||||
this.spriteList.Name = "spriteList";
|
||||
this.spriteList.Size = new System.Drawing.Size(185, 225);
|
||||
this.spriteList.Size = new System.Drawing.Size(183, 199);
|
||||
this.spriteList.TabIndex = 0;
|
||||
this.spriteList.SelectedValueChanged += new System.EventHandler(this.spriteList_SelectedValueChanged);
|
||||
this.spriteList.DragDrop += new System.Windows.Forms.DragEventHandler(this.spriteList_DragDrop);
|
||||
this.spriteList.DragOver += new System.Windows.Forms.DragEventHandler(this.spriteList_DragOver);
|
||||
this.spriteList.MouseDown += new System.Windows.Forms.MouseEventHandler(this.spriteList_MouseDown);
|
||||
//
|
||||
// addSpriteButton
|
||||
//
|
||||
@@ -144,7 +145,7 @@
|
||||
this.filePanel.Controls.Add(this.loadMapButton);
|
||||
this.filePanel.Location = new System.Drawing.Point(2, 2);
|
||||
this.filePanel.Name = "filePanel";
|
||||
this.filePanel.Size = new System.Drawing.Size(191, 62);
|
||||
this.filePanel.Size = new System.Drawing.Size(190, 62);
|
||||
this.filePanel.TabIndex = 7;
|
||||
//
|
||||
// spriteListPanel
|
||||
@@ -152,16 +153,16 @@
|
||||
this.spriteListPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.spriteListPanel.AutoSize = true;
|
||||
this.spriteListPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
|
||||
this.spriteListPanel.Controls.Add(this.rearrangeCheckBox);
|
||||
this.spriteListPanel.Controls.Add(this.moveDownButton);
|
||||
this.spriteListPanel.Controls.Add(this.moveUpButton);
|
||||
this.spriteListPanel.Controls.Add(this.spritesLabel);
|
||||
this.spriteListPanel.Controls.Add(this.spriteList);
|
||||
this.spriteListPanel.Controls.Add(this.addSpriteButton);
|
||||
this.spriteListPanel.Controls.Add(this.removeSpriteButton);
|
||||
this.spriteListPanel.Location = new System.Drawing.Point(2, 63);
|
||||
this.spriteListPanel.Name = "spriteListPanel";
|
||||
this.spriteListPanel.Size = new System.Drawing.Size(224, 286);
|
||||
this.spriteListPanel.Size = new System.Drawing.Size(190, 254);
|
||||
this.spriteListPanel.TabIndex = 8;
|
||||
//
|
||||
// spritesLabel
|
||||
@@ -177,6 +178,10 @@
|
||||
// spritePanel
|
||||
//
|
||||
this.spritePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.spritePanel.Controls.Add(this.originYPosBox);
|
||||
this.spritePanel.Controls.Add(this.originXPosBox);
|
||||
this.spritePanel.Controls.Add(this.originYPosLabel);
|
||||
this.spritePanel.Controls.Add(this.originXPosLabel);
|
||||
this.spritePanel.Controls.Add(this.spriteHeightBox);
|
||||
this.spritePanel.Controls.Add(this.spriteWidthBox);
|
||||
this.spritePanel.Controls.Add(this.spriteYPosBox);
|
||||
@@ -188,11 +193,59 @@
|
||||
this.spritePanel.Controls.Add(this.label2);
|
||||
this.spritePanel.Controls.Add(this.spriteSettingsLabel);
|
||||
this.spritePanel.Controls.Add(this.spriteNameBox);
|
||||
this.spritePanel.Location = new System.Drawing.Point(2, 353);
|
||||
this.spritePanel.Location = new System.Drawing.Point(2, 323);
|
||||
this.spritePanel.Name = "spritePanel";
|
||||
this.spritePanel.Size = new System.Drawing.Size(191, 110);
|
||||
this.spritePanel.Size = new System.Drawing.Size(190, 140);
|
||||
this.spritePanel.TabIndex = 9;
|
||||
//
|
||||
// originYPosBox
|
||||
//
|
||||
this.originYPosBox.Enabled = false;
|
||||
this.originYPosBox.Location = new System.Drawing.Point(143, 108);
|
||||
this.originYPosBox.Maximum = new decimal(new int[] {
|
||||
2147483647,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.originYPosBox.Name = "originYPosBox";
|
||||
this.originYPosBox.Size = new System.Drawing.Size(45, 20);
|
||||
this.originYPosBox.TabIndex = 22;
|
||||
this.originYPosBox.ValueChanged += new System.EventHandler(this.originYPosBox_ValueChanged);
|
||||
//
|
||||
// originXPosBox
|
||||
//
|
||||
this.originXPosBox.Enabled = false;
|
||||
this.originXPosBox.Location = new System.Drawing.Point(51, 108);
|
||||
this.originXPosBox.Maximum = new decimal(new int[] {
|
||||
2147483647,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.originXPosBox.Name = "originXPosBox";
|
||||
this.originXPosBox.Size = new System.Drawing.Size(45, 20);
|
||||
this.originXPosBox.TabIndex = 21;
|
||||
this.originXPosBox.ValueChanged += new System.EventHandler(this.originXPosBox_ValueChanged);
|
||||
//
|
||||
// originYPosLabel
|
||||
//
|
||||
this.originYPosLabel.AutoSize = true;
|
||||
this.originYPosLabel.Enabled = false;
|
||||
this.originYPosLabel.Location = new System.Drawing.Point(98, 111);
|
||||
this.originYPosLabel.Name = "originYPosLabel";
|
||||
this.originYPosLabel.Size = new System.Drawing.Size(44, 13);
|
||||
this.originYPosLabel.TabIndex = 20;
|
||||
this.originYPosLabel.Text = "Origin Y";
|
||||
//
|
||||
// originXPosLabel
|
||||
//
|
||||
this.originXPosLabel.AutoSize = true;
|
||||
this.originXPosLabel.Enabled = false;
|
||||
this.originXPosLabel.Location = new System.Drawing.Point(6, 111);
|
||||
this.originXPosLabel.Name = "originXPosLabel";
|
||||
this.originXPosLabel.Size = new System.Drawing.Size(44, 13);
|
||||
this.originXPosLabel.TabIndex = 19;
|
||||
this.originXPosLabel.Text = "Origin X";
|
||||
//
|
||||
// spriteHeightBox
|
||||
//
|
||||
this.spriteHeightBox.Location = new System.Drawing.Point(136, 82);
|
||||
@@ -345,6 +398,23 @@
|
||||
this.spriteViewerPanel.TabIndex = 14;
|
||||
this.spriteViewerPanel.Scroll += new System.Windows.Forms.ScrollEventHandler(this.spriteViewerPanel_Scroll);
|
||||
//
|
||||
// spriteSheetViewer
|
||||
//
|
||||
this.spriteSheetViewer.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("spriteSheetViewer.BackgroundImage")));
|
||||
this.spriteSheetViewer.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
this.spriteSheetViewer.Location = new System.Drawing.Point(0, 0);
|
||||
this.spriteSheetViewer.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.spriteSheetViewer.Name = "spriteSheetViewer";
|
||||
this.spriteSheetViewer.Size = new System.Drawing.Size(147, 143);
|
||||
this.spriteSheetViewer.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||
this.spriteSheetViewer.TabIndex = 13;
|
||||
this.spriteSheetViewer.TabStop = false;
|
||||
this.spriteSheetViewer.Paint += new System.Windows.Forms.PaintEventHandler(this.spriteSheetViewer_Paint);
|
||||
this.spriteSheetViewer.MouseDown += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseDown);
|
||||
this.spriteSheetViewer.MouseLeave += new System.EventHandler(this.spriteSheetViewer_MouseLeave);
|
||||
this.spriteSheetViewer.MouseMove += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseMove);
|
||||
this.spriteSheetViewer.MouseUp += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseUp);
|
||||
//
|
||||
// zoomInButton
|
||||
//
|
||||
this.zoomInButton.Location = new System.Drawing.Point(652, 5);
|
||||
@@ -374,34 +444,25 @@
|
||||
this.zoomLabel.TabIndex = 15;
|
||||
this.zoomLabel.Text = "Zoom: 3X";
|
||||
//
|
||||
// spriteSheetViewer
|
||||
// moveDownButton
|
||||
//
|
||||
this.spriteSheetViewer.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("spriteSheetViewer.BackgroundImage")));
|
||||
this.spriteSheetViewer.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
|
||||
this.spriteSheetViewer.Location = new System.Drawing.Point(0, 0);
|
||||
this.spriteSheetViewer.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.spriteSheetViewer.Name = "spriteSheetViewer";
|
||||
this.spriteSheetViewer.Size = new System.Drawing.Size(147, 143);
|
||||
this.spriteSheetViewer.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||
this.spriteSheetViewer.TabIndex = 13;
|
||||
this.spriteSheetViewer.TabStop = false;
|
||||
this.spriteSheetViewer.Paint += new System.Windows.Forms.PaintEventHandler(this.spriteSheetViewer_Paint);
|
||||
this.spriteSheetViewer.MouseDown += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseDown);
|
||||
this.spriteSheetViewer.MouseLeave += new System.EventHandler(this.spriteSheetViewer_MouseLeave);
|
||||
this.spriteSheetViewer.MouseMove += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseMove);
|
||||
this.spriteSheetViewer.MouseUp += new System.Windows.Forms.MouseEventHandler(this.spriteSheetViewer_MouseUp);
|
||||
this.moveDownButton.Location = new System.Drawing.Point(39, 233);
|
||||
this.moveDownButton.Name = "moveDownButton";
|
||||
this.moveDownButton.Size = new System.Drawing.Size(70, 18);
|
||||
this.moveDownButton.TabIndex = 5;
|
||||
this.moveDownButton.Text = "▼";
|
||||
this.moveDownButton.UseVisualStyleBackColor = true;
|
||||
this.moveDownButton.Click += new System.EventHandler(this.moveDownButton_Click);
|
||||
//
|
||||
// rearrangeCheckBox
|
||||
// moveUpButton
|
||||
//
|
||||
this.rearrangeCheckBox.AutoSize = true;
|
||||
this.rearrangeCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
|
||||
this.rearrangeCheckBox.Location = new System.Drawing.Point(82, 263);
|
||||
this.rearrangeCheckBox.Name = "rearrangeCheckBox";
|
||||
this.rearrangeCheckBox.Size = new System.Drawing.Size(106, 17);
|
||||
this.rearrangeCheckBox.TabIndex = 5;
|
||||
this.rearrangeCheckBox.Text = "Rearrange Mode";
|
||||
this.rearrangeCheckBox.UseVisualStyleBackColor = true;
|
||||
this.rearrangeCheckBox.CheckedChanged += new System.EventHandler(this.rearrangeCheckBox_CheckedChanged);
|
||||
this.moveUpButton.Location = new System.Drawing.Point(115, 233);
|
||||
this.moveUpButton.Name = "moveUpButton";
|
||||
this.moveUpButton.Size = new System.Drawing.Size(71, 18);
|
||||
this.moveUpButton.TabIndex = 6;
|
||||
this.moveUpButton.Text = "▲";
|
||||
this.moveUpButton.UseVisualStyleBackColor = true;
|
||||
this.moveUpButton.Click += new System.EventHandler(this.moveUpButton_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
@@ -424,6 +485,8 @@
|
||||
this.spriteListPanel.PerformLayout();
|
||||
this.spritePanel.ResumeLayout(false);
|
||||
this.spritePanel.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.originYPosBox)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.originXPosBox)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.spriteHeightBox)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.spriteWidthBox)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.spriteYPosBox)).EndInit();
|
||||
@@ -467,7 +530,12 @@
|
||||
private System.Windows.Forms.NumericUpDown spriteYPosBox;
|
||||
private System.Windows.Forms.NumericUpDown spriteXPosBox;
|
||||
private System.Windows.Forms.Label zoomLabel;
|
||||
private System.Windows.Forms.CheckBox rearrangeCheckBox;
|
||||
private System.Windows.Forms.NumericUpDown originYPosBox;
|
||||
private System.Windows.Forms.NumericUpDown originXPosBox;
|
||||
private System.Windows.Forms.Label originYPosLabel;
|
||||
private System.Windows.Forms.Label originXPosLabel;
|
||||
private System.Windows.Forms.Button moveDownButton;
|
||||
private System.Windows.Forms.Button moveUpButton;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+94
-40
@@ -7,18 +7,22 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using Microsoft.Xna;
|
||||
using System.IO;
|
||||
using QURO;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate;
|
||||
|
||||
|
||||
namespace SpriteMapEditor
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private BindingList<Sprite> sprites;
|
||||
private BindingList<SpriteMapRegion> sprites;
|
||||
|
||||
private bool highlight = false;
|
||||
private Sprite currentSprite;
|
||||
private SpriteMapRegion currentSprite;
|
||||
private int zoomLevel = 3;
|
||||
|
||||
private bool loadingSprite = false;
|
||||
@@ -47,7 +51,7 @@ namespace SpriteMapEditor
|
||||
spriteSheetViewer.Width = 1;
|
||||
spriteSheetViewer.Height = 1;
|
||||
|
||||
sprites = new BindingList<Sprite> { new Sprite() };
|
||||
sprites = new BindingList<SpriteMapRegion> { new SpriteMapRegion() };
|
||||
|
||||
currentSprite = sprites[0];
|
||||
|
||||
@@ -76,6 +80,14 @@ namespace SpriteMapEditor
|
||||
if (highlight)
|
||||
SurroundWithTranslucentRects(GetDrawingRect(currentSprite.Bounds, false), Color.Gray, e.Graphics);
|
||||
DrawHighContrastOutline(GetDrawingRect(currentSprite.Bounds), e.Graphics);
|
||||
/*
|
||||
* Origin display code, uncomment when ready to implement
|
||||
*
|
||||
using (Brush magentaBrush = new SolidBrush(Color.Magenta))
|
||||
{
|
||||
e.Graphics.FillRectangle(magentaBrush, GetOriginDrawingRect(currentSprite));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
base.OnPaint(e);
|
||||
@@ -89,17 +101,24 @@ namespace SpriteMapEditor
|
||||
spriteYPosBox.Value = currentSprite.Bounds.Y;
|
||||
spriteWidthBox.Value = currentSprite.Bounds.Width;
|
||||
spriteHeightBox.Value = currentSprite.Bounds.Height;
|
||||
originXPosBox.Value = (int)currentSprite.Origin.X;
|
||||
originYPosBox.Value = (int)currentSprite.Origin.Y;
|
||||
loadingSprite = false;
|
||||
}
|
||||
|
||||
private void UpdateSpriteBounds()
|
||||
{
|
||||
currentSprite.Bounds = new Rectangle((int)spriteXPosBox.Value, (int)spriteYPosBox.Value, (int)spriteWidthBox.Value, (int)spriteHeightBox.Value);
|
||||
currentSprite.Bounds = new Microsoft.Xna.Framework.Rectangle((int)spriteXPosBox.Value, (int)spriteYPosBox.Value, (int)spriteWidthBox.Value, (int)spriteHeightBox.Value);
|
||||
}
|
||||
|
||||
private Rectangle GetDrawingRect(Rectangle baseRect, bool outline = true)
|
||||
private void UpdateSpriteOrigin()
|
||||
{
|
||||
var drawingRect = baseRect;
|
||||
currentSprite.Origin = new Microsoft.Xna.Framework.Vector2((int)originXPosBox.Value, (int)originYPosBox.Value);
|
||||
}
|
||||
|
||||
private Rectangle GetDrawingRect(Microsoft.Xna.Framework.Rectangle baseRect, bool outline = true)
|
||||
{
|
||||
var drawingRect = new Rectangle(baseRect.X, baseRect.Y, baseRect.Width, baseRect.Height);
|
||||
drawingRect.X = drawingRect.X * zoomLevel - (zoomLevel - 1);
|
||||
drawingRect.Y = drawingRect.Y * zoomLevel - (zoomLevel - 1);
|
||||
drawingRect.X += drawingRectangleOffset;
|
||||
@@ -118,6 +137,18 @@ namespace SpriteMapEditor
|
||||
return drawingRect;
|
||||
}
|
||||
|
||||
private Rectangle GetOriginDrawingRect(SpriteMapRegion sprite)
|
||||
{
|
||||
var drawingRect = new Rectangle(sprite.Bounds.X, sprite.Bounds.Y, 2, 2);
|
||||
drawingRect.X = drawingRect.X * zoomLevel - (zoomLevel - 1);
|
||||
drawingRect.Y = drawingRect.Y * zoomLevel - (zoomLevel - 1);
|
||||
drawingRect.X += drawingRectangleOffset;
|
||||
drawingRect.Y += drawingRectangleOffset;
|
||||
drawingRect.X += (int)sprite.Origin.X * zoomLevel;
|
||||
drawingRect.Y += (int)sprite.Origin.Y * zoomLevel;
|
||||
return drawingRect;
|
||||
}
|
||||
|
||||
private void SurroundWithTranslucentRects(Rectangle rect, Color color, Graphics graphics)
|
||||
{
|
||||
Rectangle topBorder = new Rectangle(0, 0, spriteSheetViewer.Width, rect.Y);
|
||||
@@ -230,7 +261,7 @@ namespace SpriteMapEditor
|
||||
|
||||
private void addSpriteButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
sprites.Add(new Sprite(currentSprite.Name, currentSprite.Bounds));
|
||||
sprites.Add(new SpriteMapRegion(currentSprite.Name, currentSprite.Bounds));
|
||||
}
|
||||
|
||||
private void removeSpriteButton_Click(object sender, EventArgs e)
|
||||
@@ -253,13 +284,24 @@ namespace SpriteMapEditor
|
||||
{
|
||||
if (saveMapDialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
XmlSerializer mapSerializer = new XmlSerializer(typeof(List<Sprite>));
|
||||
TextWriter mapWriter = new StreamWriter(saveMapDialogue.FileName);
|
||||
var exportDict = new Dictionary<string, SpriteMapRegion>();
|
||||
foreach(SpriteMapRegion sprite in sprites)
|
||||
{
|
||||
if (exportDict.ContainsKey(sprite.Name))
|
||||
{
|
||||
string errorMessage = "Duplicate names found! Please ensure all sprites have unique names.";
|
||||
string caption = "Save Aborted";
|
||||
MessageBoxButtons saveError = MessageBoxButtons.OK;
|
||||
|
||||
var exportList = sprites.ToList();
|
||||
|
||||
mapSerializer.Serialize(mapWriter, exportList);
|
||||
mapWriter.Close();
|
||||
MessageBox.Show(errorMessage, caption, saveError);
|
||||
}
|
||||
else
|
||||
exportDict.Add(sprite.Name, sprite);
|
||||
}
|
||||
using (XmlWriter writer = XmlWriter.Create(saveMapDialogue.FileName))
|
||||
{
|
||||
IntermediateSerializer.Serialize(writer, exportDict, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,11 +309,17 @@ namespace SpriteMapEditor
|
||||
{
|
||||
if(loadMapDialogue.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
XmlSerializer mapSerializer = new XmlSerializer(typeof(List<Sprite>));
|
||||
TextReader mapReader = new StreamReader(loadMapDialogue.FileName);
|
||||
Dictionary<string, SpriteMapRegion> loadedSpriteMap;
|
||||
using (XmlReader xmlRead = XmlReader.Create(loadMapDialogue.FileName))
|
||||
{
|
||||
loadedSpriteMap = IntermediateSerializer.Deserialize<Dictionary<string, SpriteMapRegion>>(xmlRead, null);
|
||||
}
|
||||
|
||||
sprites = new BindingList<Sprite>((List<Sprite>)mapSerializer.Deserialize(mapReader));
|
||||
mapReader.Close();
|
||||
sprites = new BindingList<SpriteMapRegion>();
|
||||
foreach(KeyValuePair<string, SpriteMapRegion> sprite in loadedSpriteMap)
|
||||
{
|
||||
sprites.Add(sprite.Value);
|
||||
}
|
||||
|
||||
spriteList.DataSource = sprites;
|
||||
}
|
||||
@@ -337,36 +385,42 @@ namespace SpriteMapEditor
|
||||
movingWithMouse = false;
|
||||
}
|
||||
|
||||
private void spriteList_MouseDown(object sender, MouseEventArgs e)
|
||||
private void originXPosBox_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (rearrangingSprites)
|
||||
{
|
||||
if (spriteList.SelectedItem == null)
|
||||
if (loadingSprite)
|
||||
return;
|
||||
spriteList.DoDragDrop(spriteList.SelectedItem, DragDropEffects.Move);
|
||||
UpdateSpriteOrigin();
|
||||
spriteSheetViewer.Refresh();
|
||||
}
|
||||
|
||||
private void originYPosBox_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (loadingSprite)
|
||||
return;
|
||||
UpdateSpriteOrigin();
|
||||
spriteSheetViewer.Refresh();
|
||||
}
|
||||
|
||||
private void moveDownButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if(spriteList.SelectedIndex < sprites.Count - 1)
|
||||
{
|
||||
var spriteBelow = sprites[spriteList.SelectedIndex + 1];
|
||||
sprites[spriteList.SelectedIndex + 1] = currentSprite;
|
||||
sprites[spriteList.SelectedIndex] = spriteBelow;
|
||||
spriteList.SelectedIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
private void spriteList_DragOver(object sender, DragEventArgs e)
|
||||
private void moveUpButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
e.Effect = DragDropEffects.Move;
|
||||
if(spriteList.SelectedIndex > 0)
|
||||
{
|
||||
var spriteAbove = sprites[spriteList.SelectedIndex - 1];
|
||||
sprites[spriteList.SelectedIndex - 1] = currentSprite;
|
||||
sprites[spriteList.SelectedIndex] = spriteAbove;
|
||||
spriteList.SelectedIndex--;
|
||||
}
|
||||
|
||||
private void spriteList_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
Point point = spriteList.PointToClient(new Point(e.X, e.Y));
|
||||
int index = spriteList.IndexFromPoint(point);
|
||||
if (index < 0)
|
||||
index = spriteList.Items.Count - 1;
|
||||
Sprite data = (Sprite)spriteList.SelectedItem;
|
||||
sprites.Remove(data);
|
||||
sprites.Insert(index, data);
|
||||
}
|
||||
|
||||
private void rearrangeCheckBox_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
rearrangingSprites = rearrangeCheckBox.Checked;
|
||||
spriteList.AllowDrop = rearrangeCheckBox.Checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace SpriteMapEditor
|
||||
{
|
||||
public class Sprite
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Rectangle Bounds { get; set; }
|
||||
|
||||
public Sprite()
|
||||
{
|
||||
Name = "unnamed";
|
||||
Bounds = new Rectangle(1, 1, 8, 8);
|
||||
}
|
||||
|
||||
public Sprite(string name, Rectangle bounds)
|
||||
{
|
||||
Name = name;
|
||||
Bounds = bounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,13 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="MonoGame.Framework, Version=3.8.0.76, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>C:\Program Files (x86)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MonoGame.Framework.Content.Pipeline">
|
||||
<HintPath>C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools\MonoGame.Framework.Content.Pipeline.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -55,7 +62,6 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Sprite.cs" />
|
||||
<EmbeddedResource Include="Form1.resx">
|
||||
<DependentUpon>Form1.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -88,5 +94,11 @@
|
||||
<ItemGroup>
|
||||
<Content Include="transparentUI.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QURO\QURO.csproj">
|
||||
<Project>{4581e0c8-b14a-454d-9a7b-52d37535e7e9}</Project>
|
||||
<Name>QURO</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user