Example #1
0
 public void CopyValuesTo(CompositeAnimation target, CompositeEntity newParent)
 {
     target.Parent = newParent;
     target.Name   = this.Name;
     target.LerpLastFrameWithFirst = this.LerpLastFrameWithFirst;
     target.IsPaused        = this.IsPaused;
     target.IsStopped       = this.IsStopped;
     target.LoopMax         = this.LoopMax;
     target.Speed           = this.Speed;
     target.AutoPlay        = this.AutoPlay;
     target.HideWhenStopped = this.HideWhenStopped;
     // copy keyframes
     for (int i = 0; i < this._keyFrames.Count; i++)
     {
         // if no particle type is available
         if (target.KeyFrames.Count <= i)
         {
             target.KeyFrames.Add(new CompositeKeyFrame(target));
         }
         this.KeyFrames[i].CopyValuesTo(target.KeyFrames[i], target);
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.KeyFrames.Count; i > this.KeyFrames.Count; i--)
     {
         target.KeyFrames.RemoveAt(i - 1);
     }
     target.Reset();
 }
 public CompositeKeyFrame(CompositeAnimation parentAnimation)
 {
     _name = "New keyFrame";
     _boneTransforms = new List<CompositeBoneTransform>();
     _duration = 100;
     Parent = parentAnimation;
 }
 public CompositeKeyFrame(CompositeAnimation parentAnimation)
 {
     _name           = "New keyFrame";
     _boneTransforms = new List <CompositeBoneTransform>();
     _duration       = 100;
     Parent          = parentAnimation;
 }
Example #4
0
 internal void OnEndOfAnimLoopReached(CompositeAnimation compositeAnimation)
 {
     if (EndOfAnimLoopReached != null)
     {
         EndOfAnimLoopReached(compositeAnimation, EventArgs.Empty);
     }
     if (_queuedAnimationID.HasValue)
     {
         compositeAnimation.IsStopped = true;
         compositeAnimation.Reset();
         _currentAnimationID = _queuedAnimationID.Value;
         _animations[_queuedAnimationID.Value].Play();
         _queuedAnimationID = null;
     }
 }
 public void CopyValuesTo(CompositeKeyFrame target, CompositeAnimation newParent)
 {
     target.Parent   = newParent;
     target.Name     = this.Name;
     target.Duration = this.Duration;
     // copy CompositeBoneTransforms
     for (int i = 0; i < this.BoneTransforms.Count; i++)
     {
         // if no transform is available
         if (target.BoneTransforms.Count <= i)
         {
             target.BoneTransforms.Add(new CompositeBoneTransform());
         }
         this.BoneTransforms[i].CopyValuesTo(target.BoneTransforms[i], target);
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.BoneTransforms.Count; i > this.BoneTransforms.Count; i--)
     {
         target.BoneTransforms.RemoveAt(i - 1);
     }
 }
 public void CopyValuesTo(CompositeKeyFrame target, CompositeAnimation newParent)
 {
     target.Parent = newParent;
     target.Name = this.Name;
     target.Duration = this.Duration;
     // copy CompositeBoneTransforms            
     for (int i = 0; i < this.BoneTransforms.Count; i++)
     {
         // if no transform is available
         if (target.BoneTransforms.Count <= i)
         {
             target.BoneTransforms.Add(new CompositeBoneTransform());
         }
         this.BoneTransforms[i].CopyValuesTo(target.BoneTransforms[i], target);
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.BoneTransforms.Count; i > this.BoneTransforms.Count; i--)
     {
         target.BoneTransforms.RemoveAt(i - 1);
     }
 }
 public void CopyValuesTo(CompositeAnimation target, CompositeEntity newParent)
 {
     target.Parent = newParent;
     target.Name = this.Name;
     target.LerpLastFrameWithFirst = this.LerpLastFrameWithFirst;
     target.IsPaused = this.IsPaused;
     target.IsStopped = this.IsStopped;
     target.LoopMax = this.LoopMax;
     target.Speed = this.Speed;
     target.AutoPlay = this.AutoPlay;
     target.HideWhenStopped = this.HideWhenStopped;
     // copy keyframes
     for (int i = 0; i < this._keyFrames.Count; i++)
     {
         // if no particle type is available
         if (target.KeyFrames.Count <= i)
         {
             target.KeyFrames.Add(new CompositeKeyFrame(target));
         }
         this.KeyFrames[i].CopyValuesTo(target.KeyFrames[i], target);                
     }
     // Remove remaining types (can cause garbage!)
     for (int i = target.KeyFrames.Count; i > this.KeyFrames.Count; i--)
     {
         target.KeyFrames.RemoveAt(i-1);
     }
     target.Reset();
 }
