ParseNodeConditions() public static method

Takes a node tree and converts it to a Condition
public static ParseNodeConditions ( TreeNode Node ) : Condition
Node System.Windows.Forms.TreeNode
return Condition
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();
            }
        }
Example #2
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            if (List.Type == ConditionType.Not)
            {
                if (ConditionTree.Nodes[0].Nodes.Count == 0)
                {
                    MessageBox.Show("You must define a criteria.");
                    return;
                }
            }
            else
            {
                if (ConditionTree.Nodes[0].Nodes.Count < 2)
                {
                    MessageBox.Show("You must define 2 criteria's.");
                    return;
                }
            }

            // Generate a new list, and store it in the Node.Tag
            List     = (ConditionList)MedalDataParser.ParseNodeConditions(ConditionTree.Nodes[0]);
            Node.Tag = List;

            // For AND (and) OR lists, since we can add and remove elements (thus losing references),
            // we must clear the condition nodes, and rebuild them from scratch
            if (List.Type == ConditionType.And || List.Type == ConditionType.Or)
            {
                Node.Nodes.Clear();
                foreach (var something in List.GetConditions())
                {
                    Node.Nodes.Add(something.ToTree());
                }
            }

            // Signal to the DataEditor that we made changes
            MedalDataEditor.ChangesMade = true;
            this.DialogResult           = DialogResult.OK;
        }
        /// <summary>
        /// Removes a criteria from the selected awards condition tree
        /// </summary>
        public void DeleteCriteria()
        {
            // Make sure we have a node selected
            if (ConditionNode == null)
            {
                MessageBox.Show("Please select a criteria to remove.");
                return;
            }

            // Dont update tree till we are finished adding/removing
            AwardConditionsTree.BeginUpdate();

            if (ConditionNode.Parent == null)
            {
                AwardConditionsTree.Nodes.Remove(ConditionNode);
                ValidateConditions(SelectedAwardNode, SelectedAward.GetCondition());
            }

            // Dont delete on Plus / Div Trees
            else if (!(ConditionNode.Tag is ConditionList))
            {
                TreeNode      Parent = ConditionNode.Parent;
                ConditionList C      = (ConditionList)Parent.Tag;

                // Remove Not Conditions, as they only hold 1 criteria anyways
                if (C.Type == ConditionType.Not)
                {
                    AwardConditionsTree.Nodes.Remove(Parent);
                }

                // Dont remove Plus or Div elements as they need 2 or 3 to work!
                else if (C.Type == ConditionType.Plus || C.Type == ConditionType.Div)
                {
                    ConditionNode = Parent;
                    AwardConditionsTree.SelectedNode = Parent;
                    EditCriteria();
                }
                else
                {
                    // Remove Node
                    AwardConditionsTree.Nodes.Remove(ConditionNode);

                    // remove empty parent nodes
                    if (Parent.Nodes.Count == 0)
                    {
                        AwardConditionsTree.Nodes.Remove(Parent);
                    }
                }
            }
            else
            {
                AwardConditionsTree.Nodes.Remove(ConditionNode);
            }

            // Get our selected medal condition
            Condition Cond = null;

            // Set awards new conditions
            if (AwardConditionsTree.Nodes.Count > 0)
            {
                Cond = MedalDataParser.ParseNodeConditions(AwardConditionsTree.Nodes[0]);
                SelectedAward.SetCondition(Cond);
            }
            else
            {
                SelectedAward.SetCondition(null);
            }

            // Reparse conditions
            AwardConditionsTree.Nodes.Clear();
            TreeNode NN = SelectedAward.ToTree();

            if (NN != null)
            {
                AwardConditionsTree.Nodes.Add(NN);
            }

            ValidateConditions(SelectedAwardNode, Cond);
            AwardConditionsTree.EndUpdate();
            AwardConditionsTree.ExpandAll();
        }
        /// <summary>
        /// Brings up the Criteria Editor for the selected Award Condition Node
        /// </summary>
        public void EditCriteria()
        {
            // Make sure we have a node selected
            if (ConditionNode == null)
            {
                MessageBox.Show("Please select a criteria to edit.");
                return;
            }

            // Make sure its a child node
            if (ConditionNode.Parent == null && ConditionNode.Nodes.Count != 0)
            {
                return;
            }

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

            if (Child.ShowDialog() == DialogResult.OK)
            {
                // Delay tree redraw
                AwardConditionsTree.BeginUpdate();

                // Set awards new conditions from the tree node tagged conditions
                SelectedAward.SetCondition(MedalDataParser.ParseNodeConditions(AwardConditionsTree.Nodes[0]));

                // Clear all current Nodes
                AwardConditionsTree.Nodes.Clear();

                // Reparse conditions
                AwardConditionsTree.Nodes.Add(SelectedAward.ToTree());

                // Validation highlighting
                ValidateConditions(SelectedAwardNode, SelectedAward.GetCondition());

                // Conditions tree's are to be expanded at all times
                AwardConditionsTree.ExpandAll();
                AwardConditionsTree.EndUpdate();
            }
        }