/// <summary> /// If this form is a child, this function is called instead of Play(). /// It will initialize all variables and start the first animation using CHILD, not SPAWN. /// </summary> /// <param name="aniID">Animation playing by the parent (child will synchronize to this animation).</param> public void PlayChild(int aniID) { TChild child = Animations.GetAnimationChild(aniID); timer1.Enabled = false; // Stop the timer iAnimationStep = 0; // First step hwndWindow = (IntPtr)0; // It is not over a window Top = child.Position.Y.GetValue(); // Set position. If parent is flipped, mirror the position if (bMoveLeft) { Left = child.Position.X.GetValue(); } else { Left = child.Position.X.GetValue(); } dPosX = Left; dPosY = Top; dOffsetY = 0.0; Visible = true; // Now we can show this child Opacity = 1.0; pictureBox1.Cursor = Cursors.Default; pictureBox1.MouseDown += (s, e) => { }; // Replace the "drag and drop" functionality SetNewAnimation(child.Next); // Set next animation to play timer1.Enabled = true; // Enable timer (interval is known, now) }
/// <summary> /// After an animation is over and after a new animation was selected, this function will play the selected animation. /// </summary> /// <param name="id">Animation ID to play.</param> private void SetNewAnimation(int id) { if (id < 0) // no animation found, spawn! { Play(false); } else { iAnimationStep = -1; CurrentAnimation = Animations.GetAnimation(id); // Check if animation ID has a child. If so, the child will be created. if (Animations.HasAnimationChild(id)) { if (Name != "child") { TChild childInfo = Animations.GetAnimationChild(id); Form2 child = new Form2(Animations, Xml, new Point(Left, Top), !bMoveLeft); for (int i = 0; i < imageList1.Images.Count - 1; i++) { child.addImage(imageList1.Images[i]); } // To detect if it is a child, the name of the form will be renamed. child.Name = "child"; child.Show(Width, Height); child.PlayChild(id); } } timer1.Interval = CurrentAnimation.Start.Interval.GetValue(); } }
/// <summary> /// If this form is a child, this function is called instead of Play(). /// It will initialize all variables and start the first animation using CHILD, not SPAWN. /// </summary> /// <param name="aniID">Animation playing by the parent (child will synchronize to this animation).</param> public void PlayChild(int aniID) { TChild child = Animations.GetAnimationChild(aniID); timer1.Enabled = false; // Stop the timer iAnimationStep = 0; // First step hwndWindow = (IntPtr)0; // It is not over a window Top = child.Position.Y.GetValue(); // Set position. If parent is flipped, mirror the position if (bMoveLeft) { Left = child.Position.X.GetValue(); } else { Left = Screen.PrimaryScreen.Bounds.Width - child.Position.X.GetValue() - Width; } dPosX = Left; dPosY = Top; dOffsetY = 0.0; Visible = true; // Now we can show this child Opacity = 1.0; SetNewAnimation(child.Next); // Set next animation to play timer1.Enabled = true; // Enable timer (interval is known, now) }
/// <summary> /// After an animation is over and after a new animation was selected, this function will play the selected animation. /// </summary> /// <param name="id">Animation ID to play.</param> private void SetNewAnimation(int id) { if (CurrentAnimation.ID == Animations.AnimationKill) { return; } if (id < 0) // no animation found, spawn! { Play(false); } else { iAnimationStep = -1; CurrentAnimation = Animations.GetAnimation(id); // Check if animation ID has a child. If so, the child will be created. if (Animations.HasAnimationChild(id)) { // child creating childs... Maximum 5 sub-childs can be created if (Name.IndexOf("child") < 0 || int.Parse(Name.Substring(5)) < 5) { TChild childInfo = Animations.GetAnimationChild(id); Form2 child = new Form2(Animations, Xml, new Point(Left, Top), !bMoveLeft); for (int i = 0; i < imageList1.Images.Count; i++) { child.addImage(imageList1.Images[i]); } // To detect if it is a child, the name of the form will be renamed. if (Name.IndexOf("child") < 0) // first child { child.Name = "child1"; } else if (Name.IndexOf("child") == 0) // second, fifth child { child.Name = "child" + (int.Parse(Name.Substring(5)) + 1).ToString(); } child.Show(Width, Height); child.PlayChild(id); } } timer1.Interval = CurrentAnimation.Start.Interval.GetValue(); } }
/// <summary> /// Load the animations (read them from XML file) /// </summary> /// <param name="animations">Animation class where the animations should be saved</param> public void LoadAnimations(Animations animations) { if (AnimationXML.Animations == null) { StartUp.AddDebugInfo(StartUp.DEBUG_TYPE.error, "No animations for this pet"); return; } // for each animation foreach (XmlData.AnimationNode node in AnimationXML.Animations.Animation) { TAnimation ani = animations.AddAnimation(node.Id, node.Id.ToString()); ani.Border = node.Border != null; ani.Gravity = node.Gravity != null; ani.Name = node.Name; switch (ani.Name) { case "fall": animations.AnimationFall = node.Id; break; case "drag": animations.AnimationDrag = node.Id; break; case "kill": animations.AnimationKill = node.Id; break; case "sync": animations.AnimationSync = node.Id; break; } ani.Start.X = GetXMLCompute(node.Start.X, "animation " + node.Id + ": node.start.X"); ani.Start.Y = GetXMLCompute(node.Start.Y, "animation " + node.Id + ": node.start.Y"); ani.Start.Interval = GetXMLCompute(node.Start.Interval, "animation " + node.Id + ": node.start.Interval"); ani.Start.OffsetY = node.Start.OffsetY; ani.Start.Opacity = node.Start.Opacity; ani.End.X = GetXMLCompute(node.End.X, "animation " + node.Id + ": node.end.X"); ani.End.Y = GetXMLCompute(node.End.Y, "animation " + node.Id + ": node.end.Y"); ani.End.Interval = GetXMLCompute(node.End.Interval, "animation " + node.Id + ": node.end.Interval"); ani.End.OffsetY = node.End.OffsetY; ani.End.Opacity = node.End.Opacity; ani.Sequence.RepeatFrom = node.Sequence.RepeatFromFrame; ani.Sequence.Action = node.Sequence.Action; ani.Sequence.Repeat = GetXMLCompute(node.Sequence.RepeatCount, "animation " + node.Id + ": node.sequence.Repeat"); ani.Sequence.Frames.AddRange(node.Sequence.Frame); if (ani.Sequence.RepeatFrom > 0) { ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + (ani.Sequence.Frames.Count - ani.Sequence.RepeatFrom - 1) * ani.Sequence.Repeat.Value; } else { ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + ani.Sequence.Frames.Count * ani.Sequence.Repeat.Value; } if (node.Sequence.Next != null) { foreach (XmlData.NextNode nextNode in node.Sequence.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.EndAnimation.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } if (ani.Border) { foreach (XmlData.NextNode nextNode in node.Border.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.Border = true; ani.EndBorder.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } if (ani.Gravity) { foreach (XmlData.NextNode nextNode in node.Gravity.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.Gravity = true; ani.EndGravity.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } animations.SaveAnimation(ani, node.Id); } // for each spawn if (AnimationXML.Spawns.Spawn != null) { foreach (XmlData.SpawnNode node in AnimationXML.Spawns.Spawn) { TSpawn ani = animations.AddSpawn( node.Id, node.Probability); ani.Start.X = GetXMLCompute(node.X, "spawn " + node.Id + ": node.X"); ani.Start.Y = GetXMLCompute(node.Y, "spawn " + node.Id + ": node.X"); ani.Next = node.Next.Value; animations.SaveSpawn(ani, node.Id); } } // for each child if (AnimationXML.Childs.Child != null) { foreach (XmlData.ChildNode node in AnimationXML.Childs.Child) { TChild aniChild = animations.AddChild(node.Id); aniChild.AnimationID = node.Id; aniChild.Position.X = GetXMLCompute(node.X, "child " + node.Id + ": node.X"); aniChild.Position.Y = GetXMLCompute(node.Y, "child " + node.Id + ": node.Y"); aniChild.Next = node.Next; animations.SaveChild(aniChild, node.Id); } } // for each sound if (AnimationXML.Sounds != null && AnimationXML.Sounds.Sound != null) { foreach (XmlData.SoundNode node in AnimationXML.Sounds.Sound) { animations.AddSound(node.Id, node.Probability, node.Loop, node.Base64); } } }
/// <summary> /// After adding the Child and filling data, this function must be called to save values of the last child. /// </summary> /// <param name="child">Filled structure.</param> /// <param name="ID">ID of the structure.</param> public void SaveChild(TChild child, int ID) { SheepChild[ID][SheepChild[ID].Count - 1] = child; }
/// <summary> /// After adding the Child and filling data, this function must be called to save values. /// </summary> /// <param name="child">Filled structure.</param> /// <param name="ID">ID of the structure.</param> public void SaveChild(TChild child, int ID) { SheepChild[ID] = child; }
/// <summary> /// Load the animations (read them from XML file) /// </summary> /// <param name="animations">Animation class where the animations should be saved</param> public void loadAnimations(Animations animations) { // for each animation foreach (AnimationNode node in AnimationXML.Animations.Animation) { TAnimation ani = animations.AddAnimation(node.Id, node.Id.ToString()); ani.Border = node.Border != null; ani.Gravity = node.Gravity != null; ani.Name = node.Name; switch (ani.Name) { case "fall": animations.AnimationFall = node.Id; break; case "drag": animations.AnimationDrag = node.Id; break; case "kill": animations.AnimationKill = node.Id; break; case "sync": animations.AnimationSync = node.Id; break; } ani.Start.X = getXMLCompute(node.Start.X); ani.Start.Y = getXMLCompute(node.Start.Y); ani.Start.Interval = getXMLCompute(node.Start.Interval); ani.Start.OffsetY = node.Start.OffsetY; ani.Start.Opacity = node.Start.Opacity; ani.End.X = getXMLCompute(node.End.X); ani.End.Y = getXMLCompute(node.End.Y); ani.End.Interval = getXMLCompute(node.End.Interval); ani.End.OffsetY = node.End.OffsetY; ani.End.Opacity = node.End.Opacity; ani.Sequence.RepeatFrom = node.Sequence.RepeatFromFrame; ani.Sequence.Action = node.Sequence.Action; ani.Sequence.Repeat = getXMLCompute(node.Sequence.RepeatCount); foreach (int frameid in node.Sequence.Frame) { ani.Sequence.Frames.Add(frameid); } if (ani.Sequence.RepeatFrom > 0) { ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + (ani.Sequence.Frames.Count - ani.Sequence.RepeatFrom - 1) * ani.Sequence.Repeat.Value; } else { ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + ani.Sequence.Frames.Count * ani.Sequence.Repeat.Value; } if (node.Sequence.Next != null) { foreach (NextNode nextNode in node.Sequence.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.EndAnimation.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } if (ani.Border) { foreach (NextNode nextNode in node.Border.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.Border = true; ani.EndBorder.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } if (ani.Gravity) { foreach (NextNode nextNode in node.Gravity.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.Gravity = true; ani.EndGravity.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } animations.SaveAnimation(ani, node.Id); } // for each spawn if (AnimationXML.Spawns.Spawn != null) { foreach (SpawnNode node in AnimationXML.Spawns.Spawn) { TSpawn ani = animations.AddSpawn( node.Id, node.Probability); ani.Start.X = getXMLCompute(node.X); ani.Start.Y = getXMLCompute(node.Y); ani.Next = node.Next.Value; animations.SaveSpawn(ani, node.Id); } } // for each child if (AnimationXML.Childs.Child != null) { foreach (ChildNode node in AnimationXML.Childs.Child) { TChild aniChild = animations.AddChild(node.Id); aniChild.AnimationID = node.Id; aniChild.Position.X = getXMLCompute(node.X); aniChild.Position.Y = getXMLCompute(node.Y); aniChild.Next = node.Next; animations.SaveChild(aniChild, node.Id); } } // for each sound if (AnimationXML.Sounds != null && AnimationXML.Sounds.Sound != null) { foreach (SoundNode node in AnimationXML.Sounds.Sound) { animations.AddSound(node.Id, node.Probability, node.Loop, node.Base64); } } }
/// <summary> /// Load the animations (read them from XML file) /// </summary> /// <param name="animations">Animation class where the animations should be saved</param> public void loadAnimations(Animations animations) { // for each animation foreach (AnimationNode node in AnimationXML.Animations.Animation) { TAnimation ani = animations.AddAnimation(node.Id, node.Id.ToString()); ani.Border = node.Border != null; ani.Gravity = node.Gravity != null; ani.Name = node.Name; switch (ani.Name) { case "fall": animations.AnimationFall = node.Id; break; case "drag": animations.AnimationDrag = node.Id; break; case "kill": animations.AnimationKill = node.Id; break; case "sync": animations.AnimationSync = node.Id; break; } ani.Start.X = getXMLCompute(node.Start.X); ani.Start.Y = getXMLCompute(node.Start.Y); ani.Start.Interval = getXMLCompute(node.Start.Interval); ani.Start.OffsetY = node.Start.OffsetY; ani.Start.Opacity = node.Start.Opacity; ani.End.X = getXMLCompute(node.End.X); ani.End.Y = getXMLCompute(node.End.Y); ani.End.Interval = getXMLCompute(node.End.Interval); ani.End.OffsetY = node.End.OffsetY; ani.End.Opacity = node.End.Opacity; ani.Sequence.RepeatFrom = node.Sequence.RepeatFromFrame; ani.Sequence.Action = node.Sequence.Action; ani.Sequence.Repeat = getXMLCompute(node.Sequence.RepeatCount); foreach (int frameid in node.Sequence.Frame) { ani.Sequence.Frames.Add(frameid); } if (ani.Sequence.RepeatFrom > 0) { ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + (ani.Sequence.Frames.Count - ani.Sequence.RepeatFrom - 1) * ani.Sequence.Repeat.Value; } else { ani.Sequence.TotalSteps = ani.Sequence.Frames.Count + ani.Sequence.Frames.Count * ani.Sequence.Repeat.Value; } if (node.Sequence.Next != null) { foreach (NextNode nextNode in node.Sequence.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.EndAnimation.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } if (ani.Border) { foreach (NextNode nextNode in node.Border.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.Border = true; ani.EndBorder.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } if (ani.Gravity) { foreach (NextNode nextNode in node.Gravity.Next) { TNextAnimation.TOnly where; switch (nextNode.OnlyFlag) { case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; case "window": where = TNextAnimation.TOnly.WINDOW; break; case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; default: where = TNextAnimation.TOnly.NONE; break; } ani.Gravity = true; ani.EndGravity.Add( new TNextAnimation( nextNode.Value, nextNode.Probability, where ) ); } } /* OLD XML parsing: * * foreach (XmlNode node3 in node2.SelectNodes(".//pet:next", xmlNS)) * { * TNextAnimation.TOnly where = TNextAnimation.TOnly.NONE; * if (node3.Attributes["only"] != null) * { * switch (node3.Attributes["only"].InnerText) * { * case "taskbar": where = TNextAnimation.TOnly.TASKBAR; break; * case "window": where = TNextAnimation.TOnly.WINDOW; break; * case "horizontal": where = TNextAnimation.TOnly.HORIZONTAL; break; * case "horizontal+": where = TNextAnimation.TOnly.HORIZONTAL_; break; * case "vertical": where = TNextAnimation.TOnly.VERTICAL; break; * } * } * ani.Gravity = true; * ani.EndGravity.Add( * new TNextAnimation( * int.Parse(node3.InnerText, CultureInfo.InvariantCulture), * int.Parse(node3.Attributes["probability"].InnerText, CultureInfo.InvariantCulture), * where * ) * ); * } * break; */ animations.SaveAnimation(ani, node.Id); } // for each spawn if (AnimationXML.Spawns.Spawn != null) { foreach (SpawnNode node in AnimationXML.Spawns.Spawn) { TSpawn ani = animations.AddSpawn( node.Id, node.Probability); ani.Start.X = getXMLCompute(node.X); ani.Start.Y = getXMLCompute(node.Y); ani.Next = node.Next.Value; animations.SaveSpawn(ani, node.Id); } } // for each child if (AnimationXML.Childs.Child != null) { foreach (ChildNode node in AnimationXML.Childs.Child) { TChild aniChild = animations.AddChild(node.Id); aniChild.AnimationID = node.Id; aniChild.Position.X = getXMLCompute(node.X); aniChild.Position.Y = getXMLCompute(node.Y); aniChild.Next = node.Next; animations.SaveChild(aniChild, node.Id); } } }