BF2Statistics.MedalData.ConditionList.ToTree C# (CSharp) Method

ToTree() public method

Converts the list to tree view. If there is only 1 sub criteria on an "And" or "Or" type list, then the list will not collapse into the sub criteria. Invalid Sub condition nodes will be highlighted in Red.
public ToTree ( ) : TreeNode
return System.Windows.Forms.TreeNode
        public override TreeNode ToTree()
        {
            // Define vars
            string Name = "Meets All Requirements:";
            bool Trim = false;
            int i = 0;
            HasConditionErrors = false;

            // Build the name which will be displayed in the criteria view
            switch (this.Type)
            {
                case ConditionType.Div:
                    if (SubConditions.Count == 3)
                    {
                        // If a div condition has 3 conditions, the last is always a condition value
                        ConditionValue Cnd = (ConditionValue)SubConditions.Last();
                        Name = "Conditions Divided Equal to or Greater than " + Cnd.Value;
                        Trim = true;
                    }
                    else
                        Name = "Divided Value Of:";
                    break;
                case ConditionType.Not:
                    Name = "Does Not Meet Criteria:";
                    break;
                case ConditionType.Or:
                    Name = "Meets Any Criteria:";
                    break;
                case ConditionType.Plus:
                    if (SubConditions.Count == 3)
                    {
                        // If a plus condition has 3 conditions, the last is always a condition value
                        ConditionValue Cnd = (ConditionValue)SubConditions.Last();
                        Name = "Condtions Equal to or Greater than " + String.Format("{0:N0}", Int32.Parse(Cnd.Value));
                        Trim = true;
                    }
                    else
                        Name = "The Sum Of:";
                    break;
            }

            // Start the TreeNode, and add this condition list in the tag
            TreeNode Me = new TreeNode(Name);
            Me.Tag = this;

            // Add sub conditions to the nodes of this condition's tree node
            foreach (Condition C in SubConditions)
            {
                // Obviously dont add null items
                if (C == null)
                    continue;

                // Make sure not to add the last element on a plus conditionlist
                if (Trim && C is ConditionValue)
                    break;

                // Convert sub-condition to tree
                TreeNode N = C.ToTree();
                if (N == null)
                    continue;

                // Nested errors
                if (!HasConditionErrors && C is ConditionList)
                    HasConditionErrors = (C as ConditionList).HasConditionErrors;

                // Validation
                if (!ValidateParam(i, C.Returns()))
                {
                    N.ForeColor = System.Drawing.Color.Red;
                    HasConditionErrors = true;
                    N.ToolTipText = "Invalid Return Type. ";
                    N.ToolTipText += (C.Returns() == ReturnType.Bool)
                        ? "A criteria value is required"
                        : "Criteria value must be disabled";
                }
                else
                {
                    // Always reset this
                    N.ToolTipText = "";
                }

                // Add the node
                Me.Nodes.Add(N);
                i++;
            }

            return Me;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Brings up the Criteria Editor for an Award
        /// </summary>
        public void EditCriteria()
        {
            // Grab the selected treenode
            TreeNode SelectedNode = ConditionTree.SelectedNode;

            // Make sure we have a node selected
            if (SelectedNode == null)
            {
                MessageBox.Show("Please select a criteria to edit.");
                return;
            }

            // Make sure its a child node, and not the topmost
            if (SelectedNode.Parent == null) // && SelectedNode.Nodes.Count != 0)
            {
                return;
            }

            // Open correct condition editor form
            if (SelectedNode.Tag is ObjectStat)
            {
                Child = new ObjectStatForm(SelectedNode);
            }
            else if (SelectedNode.Tag is PlayerStat)
            {
                Child = new ScoreStatForm(SelectedNode);
            }
            else if (SelectedNode.Tag is MedalOrRankCondition)
            {
                Child = new MedalConditionForm(SelectedNode);
            }
            else if (SelectedNode.Tag is GlobalStatMultTimes)
            {
                Child = new GlobalStatMultTimesForm(SelectedNode);
            }
            else if (SelectedNode.Tag is ConditionList)
            {
                Child = new ConditionListForm(SelectedNode);
            }
            else
            {
                return;
            }

            if (Child.ShowDialog() == DialogResult.OK)
            {
                ConditionList NN = new ConditionList(List.Type);
                NN = (ConditionList)MedalDataParser.ParseNodeConditions(ConditionTree.Nodes[0]);

                ConditionTree.Nodes.Clear();
                ConditionTree.Nodes.Add(NN.ToTree());
                ConditionTree.Refresh();
                ConditionTree.ExpandAll();
            }
        }
All Usage Examples Of BF2Statistics.MedalData.ConditionList::ToTree