Example #1
0
 private void Edit()
 {
     if (listView1.SelectedIndices.Count == 1)
     {
         int              selectIdx    = listView1.SelectedIndices[0];
         ListViewItem     selectedItem = listView1.Items[selectIdx];
         EnumItem         enumItem     = selectedItem.Tag as EnumItem;
         EditEnumItemForm editEnumForm = new EditEnumItemForm(this, m_CustomEnum, enumItem);
         editEnumForm.ShowDialog();
     }
 }
Example #2
0
 private void BindEnum()
 {
     listView1.Items.Clear();
     for (int i = 0; i < m_CustomEnum.Enums.Count; i++)
     {
         EnumItem     enumItem     = m_CustomEnum.Enums[i];
         ListViewItem listViewItem = listView1.Items.Add(enumItem.EnumStr);
         listViewItem.Tag = enumItem;
         listViewItem.SubItems.Add(enumItem.EnumValue.ToString());
         listViewItem.SubItems.Add(enumItem.Describe);
     }
 }
Example #3
0
        private void Swap(bool up)
        {
            if (listView1.SelectedIndices.Count > 1)
            {
                MainForm.Instance.ShowInfo("请选择一条记录进行交换");
                MainForm.Instance.ShowMessage("请选择一条记录进行交换", "警告");
                return;
            }

            int selectIdx = listView1.SelectedIndices[0];

            if (up)
            {
                //第一个不能往上交换
                if (selectIdx == 0)
                {
                    return;
                }

                int preIdx = selectIdx - 1;

                EnumItem preEnum      = m_CustomEnum.Enums[preIdx];
                EnumItem selectedEnum = m_CustomEnum.Enums[selectIdx];

                m_CustomEnum.Enums[preIdx]    = selectedEnum;
                m_CustomEnum.Enums[selectIdx] = preEnum;

                selectIdx = preIdx;
            }
            else
            {
                //最后一个不能往下交换
                if (selectIdx == listView1.Items.Count - 1)
                {
                    return;
                }

                int nextIdx = selectIdx + 1;

                EnumItem preEnum      = m_CustomEnum.Enums[nextIdx];
                EnumItem selectedEnum = m_CustomEnum.Enums[selectIdx];

                m_CustomEnum.Enums[nextIdx]   = selectedEnum;
                m_CustomEnum.Enums[selectIdx] = preEnum;

                selectIdx = nextIdx;
            }

            //MainForm.Instance.NodeClassDirty = true;
            Exec("Refresh");
            MainForm.Instance.ShowInfo("交换成功 时间:" + DateTime.Now);
            listView1.Items[selectIdx].Selected = true;
        }
