/// <summary>
        /// 点击确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_OK_Click(object sender, EventArgs e)
        {
            Action SaveAction = () =>
            {
                attributeItemStruct             = new AutoItemControl.ItemStruct();
                attributeItemStruct.Label       = SetAttributeControl_Main.TextBox_Label.Text;
                attributeItemStruct.Tag         = SetAttributeControl_Main.TextBox_Tag.Text;
                attributeItemStruct.TypeTag     = SetAttributeControl_Main.TextBox_TypeTag.Text;
                attributeItemStruct.ControlType = Type.GetType(SetAttributeControl_Main.TextBox_ControlType.Text, false);
                attributeItemStruct.IsArray     = bool.Parse(SetAttributeControl_Main.TextBox_IsArray.Text);
                if (attributeItemStruct.IsArray)
                {
                    attributeItemStruct.ChildCount       = int.Parse(SetAttributeControl_Main.TextBox_ChildCount.Text);
                    attributeItemStruct.ChildControlType = SetAttributeControl_Main.TextBox_ChildControlType.Text;
                }
                else
                {
                    attributeItemStruct.ChildCount       = 0;
                    attributeItemStruct.ChildControlType = "";
                }
                DialogResult = DialogResult.OK;
            };

            if (string.IsNullOrEmpty(SetAttributeControl_Main.TextBox_Label.Text))
            {
                MessageBox.Show("Label不能为空");
                return;
            }
            if (string.IsNullOrEmpty(SetAttributeControl_Main.TextBox_Tag.Text))
            {
                MessageBox.Show("Tag不能为空");
                return;
            }
            if (!SkillDataFileEditorForm.CanUseThisTag(SetAttributeControl_Main.TextBox_Tag.Text))
            {
                MessageBox.Show("该Tag不可用");
                return;
            }

            bool isArray;

            if (bool.TryParse(SetAttributeControl_Main.TextBox_IsArray.Text, out isArray))
            {
                if (isArray)//数组
                {
                    if (string.Equals(SetAttributeControl_Main.TextBox_ControlType.Text?.Trim(), "SkillDataFileEditor.AutoArrayControl"))
                    {
                        int childCount;
                        if (!int.TryParse(SetAttributeControl_Main.TextBox_ChildCount.Text, out childCount))
                        {
                            MessageBox.Show("ChildCount必须是一个整数");
                        }
                        try
                        {
                            Type childControlType = Type.GetType(SetAttributeControl_Main.TextBox_ChildControlType.Text);
                            if (!childControlType.IsSubclassOf(typeof(Control)))
                            {
                                MessageBox.Show("ChildControlType必须是一个控件");
                            }
                            //开始保存
                            SaveAction();
                        }
                        catch
                        {
                            MessageBox.Show("ChildControlType必须是一个具体的类型");
                        }
                    }
                    else
                    {
                        MessageBox.Show("如果IsArray是True,则此处的类型必须是SkillDataFileEditor.AutoArrayControl");
                        return;
                    }
                }
                else//非数组
                {
                    Type typeTag = null;
                    try { typeTag = Type.GetType(SetAttributeControl_Main.TextBox_TypeTag.Text); } catch { }
                    if (typeTag == null)
                    {
                        MessageBox.Show("TypeTag必须是具体的类型");
                        return;
                    }
                    //开始保存
                    SaveAction();
                }
            }
            else
            {
                MessageBox.Show("IsArray必须是可以转换成Bool值");
                return;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载
        /// </summary>
        public void LoadFile()
        {
            List <AutoItemControl.ItemStruct> skillAttributeItemStructs = new List <AutoItemControl.ItemStruct>();

            if (File.Exists(attributeSettingPath))
            {
                using (StreamReader sr = new StreamReader(attributeSettingPath, Encoding.UTF8))
                {
                    string   readLine   = null;
                    string[] itemsSplit = new string[] { "^^^" };
                    string[] valueSplit = new string[] { ":::" };
                    while ((readLine = sr.ReadLine()) != null)
                    {
                        string[] Items = readLine.Split(itemsSplit, StringSplitOptions.RemoveEmptyEntries);
                        if (Items.Length == 7)
                        {
                            AutoItemControl.ItemStruct skillAttributeItemStruct = new AutoItemControl.ItemStruct();
                            foreach (string item in Items)
                            {
                                string[] values = item.Split(valueSplit, StringSplitOptions.RemoveEmptyEntries);
                                if (values.Length != 2)
                                {
                                    string[] tempValues = new string[2];
                                    for (int i = 0; i < 2; i++)
                                    {
                                        tempValues[i] = "";
                                    }
                                    int index = 0;
                                    while (index < tempValues.Length && index < values.Length)
                                    {
                                        tempValues[index] = values[index];
                                        index++;
                                    }
                                }
                                switch (values[0].Trim())
                                {
                                case "Label":
                                    skillAttributeItemStruct.Label = values[1].Trim();
                                    break;

                                case "Tag":
                                    skillAttributeItemStruct.Tag = values[1].Trim();
                                    break;

                                case "TypeTag":
                                    skillAttributeItemStruct.TypeTag = values[1].Trim();
                                    break;

                                case "ControlType":
                                    try { skillAttributeItemStruct.ControlType = Type.GetType(values[1].Trim()); } catch { }
                                    break;

                                case "IsArray":
                                    try { skillAttributeItemStruct.IsArray = bool.Parse(values[1].Trim()); } catch { }
                                    break;

                                case "ChildControlType":
                                    skillAttributeItemStruct.ChildControlType = values[1].Trim();
                                    break;

                                case "ChildCount":
                                    try { skillAttributeItemStruct.ChildCount = int.Parse(values[1].Trim()); } catch { }
                                    break;
                                }
                            }
                            skillAttributeItemStructs.Add(skillAttributeItemStruct);
                        }
                    }
                }
            }

            foreach (AutoItemControl.ItemStruct skillAttributeItemStruct in skillAttributeItemStructs)
            {
                TabPage tabPage = new TabPage();
                TabControl_SkillAttribute.TabPages.Add(tabPage);
                SetAttributeControl setAttributeControl = new SetAttributeControl();
                tabPage.Controls.Add(setAttributeControl);
                setAttributeControl.Dock = DockStyle.Fill;
                setAttributeControl.TextBox_Label.TextChanged    += (sender, e) => { tabPage.Text = "Name:" + setAttributeControl.TextBox_Label.Text; };
                setAttributeControl.TextBox_Label.Text            = skillAttributeItemStruct.Label;
                setAttributeControl.TextBox_Tag.Text              = skillAttributeItemStruct.Tag;
                setAttributeControl.TextBox_TypeTag.Text          = skillAttributeItemStruct.TypeTag;
                setAttributeControl.TextBox_ControlType.Text      = skillAttributeItemStruct.ControlType?.FullName;
                setAttributeControl.TextBox_IsArray.Text          = skillAttributeItemStruct.IsArray.ToString();
                setAttributeControl.TextBox_ChildCount.Text       = skillAttributeItemStruct.ChildCount.ToString();
                setAttributeControl.TextBox_ChildControlType.Text = skillAttributeItemStruct.ChildControlType;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置当前选中树节点应该显示的数据
        /// </summary>
        private void SetSelectNodeShowData()
        {
            if (selectNode == null || string.IsNullOrEmpty(projectFilePath))
            {
                return;
            }
            string id = selectNode.Name;

            FlowLayoutPanel_Other.Controls.Clear();

            IEnumerable <TabPage> allTabPage = TabControl_Setting.TabPages.OfType <TabPage>();

            EnumTypeComboBox[] enumTypeComboBoxs = allTabPage.Select(temp => temp.Controls.OfType <EnumTypeComboBox>()).Combine().ToArray();
            foreach (EnumTypeComboBox enumTypeComboBox in enumTypeComboBoxs)
            {
                enumTypeComboBox.InitListenControl();
                string fieldName = (string)enumTypeComboBox.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    enumTypeComboBox.TextValue = skillAnalysisData.GetValue <string>(id, fieldName);
                }
            }
            TextBox[] textBoxs = allTabPage.Select(temp => temp.Controls.OfType <TextBox>()).Combine().ToArray();
            foreach (TextBox textBox in textBoxs)
            {
                string fieldName = (string)textBox.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    textBox.Text = skillAnalysisData.GetValue <string>(id, fieldName);
                }
            }
            AutoArrayControl[] autoArrayControls = allTabPage.Select(temp => temp.Controls.OfType <AutoArrayControl>()).Combine().ToArray();
            foreach (AutoArrayControl autoArrayControl in autoArrayControls)
            {
                string fieldName = (string)autoArrayControl.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    string[] getValues = skillAnalysisData.GetValues <string>(id, fieldName);
                    string[] nowValues = autoArrayControl.TextValues;
                    int      index     = 0;
                    while (index < getValues.Length && index < nowValues.Length)
                    {
                        nowValues[index] = getValues[index];
                        index++;
                    }
                    autoArrayControl.TextValues = nowValues;
                }
            }
            TypeTextBox[] typeTextBoxs = allTabPage.Select(temp => temp.Controls.OfType <TypeTextBox>()).Combine().ToArray();
            foreach (TypeTextBox typeTextBox in typeTextBoxs)
            {
                string fieldName = (string)typeTextBox.Tag;
                if (!string.IsNullOrEmpty(fieldName))
                {
                    typeTextBox.TextValue = skillAnalysisData.GetValue <string>(id, fieldName);
                }
            }
            AutoItemControl[] autoItemControls = allTabPage.Select(temp => temp.Controls.OfType <AutoItemControl>()).Combine().ToArray();
            foreach (AutoItemControl autoItemControl in autoItemControls)
            {
                autoItemControl.UpdateItems();
            }
            //处理技能属性(根据等级附加属性)
            AutoItemControl[] attributeSkillLevelControls = FlowLayoutPanel_Attribute.Controls.OfType <AutoItemControl>().ToArray();
            foreach (AutoItemControl attributeSkillLevelControl in attributeSkillLevelControls)
            {
                attributeSkillLevelControl.SkillAnalysisData = skillAnalysisData;
                attributeSkillLevelControl.Tag = id;
                attributeSkillLevelControl.UpdateItems(true);
            }
            //处理其他属性
            string[] oldOtherSettings = skillAnalysisData.GetValues <string>(id, "OtherFieldSet");
            string[] otherSplit       = new string[] { "***" };
            ComboBox_Other_Item.Items.Clear();
            Func <string, string> JCFZFunc = (target) => //解除封装
            {
                if (target.Length < 2)
                {
                    return("");
                }
                target = target.Remove(0, 1);
                target = target.Remove(target.Length - 1, 1);
                return(target);
            };

            foreach (string oldOtherSetting in oldOtherSettings)
            {
                string[] otherFieldSets = oldOtherSetting.Split(otherSplit, StringSplitOptions.RemoveEmptyEntries);
                if (otherFieldSets.Length == 7)
                {
                    AutoItemControl autoItemContorl = new AutoItemControl();
                    autoItemContorl.SkillAnalysisData = skillAnalysisData;
                    autoItemContorl.Tag = id;
                    AutoItemControl.ItemStruct itemStruct = autoItemContorl.CreateItem();
                    itemStruct.Label = JCFZFunc(otherFieldSets[0]);
                    itemStruct.Tag   = JCFZFunc(otherFieldSets[1]);
                    Type controlType = null;
                    try { controlType = Type.GetType(JCFZFunc(otherFieldSets[2])); } catch { }
                    itemStruct.ControlType = controlType;
                    itemStruct.TypeTag     = JCFZFunc(otherFieldSets[3]);
                    bool isArray = false;
                    try { isArray = bool.Parse(JCFZFunc(otherFieldSets[4])); } catch { }
                    itemStruct.IsArray = isArray;
                    int childCount = 0;
                    try { childCount = int.Parse(JCFZFunc(otherFieldSets[5])); } catch { }
                    itemStruct.ChildCount       = childCount;
                    itemStruct.ChildControlType = JCFZFunc(otherFieldSets[6]);

                    autoItemContorl.Size = new Size(Panel_Other.Size.Width / 2 - 7, Panel_Other.Size.Height / 3);
                    FlowLayoutPanel_Other.Controls.Add(autoItemContorl);
                    autoItemContorl.UpdateItems(true);
                    autoItemContorl.IsChangedValue = false;

                    ComboBox_Other_Item.Items.Add(itemStruct.Tag);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 添加一个Item到Other选项卡
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Other_Add_Click(object sender, EventArgs e)
        {
            if (selectNode == null || string.IsNullOrEmpty(projectFilePath))
            {
                return;
            }

            AddOtherAttributeForm addOtherAttributeForm = new AddOtherAttributeForm();
            DialogResult          dr = addOtherAttributeForm.ShowDialog();

            if (dr == DialogResult.OK)
            {
                AutoItemControl autoItemContorl = new AutoItemControl();
                autoItemContorl.SkillAnalysisData = skillAnalysisData;
                TreeNode selectNode = TreeView_Skills.SelectedNode;
                if (selectNode != null)
                {
                    try
                    {
                        string[] values = selectNode.Tag as string[];
                        autoItemContorl.Tag = values[0];
                    }
                    catch { }
                }
                AutoItemControl.ItemStruct itemStruct = autoItemContorl.CreateItem();
                itemStruct.Label            = addOtherAttributeForm.attributeItemStruct.Label;
                itemStruct.Tag              = addOtherAttributeForm.attributeItemStruct.Tag;
                itemStruct.ControlType      = addOtherAttributeForm.attributeItemStruct.ControlType;
                itemStruct.TypeTag          = addOtherAttributeForm.attributeItemStruct.TypeTag;
                itemStruct.IsArray          = addOtherAttributeForm.attributeItemStruct.IsArray;
                itemStruct.ChildCount       = addOtherAttributeForm.attributeItemStruct.ChildCount;
                itemStruct.ChildControlType = addOtherAttributeForm.attributeItemStruct.ChildControlType;
                autoItemContorl.Size        = new Size(Panel_Other.Size.Width / 2 - 7, Panel_Other.Size.Height / 3);
                FlowLayoutPanel_Other.Controls.Add(autoItemContorl);
                autoItemContorl.UpdateItems();
                autoItemContorl.IsChangedValue = true;
                if (skillAnalysisData != null && selectNode != null)//将本次设置的内容保存到OtherFieldSet字段中
                {
                    string[] tagValues = selectNode.Tag as string[];
                    if (tagValues != null && tagValues.Length > 0)
                    {
                        string[] oldOtherSettings = skillAnalysisData.GetValues <string>(tagValues[0], "OtherFieldSet");
                        if (oldOtherSettings == null)
                        {
                            oldOtherSettings = new string[0];
                        }
                        string[] newOtherSettings = new string[oldOtherSettings.Length + 1];
                        Array.Copy(oldOtherSettings, newOtherSettings, oldOtherSettings.Length);
                        string split = "***";
                        Func <object, string> FZFunc = (target) =>//封装[]
                        {
                            if (target == null)
                            {
                                return("[]");
                            }
                            if (object.Equals(target.GetType(), typeof(Type)))
                            {
                                Type t = target as Type;
                                return("[" + t.FullName + "]");
                            }
                            return("[" + target.ToString() + "]");
                        };
                        string otherFieldSet =
                            FZFunc(itemStruct.Label) + split +
                            FZFunc(itemStruct.Tag) + split +
                            FZFunc(itemStruct.ControlType) + split +
                            FZFunc(itemStruct.TypeTag) + split +
                            FZFunc(itemStruct.IsArray) + split +
                            FZFunc(itemStruct.ChildCount) + split +
                            FZFunc(itemStruct.ChildControlType);
                        newOtherSettings[newOtherSettings.Length - 1] = otherFieldSet;
                        skillAnalysisData.SetValues <string>(tagValues[0], "OtherFieldSet", newOtherSettings);
                    }
                }
                //添加到下拉列表中
                ComboBox_Other_Item.Items.Add(itemStruct.Tag);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 初始化技能属性面板
        /// </summary>
        void InitSkillAttributePanel()
        {
            List <AutoItemControl.ItemStruct> skillAttributeItemStructs = new List <AutoItemControl.ItemStruct>();
            string exePath              = Process.GetCurrentProcess().MainModule.FileName;
            string directoryPath        = Path.GetDirectoryName(exePath);
            string attributeSettingPath = directoryPath + "\\SkillAttribute.Setting";

            if (File.Exists(attributeSettingPath))
            {
                using (StreamReader sr = new StreamReader(attributeSettingPath, Encoding.UTF8))
                {
                    string   readLine   = null;
                    string[] itemsSplit = new string[] { "^^^" };
                    string[] valueSplit = new string[] { ":::" };
                    while ((readLine = sr.ReadLine()) != null)
                    {
                        string[] Items = readLine.Split(itemsSplit, StringSplitOptions.RemoveEmptyEntries);
                        if (Items.Length == 7)
                        {
                            AutoItemControl.ItemStruct skillAttributeItemStruct = new AutoItemControl.ItemStruct();
                            foreach (string item in Items)
                            {
                                string[] values = item.Split(valueSplit, StringSplitOptions.RemoveEmptyEntries);
                                if (values.Length != 2)
                                {
                                    string[] tempValues = new string[2];
                                    for (int i = 0; i < 2; i++)
                                    {
                                        tempValues[i] = "";
                                    }
                                    int index = 0;
                                    while (index < tempValues.Length && index < values.Length)
                                    {
                                        tempValues[index] = values[index];
                                        index++;
                                    }
                                }
                                switch (values[0].Trim())
                                {
                                case "Label":
                                    skillAttributeItemStruct.Label = values[1].Trim();
                                    break;

                                case "Tag":
                                    skillAttributeItemStruct.Tag = values[1].Trim();
                                    break;

                                case "TypeTag":
                                    skillAttributeItemStruct.TypeTag = values[1].Trim();
                                    break;

                                case "ControlType":
                                    try { skillAttributeItemStruct.ControlType = Type.GetType(values[1].Trim()); } catch { }
                                    break;

                                case "IsArray":
                                    try { skillAttributeItemStruct.IsArray = bool.Parse(values[1].Trim()); } catch { }
                                    break;

                                case "ChildControlType":
                                    skillAttributeItemStruct.ChildControlType = values[1].Trim();
                                    break;

                                case "ChildCount":
                                    try { skillAttributeItemStruct.ChildCount = int.Parse(values[1].Trim()); } catch { }
                                    break;
                                }
                            }
                            skillAttributeItemStructs.Add(skillAttributeItemStruct);
                        }
                    }
                }
            }

            FlowLayoutPanel_Attribute.Controls.Clear();
            //在技能属性(根据技能等级设置属性)面板添加控件
            Func <AutoItemControl.ItemStruct, AutoItemControl> GetAutoItemControl_SkillAttribute = (_itemStruct) =>
            {
                AutoItemControl autoItemControl = new AutoItemControl();
                autoItemControl.SkillAnalysisData = skillAnalysisData;
                autoItemControl.Size   = new Size(Panel_Attribute.Size.Width / 2 - 25, Panel_Attribute.Height / 2);
                autoItemControl.Margin = new Padding(3, 3, 3, 25);
                AutoItemControl.ItemStruct itemStruct = autoItemControl.CreateItem();
                itemStruct.Tag              = _itemStruct.Tag;
                itemStruct.Label            = _itemStruct.Label;
                itemStruct.TypeTag          = _itemStruct.TypeTag;
                itemStruct.ControlType      = _itemStruct.ControlType;
                itemStruct.IsArray          = _itemStruct.IsArray;
                itemStruct.ChildControlType = _itemStruct.ChildControlType;
                itemStruct.ChildCount       = _itemStruct.ChildCount;
                return(autoItemControl);
            };

            Action <AutoItemControl, FlowLayoutPanel> AddItemToPanel = (autoItemControl, flowLayoutPanel) =>
            {
                flowLayoutPanel.Controls.Add(autoItemControl);
                autoItemControl.UpdateItems();
            };

            foreach (AutoItemControl.ItemStruct itemStruct in skillAttributeItemStructs)
            {
                AddItemToPanel(GetAutoItemControl_SkillAttribute(itemStruct), FlowLayoutPanel_Attribute);
            }
            TreeView_Skills.SelectedNode = selectNode = null;
            attributeTags = skillAttributeItemStructs.Select(temp => temp.Tag).ToArray();
        }