static public XmlData.SpawnNode GetXmlSpawnNode(int id) { XmlData.SpawnNode node = null; if (Program.AnimationXML.Spawns != null && Program.AnimationXML.Spawns.Spawn != null) { foreach (var n in Program.AnimationXML.Spawns.Spawn) { if (n.Id == id) { return(n); } } } return(node); }
static public void UpdateXmlSpawnNode(XmlData.SpawnNode oldNode, XmlData.SpawnNode newNode) { if (Program.AnimationXML.Spawns == null || Program.AnimationXML.Spawns.Spawn == null || oldNode == null) { var newNodes = new XmlData.SpawnNode[1]; newNodes[0] = newNode; if (Program.AnimationXML.Spawns == null) { Program.AnimationXML.Spawns = new XmlData.SpawnsNode(); } if (Program.AnimationXML.Spawns.Spawn == null) { Program.AnimationXML.Spawns.Spawn = new XmlData.SpawnNode[0]; } Program.AnimationXML.Spawns.Spawn = Program.AnimationXML.Spawns.Spawn.Concat(newNodes).ToArray(); } else { foreach (var n in Program.AnimationXML.Spawns.Spawn) { if (n.Id == oldNode.Id) { if (newNode == null) { var newSpawns = new List <XmlData.SpawnNode>(Program.AnimationXML.Spawns.Spawn); newSpawns.Remove(n); Program.AnimationXML.Spawns.Spawn = newSpawns.ToArray(); } else { n.Id = newNode.Id; n.Next = newNode.Next; n.Probability = newNode.Probability; n.X = newNode.X; n.Y = newNode.Y; } break; } } } }
private void insertNodeToolStripMenuItem_Click(object sender, EventArgs e) { var cms = contextMenuStrip1; var lv = cms.SourceControl as ListView; if (lv == listView1) // spawn { treeView1.SelectedNode = treeView1.Nodes[0].Nodes[2]; var node = new XmlData.SpawnNode(); for (var j = 1; j <= listView1.Items.Count + 2; j++) { if (XmlTools.GetXmlSpawnNode(j) == null) { node.Id = j; node.Next = new XmlData.NextNode(); node.Probability = 10; node.X = ""; node.Y = ""; XmlTools.UpdateXmlSpawnNode(null, node); MainWindow.MainWin.UpdateData(); break; } } } else if (lv == listView2) // animations { treeView1.SelectedNode = treeView1.Nodes[0].Nodes[3]; var node = new XmlData.AnimationNode(); for (var j = 1; j <= listView2.Items.Count + 2; j++) { if (XmlTools.GetXmlAnimationNode(j) == null) { node.Id = j; node.Name = "New"; XmlTools.UpdateXmlAnimationNode(null, node); MainWindow.MainWin.UpdateData(); break; } } } else if (lv == listView3) // childs { treeView1.SelectedNode = treeView1.Nodes[0].Nodes[4]; var node = new XmlData.ChildNode(); for (var j = 1; j <= listView3.Items.Count + 2; j++) { if (XmlTools.GetXmlChildNode(j) == null) { node.Id = j; node.Next = j; XmlTools.UpdateXmlChildNode(null, node); MainWindow.MainWin.UpdateData(); break; } } } else if (lv == listView4) // sounds { treeView1.SelectedNode = treeView1.Nodes[0].Nodes[5]; var node = new XmlData.SoundNode(); for (var j = 1; j <= listView4.Items.Count + 2; j++) { if (XmlTools.GetXmlSoundNode(j) == null) { node.Id = j; XmlTools.UpdateXmlSoundNode(null, node); MainWindow.MainWin.UpdateData(); break; } } } }