public static VarElement createElement(VarsManager managerT)
 {
     manager = managerT;
     element = new VarElement(manager,Consts.PARAM_STR);
     SmallDialog_NewVar_String dialog = new SmallDialog_NewVar_String("新建字符变量");
     dialog.ShowDialog();
     return element;
 }
 public static VarElement createElement(VarsManager managerT)
 {
     manager = managerT;
     element = new VarElement(manager, Consts.PARAM_INT);
     SmallDialog_NewVar_INT dialog = new SmallDialog_NewVar_INT("新建整型变量");
     dialog.ShowDialog();
     return element;
 }
 //设置地图单元
 public static void configElement(VarElement elementT)
 {
     if (elementT == null)
     {
         Console.WriteLine("error in configElement");
         return;
     }
     manager = (VarsManager)elementT.parent;
     element = elementT;
     SmallDialog_NewVar_String dialog = new SmallDialog_NewVar_String("设置字符变量");
     dialog.textBox_name.Text = element.name;
     dialog.textBox_Value.Text = (String)element.getValue();
     dialog.ShowDialog();
 }
 //设置地图单元
 public static void configElement(VarElement elementT)
 {
     if (elementT == null)
     {
         Console.WriteLine("error in configElement");
         return;
     }
     manager = (VarsManager)elementT.parent;
     element = elementT;
     SmallDialog_NewVar_INT dialog = new SmallDialog_NewVar_INT("设置整型变量");
     dialog.textBox_name.Text = element.name;
     dialog.numericUpDown_Value.Value = (int)element.getValue();
     dialog.ShowDialog();
 }
 //更新常量
 public void updateVarElement(VarElement elementNew)
 {
     if (elementNew == null)
     {
         return;
     }
     for (int i = 0; i < getElementCount(); i++)
     {
         VarElement elementLocal = (VarElement)getElement(i);
         if (elementNew.equalsNameAndType(elementLocal))
         {
             elementLocal.setValue(elementNew.getValue());
             refreshUI_Element(i);
             return;
         }
     }
     addElement(elementNew);
 }
 private void button_GenIDs_Click(object sender, EventArgs e)
 {
     if (currentAntetypeFolder == null)
     {
         return;
     }
     for (int i = 0; i < currentAntetypeFolder.Count(); i++)
     {
         Antetype anteType = (Antetype)currentAntetypeFolder[i];
         String IDName = "ANTETYPE_" + currentAntetypeFolder.name+"_" + anteType.name;
         int IDValue = anteType.GetID();
         VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
         varElementNew.setValue(IDValue);
         varElementNew.name = IDName;
         iDsManager.updateVarElement(varElementNew);
     }
     iDsManager.refreshUI();
 }
 private void button_es_PropertyInstants_Click(object sender, EventArgs e)
 {
     PropertyTypeElement propertyTypeElement = currentObjTypeElement;
     if (currentObjTypeElement == null)
     {
         return;
     }
     listBox_IDs.BeginUpdate();
     //生成实例常量
     for (int j = 0; j < propertyTypeElement.instancesManager.getElementCount(); j++)
     {
         InstanceElement instanceElement = (InstanceElement)propertyTypeElement.instancesManager.getElement(j);
         String IDName = "PROP_INST_" + propertyTypeElement.name + "_" + instanceElement.name;
         int IDValue = j;
         VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
         varElementNew.setValue(IDValue);
         varElementNew.name = IDName;
         iDsManager.updateVarElement(varElementNew);
     }
     iDsManager.refreshUI();
     listBox_IDs.EndUpdate();
 }
 private void button_es_propertyTypes_Click(object sender, EventArgs e)
 {
     listBox_IDs.BeginUpdate();
     //生成对象类型常量
     for (int i = 0; i < propertyTypesManager.getElementCount(); i++)
     {
         PropertyTypeElement propertyTypeElement = (PropertyTypeElement)propertyTypesManager.getElement(i);
         String IDName = "PROP_GENE_" + propertyTypeElement.name;
         int IDValue = i;
         VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
         varElementNew.setValue(IDValue);
         varElementNew.name = IDName;
         iDsManager.updateVarElement(varElementNew);
     }
     iDsManager.refreshUI();
     listBox_IDs.EndUpdate();
 }
 ////从脚本数据自动生成
 //private void generateElement_IDS_Script()
 //{
     //for (int i = 0; i < triggersManager.getElementCount(); i++)
     //{
     //    TriggerPackElement triggerElement = (TriggerPackElement)triggersManager.getElement(i);
     //    String IDName = "TRIGGER_" + triggerElement.name;
     //    VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
     //    varElementNew.setValue(i);
     //    varElementNew.name = IDName;
     //    iDsManager.updateVarElement(varElementNew);
     //}
     //for (int i = 0; i < triggersManager.getElementCount(); i++)
     //{
     //    TriggerPackElement trigger = (TriggerPackElement)triggersManager.getElement(i);
     //    for (int j = 0; j < trigger.triggersManager.getElementCount(); j++)
     //    {
     //        Trigger exeStruct = (Trigger)trigger.triggersManager.getElement(j);
     //        String IDName = "TRIGGER_" + trigger.name + "_" + exeStruct.name;
     //        VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
     //        varElementNew.setValue(j);
     //        varElementNew.name = IDName;
     //        iDsManager.updateVarElement(varElementNew);
     //    }
     //}
 //}
 //从角色原型自动生成
 private void generateElement_IDS_AnteType()
 {
     listBox_IDs.BeginUpdate();
     for (int i = 0; i < form_main.mapsManager.antetypesManager.Count(); i++)
     {
         AntetypeFolder folder = form_main.mapsManager.antetypesManager[i];
         String IDName = "AntetypeFolder_" + folder.name;
         VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
         varElementNew.setValue(i);
         varElementNew.name = IDName;
         iDsManager.updateVarElement(varElementNew);
         for (int j = 0; j < folder.Count(); j++)
         {
             Antetype anteType = folder[j];
             IDName = "Antetype_" + folder.name + "_" + anteType.name;
             varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
             varElementNew.setValue(j);
             varElementNew.name = IDName;
             iDsManager.updateVarElement(varElementNew);
         }
     }
     listBox_IDs.EndUpdate();
 }
 //从地图数据自动生成
 private void generateElement_IDS_Map()
 {
     listBox_IDs.BeginUpdate();
     for (int i = 0; i < form_main.mapsManager.getElementCount(); i++)
     {
         MapElement mapElement = form_main.mapsManager.getElement(i);
         String IDName = "Map_" + mapElement.getName();
         int IDValue = mapElement.getID();
         VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
         varElementNew.setValue(IDValue);
         varElementNew.name = IDName;
         iDsManager.updateVarElement(varElementNew);
         for (int j = 0; j < mapElement.stageList.getElementCount(); j++)
         {
             StageElement stage = (StageElement)mapElement.stageList.getElement(j);
             IDName = "Stage_" + mapElement.getName() + "_" + stage.name;
             IDValue = j;
             varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
             varElementNew.setValue(IDValue);
             varElementNew.name = IDName;
             iDsManager.updateVarElement(varElementNew);
         }
     }
     listBox_IDs.EndUpdate();
 }
        //从属性数据自动生成
        private void generateElement_IDS_Prop()
        {
            listBox_IDs.BeginUpdate();
            //生成对象类型常量
            for (int i = 0; i < propertyTypesManager.getElementCount(); i++)
            {
                PropertyTypeElement propertyTypeElement = (PropertyTypeElement)propertyTypesManager.getElement(i);
                String IDName = "Prop_Gene_" + propertyTypeElement.name;
                int IDValue = i;
                VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
                varElementNew.setValue(IDValue);
                varElementNew.name = IDName;
                iDsManager.updateVarElement(varElementNew);
            }

            for (int i = 0; i < propertyTypesManager.getElementCount(); i++)
            {
                PropertyTypeElement propertyTypeElement = (PropertyTypeElement)propertyTypesManager.getElement(i);
                //生成类型属性常量
                for (int j = 0; j < propertyTypeElement.propertiesManager.getElementCount(); j++)
                {
                    PropertyElement priopertyElement = (PropertyElement)propertyTypeElement.propertiesManager.getElement(j);
                    String IDName = "Prop_Attr_" + propertyTypeElement.name + "_" + priopertyElement.name;
                    int IDValue = j;
                    VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
                    varElementNew.setValue(IDValue);
                    varElementNew.name = IDName;
                    iDsManager.updateVarElement(varElementNew);
                }
                //生成实例常量
                for (int j = 0; j < propertyTypeElement.instancesManager.getElementCount(); j++)
                {
                    InstanceElement instanceElement = (InstanceElement)propertyTypeElement.instancesManager.getElement(j);
                    String IDName = "Prop_Inst_" + propertyTypeElement.name + "_" + instanceElement.name;
                    int IDValue = j;
                    VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
                    varElementNew.setValue(IDValue);
                    varElementNew.name = IDName;
                    iDsManager.updateVarElement(varElementNew);
                }
            }
            listBox_IDs.EndUpdate();

        }
 //从动画数据自动生成
 private void generateElement_IDS_Anim()
 {
     listBox_IDs.BeginUpdate();
     MActorsManager actorsManager = form_main.form_MAnimation.form_MActorList.actorsManager;
     for (int i = 0; i < actorsManager.Count(); i++)
     {
         String IDName = "SpriteFolder_" + actorsManager[i].name;
         VarElement varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
         varElementNew.setValue(i);
         varElementNew.name = IDName;
         iDsManager.updateVarElement(varElementNew);
         for (int j = 0; j < actorsManager[i].Count(); j++)
         {
             MActor actorElement = actorsManager[i][j];
             IDName = "Sprite_" + actorsManager[i].name + "_" + actorElement.name;
             varElementNew = new VarElement(iDsManager, Consts.PARAM_INT);
             varElementNew.setValue(j);
             varElementNew.name = IDName;
             iDsManager.updateVarElement(varElementNew);
         }
     }
     listBox_IDs.EndUpdate();
 }
 public override ObjectElement clone()
 {
     VarElement newInstance = new VarElement((VarsManager)parent, varType);
     baseCloneTo(newInstance);
     newInstance.isFixed=isFixed;
     newInstance.isUsedInHeadFile = isUsedInHeadFile;
     switch (varType)
     {
         case Consts.PARAM_INT:
         case Consts.PARAM_INT_VAR:
         case Consts.PARAM_STR_VAR:
         case Consts.PARAM_INT_ID:
             newInstance.value = (int)value;
             break;
         case Consts.PARAM_STR:
             newInstance.value = name + "";
             break;
     }
     return newInstance;
 }
 //将对自己的引用转移到别的对象上
 public void changeUseInfor(VarElement varDest)
 {
     //在脚本中查找-------------------------------------------------------------------
     //TriggerPacksManager triggersManager = ((VarsManager)parent).form_main.triggersManager;
     //for (int i = 0; i < triggersManager.getElementCount(); i++)
     //{
     //    TriggerPackElement trigger = (TriggerPackElement)triggersManager.getElement(i);
     //    for (int j = 0; j < trigger.sentences_Trigger.getElementCount(); j++)
     //    {
     //        Sentence sentence = (Sentence)trigger.sentences_Trigger.getElement(j);
     //        for (int k = 0; k < sentence.paramsList.Count; k++)
     //        {
     //            if (sentence.paramsList[k] != null && sentence.paramsList[k].Equals(this))
     //            {
     //                sentence.paramsList[k] = varDest;
     //            }
     //        }
     //    }
     //    for (int j = 0; j < trigger.sentences_Context.getElementCount(); j++)
     //    {
     //        Sentence sentence = (Sentence)trigger.sentences_Context.getElement(j);
     //        for (int k = 0; k < sentence.paramsList.Count; k++)
     //        {
     //            if (sentence.paramsList[k] != null && sentence.paramsList[k].Equals(this))
     //            {
     //                sentence.paramsList[k] = varDest;
     //            }
     //        }
     //    }
     //    for (int j = 0; j < trigger.triggersManager.getElementCount(); j++)
     //    {
     //        Trigger exeStruct = (Trigger)trigger.triggersManager.getElement(j);
     //        for (int k = 0; k < exeStruct.sentences_Context.getElementCount(); k++)
     //        {
     //            Sentence sentence = (Sentence)exeStruct.sentences_Context.getElement(k);
     //            for (int m = 0; m < sentence.paramsList.Count; m++)
     //            {
     //                if (sentence.paramsList[m] != null && sentence.paramsList[m].Equals(this))
     //                {
     //                    sentence.paramsList[m] = varDest;
     //                }
     //            }
     //        }
     //        for (int k = 0; k < exeStruct.sentences_Executions.getElementCount(); k++)
     //        {
     //            Sentence sentence = (Sentence)exeStruct.sentences_Executions.getElement(k);
     //            for (int m = 0; m < sentence.paramsList.Count; m++)
     //            {
     //                if (sentence.paramsList[m] != null && sentence.paramsList[m].Equals(this))
     //                {
     //                    sentence.paramsList[m] = varDest;
     //                }
     //            }
     //        }
     //    }
     //}
     //在属性中查找-------------------------------------------------------------------
     PropertyTypesManager propertyTypesManager = (PropertyTypesManager)(((VarsManager)parent).form_main.propertyTypesManager);
     for (int i = 0; i < propertyTypesManager.getElementCount(); i++)
     {
         PropertyTypeElement propertyTypeElement = (PropertyTypeElement)propertyTypesManager.getElement(i);
         InstancesManager instancesManager = (InstancesManager)propertyTypeElement.instancesManager;
         for (int j = 0; j < instancesManager.getElementCount(); j++)
         {
             InstanceElement instanceElement = (InstanceElement)instancesManager.getElement(j);
             for (int k = 0; k < instanceElement.propertyValueManager.getElementCount(); k++)
             {
                 PropertyValueElement propertyValueElement = (PropertyValueElement)(instanceElement.propertyValueManager.getElement(k));
                 if (propertyValueElement != null)
                 {
                     Object value = propertyValueElement.getValue();
                     if (value != null && value.Equals(this))
                     {
                         propertyValueElement.setValue(varDest);
                     }
                 }
             }
         }
     }
 }
 //判断名称和类型相同(不包括“值判断,在合并时旧值将被新值更新)
 public bool equalsNameAndType(VarElement destVar)
 {
     if (destVar==null||name == null || !name.Equals(destVar.name))
     {
         return false;
     }
     if (varType != destVar.varType)
     {
         return false;
     }
     return true;
     //switch (varType)
     //{
     //    case Consts.PARAM_INT:
     //    case Consts.PARAM_INT_VAR:
     //    case Consts.PARAM_STR_VAR:
     //    case Consts.PARAM_INT_ID:
     //        int intValueLocal = Convert.ToInt32(value);
     //        int intValueDest = Convert.ToInt32(destVar.value);
     //        if (intValueLocal == intValueDest)
     //        {
     //            return true;
     //        }
     //        break;
     //    case Consts.PARAM_STR:
     //        String strValueLocal = (String)(value);
     //        String strValueDest = (String)(destVar.value);
     //        if (strValueLocal.Equals(strValueDest))
     //        {
     //            return true;
     //        }
     //        break;
     //}
     //return false;
 }
        public void ReadObject(System.IO.Stream s)
        {
            short len = 0;
            len = IOUtil.readShort(s);

            for (int i = 0; i < len; i++)
            {
                VarElement element = new VarElement(this, Consts.PARAM_INT);
                element.ReadObject(s);
                addElement(element);
            }
        }