Esempio n. 1
0
        /// <summary>
        /// 从Other选项卡中移除一个Item
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Other_Delete_Click(object sender, EventArgs e)
        {
            if (selectNode == null || string.IsNullOrEmpty(projectFilePath))
            {
                return;
            }

            int selectIndex = ComboBox_Other_Item.SelectedIndex;

            if (selectIndex < 0)
            {
                return;
            }
            //选择的关联对象
            string selectTag = ComboBox_Other_Item.Items[selectIndex].ToString();

            try
            {
                AutoItemControl autoItemControl = FlowLayoutPanel_Other.Controls.OfType <AutoItemControl>().
                                                  Select(temp => new { control = temp, tag = temp.Items[0].Tag }).
                                                  Where(temp => string.Equals(temp.tag, selectTag)).
                                                  Select(temp => temp.control).FirstOrDefault();
                if (autoItemControl != null)
                {
                    FlowLayoutPanel_Other.Controls.Remove(autoItemControl);
                    ComboBox_Other_Item.Items.RemoveAt(selectIndex);
                    if (selectNode != null)
                    {
                        string[] selectNodeValues = selectNode.Tag as string[];
                        if (selectNodeValues != null && selectNodeValues.Length > 0)
                        {
                            skillAnalysisData.RemoveValue(selectNodeValues[0], selectTag);
                        }
                        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];
                                }
                                List <string>         newOtherSettings = new List <string>();
                                string[]              split            = new string[] { "***" };
                                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(split, StringSplitOptions.RemoveEmptyEntries);
                                    if (otherFieldSets.Length == 7)
                                    {
                                        string thisID = JCFZFunc(otherFieldSets[1]);
                                        if (!string.Equals(thisID, selectTag))
                                        {
                                            newOtherSettings.Add(oldOtherSetting);
                                        }
                                    }
                                }
                                skillAnalysisData.SetValues <string>(tagValues[0], "OtherFieldSet", newOtherSettings.ToArray());
                            }
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("移除失败");
            }
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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();
        }