Add() public method

Adds a new sub condition under this list
public Add ( Condition Condition ) : void
Condition Condition
return void
        /// <summary>
        /// Adds a new criteria to an award from the Add Critera Dialog
        /// </summary>
        private void AddNewCriteria(object sender, FormClosingEventArgs e)
        {
            // If there is a node referenced.
            if (ConditionNode != null && ConditionNode.Tag is ConditionList)
            {
                Condition     Add  = Child.GetCondition();
                ConditionList List = (ConditionList)ConditionNode.Tag;
                List.Add(Add);
            }
            else
            {
                // No Node referenced... Use top most
                ConditionList A = new ConditionList(ConditionType.And);
                Condition     B = SelectedAward.GetCondition();
                if (B is ConditionList)
                {
                    ConditionList C = (ConditionList)B;
                    if (C.Type == ConditionType.And)
                    {
                        A = C;
                    }
                    else
                    {
                        A.Add(B);
                    }
                }
                else
                {
                    // Add existing conditions into the condition list
                    A.Add(B);
                }

                // Add the new condition
                A.Add(Child.GetCondition());

                // Parse award conditions into tree view
                SelectedAward.SetCondition(A);
            }

            // Update the tree view
            AwardConditionsTree.BeginUpdate();
            AwardConditionsTree.Nodes.Clear();
            AwardConditionsTree.Nodes.Add(SelectedAward.ToTree());
            ValidateConditions(SelectedAwardNode, SelectedAward.GetCondition());
            AwardConditionsTree.ExpandAll();
            AwardConditionsTree.EndUpdate();
        }
Example #2
0
        /// <summary>
        /// Returns a copy (clone) of this object
        /// </summary>
        public override object Clone()
        {
            ConditionList Clone = new ConditionList(this.Type);

            foreach (Condition Cond in SubConditions)
            {
                Clone.Add(Cond.Clone() as Condition);
            }

            return(Clone as object);
        }
Example #3
0
        private void UpdateRoot()
        {
            ConditionList NList = new ConditionList(List.Type);

            // Add existing nodes to the new list
            foreach (TreeNode E in ConditionTree.Nodes[0].Nodes)
            {
                NList.Add((Condition)E.Tag);
            }

            // Add condition value if enabled
            if (ValueBox.Enabled)
            {
                NList.Add(new ConditionValue(ValueBox.Value.ToString()));
            }

            // update tree
            ConditionTree.BeginUpdate();
            ConditionTree.Nodes.Clear();
            ConditionTree.Nodes.Add(NList.ToTree());
            ConditionTree.ExpandAll();
            ConditionTree.EndUpdate();
        }
