示例#1
0
        private void typeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.GetMetaType() == MetaTypes.Agent)
            {
                if (_customizedAgent == null)
                {
                    _customizedAgent = new AgentType(this.nameTextBox.Text, null, this.dispTextBox.Text, this.descTextBox.Text);
                }
            }
            else if (this.GetMetaType() == MetaTypes.Enum)
            {
                if (_customizedEnum == null)
                {
                    _customizedEnum = new CustomizedEnum(this.nameTextBox.Text, this.dispTextBox.Text, this.descTextBox.Text);
                }
            }
            else if (this.GetMetaType() == MetaTypes.Struct)
            {
                if (_customizedStruct == null)
                {
                    _customizedStruct = new CustomizedStruct(this.nameTextBox.Text, this.dispTextBox.Text, this.descTextBox.Text);
                }
            }

            resetBaseTypes();

            if (_initialized)
            {
                this.IsModified = true;
            }
        }
示例#2
0
        public MetaPropertyDialog(bool canBeEdited, AgentType agent, CustomizedStruct customizedStruct, PropertyDef prop, bool canBePar)
        {
            InitializeComponent();

            this.Owner = MainWindow.Instance;

            this.metaPropertyPanel.Initialize(canBeEdited, agent, customizedStruct, prop, canBePar);
        }
示例#3
0
        public void Initialize(bool canBeEdit, AgentType agent, CustomizedStruct customizedStruct, PropertyDef prop, bool canBePar)
        {
            Debug.Check(agent != null || customizedStruct != null);

            _initialized      = false;
            _isModified       = false;
            _isNew            = (prop == null);
            _agent            = agent;
            _customizedStruct = customizedStruct;
            _originalProperty = prop;

            setTypes();

            if (_isNew)
            {
                this.Text = canBeEdit ? Resources.AddProperty : Resources.ViewProperty;

                if (customizedStruct == null)
                {
                    _property = new PropertyDef(agent, null, agent.AgentTypeName, "", "", "");
                }
                else
                {
                    _property = new PropertyDef(null, null, customizedStruct.Name, "", "", "");
                }
            }
            else
            {
                this.Text = canBeEdit ? Resources.EditProperty : Resources.ViewProperty;

                resetProperty(prop, prop.IsPar);
            }

            this.isStaticCheckBox.Visible   = (agent != null);
            this.isPublicCheckBox.Visible   = !canBeEdit && (agent != null);
            this.isConstcheckBox.Visible    = (agent != null);
            this.customizedCheckBox.Visible = !canBeEdit && !_property.IsInherited;
            this.isLocalCheckBox.Checked    = customizedStruct == null && _property.IsPar;
            this.isLocalCheckBox.Visible    = canBePar && customizedStruct == null && !_property.IsMember;
            this.nameTextBox.Enabled        = canBeEdit;
            this.arrayCheckBox.Enabled      = canBeEdit;
            this.typeComboBox.Enabled       = canBeEdit;
            this.isStaticCheckBox.Enabled   = canBeEdit;
            this.isConstcheckBox.Enabled    = canBeEdit;
            this.dispTextBox.Enabled        = canBeEdit;
            this.descTextBox.Enabled        = canBeEdit;

            _initialized = true;
        }
示例#4
0
        public void Initialize(object typeObject)
        {
            _initialized = false;
            _isModified  = false;
            _isNew       = (typeObject == null);
            this.Text    = _isNew ? Resources.AddType : Resources.EditType;

            MetaTypes metaType = MetaTypes.Agent;

            if (typeObject != null)
            {
                if (typeObject is AgentType)
                {
                    metaType         = MetaTypes.Agent;
                    _customizedAgent = typeObject as AgentType;
                }
                else if (typeObject is CustomizedEnum)
                {
                    metaType        = MetaTypes.Enum;
                    _customizedEnum = typeObject as CustomizedEnum;
                }
                else if (typeObject is CustomizedStruct)
                {
                    metaType          = MetaTypes.Struct;
                    _customizedStruct = typeObject as CustomizedStruct;
                }
            }

            this.typeComboBox.Items.Clear();
            this.typeComboBox.Enabled = _isNew;
            foreach (string type in Enum.GetNames(typeof(MetaTypes)))
            {
                this.typeComboBox.Items.Add(type);
            }
            this.typeComboBox.SelectedIndex = (int)metaType;

            if (this.GetMetaType() == MetaTypes.Agent)
            {
                Debug.Check(_customizedAgent != null);

                if (_customizedAgent.Base != null)
                {
                    this.baseComboBox.SelectedText = _customizedAgent.Base.AgentTypeName;
                }

                this.nameTextBox.Text = _customizedAgent.AgentTypeName;
                this.dispTextBox.Text = _customizedAgent.DisplayName;
                this.descTextBox.Text = _customizedAgent.Description;

                this.typeComboBox.Enabled = _customizedAgent.IsCustomized;
                this.nameTextBox.Enabled  = _customizedAgent.IsCustomized;
                this.baseComboBox.Enabled = _customizedAgent.IsCustomized;
                this.dispTextBox.Enabled  = _customizedAgent.IsCustomized;
                this.descTextBox.Enabled  = _customizedAgent.IsCustomized;
            }
            else
            {
                if (this.GetMetaType() == MetaTypes.Enum)
                {
                    Debug.Check(_customizedEnum != null);

                    this.nameTextBox.Text = _customizedEnum.Name;
                    this.dispTextBox.Text = _customizedEnum.DisplayName;
                    this.descTextBox.Text = _customizedEnum.Description;
                }
                else if (this.GetMetaType() == MetaTypes.Struct)
                {
                    Debug.Check(_customizedStruct != null);

                    this.nameTextBox.Text = _customizedStruct.Name;
                    this.dispTextBox.Text = _customizedStruct.DisplayName;
                    this.descTextBox.Text = _customizedStruct.Description;
                }

                this.typeComboBox.Enabled = true;
                this.nameTextBox.Enabled  = true;
                this.baseComboBox.Enabled = true;
                this.dispTextBox.Enabled  = true;
                this.descTextBox.Enabled  = true;
            }

            this.nameTextBox.Focus();
            this.nameTextBox.SelectionStart = this.nameTextBox.TextLength;

            _initialized = true;
        }
示例#5
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("}");
                }
            }
        }