private void SaveToXmlEchoes(string filename, int index)
        {
            XmlTextWriter writer = new XmlTextWriter(filename, System.Text.Encoding.UTF8);

            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartDocument();
            writer.WriteComment("WillowTree Echo File");
            writer.WriteComment("Note: the XML tags are case sensitive");
            writer.WriteStartElement("WT");
            writer.WriteStartElement("Echoes");

            WillowSaveGame.EchoTable et = CurrentWSG.EchoLists[index];

            int count = CurrentWSG.EchoLists[index].TotalEchoes;

            for (int i = 0; i < count; i++)
            {
                WillowSaveGame.EchoEntry ee = et.Echoes[i];
                writer.WriteStartElement("Echo");
                writer.WriteElementString("Name", ee.Name);
                writer.WriteElementString("DLCValue1", ee.DlcValue1.ToString());
                writer.WriteElementString("DLCValue2", ee.DlcValue2.ToString());
                writer.WriteEndElement();
            }

            writer.WriteEndDocument();
            writer.Close();
        }
        public void MergeAllFromXmlEchoes(string filename, int index)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            if (doc.SelectSingleNode("WT/Echoes") == null)
            {
                throw new ApplicationException("NoEchoes");
            }

            XmlNodeList echonodes = doc.SelectNodes("WT/Echoes/Echo");

            if (echonodes == null)
            {
                return;
            }

            WillowSaveGame.EchoTable et = CurrentWSG.EchoLists[index];

            EchoTree.BeginUpdate();

            // Copy only the echos that are not duplicates from the XML file
            foreach (XmlNode node in echonodes)
            {
                string name = node.GetElement("Name", "");

                // Make sure the echo is not already in the list
                EchoSearchKey = name;
                if (et.Echoes.FindIndex(EchoSearchByName) != -1)
                {
                    continue;
                }

                // Create a new echo entry an populate it from the node
                WillowSaveGame.EchoEntry ee = new WillowSaveGame.EchoEntry();
                ee.Name      = name;
                ee.DlcValue1 = node.GetElementAsInt("DLCValue1", 0);
                ee.DlcValue2 = node.GetElementAsInt("DLCValue2", 0);

                // Add the echo entry to the echo list
                et.Echoes.Add(ee);
                et.TotalEchoes++;

                // Add the echo to the tree view
                ColoredTextNode treeNode = new ColoredTextNode();
                treeNode.Tag  = name;
                treeNode.Text = EchoesXml.XmlReadValue(name, "Subject");
                if (treeNode.Text == "")
                {
                    treeNode.Text = "(" + name + ")";
                }
                EchoTree.Root.Children[index].AddNode(treeNode);
            }
            EchoTree.EndUpdate();
        }
        private void EchoList_Click(object sender, EventArgs e)
        {
            newToolStripMenuItem1.HideDropDown();

            if (EchoList.SelectedIndex == -1)
            {
                return;
            }

            int index = GetSelectedEchoList();

            if (index == -1)
            {
                MessageBox.Show("Select an echo list first.");
                return;
            }

            string name = EchoesXml.stListSectionNames()[EchoList.SelectedIndex];

            // Create a new echo entry and populate it
            WillowSaveGame.EchoEntry ee = new WillowSaveGame.EchoEntry();
            ee.Name = name;
            // TODO: These values shouldn't always be zero, but the data doesn't
            // exist in the data files yet.  When the proper data is in the data
            // file then it needs to be looked up here.
            ee.DlcValue1 = 0;
            ee.DlcValue2 = 0;

            // Add the new echo to the echo list
            WillowSaveGame.EchoTable et = CurrentWSG.EchoLists[index];
            et.Echoes.Add(ee);
            et.TotalEchoes++;

            // Add the new echo to the echo tree view
            ColoredTextNode treeNode = new ColoredTextNode();

            treeNode.Tag  = name;
            treeNode.Text = EchoesXml.XmlReadValue(name, "Subject");
            if (treeNode.Text == "")
            {
                treeNode.Text = "(" + treeNode.Tag as string + ")";
            }
            TreeNodeAdv parent = EchoTree.Root.Children[index];

            parent.AddNode(treeNode);

            // Select the newly added node so the user will know it was added
            EchoTree.SelectedNode = parent.Children[parent.Children.Count - 1];
            EchoTree.EnsureVisible(EchoTree.SelectedNode);
        }
        private void SaveSelectedToXmlEchoes(string filename, int index)
        {
            TreeNodeAdv[] selected;

            // There are two valid ways a user can select nodes to save to xml.
            // He can choose exactly one category node or he can choose multiple
            // echo nodes.  Figure out which and create an array of the nodes.
            if (EchoTree.SelectedNode.Parent == EchoTree.Root && EchoTree.SelectedNodes.Count == 1)
            {
                selected = EchoTree.Root.Children[index].Children.ToArray();
            }
            else
            {
                selected = EchoTree.SelectedNodes.ToArray();
            }

            XmlTextWriter writer = new XmlTextWriter(filename, System.Text.Encoding.UTF8);

            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartDocument();
            writer.WriteComment("WillowTree Echo File");
            writer.WriteComment("Note: the XML tags are case sensitive");
            writer.WriteStartElement("WT");
            writer.WriteStartElement("Echoes");

            WillowSaveGame.EchoTable et = CurrentWSG.EchoLists[index];

            foreach (TreeNodeAdv nodeAdv in selected)
            {
                string key = nodeAdv.GetKey();
                EchoSearchKey = nodeAdv.GetKey();

                int i = et.Echoes.FindIndex(EchoSearchByName);
                if (i == -1)
                {
                    continue;
                }

                WillowSaveGame.EchoEntry ee = et.Echoes[i];
                writer.WriteStartElement("Echo");
                writer.WriteElementString("Name", ee.Name);
                writer.WriteElementString("DLCValue1", ee.DlcValue1.ToString());
                writer.WriteElementString("DLCValue2", ee.DlcValue2.ToString());
                writer.WriteEndElement();
            }

            writer.WriteEndDocument();
            writer.Close();
        }
        public void LoadEchoes(string filename, int index)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(filename);

            if (doc.SelectSingleNode("WT/Echoes") == null)
            {
                throw new ApplicationException("NoEchoes");
            }

            XmlNodeList echonodes = doc.SelectNodes("WT/Echoes/Echo");

            int count = echonodes.Count;

            WillowSaveGame.EchoTable et = CurrentWSG.EchoLists[index];
            et.Echoes.Clear();
            et.TotalEchoes = 0;

            EchoTree.BeginUpdate();

            for (int i = 0; i < count; i++)
            {
                // Create a new echo entry and populate it from the xml node
                WillowSaveGame.EchoEntry ee = new WillowSaveGame.EchoEntry();
                XmlNode node = echonodes[i];
                string  name = node.GetElement("Name", "");
                ee.Name      = name;
                ee.DlcValue1 = node.GetElementAsInt("DLCValue1", 0);
                ee.DlcValue2 = node.GetElementAsInt("DLCValue2", 0);

                // Add the echo to the list
                et.Echoes.Add(ee);
                et.TotalEchoes++;

                // Add the echo to the tree view
                ColoredTextNode treeNode = new ColoredTextNode();
                treeNode.Tag  = name;
                treeNode.Text = EchoesXml.XmlReadValue(name, "Subject");
                if (treeNode.Text == "")
                {
                    treeNode.Text = "(" + name + ")";
                }
                EchoTree.Root.Children[index].AddNode(treeNode);
            }

            EchoTree.EndUpdate();
        }
        private void EchoTree_SelectionChanged(object sender, EventArgs e)
        {
            int index = GetSelectedEchoList();

            // If a echo node is not selected reset the UI elements and exit
            if (index == -1 || EchoTree.SelectedNode.Parent == EchoTree.Root)
            {
                UIClearEchoPanel();
                return;
            }

            WillowSaveGame.EchoEntry ee = CurrentWSG.EchoLists[index].Echoes[EchoTree.SelectedNode.Index];

            Util.SetNumericUpDown(EchoDLCValue1, ee.DlcValue1);
            Util.SetNumericUpDown(EchoDLCValue2, ee.DlcValue2);
            EchoString.Text = ee.Name;
        }
 public bool EchoSearchByName(WillowSaveGame.EchoEntry ee)
 {
     return(ee.Name == EchoSearchKey);
 }