Example #1
0
        // Aga.Controls is basically just TreeViewAdv and all the utility stuff
        // needed to make it work.  These are extensions added to try to help do
        // normal things like insert and remove nodes because the way the
        // TreeViewAdv control works is very strange.
        //
        // TreeViewAdv uses two layers of nodes.  One set of nodes (class
        // TreeNodeAdv) is used to return user selection information and the other
        // set of nodes (class Node) is used to create the tree and store data in.
        // Both sets confusingly hold navigation information.  The Tag property
        // of each (TreeNodeAdv) points to one (Node) which holds the data, so
        // each time you check the selection of nodes you get a list of
        // (TreeNodeAdv)s but you can only add (Node)s to the tree.

        // This is not actually an extension method, but it is needed to work with
        // TreeViewAdv and is not form-specific so I placed it here.
        public static void ColoredTextNode_DrawText(object sender, DrawEventArgs e)
        {
            TreeViewTheme theme = (e.Node.Tree as WTTreeView).Theme;
            // When a text node is drawn, this callback is called to determine
            // the colors to use.  It is not necessary to set or modify any colors
            // in e (DrawEventArgs) unless custom colors are desired.  The color of
            // nodes usually depends on whether they are selected or active.  That
            // information is stored in e.Context.DrawSelectionMode.

            // e.Node is a TreeNodeAdv navigation node.  e.Node.Tag points to the
            // actual data node which must be of type Node or a descendant of
            // Node.  It is ColoredTextNode in this program.
            ColoredTextNode node = e.Node.Tag as ColoredTextNode;

            // The node is drawn with different colors depending on whether it is
            // selected and whether or not the control is active.  The state is
            // provided in e.Context.DrawSelection.
            //if (e.Context.DrawSelection == DrawSelectionMode.None)
            //{
            //    e.TextColor = theme.ForeColor;
            //    e.BackgroundBrush = theme.BackBrush;
            //}
            if (e.Context.DrawSelection == DrawSelectionMode.None)
            {
                e.TextColor       = (e.Node.Tag as ColoredTextNode).ForeColor;
                e.BackgroundBrush = theme.BackBrush;
            }
            else if (e.Context.DrawSelection == DrawSelectionMode.Active)
            {
                e.TextColor       = theme.HighlightForeColor;
                e.BackgroundBrush = theme.HighlightBackBrush;
            }
            else if (e.Context.DrawSelection == DrawSelectionMode.Inactive)
            {
                e.TextColor       = theme.InactiveForeColor;
                e.BackgroundBrush = theme.InactiveBackBrush;
            }
            else if (e.Context.DrawSelection == DrawSelectionMode.FullRowSelect)
            {
                e.TextColor       = theme.HighlightForeColor;
                e.BackgroundBrush = theme.BackBrush;
            }

            if (!e.Context.Enabled)
            {
                e.TextColor = theme.DisabledForeColor;
            }

            // Apply a custom font if the node has one
            if (node.Font != null)
            {
                e.Font = node.Font;
            }
        }
        public static void DoPartsCategory(string Category, TreeViewAdv Tree)
        {
            XmlFile   PartList = XmlFile.XmlFileFromCache(db.DataPath + Category + ".txt");
            TreeModel model    = Tree.Model as TreeModel;

            Tree.BeginUpdate();
            Tree.Model = model;

            ColoredTextNode parent = new ColoredTextNode(Category);

            parent.Tag = Category;
            model.Nodes.Add(parent);

            foreach (string section in PartList.stListSectionNames())
            {
                ColoredTextNode child = new ColoredTextNode();
                child.Text = section;
                child.Tag  = section;
                parent.Nodes.Add(child);
            }
            Tree.EndUpdate();
        }
