Ejemplo n.º 1
0
    public override bool doTool()
    {
        Condition newCondition = null;
        int       type         = ConditionsController.getTypeFromstring(conditionType);

        if (type == ConditionsController.FLAG_CONDITION)
        {
            newCondition = new FlagCondition(conditionId, ConditionsController.getStateFromstring(conditionState));
        }
        else if (type == ConditionsController.VAR_CONDITION)
        {
            newCondition = new VarCondition(conditionId, ConditionsController.getStateFromstring(conditionState), int.Parse(value));
        }
        else if (type == ConditionsController.GLOBAL_STATE_CONDITION)
        {
            newCondition = new GlobalStateCondition(conditionId, ConditionsController.getStateFromstring(conditionState));
        }

        if (newCondition != null)
        {
            if (index1 < conditions.size())
            {
                if (index2 == ConditionsController.INDEX_NOT_USED)
                {
                    // Add new block
                    List <Condition> newBlock = new List <Condition>();
                    newBlock.Add(newCondition);
                    conditions.add(index1, newBlock);
                    indexAdded = index1;
                    blockAdded = newBlock;
                }
                else
                {
                    List <Condition> block = conditions.get(index1);
                    if (index2 < 0 || index2 > block.Count)
                    {
                        return(false);
                    }

                    if (index2 == conditions.size())
                    {
                        block.Add(newCondition);
                        indexAdded     = block.IndexOf(newCondition);
                        conditionAdded = newCondition;
                    }
                    else
                    {
                        indexAdded     = index2;
                        conditionAdded = newCondition;
                        block.Insert(index2, newCondition);
                    }
                }
            }
            else
            {
                // Add new block
                List <Condition> newBlock = new List <Condition>();
                newBlock.Add(newCondition);
                conditions.add(newBlock);
                indexAdded = conditions.size() - 1;
                blockAdded = newBlock;
            }
            Controller.getInstance().updateVarFlagSummary();
            Controller.getInstance().updatePanel();
            return(true);
        }
        return(false);
    }