Example #4
0
        /// <summary>
        /// Takes a node tree and converts it to a Condition
        /// </summary>
        /// <param name="Node"></param>
        /// <returns></returns>
        public static Condition ParseNodeConditions(TreeNode Node)
        {
            if (Node.Tag == null)
            {
                return(null);
            }

            if (Node.Tag is ConditionList)
            {
                ConditionList    C  = (ConditionList)Node.Tag;
                List <Condition> Cs = C.GetConditions();

                // If a Plus / Div list has 3rd param, add the node
                if (Cs.Count == 3 && (C.Type == ConditionType.Plus || C.Type == ConditionType.Div))
                {
                    Node.Nodes.Add(Cs[2].ToTree());
                }

                // Remove old conditions
                C.Clear();

                foreach (TreeNode Sub in Node.Nodes)
                {
                    Condition SC = ParseNodeConditions(Sub);
                    if (SC == null)
                    {
                        continue;
                    }

                    C.Add(SC);
                }
                return(C);
            }
            else
            {
                return((Node.Tag is ConditionValue) ? (ConditionValue)Node.Tag : (Condition)Node.Tag);
            }
        }
        /// <summary>
        /// Adds a new criteria to an award from the Add Critera Dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewCriteria(object sender, FormClosingEventArgs e)
        {
            TreeNode Node = AwardConditionsTree.SelectedNode;
            TreeNode AwardNode = AwardTree.SelectedNode;
            IAward Award = AwardCache.GetAward(AwardNode.Name);

            // If there is a node referenced.
            if (Node != null && Node.Tag is ConditionList)
            {
                //Condition C = (Condition)Node.Tag;
                Condition Add = Child.GetCondition();
                ConditionList List = (ConditionList)Node.Tag;
                List.Add(Add);
            }
            else
            {
                // No Node referenced... Use top most
                ConditionList A = new ConditionList(ConditionType.And);
                Condition B = Award.GetCondition();
                if (B is ConditionList)
                {
                    ConditionList C = (ConditionList)B;
                    if (C.Type == ConditionType.And)
                        A = C;
                    else
                        A.Add(B);
                }
                else
                {
                    // Add existing conditions into the condition list
                    A.Add(B);
                }

                // Add the new condition
                A.Add(Child.GetCondition());

                // Parse award conditions into tree view
                Award.SetCondition(A);
            }

            // Update the tree view
            AwardConditionsTree.BeginUpdate();
            AwardConditionsTree.Nodes.Clear();
            AwardConditionsTree.Nodes.Add(Award.ToTree());
            AwardConditionsTree.ExpandAll();
            AwardConditionsTree.EndUpdate();
        }
        /// <summary>
        /// Returns a copy (clone) of this object
        /// </summary>
        public override object Clone()
        {
            ConditionList Clone = new ConditionList(this.Type);
            foreach (Condition Cond in SubConditions)
                Clone.Add(Cond.Clone() as Condition);

            return Clone as object;
        }
        private void UpdateRoot()
        {
            ConditionList NList = new ConditionList(List.Type);

            // Add existing nodes to the new list
            foreach (TreeNode E in ConditionTree.Nodes[0].Nodes)
                NList.Add((Condition)E.Tag);

            // Add condition value if enabled
            if (ValueBox.Enabled)
                NList.Add(new ConditionValue(ValueBox.Value.ToString()));

            // update tree
            ConditionTree.BeginUpdate();
            ConditionTree.Nodes.Clear();
            ConditionTree.Nodes.Add(NList.ToTreeNoCollapse());
            ConditionTree.ExpandAll();
            ConditionTree.EndUpdate();
        }
        /// <summary>
        /// Parses a string condition into condition objects
        /// </summary>
        /// <param name="parts"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        private static Condition ParseCondition(List<Token> parts, ref int i)
        {
            ParseFunctions(ref parts);

            ConditionList List;

            for(; i < parts.Count; i++)
            {
                if (parts[i].Kind == TokenType.ConditionFunction)
                {
                    // Default
                    ConditionType Type = ConditionType.And;

                    switch (parts[i].Value)
                    {
                        case "f_and":
                            Type = ConditionType.And;
                            break;
                        case "f_or":
                            Type = ConditionType.Or;
                            break;
                        case "f_not":
                            Type = ConditionType.Not;
                            break;
                        case "f_plus":
                            Type = ConditionType.Plus;
                            break;
                        case "f_div":
                            Type = ConditionType.Div;
                            break;
                    }

                    // Create the new condition list
                    List = new ConditionList(Type);

                    // Parse sub conditions
                    i++;
                    while(i < parts.Count && parts[i].Kind != TokenType.CloseParen)
                        List.Add(ParseCondition(parts, ref i));
                    i++;

                    // Return condition list
                    return List;
                }
                else if (parts[i].Kind == TokenType.StatFunction)
                {
                    List<string> Params = new List<string>();
                    string Name = parts[i].Value;

                    for (; i < parts.Count; i++)
                    {
                        if (parts[i].Kind == TokenType.CloseParen)
                            break;

                        if (parts[i].Kind == TokenType.OpenParen)
                            continue;

                        Params.Add(parts[i].Value);
                    }

                    i++;

                    // Create the condition
                    switch (Name)
                    {
                        case "object_stat":
                            return new ObjectStat(Params);
                        case "global_stat":
                        case "player_stat":
                            return new PlayerStat(Params);
                        case "has_medal":
                        case "has_rank":
                            return new MedalOrRankCondition(Params);
                        case "global_stat_multiple_times":
                            return new GlobalStatMultTimes(Params);
                    }
                }
                else if (parts[i].Kind == TokenType.Literal)
                {
                    ConditionValue V = new ConditionValue(parts[i].Value);
                    i++;
                    return V;
                }
            }

            return new ConditionList( ConditionType.And );
        }
Example #9
0
        /// <summary>
        /// Parses a string condition into condition objects
        /// </summary>
        /// <param name="parts"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        private static Condition ParseCondition(List <Token> parts, ref int i)
        {
            ParseFunctions(ref parts);

            ConditionList List;

            for (; i < parts.Count; i++)
            {
                if (parts[i].Kind == TokenType.ConditionFunction)
                {
                    // Default
                    ConditionType Type = ConditionType.And;

                    switch (parts[i].Value)
                    {
                    case "f_and":
                        Type = ConditionType.And;
                        break;

                    case "f_or":
                        Type = ConditionType.Or;
                        break;

                    case "f_not":
                        Type = ConditionType.Not;
                        break;

                    case "f_plus":
                        Type = ConditionType.Plus;
                        break;

                    case "f_div":
                        Type = ConditionType.Div;
                        break;
                    }

                    // Create the new condition list
                    List = new ConditionList(Type);

                    // Parse sub conditions
                    i++;
                    while (i < parts.Count && parts[i].Kind != TokenType.CloseParen)
                    {
                        List.Add(ParseCondition(parts, ref i));
                    }
                    i++;

                    // Return condition list
                    return(List);
                }
                else if (parts[i].Kind == TokenType.StatFunction)
                {
                    List <string> Params = new List <string>();
                    string        Name   = parts[i].Value;

                    for (; i < parts.Count; i++)
                    {
                        if (parts[i].Kind == TokenType.CloseParen)
                        {
                            break;
                        }

                        if (parts[i].Kind == TokenType.OpenParen)
                        {
                            continue;
                        }

                        Params.Add(parts[i].Value);
                    }

                    i++;

                    // Create the condition
                    switch (Name)
                    {
                    case "object_stat":
                        return(new ObjectStat(Params));

                    case "global_stat":
                    case "player_stat":
                    case "player_score":
                        return(new PlayerStat(Params));

                    case "has_medal":
                    case "has_rank":
                        return(new MedalOrRankCondition(Params));

                    case "global_stat_multiple_times":
                        return(new GlobalStatMultTimes(Params));
                    }
                }
                else if (parts[i].Kind == TokenType.Literal)
                {
                    ConditionValue V = new ConditionValue(parts[i].Value);
                    i++;
                    return(V);
                }
            }

            return(new ConditionList(ConditionType.And));
        }