Implemented mod: MoveSprite
This commit is contained in:
@@ -93,6 +93,7 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Modifications\ModHelper.cs" />
|
<Compile Include="Modifications\ModHelper.cs" />
|
||||||
<Compile Include="Modifications\SelectionState.cs" />
|
<Compile Include="Modifications\SelectionState.cs" />
|
||||||
|
<Compile Include="Modifications\SpriteDragArgs.cs" />
|
||||||
<Compile Include="MonoGame.Framework.Content.Pipeline\ContentIdentity.cs" />
|
<Compile Include="MonoGame.Framework.Content.Pipeline\ContentIdentity.cs" />
|
||||||
<Compile Include="MonoGame.Framework.Content.Pipeline\InvalidContentException.cs" />
|
<Compile Include="MonoGame.Framework.Content.Pipeline\InvalidContentException.cs" />
|
||||||
<Compile Include="MonoGame.Framework.Content.Pipeline\NamedValueDictionary.cs" />
|
<Compile Include="MonoGame.Framework.Content.Pipeline\NamedValueDictionary.cs" />
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ namespace AnimationEditor
|
|||||||
private MouseState mState;
|
private MouseState mState;
|
||||||
private MouseState mState_old;
|
private MouseState mState_old;
|
||||||
|
|
||||||
|
private Vector2 totalDragDist;
|
||||||
|
|
||||||
private Vector2 centerPoint
|
private Vector2 centerPoint
|
||||||
{
|
{
|
||||||
get { return new Vector2((Editor.graphics.PresentationParameters.BackBufferWidth / 2), (Editor.graphics.PresentationParameters.BackBufferHeight / 2)); }
|
get { return new Vector2((Editor.graphics.PresentationParameters.BackBufferWidth / 2), (Editor.graphics.PresentationParameters.BackBufferHeight / 2)); }
|
||||||
@@ -54,16 +56,29 @@ namespace AnimationEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private EventHandler onSpriteMoved;
|
private EventHandler onSpriteDragUpdate;
|
||||||
public event EventHandler SpriteMoved
|
public event EventHandler SpriteDragUpdate
|
||||||
{
|
{
|
||||||
add
|
add
|
||||||
{
|
{
|
||||||
onSpriteMoved += value;
|
onSpriteDragUpdate += value;
|
||||||
}
|
}
|
||||||
remove
|
remove
|
||||||
{
|
{
|
||||||
onSpriteMoved -= value;
|
onSpriteDragUpdate -= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private EventHandler onSpriteDragCompleted;
|
||||||
|
public event EventHandler SpriteDragCompleted
|
||||||
|
{
|
||||||
|
add
|
||||||
|
{
|
||||||
|
onSpriteDragCompleted += value;
|
||||||
|
}
|
||||||
|
remove
|
||||||
|
{
|
||||||
|
onSpriteDragCompleted -= value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,10 +195,23 @@ namespace AnimationEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mState.LeftButton == ButtonState.Pressed && mState.RightButton != ButtonState.Pressed && mState_old.LeftButton != ButtonState.Pressed)
|
if (mState.LeftButton == ButtonState.Pressed && mState.RightButton != ButtonState.Pressed && mState_old.LeftButton != ButtonState.Pressed)
|
||||||
|
{
|
||||||
dragging = hovering;
|
dragging = hovering;
|
||||||
|
if (dragging)
|
||||||
|
{
|
||||||
|
totalDragDist = Vector2.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mState.LeftButton != ButtonState.Pressed)
|
if (mState.LeftButton != ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if(dragging && totalDragDist != Vector2.Zero)
|
||||||
|
{
|
||||||
|
OnSpriteDragCompleted(new Modifications.SpriteDragArgs(totalDragDist));
|
||||||
|
|
||||||
|
}
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (dragging)
|
if (dragging)
|
||||||
{
|
{
|
||||||
@@ -194,11 +222,12 @@ namespace AnimationEditor
|
|||||||
|
|
||||||
if (distMoved != Vector2.Zero)
|
if (distMoved != Vector2.Zero)
|
||||||
{
|
{
|
||||||
|
totalDragDist += distMoved;
|
||||||
foreach(Sprite spr in EditSprites)
|
foreach(Sprite spr in EditSprites)
|
||||||
{
|
{
|
||||||
spr.Offset += distMoved;
|
spr.Offset += distMoved;
|
||||||
}
|
}
|
||||||
OnSpriteMoved(new EventArgs());
|
OnSpriteDragUpdate(new EventArgs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,9 +260,14 @@ namespace AnimationEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnSpriteMoved(EventArgs e)
|
protected virtual void OnSpriteDragCompleted(EventArgs e)
|
||||||
|
{
|
||||||
|
onSpriteDragCompleted?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnSpriteDragUpdate(EventArgs e)
|
||||||
{
|
{
|
||||||
onSpriteMoved?.Invoke(this, e);
|
onSpriteDragUpdate?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnFrameChanged(EventArgs e)
|
protected virtual void OnFrameChanged(EventArgs e)
|
||||||
|
|||||||
@@ -57,7 +57,17 @@ namespace AnimationEditor
|
|||||||
importDelayBox.Value = 0;
|
importDelayBox.Value = 0;
|
||||||
animationPreview.FrameChanged += animationPreview_FrameChanged;
|
animationPreview.FrameChanged += animationPreview_FrameChanged;
|
||||||
animationPreview.AnimationEnded += animationPreview_AnimationEnded;
|
animationPreview.AnimationEnded += animationPreview_AnimationEnded;
|
||||||
animationPreview.SpriteMoved += animationPreview_SpriteMoved;
|
animationPreview.SpriteDragUpdate += animationPreview_SpriteDragUpdate;
|
||||||
|
animationPreview.SpriteDragCompleted += animationPreview_SpriteDragComplete;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void animationPreview_SpriteDragComplete(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var args = e as SpriteDragArgs;
|
||||||
|
var mod = new MoveSprite(frameSprites, frameSpriteListBox, args.DragDistance);
|
||||||
|
mod.Undo();
|
||||||
|
ModHelper.DoModificationWithSelectionTracking(mod, animationBox, frameListBox, frameSpriteListBox);
|
||||||
|
undoHistory.Add(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void frameListBox_SetSingleSelection(int index)
|
private void frameListBox_SetSingleSelection(int index)
|
||||||
@@ -116,6 +126,7 @@ namespace AnimationEditor
|
|||||||
{
|
{
|
||||||
if(frames?.Count > 0)
|
if(frames?.Count > 0)
|
||||||
{
|
{
|
||||||
|
//update currentAnimation's data
|
||||||
if(currentAnimation == null)
|
if(currentAnimation == null)
|
||||||
currentAnimation = new Animation("unnamed", frames.ToArray(), true);
|
currentAnimation = new Animation("unnamed", frames.ToArray(), true);
|
||||||
else
|
else
|
||||||
@@ -124,13 +135,19 @@ namespace AnimationEditor
|
|||||||
currentAnimation.Frames = frames.ToArray();
|
currentAnimation.Frames = frames.ToArray();
|
||||||
currentAnimation.IsLooping = animationLoopCheckBox.Checked;
|
currentAnimation.IsLooping = animationLoopCheckBox.Checked;
|
||||||
}
|
}
|
||||||
|
//ensure frameTrackBar length matches current animation
|
||||||
|
frameTrackBar.Maximum = currentAnimation.Frames.Count() - 1;
|
||||||
|
//send currentAnimation to animationPreview
|
||||||
if (animationPreview.PreviewSprite == null)
|
if (animationPreview.PreviewSprite == null)
|
||||||
animationPreview.PreviewSprite = new AnimatedSprite(currentAnimation);
|
animationPreview.PreviewSprite = new AnimatedSprite(currentAnimation);
|
||||||
else
|
else
|
||||||
animationPreview.PreviewSprite.CurrentAnimation = currentAnimation;
|
animationPreview.PreviewSprite.CurrentAnimation = currentAnimation;
|
||||||
frameTrackBar.Maximum = currentAnimation.Frames.Count() - 1;
|
//restore currently viewed frame
|
||||||
if(frameListBox.SelectedIndices.Count < 2 && frameListBox.SelectedIndex != frameTrackBar.Value)
|
if (frameListBox.SelectedIndices.Count < 2)
|
||||||
frameListBox_SetSingleSelection(frameTrackBar.Value);
|
frameListBox_SetSingleSelection(frameTrackBar.Value);
|
||||||
|
else
|
||||||
|
frameListBox.SelectedIndex = frameTrackBar.Value;
|
||||||
|
//if animations list is empty, send created currentAnimation to it
|
||||||
if(animations.Count < 1)
|
if(animations.Count < 1)
|
||||||
{
|
{
|
||||||
animations.Add(currentAnimation);
|
animations.Add(currentAnimation);
|
||||||
@@ -722,7 +739,7 @@ namespace AnimationEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void animationPreview_SpriteMoved(object sender, EventArgs e)
|
private void animationPreview_SpriteDragUpdate(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if(frameSpriteListBox.SelectedIndices.Count == 1)
|
if(frameSpriteListBox.SelectedIndices.Count == 1)
|
||||||
ReadSpriteOffset();
|
ReadSpriteOffset();
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ namespace AnimationEditor.Modifications
|
|||||||
private BindingList<Sprite> sprites;
|
private BindingList<Sprite> sprites;
|
||||||
private ListBox listBox;
|
private ListBox listBox;
|
||||||
private List<int> indices;
|
private List<int> indices;
|
||||||
private Dictionary<int, Vector2> originalPositions;
|
|
||||||
private Vector2 dist;
|
private Vector2 dist;
|
||||||
|
|
||||||
public MoveSprite(BindingList<Sprite> spriteList, ListBox spriteListBox, Vector2 distance)
|
public MoveSprite(BindingList<Sprite> spriteList, ListBox spriteListBox, Vector2 distance)
|
||||||
@@ -27,12 +26,6 @@ namespace AnimationEditor.Modifications
|
|||||||
sprites = spriteList;
|
sprites = spriteList;
|
||||||
listBox = spriteListBox;
|
listBox = spriteListBox;
|
||||||
indices = new List<int>();
|
indices = new List<int>();
|
||||||
originalPositions = new Dictionary<int, Vector2>();
|
|
||||||
foreach (int i in spriteListBox.SelectedIndices)
|
|
||||||
{
|
|
||||||
indices.Add(i);
|
|
||||||
originalPositions.Add(i, sprites[i].Offset);
|
|
||||||
}
|
|
||||||
dist = distance;
|
dist = distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +41,7 @@ namespace AnimationEditor.Modifications
|
|||||||
{
|
{
|
||||||
foreach (int index in indices)
|
foreach (int index in indices)
|
||||||
{
|
{
|
||||||
sprites[index].Offset = originalPositions[index];
|
sprites[index].Offset -= dist;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace AnimationEditor.Modifications
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return "Move Sprite";
|
return "Reorder Sprite";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AnimationEditor.Modifications
|
||||||
|
{
|
||||||
|
class SpriteDragArgs : EventArgs
|
||||||
|
{
|
||||||
|
public Vector2 DragDistance { get; private set; }
|
||||||
|
|
||||||
|
public SpriteDragArgs(Vector2 drag)
|
||||||
|
{
|
||||||
|
DragDistance = drag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user