Example #8
0
 internal void OnEndOfAnimLoopReached(CompositeAnimation compositeAnimation)
 {
     if (EndOfAnimLoopReached != null)
     {
         EndOfAnimLoopReached(compositeAnimation, EventArgs.Empty);
     }
     if (_queuedAnimationID.HasValue)
     {
         compositeAnimation.IsStopped = true;
         compositeAnimation.Reset();
         _currentAnimationID = _queuedAnimationID.Value;
         _animations[_queuedAnimationID.Value].Play();
         _queuedAnimationID = null;
     }
 }
Example #9
0
        private static void SetProperty(string p, object targetObject, XmlNode node, object defaultValue)
        {
            if (targetObject is SceneItem)
            {
                TraceLogger.TraceVerbose("Setting Property " + p + " On SceneItem - " + ((SceneItem)targetObject).Name);
            }
            else
            {
                TraceLogger.TraceVerbose("Setting Property " + p + " On Object - " + targetObject.GetType().Name);
            }

            PropertyInfo _prop = targetObject.GetType().GetProperty(p);
            if (_prop == null)
            {
                return;
            }         
            XmlNode _newNode = node.SelectSingleNode(_prop.Name);
            if (_newNode == null)
            {
                if (defaultValue != null)
                {
                    _prop.SetValue(targetObject, defaultValue, null);
                    return;
                }
                if (_prop.PropertyType == typeof(bool))
                {
                    _prop.SetValue(targetObject, false, null);
                }
                else if (_prop.PropertyType == typeof(bool?))
                {
                    _prop.SetValue(targetObject, null, null);
                }
                else if (_prop.PropertyType == typeof(int))
                {
                    _prop.SetValue(targetObject, 0, null);
                }
                else if (_prop.PropertyType == typeof(String))
                {
                    _prop.SetValue(targetObject, String.Empty, null);
                }
                else if (_prop.PropertyType == typeof(Vector2))
                {
                    _prop.SetValue(targetObject, Vector2.Zero, null);
                }
                else if (_prop.PropertyType == typeof(Point))
                {
                    _prop.SetValue(targetObject, Point.Zero, null);
                }
                return;
            }
            TraceLogger.TraceVerbose("Property Type [" + _prop.PropertyType.Name + "]");

            if (_prop.PropertyType == typeof(Vector2))
            {
                _prop.SetValue(targetObject, ParseVector(_newNode), null);
            }
            else if (_prop.PropertyType == typeof(List<Vector2>))
            {
                
                List<Vector2> list = new List<Vector2>();
                foreach (XmlNode vecnode in _newNode.ChildNodes)
                {
                    list.Add(ParseVector(vecnode));
                }
                _prop.SetValue(targetObject, list, null);
            }
            /* FARSEER tile polygone serialization
            else if (_prop.PropertyType == typeof(List<Polygon>))
            {                
                List<Polygon> list = new List<Polygon>();
                foreach (XmlNode vecnode in _newNode.ChildNodes)
                {
                    list.Add(Polygon.FromString(vecnode.InnerText));
                }
                _prop.SetValue(targetObject, list, null);
            }*/
            else if (_prop.PropertyType == typeof(Rectangle?))
            {
                if (_newNode.Attributes.Count == 4)
                {
                    _prop.SetValue(targetObject, ParseRectangleNullable(_newNode), null);
                }
                else
                {
                    _prop.SetValue(targetObject, null, null);
                }
                
            }
            else if (_prop.PropertyType == typeof(Rectangle))
            {
                if (_newNode.Attributes.Count == 4)
                    {
                        _prop.SetValue(targetObject, ParseRectangle(_newNode), null);
                    }                
            }
            else if (_prop.PropertyType == typeof(Point))
            {
                Point _point = new Point(
                    int.Parse(node.SelectSingleNode(_prop.Name + "/X").InnerText, CultureInfo.InvariantCulture),
                    int.Parse(node.SelectSingleNode(_prop.Name + "/Y").InnerText, CultureInfo.InvariantCulture));
                _prop.SetValue(targetObject, _point, null);
            }
            else if (_prop.PropertyType == typeof(float))
            {
                _prop.SetValue(targetObject, Single.Parse(_newNode.InnerText,
                    CultureInfo.InvariantCulture), null);
            }
            else if (_prop.PropertyType == typeof(Color))
            {
                Color newColor = (Color)ParseToColor(_newNode.InnerText);
                    _prop.SetValue(targetObject, newColor, null);
               
            }
            else if (_prop.PropertyType == typeof(bool))
            { 
                _prop.SetValue(targetObject, bool.Parse(_newNode.InnerText), null);
            }
            else if (_prop.PropertyType == typeof(bool?))
            {
                if (String.IsNullOrEmpty(_newNode.InnerText) == false)
                {
                    _prop.SetValue(targetObject, bool.Parse(_newNode.InnerText), null);
                }
                else
                {
                    _prop.SetValue(targetObject, null, null);
                }
            }
            else if (_prop.PropertyType == typeof(byte))
            {
#if(WINDOWS)
                _prop.SetValue(targetObject, byte.Parse(_newNode.InnerText,
                    CultureInfo.InvariantCulture), null);
#else
                byte b = (byte)int.Parse(_newNode.InnerText);
                _prop.SetValue(targetObject, b, null);
#endif
            }
            else if (_prop.PropertyType == typeof(byte?))
            {
                if (String.IsNullOrEmpty(_newNode.InnerText) == false)
                {
#if(WINDOWS)
                    _prop.SetValue(targetObject, byte.Parse(_newNode.InnerText, CultureInfo.InvariantCulture), null);
#else
                    byte b = (byte)int.Parse(_newNode.InnerText);
                    _prop.SetValue(targetObject, b, null);
#endif
                }
            }
            else if (_prop.PropertyType == typeof(int))
            {
                _prop.SetValue(targetObject, int.Parse(_newNode.InnerText, CultureInfo.InvariantCulture), null);
            }
            else if (_prop.PropertyType == typeof(string))
            {
                _prop.SetValue(targetObject, _newNode.InnerText, null);
            }
            else if (_prop.PropertyType.BaseType == typeof(Enum))
            {
#if(WINDOWS)
                Enum val = (Enum)Enum.Parse(_prop.PropertyType, _newNode.InnerText);
                _prop.SetValue(targetObject, Convert.ChangeType(val, _prop.PropertyType), null);
#else

                Enum val = (Enum)Enum.Parse(_prop.PropertyType, _newNode.InnerText, true);
                _prop.SetValue(targetObject, Convert.ChangeType(val, _prop.PropertyType, null), null);
#endif
            }
            else if (_prop.PropertyType == typeof(CompositeBone))
            {
                CompositeBone bone = GetCompositeBone(_newNode);
                _prop.SetValue(targetObject, bone, null);
            }
            else if (_prop.PropertyType == typeof(List<CompositeBone>))
            {
                CompositeBone parent = targetObject as CompositeBone;
                foreach (XmlNode vecnode in _newNode.ChildNodes)
                {
                    CompositeBone anim = GetCompositeBone(vecnode);
                    anim.ParentBone = parent;
                    parent.ChildBones.Add(anim);
                }
            }            
            else if (_prop.PropertyType == typeof(Dictionary<string, SceneItem>))
            {

                Dictionary<string, SceneItem> dict = new Dictionary<string, SceneItem>();
                foreach (XmlNode vecnode in _newNode.ChildNodes)
                {
                    string type = vecnode.Attributes[0].InnerText;
                    XmlNode _itemNode = vecnode.ChildNodes[0];
                    SceneItem item = LoadSceneItem(_itemNode, _storedScene);
                    dict.Add(type, item);
                }
                _prop.SetValue(targetObject, dict, null);
            }
            else if (_prop.PropertyType == typeof(List<CompositeAnimation>))
            {
                List<CompositeAnimation> list = new List<CompositeAnimation>();
                foreach (XmlNode vecnode in _newNode.ChildNodes)
                {
                    CompositeAnimation anim = new CompositeAnimation();
                    anim.Parent = targetObject as CompositeEntity;
                    anim.Name = vecnode.Attributes["Name"].Value;
                    SetProperty("LerpLastFrameWithFirst", anim, vecnode);
                    SetProperty("Speed", anim, vecnode);
                    SetProperty("KeyFrames", anim, vecnode);
                    SetIAnimationProperties(vecnode, anim as IAnimation);
                    list.Add(anim);
                }

                _prop.SetValue(targetObject, list, null);
            }
            else if (_prop.PropertyType == typeof(List<CompositeKeyFrame>))
            {

                List<CompositeKeyFrame> list = new List<CompositeKeyFrame>();
                foreach (XmlNode vecnode in _newNode.ChildNodes)
                {
                    CompositeKeyFrame animKeyFrame = new CompositeKeyFrame();
                    animKeyFrame.Parent = targetObject as CompositeAnimation;
                    animKeyFrame.Name = vecnode.Attributes["Name"].Value;
                    animKeyFrame.Duration = int.Parse(vecnode.Attributes["Duration"].Value, CultureInfo.InvariantCulture);
                    //Bone transforms
                    XmlNode _boneTransNode = vecnode.SelectSingleNode("BoneTransforms");
                    foreach (XmlNode transNode in _boneTransNode.ChildNodes)
                    {
                        CompositeBoneTransform boneTransform = new CompositeBoneTransform();
                        boneTransform.Parent = animKeyFrame;
                        SetProperty("BoneReference", boneTransform, transNode);
                        SetProperty("SceneItem", boneTransform, transNode);
                        SetProperty("SubItem", boneTransform, transNode);
                        SetProperty("IsVisible", boneTransform, transNode, true);
                        SetProperty("Position", boneTransform, transNode, Vector2.Zero);
                        SetProperty("Rotation", boneTransform, transNode, 0);
                        SetProperty("Opacity", boneTransform, transNode);
                        SetProperty("Scale", boneTransform, transNode, Vector2.One);
                        SetProperty("InheritPosition", boneTransform, transNode);
                        SetProperty("InheritRotation", boneTransform, transNode);
                        SetProperty("InheritScale", boneTransform, transNode);
                        SetProperty("InheritVisibility", boneTransform, transNode);
                        SetProperty("FlipHorizontal", boneTransform, transNode);
                        SetProperty("FlipVertical", boneTransform, transNode);
                        animKeyFrame.AddCompositeBoneTransform(boneTransform);
                    }
                    list.Add(animKeyFrame);
                }

                _prop.SetValue(targetObject, list, null);
            }
            else if (_prop.PropertyType == typeof(List<AnimationFrame>))
            {

                List<AnimationFrame> listFrames = new List<AnimationFrame>();
                foreach (XmlNode vecnode in _newNode.ChildNodes)
                {
                    AnimationFrame frame = new AnimationFrame();
                    frame.Area = vecnode.Attributes["Area"].Value;
                    frame.Duration = int.Parse(vecnode.Attributes["Duration"].Value,
                        CultureInfo.InvariantCulture);
                    listFrames.Add(frame);
                }
                _prop.SetValue(targetObject, listFrames, null);
            }
            else if (_prop.PropertyType == typeof(LinearProperty))
            {
                LinearProperty lin = (LinearProperty)_prop.GetValue(targetObject, null);
                lin.Description = _newNode.SelectSingleNode("Description").InnerText;
                lin.LowerBound = int.Parse(_newNode.SelectSingleNode("LowerBound").InnerText, CultureInfo.InvariantCulture);
                lin.UpperBound = int.Parse(_newNode.SelectSingleNode("UpperBound").InnerText, CultureInfo.InvariantCulture);

                foreach (XmlNode item in _newNode.SelectSingleNode("Values").ChildNodes)
                {
                    lin.Values.Add(new Vector2(
                        float.Parse(item.SelectSingleNode("X").InnerText, CultureInfo.InvariantCulture),
                        float.Parse(item.SelectSingleNode("Y").InnerText, CultureInfo.InvariantCulture)));
                }
            }
            else
            {
                TraceLogger.TraceWarning("Not Set By SetProperty - " + p);
            }
        }
 private void toolStripButtonDuplicateAnim_Click(object sender, EventArgs e)
 {
     if (listViewAnimations.SelectedIndices.Count > 0)
     {
         int selectedAnim = listViewAnimations.SelectedIndices[0];
         CompositeAnimation duplicate = new CompositeAnimation();
         this.SelectedCompositeAnimation.CopyValuesTo(duplicate, this.SelectedCompositeAnimation.Parent);
         duplicate.Name = GetNewAnimationName(duplicate.Name + " ");
         CompositeEntity.Animations.Add(duplicate);
         listViewAnimations.Items.Add(duplicate.Name);
     }
 }
 private void toolStripButtonAddAnimation_Click(object sender, EventArgs e)
 {            
     CompositeAnimation newAnim = new CompositeAnimation(CompositeEntity);
     newAnim.Name = GetNewAnimationName("Animation ");
     CompositeEntity.Animations.Add(newAnim);
     listViewAnimations.Items.Add(newAnim.Name);
 }