Example #4
0
        /// <summary>
        /// 校验是否存在空的枚举名
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyEmptyEnumStr()
        {
            for (int i = 0; i < m_Enums.Count; i++)
            {
                EnumItem enumItem = m_Enums[i];
                if (string.IsNullOrEmpty(enumItem.EnumStr))
                {
                    return(new VerifyInfo("存在空枚举选项名"));
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
Example #5
0
        public void UpdateEnumItem(EnumItem enumItem)
        {
            if (enumItem == null)
            {
                return;
            }

            Exec("Refresh");

            ListViewItem listViewItem = GetListViewItem(enumItem);

            if (listViewItem != null)
            {
                listViewItem.Selected = true;
            }
        }
Example #6
0
 public EnumItem FindEnum(string enumStr)
 {
     for (int i = 0; i < m_Enums.Count; i++)
     {
         EnumItem item = m_Enums[i];
         if (item == null)
         {
             continue;
         }
         if (item.EnumStr == enumStr)
         {
             return(item);
         }
     }
     return(null);
 }
Example #7
0
        public override string ToString()
        {
            string content = m_EnumType + ":[";

            for (int i = 0; i < m_Enums.Count; i++)
            {
                EnumItem item = m_Enums[i];
                if (item == null)
                {
                    continue;
                }
                content += item.EnumStr + (i < m_Enums.Count - 1 ? "," : string.Empty);
            }
            content += "]";
            return(content);
        }
Example #8
0
 /// <summary>
 /// 是否存相同枚举值
 /// </summary>
 /// <returns></returns>
 public VerifyInfo VerifySameEnumValue()
 {
     //检测EnumValue是否存在相同
     for (int i = 0; i < m_Enums.Count; i++)
     {
         EnumItem enum_i = m_Enums[i];
         for (int ii = i + 1; ii < m_Enums.Count; ii++)
         {
             EnumItem enum_ii = m_Enums[ii];
             if (enum_i.EnumValue == enum_ii.EnumValue)
             {
                 return(new VerifyInfo(string.Format("存在重复枚举值:{0}", enum_ii.EnumValue)));
             }
         }
     }
     return(VerifyInfo.DefaultVerifyInfo);
 }
Example #9
0
 public bool Remove(string enumStr)
 {
     for (int i = 0; i < m_Enums.Count; i++)
     {
         EnumItem item = m_Enums[i];
         if (item == null)
         {
             continue;
         }
         if (item.EnumStr == enumStr)
         {
             m_Enums.RemoveAt(i);
             return(true);
         }
     }
     return(false);
 }
Example #10
0
 /// <summary>
 /// 是否存在相同枚举选项名
 /// </summary>
 /// <returns></returns>
 public bool ExistSameEnumStr()
 {
     //检测EnumStr是否重复
     for (int i = 0; i < m_Enums.Count; i++)
     {
         EnumItem enum_i = m_Enums[i];
         for (int ii = i + 1; ii < m_Enums.Count; ii++)
         {
             EnumItem enum_ii = m_Enums[ii];
             if (enum_i.EnumStr == enum_ii.EnumStr)
             {
                 MainForm.Instance.ShowMessage(string.Format("存在重复枚举选项:{0}", enum_ii.EnumStr));
                 MainForm.Instance.ShowInfo(string.Format("存在重复枚举选项:{0} 时间:{1}", enum_ii.EnumStr, DateTime.Now));
                 return(true);
             }
         }
     }
     return(false);
 }
Example #11
0
 public bool ExistEnumValue(int enumValue, EnumItem ignore = null)
 {
     for (int i = 0; i < m_Enums.Count; i++)
     {
         EnumItem item = m_Enums[i];
         if (item == null)
         {
             continue;
         }
         if (ignore != null && ignore == item)
         {
             continue;
         }
         if (item.EnumValue == enumValue)
         {
             return(true);
         }
     }
     return(false);
 }
        private void BindEnum()
        {
            if (m_NodeClasses == null)
                return;

            listView1.Items.Clear();
            for (int i = 0; i < m_NodeClasses.Enums.Count; i++)
            {
                CustomEnum customEnum = m_NodeClasses.Enums[i];
                ListViewItem listViewItem = listView1.Items.Add(customEnum.EnumType);
                listViewItem.Tag = customEnum;
                string content = string.Empty;
                for (int j = 0; j < customEnum.Enums.Count; j++)
                {
                    EnumItem enumItem = customEnum.Enums[j];
                    content += string.Format("{0} = {1} {2}", enumItem.EnumStr, enumItem.EnumValue, j < customEnum.Enums.Count - 1 ? "," : string.Empty);
                }
                listViewItem.SubItems.Add(content);
                listViewItem.SubItems.Add(customEnum.Describe);
            }
        }
Example #13
0
        private void Paste()
        {
            try
            {
                EnumItemListContent content = XmlUtility.StringToObject <EnumItemListContent>(Clipboard.GetText());

                for (int i = 0; i < content.DataList.Count; i++)
                {
                    EnumItem customEnum = content.DataList[i];
                    string   enumStr    = customEnum.EnumStr;
                    do
                    {
                        enumStr += "_New";
                    }while (m_CustomEnum.ExistEnumStr(enumStr));

                    int enumValue = customEnum.EnumValue;
                    do
                    {
                        enumValue++;
                    }while (m_CustomEnum.ExistEnumValue(enumValue));

                    customEnum.EnumStr   = enumStr;
                    customEnum.EnumValue = enumValue;

                    m_CustomEnum.AddEnumItem(customEnum);
                }

                Exec("Refresh");
                MainForm.Instance.ShowInfo("您粘贴了" + content.DataList.Count + "个枚举选项!!!");
            }
            catch (Exception ex)
            {
                MainForm.Instance.ShowInfo("无法进行粘贴,错误信息:" + ex.Message);
                MainForm.Instance.ShowMessage("无法进行粘贴,错误信息:" + ex.Message, "警告");
            }
        }
        /// <summary>
        /// 是否存在无效枚举类型
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyEnum()
        {
            //校验枚举类型
            //检测字段是否重复
            for (int i = 0; i < m_Fields.Count; i++)
            {
                NodeField field = m_Fields[i];
                if (field.FieldType == FieldType.EnumField)
                {
                    EnumDefaultValue enumDeaultValue = field.DefaultValue as EnumDefaultValue;
                    if (enumDeaultValue != null)
                    {
                        if (string.IsNullOrEmpty(enumDeaultValue.EnumType))
                        {
                            return(new VerifyInfo(string.Format("节点类型[{0}]的字段[{1}]的枚举类型为空", this.ClassType, field.FieldName)));
                        }

                        CustomEnum customEnum = MainForm.Instance.NodeClasses.FindEnum(enumDeaultValue.EnumType);
                        if (customEnum == null)
                        {
                            return(new VerifyInfo(string.Format("节点类型[{0}]的字段[{1}]的枚举类型[{2}]不存在", this.ClassType, field.FieldName, enumDeaultValue.EnumType)));
                        }
                        else
                        {
                            EnumItem enumItem = customEnum.FindEnum(enumDeaultValue.DefaultValue);
                            if (enumItem == null)
                            {
                                return(new VerifyInfo(string.Format("节点类型[{0}]的字段[{1}]的枚举类型[{2}]不存在选项[{3}]", this.ClassType, field.FieldName, customEnum.EnumType, enumDeaultValue.DefaultValue)));
                            }
                        }
                    }
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
Example #15
0
        /// <summary>
        /// 是否存在无效枚举类型
        /// </summary>
        /// <returns></returns>
        public VerifyInfo VerifyEnum()
        {
            //校验枚举类型
            //检测字段是否重复
            for (int i = 0; i < m_Fields.Count; i++)
            {
                FieldDesigner field = m_Fields[i];
                if (field.FieldType == FieldType.EnumField)
                {
                    EnumFieldDesigner enumFieldDesigner = field.Field as EnumFieldDesigner;
                    if (enumFieldDesigner != null)
                    {
                        if (string.IsNullOrEmpty(enumFieldDesigner.EnumType))
                        {
                            return(new VerifyInfo(string.Format("行为树[{0}]的字段[{1}]的枚举类型为空", m_TreeID, field.FieldName)));
                        }

                        CustomEnum customEnum = MainForm.Instance.NodeTemplate.FindEnum(enumFieldDesigner.EnumType);
                        if (customEnum == null)
                        {
                            return(new VerifyInfo(string.Format("行为树[{0}]的字段[{1}]的枚举类型[{2}]不存在", m_TreeID, field.FieldName, enumFieldDesigner.EnumType)));
                        }
                        else
                        {
                            EnumItem enumItem = customEnum.FindEnum(enumFieldDesigner.Value);
                            if (enumItem == null)
                            {
                                return(new VerifyInfo(string.Format("行为树[{0}]的字段[{1}]的枚举类型[{2}]\n不存在选项[{3}]", m_TreeID, field.FieldName, customEnum.EnumType, enumFieldDesigner.Value)));
                            }
                        }
                    }
                }
            }

            return(VerifyInfo.DefaultVerifyInfo);
        }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            m_EnumStr = null;
            if (context.Instance is EnumDefaultValue)
            {
                EnumDefaultValue enumDeaultValue = context.Instance as EnumDefaultValue;
                if (enumDeaultValue != null)
                {
                    m_EnumStr = enumDeaultValue.DefaultValue;
                    if (string.IsNullOrEmpty(enumDeaultValue.EnumType))
                    {
                        MainForm.Instance.ShowMessage("请先选择枚举类型");
                    }
                    else
                    {
                        m_CustomEnum = MainForm.Instance.NodeTemplate.FindEnum(enumDeaultValue.EnumType);
                        if (m_CustomEnum == null)
                        {
                            MainForm.Instance.ShowMessage(string.Format("不存在枚举类型:{0},请先注册", enumDeaultValue.EnumType));
                        }
                    }
                }
            }
            else if (context.Instance is EnumFieldDesigner)
            {
                EnumFieldDesigner enumFieldDesigner = context.Instance as EnumFieldDesigner;
                if (enumFieldDesigner != null)
                {
                    m_EnumStr = enumFieldDesigner.Value;
                    if (string.IsNullOrEmpty(enumFieldDesigner.EnumType))
                    {
                        MainForm.Instance.ShowMessage("请先选择枚举类型");
                    }
                    else
                    {
                        m_CustomEnum = MainForm.Instance.NodeTemplate.FindEnum(enumFieldDesigner.EnumType);
                        if (m_CustomEnum == null)
                        {
                            MainForm.Instance.ShowMessage(string.Format("不存在枚举类型:{0},请先注册", enumFieldDesigner.EnumType));
                        }
                    }
                }
            }

            if (m_CustomEnum != null)
            {
                //绑定
                m_EnumItemList.Clear();
                if (m_CustomEnum.Enums.Count > 0)
                {
                    int selectedIndex = 0;

                    for (int i = 0; i < m_CustomEnum.Enums.Count; i++)
                    {
                        EnumItem enumItem = m_CustomEnum.Enums[i];
                        m_EnumItemList.Add(enumItem.EnumStr);
                        if (m_EnumStr == enumItem.EnumStr)
                        {
                            selectedIndex = i;
                        }
                    }
                }

                return(new StandardValuesCollection(m_EnumItemList));
            }

            return(base.GetStandardValues(context));
        }