Пример #1
0
        public EditEnumMemberDialog(CustomizedEnum customizedEnum, CustomizedEnum.CustomizedEnumMember enumMember)
        {
            InitializeComponent();

            this.Owner = MainWindow.Instance;
            this.Text  = (enumMember == null) ? Resources.AddEnumMember : Resources.EditEnumMember;

            this.editEnumMemberPanel.Initialize(customizedEnum, enumMember);
        }
Пример #2
0
        public bool Verify()
        {
            Debug.Check(_customizedEnum != null);
            Debug.Check(_enumMember != null);

            string memberName = this.nameTextBox.Text;
            bool   isValid    = !string.IsNullOrEmpty(memberName) && Char.IsLetter(memberName[0]);

            if (isValid && _enumMember != null)
            {
                CustomizedEnum.CustomizedEnumMember member = _customizedEnum.GetMemberByName(memberName);

                if (_isNew)
                {
                    isValid = (member == null);
                }
                else
                {
                    isValid = (member == null || member == _originalMember);
                }
            }

            return(isValid);
        }
Пример #3
0
        public void Initialize(CustomizedEnum customizedEnum, CustomizedEnum.CustomizedEnumMember enumMember)
        {
            _initialized    = false;
            _isModified     = false;
            _customizedEnum = customizedEnum;
            _originalMember = enumMember;
            if (enumMember == null)
            {
                _isNew      = true;
                _enumMember = new CustomizedEnum.CustomizedEnumMember(enumMember);
            }
            else
            {
                _isNew      = false;
                _enumMember = enumMember;
            }

            this.nameTextBox.Text         = _enumMember.Name;
            this.valueNumericUpDown.Value = _enumMember.Value;
            this.dispTextBox.Text         = _enumMember.DisplayName;
            this.descTextBox.Text         = _enumMember.Description;

            _initialized = true;
        }
Пример #4
0
        private void ExportCustomizedTypes(string agentFolder)
        {
            if (CustomizedTypeManager.Instance.Enums.Count > 0 || CustomizedTypeManager.Instance.Structs.Count > 0)
            {
                string   filename    = Path.Combine(agentFolder, "customizedtypes.cs");
                Encoding utf8WithBom = new UTF8Encoding(true);

                using (StreamWriter file = new StreamWriter(filename, false, utf8WithBom))
                {
                    // write comments
                    file.WriteLine("// ---------------------------------------------------------------------");
                    file.WriteLine("// This file is auto-generated by behaviac designer, so please don't modify it by yourself!");
                    file.WriteLine("// ---------------------------------------------------------------------\n");

                    file.WriteLine("using System.Collections;");
                    file.WriteLine("using System.Collections.Generic;");
                    file.WriteLine();

                    //file.WriteLine("namespace behaviac");
                    //file.WriteLine("{");

                    file.WriteLine("// -------------------");
                    file.WriteLine("// Customized enums");
                    file.WriteLine("// -------------------\n");

                    for (int e = 0; e < CustomizedTypeManager.Instance.Enums.Count; ++e)
                    {
                        if (e > 0)
                        {
                            file.WriteLine();
                        }

                        CustomizedEnum customizedEnum = CustomizedTypeManager.Instance.Enums[e];
                        file.WriteLine("[behaviac.TypeMetaInfo(\"{0}\", \"{1}\")]", customizedEnum.DisplayName, customizedEnum.Description);

                        file.WriteLine("public enum {0}", customizedEnum.Name);
                        file.WriteLine("{");

                        for (int m = 0; m < customizedEnum.Members.Count; ++m)
                        {
                            if (m > 0)
                            {
                                file.WriteLine();
                            }

                            CustomizedEnum.CustomizedEnumMember member = customizedEnum.Members[m];
                            if (member.DisplayName != member.Name || !string.IsNullOrEmpty(member.Description))
                            {
                                file.WriteLine("\t[behaviac.MemberMetaInfo(\"{0}\", \"{1}\")]", member.DisplayName, member.Description);
                            }

                            if (member.Value >= 0)
                            {
                                file.WriteLine("\t{0} = {1},", member.Name, member.Value);
                            }
                            else
                            {
                                file.WriteLine("\t{0},", member.Name);
                            }
                        }

                        file.WriteLine("}");
                    }

                    if (CustomizedTypeManager.Instance.Enums.Count > 0)
                    {
                        file.WriteLine();
                    }

                    file.WriteLine("// -------------------");
                    file.WriteLine("// Customized structs");
                    file.WriteLine("// -------------------\n");

                    for (int s = 0; s < CustomizedTypeManager.Instance.Structs.Count; s++)
                    {
                        if (s > 0)
                        {
                            file.WriteLine();
                        }

                        CustomizedStruct customizedStruct = CustomizedTypeManager.Instance.Structs[s];
                        file.WriteLine("[behaviac.TypeMetaInfo(\"{0}\", \"{1}\")]", customizedStruct.DisplayName, customizedStruct.Description);

                        file.WriteLine("public struct {0}", customizedStruct.Name);
                        file.WriteLine("{");

                        for (int m = 0; m < customizedStruct.Properties.Count; ++m)
                        {
                            if (m > 0)
                            {
                                file.WriteLine();
                            }

                            PropertyDef member = customizedStruct.Properties[m];
                            if (member.DisplayName != member.Name || !string.IsNullOrEmpty(member.BasicDescription))
                            {
                                file.WriteLine("\t[behaviac.MemberMetaInfo(\"{0}\", \"{1}\")]", member.DisplayName, member.BasicDescription);
                            }

                            file.WriteLine("\tpublic {0} {1};", DataCsExporter.GetGeneratedNativeType(member.NativeType), member.BasicName);
                        }

                        file.WriteLine("}");
                    }

                    //file.WriteLine("}");
                }
            }
        }