Example #3
0
        // Clear duplicate items from an xml item/weapon file
        // TODO: This is an ugly method that probably could be done in an easier
        // to understand, more correct, or faster way.  It does seem to work
        // though, so I'm not going to try to rewrite it right now.
        public static void PurgeDuplicates(string InputFile)
        {
            // A tree model to store the nodes in
            TreeModel model = new TreeModel();

            // rootnode
            Node ndroot = new Node("INI");

            model.Nodes.Add(ndroot);

            XmlDocument xmlrdrdoc = new XmlDocument();

            xmlrdrdoc.Load(InputFile);

            // get a list of all items
            XmlNodeList xnrdrList = xmlrdrdoc.SelectNodes("/INI/Section");

            foreach (XmlNode xn in xnrdrList)
            {
                Node ndparent = ndroot;
                Node ndchild  = null;
                bool bFound;

                string[] strParts = new string[]
                {
                    xn.GetElement("Type", ""),
                    xn.GetElement("Part1", ""),
                    xn.GetElement("Part2", ""),
                    xn.GetElement("Part3", ""),
                    xn.GetElement("Part4", ""),
                    xn.GetElement("Part5", ""),
                    xn.GetElement("Part6", ""),
                    xn.GetElement("Part7", ""),
                    xn.GetElement("Part8", ""),
                    xn.GetElement("Part9", ""),
                    xn.GetElement("Part10", ""),
                    xn.GetElement("Part11", ""),
                    xn.GetElement("Part12", ""),
                    xn.GetElement("Part13", ""),
                    xn.GetElement("Part14", ""),
                    xn.GetElement("Name", ""),
                    xn.GetElement("Rating", ""),
                    xn.GetElement("Description", ""),
                    xn.GetElement("RemAmmo_Quantity", ""),
                    xn.GetElement("Quality", ""),
                    xn.GetElement("Level", ""),
                };

                for (int partindex = 0; partindex < 21; partindex++)
                {
                    // All sections
                    // read the xml values
                    bFound = false;

                    for (int ndcnt = 0; ndcnt < ndparent.Nodes.Count; ndcnt++)
                    {
                        if (ndparent.Nodes[ndcnt].Text == strParts[partindex])
                        {
                            bFound   = true;
                            ndparent = ndparent.Nodes[ndcnt];
                            break;
                        }
                    }
                    if (!bFound)
                    {
                        ndchild      = new ColoredTextNode();
                        ndchild.Text = strParts[partindex];
                        //                        ndchild.Expand();
                        ndparent.Nodes.Add(ndchild);
                        ndparent = ndchild;
                    }
                }
            }
            //            LockerTreetry2.EndUpdate();

            List <string> listNames = new List <string>();

            XmlTextWriter writer = new XmlTextWriter(InputFile, new System.Text.ASCIIEncoding());

            writer.Formatting  = Formatting.Indented;
            writer.Indentation = 2;
            writer.WriteStartDocument();
            writer.WriteComment("Comment");
            writer.WriteStartElement("INI");

            for (int ndcntrt = 0; ndcntrt < ndroot.Nodes.Count; ndcntrt++)
            {
                Node ndtype = ndroot.Nodes[ndcntrt];
                for (int ndcnttype = 0; ndcnttype < ndtype.Nodes.Count; ndcnttype++)
                {
                    Node ndpart1 = ndtype.Nodes[ndcnttype];

                    for (int ndcntpart1 = 0; ndcntpart1 < ndpart1.Nodes.Count; ndcntpart1++)
                    {
                        Node ndpart2 = ndpart1.Nodes[ndcntpart1];

                        for (int ndcntpart2 = 0; ndcntpart2 < ndpart2.Nodes.Count; ndcntpart2++)
                        {
                            Node ndpart3 = ndpart2.Nodes[ndcntpart2];
                            for (int ndcntpart3 = 0; ndcntpart3 < ndpart3.Nodes.Count; ndcntpart3++)
                            {
                                Node ndpart4 = ndpart3.Nodes[ndcntpart3];

                                for (int ndcntpart4 = 0; ndcntpart4 < ndpart4.Nodes.Count; ndcntpart4++)
                                {
                                    Node ndpart5 = ndpart4.Nodes[ndcntpart4];

                                    for (int ndcntpart5 = 0; ndcntpart5 < ndpart5.Nodes.Count; ndcntpart5++)
                                    {
                                        Node ndpart6 = ndpart5.Nodes[ndcntpart5];

                                        for (int ndcntpart6 = 0; ndcntpart6 < ndpart6.Nodes.Count; ndcntpart6++)
                                        {
                                            Node ndpart7 = ndpart6.Nodes[ndcntpart6];

                                            for (int ndcntpart7 = 0; ndcntpart7 < ndpart7.Nodes.Count; ndcntpart7++)
                                            {
                                                Node ndpart8 = ndpart7.Nodes[ndcntpart7];

                                                for (int ndcntpart8 = 0; ndcntpart8 < ndpart8.Nodes.Count; ndcntpart8++)
                                                {
                                                    Node ndpart9 = ndpart8.Nodes[ndcntpart8];

                                                    for (int ndcntpart9 = 0; ndcntpart9 < ndpart9.Nodes.Count; ndcntpart9++)
                                                    {
                                                        Node ndpart10 = ndpart9.Nodes[ndcntpart9];

                                                        for (int ndcntpart10 = 0; ndcntpart10 < ndpart10.Nodes.Count; ndcntpart10++)
                                                        {
                                                            Node ndpart11 = ndpart10.Nodes[ndcntpart10];

                                                            for (int ndcntpart11 = 0; ndcntpart11 < ndpart11.Nodes.Count; ndcntpart11++)
                                                            {
                                                                Node ndpart12 = ndpart11.Nodes[ndcntpart11];

                                                                for (int ndcntpart12 = 0; ndcntpart12 < ndpart12.Nodes.Count; ndcntpart12++)
                                                                {
                                                                    Node ndpart13 = ndpart12.Nodes[ndcntpart12];

                                                                    for (int ndcntpart13 = 0; ndcntpart13 < ndpart13.Nodes.Count; ndcntpart13++)
                                                                    {
                                                                        Node ndpart14 = ndpart13.Nodes[ndcntpart13];

                                                                        for (int ndcntpart14 = 0; ndcntpart14 < ndpart14.Nodes.Count; ndcntpart14++)
                                                                        {
                                                                            Node ndpart15 = ndpart14.Nodes[ndcntpart14];
                                                                            for (int ndcntpart15 = 0; ndcntpart15 < ndpart15.Nodes.Count; ndcntpart15++)
                                                                            {
                                                                                Node ndpart16 = ndpart15.Nodes[ndcntpart15];
                                                                                for (int ndcntpart16 = 0; ndcntpart16 < ndpart16.Nodes.Count; ndcntpart16++)
                                                                                {
                                                                                    Node ndpart17 = ndpart16.Nodes[ndcntpart16];
                                                                                    for (int ndcntpart17 = 0; ndcntpart17 < ndpart17.Nodes.Count; ndcntpart17++)
                                                                                    {
                                                                                        Node ndpart18 = ndpart17.Nodes[ndcntpart17];
                                                                                        for (int ndcntpart18 = 0; ndcntpart18 < ndpart18.Nodes.Count; ndcntpart18++)
                                                                                        {
                                                                                            Node ndpart19 = ndpart18.Nodes[ndcntpart18];
                                                                                            for (int ndcntpart19 = 0; ndcntpart19 < ndpart19.Nodes.Count; ndcntpart19++)
                                                                                            {
                                                                                                Node ndpart20 = ndpart19.Nodes[ndcntpart19];

                                                                                                writer.WriteStartElement("Section");
                                                                                                writer.WriteElementString("Name", ndpart15.Text);
                                                                                                writer.WriteElementString("Type", ndtype.Text);
                                                                                                writer.WriteElementString("Rating", ndpart16.Text);
                                                                                                writer.WriteElementString("Description", ndpart17.Text.Replace('\"', ' ').Trim());

                                                                                                writer.WriteElementString("Part1", ndpart1.Text);
                                                                                                writer.WriteElementString("Part2", ndpart2.Text);
                                                                                                writer.WriteElementString("Part3", ndpart3.Text);
                                                                                                writer.WriteElementString("Part4", ndpart4.Text);
                                                                                                writer.WriteElementString("Part5", ndpart5.Text);
                                                                                                writer.WriteElementString("Part6", ndpart6.Text);
                                                                                                writer.WriteElementString("Part7", ndpart7.Text);
                                                                                                writer.WriteElementString("Part8", ndpart8.Text);
                                                                                                writer.WriteElementString("Part9", ndpart9.Text);
                                                                                                writer.WriteElementString("Part10", ndpart10.Text);
                                                                                                writer.WriteElementString("Part11", ndpart11.Text);
                                                                                                writer.WriteElementString("Part12", ndpart12.Text);
                                                                                                writer.WriteElementString("Part13", ndpart13.Text);
                                                                                                writer.WriteElementString("Part14", ndpart14.Text);
                                                                                                writer.WriteElementString("RemAmmo_Quantity", ndpart18.Text);
                                                                                                writer.WriteElementString("Quality", ndpart19.Text);
                                                                                                writer.WriteElementString("Level", ndpart20.Text);
                                                                                                writer.WriteEndElement();
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
            writer.Flush();
            writer.Close();
        }