private void HandleDrop(TreeNode movedNode, TreeNode targetNode) { if (targetNode != movedNode) { AnimationChainSave animationDroppedOn = targetNode.Tag as AnimationChainSave; AnimationFrameSave frameDroppedOn = targetNode.Tag as AnimationFrameSave; if (frameDroppedOn != null) { animationDroppedOn = targetNode.Parent.Tag as AnimationChainSave; } AnimationFrameSave movedFrame = movedNode.Tag as AnimationFrameSave; if (movedFrame != null && animationDroppedOn.Frames.Contains(movedFrame)) { animationDroppedOn.Frames.Remove(movedFrame); int indexToInsert = 0; if (frameDroppedOn != null) { indexToInsert = animationDroppedOn.Frames.IndexOf(frameDroppedOn) + 1; } animationDroppedOn.Frames.Insert(indexToInsert, movedFrame); RefreshTreeNode(animationDroppedOn); } } }
private void ApplyJustifyOffsets() { switch (this.Justification) { case AnimationEditorForms.Controls.Justification.Bottom: AnimationChainSave chain = SelectedState.Self.SelectedChain; if (chain != null) { foreach (var frame in chain.Frames) { Texture2D texture = WireframeManager.Self.GetTextureForFrame(frame); if (texture != null) { float textureAmount = texture.Height * (frame.BottomCoordinate - frame.TopCoordinate); // AnimationFrames treat positive Y as up frame.RelativeY = (textureAmount / 2.0f) / PreviewManager.Self.OffsetMultiplier; } } } break; } }
public void AfterTreeItemSelect() { AnimationChainSave lastChain = SelectedState.Self.Snapshot.AnimationChainSave; AnimationFrameSave lastFrame = SelectedState.Self.Snapshot.AnimationFrameSave; // Refresh the wireframe before the property grid so the property // grid can get the texture information. WireframeManager.Self.RefreshAll(); PropertyGridManager.Self.Refresh(); SelectedState.Self.TakeSnapshot(); if (lastChain != SelectedState.Self.SelectedChain) { // handle new chain selected here WireframeManager.Self.HandleAnimationChainChanged(); PreviewManager.Self.ReactToAnimationChainSelected(); } if (lastFrame != SelectedState.Self.SelectedFrame) { PreviewManager.Self.ReactToAnimationFrameSelected(); } if (SelectedState.Self.SelectedFrame != null) { WireframeManager.Self.FocusSelectionIfOffScreen(); } }
private void WithoutEnvokeRefreshTreeNode(TreeNode treeNode, AnimationChainSave animationChain) { treeNode.Nodes.Clear(); treeNode.Tag = animationChain; treeNode.Text = animationChain.Name; foreach (var frame in animationChain.Frames) { TreeNode frameNode = new TreeNode(); frameNode.Text = frame.TextureName; if (string.IsNullOrEmpty(frame.TextureName)) { frameNode.Text = "<UNTEXTURED>"; } else { var texture = WireframeManager.Self.GetTextureForFrame(frame); if (texture != null) { frameNode.Text += string.Format( " {0},{1}", frame.LeftCoordinate * texture.Width, frame.TopCoordinate * texture.Height); } } frameNode.Tag = frame; treeNode.Nodes.Add(frameNode); } }
internal void HandlePaste() { var dataObject = Clipboard.GetDataObject(); if (ProjectManager.Self.AnimationChainListSave != null) { if (dataObject.GetDataPresent("frame") && SelectedState.Self.SelectedChain != null) { // paste this in the chain // clone it, in case multiple pastes occur: AnimationFrameSave whatToCopy = dataObject.GetData("frame") as AnimationFrameSave; AnimationFrameSave newAfs = FileManager.CloneObject(whatToCopy); SelectedState.Self.SelectedChain.Frames.Add(newAfs); TreeViewManager.Self.RefreshTreeNode(SelectedState.Self.SelectedChain); SelectedState.Self.SelectedFrame = newAfs; MainControl.Self.RaiseAnimationChainChanges(null, null); } else if (dataObject.GetDataPresent("chain")) { object data = dataObject.GetData("chain"); AnimationChainSave whatToCopy = data as AnimationChainSave; Duplicate(whatToCopy); } } }
private void UpdateShownProperties() { AnimationChainSave acs = new AnimationChainSave(); ExcludeMember("ParentFile"); ExcludeMember("Frames"); ExcludeMember("ColorKey"); }
private void FlipAnimationChainHorizontally(object sender, EventArgs e) { AnimationChainSave acs = SelectedState.Self.SelectedChain; if (acs != null) { FlipHorizontally(acs); CallAnimationChainsChange(); } }
public TreeNode GetTreeNodeFor(AnimationChainSave acs) { if (acs == null) { return(null); } else { return(GetTreeNodeByTag(acs, mTreeView.Nodes)); } }
private void FlipHorizontally(AnimationChainSave acs) { foreach (AnimationFrameSave afs in acs.Frames) { afs.RelativeX *= -1; afs.FlipHorizontal = !afs.FlipHorizontal; } WireframeManager.Self.RefreshAll(); PreviewManager.Self.RefreshAll(); }
public void RefreshTreeView() { mTreeView.Invoke((MethodInvoker) delegate() { AnimationFrameSave selectedAnimationFrame = SelectedState.Self.SelectedFrame; AnimationChainSave selectedAnimationChain = SelectedState.Self.SelectedChain; List <AnimationChainSave> expandedAnimationChains = new List <AnimationChainSave>(); foreach (TreeNode treeNode in mTreeView.Nodes) { if (treeNode.IsExpanded) { expandedAnimationChains.Add(treeNode.Tag as AnimationChainSave); } } mTreeView.Nodes.Clear(); if (ProjectManager.Self.AnimationChainListSave != null) { TreeNode[] nodesToAdd = new TreeNode[ProjectManager.Self.AnimationChainListSave.AnimationChains.Count]; int index = 0; foreach (var animationChain in ProjectManager.Self.AnimationChainListSave.AnimationChains) { TreeNode treeNode = new TreeNode(); nodesToAdd[index] = treeNode; WithoutEnvokeRefreshTreeNode(treeNode, animationChain); if (expandedAnimationChains.Contains(animationChain)) { treeNode.Expand(); } index++; } mTreeView.Nodes.AddRange(nodesToAdd); if (selectedAnimationFrame != null) { SelectedState.Self.SelectedFrame = selectedAnimationFrame; } if (mTreeView.SelectedNode == null && selectedAnimationChain != null) { SelectedState.Self.SelectedChain = selectedAnimationChain; } } }); }
private static AnimationChainSave[] _GenerateAnimChain(AnimDef animDef) { // * frame coordinates are in pixels. top-left = 0,0 bottom-right = +X +Y float xStart = animDef.CellXstartIndex * _FrameSize.Width; float yStart = animDef.CellYstartIndex * _FrameSize.Height; AnimationChainSave[] animsList = new AnimationChainSave[_Rotations]; //float currentXStart; float currentYTop; float currentYBottom; float left; AnimationChainSave oneRotAnim; AnimationFrameSave frame; for (ushort iRotation = 0; iRotation < 16; iRotation++) { currentYTop = yStart + iRotation * _FrameSize.Height; currentYBottom = currentYTop + _FrameSize.Height; oneRotAnim = new AnimationChainSave(); // animDef.FramesPerRotation oneRotAnim.Name = animDef.AnimName + '_' + iRotation.ToString(); for (ushort iFrame = 0; iFrame < animDef.FramesPerRotation; iFrame++) { left = xStart + iFrame * _FrameSize.Width; frame = new AnimationFrameSave // (_FramesTexture, 0) { TextureName = _SpriteSheetFileName, TopCoordinate = currentYTop, BottomCoordinate = currentYBottom, LeftCoordinate = left, RightCoordinate = left + _FrameSize.Width, RelativeX = _AllFramesOffset.X, RelativeY = _AllFramesOffset.Y, FrameLength = 0.1f }; //oneRotAnim.Add(frame); oneRotAnim.Frames.Add(frame); } //animsList.Add(oneRotAnim); animsList[iRotation] = oneRotAnim; } return(animsList); }
private void FlipAnimationChainHorizontally(object sender, EventArgs e) { AnimationChainSave acs = SelectedState.Self.SelectedChain; if (acs != null) { foreach (AnimationFrameSave afs in acs.Frames) { afs.RelativeX *= -1; afs.FlipHorizontal = !afs.FlipHorizontal; } WireframeManager.Self.RefreshAll(); PreviewManager.Self.RefreshAll(); CallAnimationChainsChange(); } }
void AdjustFrameTimeClick(object sender, EventArgs args) { float oldTotalLength = 0; AnimationChainSave animation = SelectedState.Self.SelectedChain; foreach (var frame in animation.Frames) { oldTotalLength += frame.FrameLength; } AnimationChainTimeScaleWindow window = new AnimationChainTimeScaleWindow(); window.Value = oldTotalLength; window.FrameCount = animation.Frames.Count; DialogResult result = window.ShowDialog(); if (result == DialogResult.OK && animation.Frames.Count != 0) { float newValue = window.Value; if (window.ScaleMode == ScaleMode.KeepProportional) { float scaleValue = window.Value / oldTotalLength; foreach (var frame in animation.Frames) { frame.FrameLength *= scaleValue; } } else // value is to set all frames { int frameCount = animation.Frames.Count; foreach (var frame in animation.Frames) { frame.FrameLength = window.Value / frameCount; } } PropertyGridManager.Self.Refresh(); PreviewManager.Self.RefreshAll(); this.CallAnimationChainsChange(); } }
public void RefreshTreeNode(AnimationChainSave animationChain) { if (animationChain != null) { mTreeView.Invoke((MethodInvoker) delegate() { TreeNode treeNode = GetTreeNodeByTag(animationChain, mTreeView.Nodes); if (treeNode == null) { treeNode = new TreeNode(); mTreeView.Nodes.Add(treeNode); } WithoutEnvokeRefreshTreeNode(treeNode, animationChain); }); } }
public void AddFrameClick(object sender, EventArgs args) { AnimationChainSave chain = SelectedState.Self.SelectedChain; if (string.IsNullOrEmpty(ProjectManager.Self.FileName)) { MessageBox.Show("You must first save this file before adding frames"); } else if (chain == null) { MessageBox.Show("First select an Animation to add a frame to"); } else { AnimationFrameSave afs = new AnimationFrameSave(); if (chain.Frames.Count != 0) { AnimationFrameSave copyFrom = chain.Frames[0]; afs.TextureName = copyFrom.TextureName; afs.FrameLength = copyFrom.FrameLength; afs.LeftCoordinate = copyFrom.LeftCoordinate; afs.RightCoordinate = copyFrom.RightCoordinate; afs.TopCoordinate = copyFrom.TopCoordinate; afs.BottomCoordinate = copyFrom.BottomCoordinate; } else { afs.FrameLength = .1f; // default to .1 seconds. } chain.Frames.Add(afs); TreeViewManager.Self.RefreshTreeNode(chain); SelectedState.Self.SelectedFrame = afs; CallAnimationChainsChange(); } }
private void MoveSpriteAccordingToAlignmentAndOffset(RenderingLibrary.Graphics.Sprite sprite, AnimationFrameSave frame) { // Event though we may not be rendering the main Sprite, we want to use the main Sprite's animation: IAnimation animation = mSprite.Animation; if (sprite != null && sprite.Visible && mSprite.Animation != null) { int index = sprite.Animation.CurrentFrameIndex; float animationXOffset = 0; float animationYOffset = 0; AnimationChainSave chain = SelectedState.Self.SelectedChain; if (chain != null && chain.Frames.Count > index) { if (frame == null) { frame = chain.Frames[index]; } animationXOffset = frame.RelativeX * OffsetMultiplier; animationYOffset = frame.RelativeY * OffsetMultiplier; } if (SpriteAlignment == Data.SpriteAlignment.Center) { float xOffset = (-sprite.EffectiveWidth) / 2.0f; float yOffset = (-sprite.EffectiveHeight) / 2.0f; sprite.X = xOffset + animationXOffset; sprite.Y = yOffset - animationYOffset; } else { sprite.X = 0 + animationXOffset; sprite.Y = 0 - animationYOffset; } } }
private void HandleDroppedImageOnAnimationChain(TreeNode targetNode, string folder, string fileNameCopy, bool isCtrlDown) { AnimationChainSave animationChainSave = targetNode.Tag as AnimationChainSave; string relativeFile = FileManager.MakeRelative(fileNameCopy, folder); bool madeChanges = false; if (isCtrlDown) { // ctrl is down, so add a new animation frame AnimationFrameSave newFrame = new AnimationFrameSave(); newFrame.FrameLength = .1f; newFrame.TextureName = relativeFile; animationChainSave.Frames.Add(newFrame); madeChanges = true; } else { string message = "Set all contained AnimationFrames' texture? Texture name:\n" + fileNameCopy; DialogResult result = MessageBox.Show(message, "Set all Textures?", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { foreach (AnimationFrameSave animationFrame in animationChainSave.Frames) { animationFrame.TextureName = relativeFile; } madeChanges = true; } } if (madeChanges) { PreviewManager.Self.RefreshAll(); WireframeManager.Self.RefreshAll(); TreeViewManager.Self.RefreshTreeView(); CallAnimationChainsChange(); } }
private static AnimationChainSave Duplicate(AnimationChainSave whatToCopy, string requestedName = null) { AnimationChainSave newAcs = FileManager.CloneObject(whatToCopy); if (requestedName != null) { newAcs.Name = requestedName; } List <string> existingNames = ProjectManager.Self.AnimationChainListSave.AnimationChains.Select(item => item.Name).ToList(); newAcs.Name = StringFunctions.MakeStringUnique(newAcs.Name, existingNames, 2); ProjectManager.Self.AnimationChainListSave.AnimationChains.Add(newAcs); TreeViewManager.Self.RefreshTreeNode(newAcs); MainControl.Self.RaiseAnimationChainChanges(null, null); SelectedState.Self.SelectedChain = newAcs; return(newAcs); }
private void CreateNewFrameFromMagicWand(int minX, int minY, int maxX, int maxY) { AnimationChainSave chain = SelectedState.Self.SelectedChain; if (string.IsNullOrEmpty(ProjectManager.Self.FileName)) { MessageBox.Show("You must first save this file before adding frames"); } else if (chain == null) { MessageBox.Show("First select an Animation to add a frame to"); } else { AnimationFrameSave afs = new AnimationFrameSave(); var texture = this.mInspectableTexture.Texture; var achxFolder = FlatRedBall.IO.FileManager.GetDirectory(ProjectManager.Self.FileName); var relative = FlatRedBall.IO.FileManager.MakeRelative(texture.Name, achxFolder); afs.TextureName = relative; afs.LeftCoordinate = minX / (float)texture.Width; afs.RightCoordinate = maxX / (float)texture.Width; afs.TopCoordinate = minY / (float)texture.Height; afs.BottomCoordinate = maxY / (float)texture.Height; afs.FrameLength = .1f; // default to .1 seconds. chain.Frames.Add(afs); TreeViewManager.Self.RefreshTreeNode(chain); SelectedState.Self.SelectedFrame = afs; AnimationChainChange?.Invoke(this, null); } }
public void AddChainClick(object sender, EventArgs args) { if (ProjectManager.Self.AnimationChainListSave == null) { MessageBox.Show("You must first save a file before working in the Animation Editor"); } else { TextInputWindow tiw = new TextInputWindow(); tiw.DisplayText = "Enter new AnimationChain name"; if (tiw.ShowDialog() == DialogResult.OK) { string result = tiw.Result; string whyIsntValid = GetWhyNameIsntValid(result); if (!string.IsNullOrEmpty(whyIsntValid)) { MessageBox.Show(whyIsntValid); } else { AnimationChainSave acs = new AnimationChainSave(); acs.Name = result; ProjectManager.Self.AnimationChainListSave.AnimationChains.Add(acs); TreeViewManager.Self.RefreshTreeView(); SelectedState.Self.SelectedChain = acs; CallAnimationChainsChange(); } } } }
public static Animation FromAnimationSave(AnimationChainSave animationSave) { Animation toReturn = new Animation(); toReturn.Name = animationSave.Name; foreach (var frame in animationSave.Frames) { CCRect rectangle; rectangle = new CCRect( frame.LeftCoordinate, frame.TopCoordinate, frame.RightCoordinate - frame.LeftCoordinate, frame.BottomCoordinate - frame.TopCoordinate); var duration = TimeSpan.FromSeconds(frame.FrameLength); toReturn.AddFrame(rectangle, duration, flipHorizontal: frame.FlipHorizontal); } return(toReturn); }
internal void HandlePaste() { var dataObject = Clipboard.GetDataObject(); if (ProjectManager.Self.AnimationChainListSave != null) { if (dataObject.GetDataPresent("frame") && SelectedState.Self.SelectedChain != null) { // paste this in the chain // clone it, in case multiple pastes occur: AnimationFrameSave whatToCopy = dataObject.GetData("frame") as AnimationFrameSave; AnimationFrameSave newAfs = FileManager.CloneObject(whatToCopy); SelectedState.Self.SelectedChain.Frames.Add(newAfs); TreeViewManager.Self.RefreshTreeNode(SelectedState.Self.SelectedChain); SelectedState.Self.SelectedFrame = newAfs; MainControl.Self.RaiseAnimationChainChanges(null, null); } else if (dataObject.GetDataPresent("chain")) { object data = dataObject.GetData("chain"); AnimationChainSave whatToCopy = data as AnimationChainSave; AnimationChainSave newAcs = FileManager.CloneObject(whatToCopy); List <string> existingNames = ProjectManager.Self.AnimationChainListSave.AnimationChains.Select(item => item.Name).ToList(); newAcs.Name = StringFunctions.MakeStringUnique(newAcs.Name, existingNames, 2); ProjectManager.Self.AnimationChainListSave.AnimationChains.Add(newAcs); TreeViewManager.Self.RefreshTreeNode(newAcs); MainControl.Self.RaiseAnimationChainChanges(null, null); SelectedState.Self.SelectedChain = newAcs; } } }
public void RefreshTreeNode(AnimationChainSave animationChain) { mTreeView.Invoke((MethodInvoker)delegate() { TreeNode treeNode = GetTreeNodeByTag(animationChain, mTreeView.Nodes); if(treeNode == null) { treeNode = new TreeNode(); mTreeView.Nodes.Add(treeNode); } WithoutEnvokeRefreshTreeNode(treeNode, animationChain); }); }
public TreeNode GetTreeNodeFor(AnimationChainSave acs) { if (acs == null) { return null; } else { return GetTreeNodeByTag(acs, mTreeView.Nodes); } }