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 override void CopyValuesTo(SceneItem target) { base.CopyValuesTo(target); CompositeEntity compositeEntity = target as CompositeEntity; if (this.RootBone == null) { compositeEntity.RootBone = null; } else { this.RootBone.CopyValuesTo(compositeEntity.RootBone, null, compositeEntity); } // copy animations for (int i = 0; i < this._animations.Count; i++) { // if no animation is available if (compositeEntity.Animations.Count <= i) { compositeEntity.Animations.Add(new CompositeAnimation(compositeEntity)); } this.Animations[i].CopyValuesTo(compositeEntity.Animations[i], compositeEntity); compositeEntity.Animations[i].Parent = compositeEntity; } // Remove remaining animations (can cause garbage!) for (int i = compositeEntity.Animations.Count; i > this.Animations.Count; i--) { compositeEntity.Animations.RemoveAt(i - 1); } // copy bank foreach (String key in this.SceneItemBank.Keys) { // if the entry is not available, create it if (compositeEntity.SceneItemBank.ContainsKey(key) == false || this.SceneItemBank[key].GetType() != compositeEntity.SceneItemBank[key].GetType()) { //Can't just create a blank sceneitem. it won't create a new instance of AnimatedSprite for instance SceneItem newItem = CreateNewInstaceCopyOf(this.SceneItemBank[key]); compositeEntity.SceneItemBank[key] = newItem; } this.SceneItemBank[key].CopyValuesTo(compositeEntity.SceneItemBank[key]); } // Remove remaining unused key (can cause garbage!) List <String> keysToRemove = new List <string>(); foreach (String key in compositeEntity.SceneItemBank.Keys) { if (this.SceneItemBank.ContainsKey(key) == false) { keysToRemove.Add(key); } } foreach (String key in keysToRemove) { compositeEntity.SceneItemBank.Remove(key); } }
public CompositeAnimation(CompositeEntity parent) { _keyFrames = new List <CompositeKeyFrame>(); _name = "New Animation"; _currentLife = 0; _currentKeyFrameIndex = 0; _loopMax = 0; _loopCounter = 0; _speed = 1; this.Parent = parent; this.AutoPlay = true; this.LerpLastFrameWithFirst = true; }
public CompositeAnimation(CompositeEntity parent) { _keyFrames = new List<CompositeKeyFrame>(); _name = "New Animation"; _currentLife = 0; _currentKeyFrameIndex = 0; _loopMax = 0; _loopCounter = 0; _speed = 1; this.Parent = parent; this.AutoPlay = true; this.LerpLastFrameWithFirst = true; }
public void CopyValuesTo(CompositeBone target, CompositeBone parentBone, CompositeEntity newParentEntity) { target.Parent = newParentEntity; target.ParentBone = parentBone; target.Name = this.Name; target.SceneItem = this.SceneItem; target.SubItem = this.SubItem; target.InheritPosition = this.InheritPosition; target.InheritRotation = this.InheritRotation; target.InheritScale = this.InheritScale; target.InheritVisibility = this.InheritVisibility; target.MasterVisibility = this.MasterVisibility; target.Interpolate = this.Interpolate; // copy bones for (int i = 0; i < this.ChildBones.Count; i++) { CompositeBone targetCBone; bool addToList = false; // if no child bone is available, create a new one if (target.ChildBones.Count <= i) { targetCBone = new CompositeBone(); addToList = true; } else { targetCBone = target.ChildBones[i]; } this.ChildBones[i].CopyValuesTo(targetCBone, target, newParentEntity); if (addToList == true) { target.AddChildBone(targetCBone); } } // Remove remaining types (can cause garbage!) for (int i = target.ChildBones.Count; i > this.ChildBones.Count; i--) { target.ChildBones.RemoveAt(i - 1); } }
public void Draw(float elapsed) { if (Parent == null) { throw new Exception("The Parent of this boneTransform isn't set"); } SceneItem item = GetSceneItem(); if (item != null) { if (_currentVisibleState == true) { CompositeEntity parentEntity = Parent.Parent.Parent; Vector2 tmpPivot = item.Pivot; bool tmpPivotRelative = item.IsPivotRelative; item.Rotation = parentEntity.Rotation + _rotation; item.Scale = parentEntity.Scale * _scale; item.Visible = true; item.Position = parentEntity.Position + _position; float parentOpacityFactor = parentEntity.Opacity / 255.0f; if (_opacity.HasValue) { item.Opacity = (byte)(_opacity.Value * parentOpacityFactor); } else { item.Opacity = parentEntity.Opacity; } item.Layer = parentEntity.Layer; item.Pivot = _transformPivot; item.IsPivotRelative = false; item.Draw(elapsed); item.Pivot = tmpPivot; item.IsPivotRelative = tmpPivotRelative; } else { item.Visible = false; } } }
public SceneItem GetSceneItem() { String targetItem = null; // use the default if no local override if (String.IsNullOrEmpty(_sceneItem) == true) { targetItem = this.Bone.SceneItem; } else { targetItem = _sceneItem; } CompositeEntity parentEntity = Parent.Parent.Parent; if (String.IsNullOrEmpty(targetItem) == false && parentEntity.SceneItemBank.ContainsKey(targetItem)) { return(parentEntity.SceneItemBank[targetItem]); } return(null); }
public void LerpSceneItemWith(CompositeBoneTransform nextState, float amount, bool nextStateOverride) { // original is only used when bone.Interpolate is set to false, and refer to the 1st KF of the 1st anim SceneItem item = GetSceneItem(); String subItem = GetSubItem(); if (String.IsNullOrEmpty(subItem) == false && item is ISubItemCollection) { ((ISubItemCollection)item).SetCurrentSubItem(subItem); } if (item != null) { item.Update(1 / 60f); amount = MathHelper.Clamp(amount, 0, 1); CompositeEntity parentEntity = Parent.Parent.Parent; CompositeBoneTransform parentTransform = this.ParentBoneTransform; _currentVisibleState = GetVisibilityState(parentTransform); if (_currentVisibleState == false) { return; } bool nextStateVisibility = nextState.GetVisibilityState(nextState.ParentBoneTransform); // no lerping if the next state isnt visible if (nextStateVisibility == false) { nextState = this; } if (nextStateOverride == true) { _position = nextState.Position; _scale = nextState.Scale; _rotation = nextState.Rotation; } else { _position = Vector2.Lerp(this.Position, nextState.Position, amount); _scale = Vector2.Lerp(this.Scale, nextState.Scale, amount); _rotation = MathHelper.Lerp(this.Rotation, nextState.Rotation, amount); } if (this.Opacity.HasValue == true || nextState.Opacity.HasValue == true) { if (this.Opacity.HasValue == true && nextState.Opacity.HasValue == false) { _opacity = this.Opacity.Value; } else if (this.Opacity.HasValue == false && nextState.Opacity.HasValue == true) { _opacity = nextState.Opacity.Value; } else { _opacity = IceMath.Lerp(this.Opacity.Value, nextState.Opacity.Value, amount); } } else { _opacity = null; } _transformPivot = item.GetAbsolutePivot(false); item.FlipHorizontal = parentEntity.FlipHorizontal ^ this.FlipHorizontal; item.FlipVertical = parentEntity.FlipVertical ^ this.FlipVertical; if (parentEntity.FlipHorizontal == true) { _position.X = -_position.X; _transformPivot.X = item.BoundingRectSize.X - _transformPivot.X; _rotation = -_rotation; } if (parentEntity.FlipVertical == true) { _position.Y = -_position.Y; _transformPivot.Y = item.BoundingRectSize.Y - _transformPivot.Y; _rotation = -_rotation; } if (parentEntity.Scale != Vector2.One) { _position *= parentEntity.Scale; } if (parentEntity.Rotation != 0) { Vector2 offset = _position; float length = offset.Length(); double angle = Math.Atan2((float)offset.Y, (float)offset.X) + parentEntity.Rotation; offset.X = (float)(length * Math.Cos(angle)); offset.Y = (float)(length * Math.Sin(angle)); _position = offset; } if (parentTransform != null) { if (this.InheritRotation.HasValue == false && this.Bone.InheritRotation == true || this.InheritRotation.HasValue == true && this.InheritRotation == true) { _rotation += parentTransform.CurrentRotation; } if (this.InheritScale.HasValue == false && this.Bone.InheritScale == true || this.InheritScale.HasValue == true && this.InheritScale == true) { _scale *= parentTransform.CurrentScale; } if (this.InheritPosition.HasValue == false && this.Bone.InheritPosition == true || this.InheritPosition.HasValue == true && this.InheritPosition == true) { Vector2 offset = _position; float length = offset.Length(); double angle = Math.Atan2((float)offset.Y, (float)offset.X) + parentTransform._rotation; offset.X = (float)(length * Math.Cos(angle)); offset.Y = (float)(length * Math.Sin(angle)); _position = parentTransform.CurrentPosition + offset; } } } }
public void CopyValuesTo(CompositeBone target, CompositeBone parentBone, CompositeEntity newParentEntity) { target.Parent = newParentEntity; target.ParentBone = parentBone; target.Name = this.Name; target.SceneItem = this.SceneItem; target.SubItem = this.SubItem; target.InheritPosition = this.InheritPosition; target.InheritRotation = this.InheritRotation; target.InheritScale = this.InheritScale; target.InheritVisibility = this.InheritVisibility; target.MasterVisibility = this.MasterVisibility; target.Interpolate = this.Interpolate; // copy bones for (int i = 0; i < this.ChildBones.Count; i++) { CompositeBone targetCBone; bool addToList = false; // if no child bone is available, create a new one if (target.ChildBones.Count <= i) { targetCBone = new CompositeBone(); addToList = true; } else { targetCBone = target.ChildBones[i]; } this.ChildBones[i].CopyValuesTo(targetCBone, target, newParentEntity); if (addToList == true) { target.AddChildBone(targetCBone); } } // Remove remaining types (can cause garbage!) for (int i = target.ChildBones.Count; i > this.ChildBones.Count; i--) { target.ChildBones.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(); }
internal SceneItem InstanciateNewItemOfType(SceneItemType type) { SceneItem item = null; switch (type) { case SceneItemType.AnimatedSprite: item = new AnimatedSprite(); AnimatedSprite animatedSprite = item as AnimatedSprite; animatedSprite.Material = SceneManager.GetEmbeddedTileGridMaterial(); AnimationInfo newAnim = new AnimationInfo("Counting"); newAnim.AnimationFrames.Add(new AnimationFrame(20, "1")); newAnim.AnimationFrames.Add(new AnimationFrame(20, "2")); newAnim.AnimationFrames.Add(new AnimationFrame(20, "3")); newAnim.AnimationFrames.Add(new AnimationFrame(20, "4")); animatedSprite.AddAnimation(newAnim); animatedSprite.PlayAnimation("Counting"); break; case SceneItemType.ParticleEffect: item = new ParticleEffect(); ParticleEffect effect = item as ParticleEffect; IceCream.SceneItems.ParticlesClasses.ParticleType pType = new IceCream.SceneItems.ParticlesClasses.ParticleType(); pType.Material = SceneManager.GetEmbeddedParticleMaterial(); effect.Emitter.ParticleTypes.Add(pType); effect.Name = "New Particle Effect"; effect.Play(); break; case SceneItemType.PostProcessingAnimation: item = new PostProcessAnimation(); item.Layer = 1; break; case SceneItemType.Sprite: item = new Sprite(); Sprite sprite = item as Sprite; sprite.Name = GetNewSpriteName(); ; sprite.Material = SceneManager.GetEmbeddedParticleMaterial(); break; case SceneItemType.TextItem: item = new TextItem(); TextItem text = item as TextItem; text.Name = GetNewTextItemName(); text.Font = SceneManager.GetEmbeddedFont("DefaultFont"); break; case SceneItemType.TileGrid: item = new TileGrid(); TileGrid tileGrid = item as TileGrid; tileGrid.Name = "New Tile Grid"; tileGrid.Material = SceneManager.GetEmbeddedTileGridMaterial(); tileGrid.TileRows = 4; tileGrid.TileCols = 10; tileGrid.TileSize = new Microsoft.Xna.Framework.Point(32, 32); TileLayer newLayer = new TileLayer(tileGrid.TileCols, tileGrid.TileRows); newLayer.Parent = tileGrid; newLayer.Visible = true; newLayer.Name = "Layer 1"; for (int tx = 0; tx < tileGrid.TileCols; tx++) { for (int ty = 0; ty < tileGrid.TileRows; ty++) { newLayer.Tiles[tx][ty].Index = 0; } } tileGrid.TileLayers.Add(newLayer); break; case SceneItemType.CompositeEntity: item = new CompositeEntity(); CompositeEntity composite = item as CompositeEntity; break; default: item = new SceneItem(); break; } return item; }
private static void WriteCompositeEntity(XmlNode itemNode, XmlDocument doc, CompositeEntity compositeEntity) { XmlNode entity = itemNode.AppendChild(doc.CreateElement("CompositeEntityData")); entity.AppendChildIfNotNull(WriteProperty("Animations", compositeEntity, doc)); entity.AppendChildIfNotNull(WriteProperty("SceneItemBank", compositeEntity, doc)); entity.AppendChildIfNotNull(WriteProperty("RootBone", compositeEntity, doc)); WriteIAnimationDirectorProperties(doc, entity, compositeEntity as IAnimationDirector); }
private static SceneItem LoadCompositeEntity(XmlNode node, SceneBase scene) { TraceLogger.TraceInfo("Beginning LoadCompositeAnimation"); _storedScene = scene as IceScene; CompositeEntity _compositeEntity = new CompositeEntity(); LoadBaseSceneItem(node, _compositeEntity); XmlNode _node = node.SelectSingleNode("CompositeEntityData"); SetProperty("SceneItemBank", _compositeEntity, _node); SetProperty("RootBone", _compositeEntity, _node); SetProperty("Animations", _compositeEntity, _node); SetIAnimationDirectorProperties(_node, _compositeEntity as IAnimationDirector); TraceLogger.TraceInfo("Ending LoadCompositeEntity"); return _compositeEntity; }
public CompositeEntityEditor() { InitializeComponent(); this.treeViewSceneItems.ImageList = MilkshakeForm.Instance.imageListTreeview; InitializeSceneItemsTreeViewNodes(); compositeEntityEditorControl.ParentEditor = this; ZoomBox = new ZoomBox(); ZoomBox.Camera.Pivot = new Vector2(0.5f); ZoomBox.SetToolStripButtomZoomIn(toolStripButtonZoomIn); ZoomBox.SetToolStripButtomZoomOut(toolStripButtonZoomOut); ZoomBox.SetToolStripButtomZoomNormal(toolStripButtonZoomNormal); IgnoreBoneTransformSelectionEvent = false; tableKeyFrames.HeaderRenderer = new XPTable.Renderers.FlatHeaderRenderer(); tableBoneTransforms.HeaderRenderer = new XPTable.Renderers.FlatHeaderRenderer(); sceneItemPreviewControl.SceneItem = null; sceneItemPreviewCompositeAnimationPreview.SceneItem = null; sceneItemPreviewCompositeAnimationPreview.Camera.Zoom = new Vector2(0.4f); // clear the lists/table listViewAnimations.Clear(); tableBoneTransforms.TableModel.Rows.Clear(); tableKeyFrames.TableModel.Rows.Clear(); propertyGridCompositeBoneTransform.SelectedObject = null; _previewEntity = new CompositeEntity(); _previewEntity.Animations.Add(new CompositeAnimation(_previewEntity)); }