Ejemplo n.º 1
0
        private void btnExotic_Click(object sender, EventArgs e)
        {
            XmlDocument          xmlSkillsDocument  = XmlManager.Load("skills.xml");
            frmSelectExoticSkill frmPickExoticSkill = new frmSelectExoticSkill(_objCharacter);

            frmPickExoticSkill.ShowDialog(this);

            if (frmPickExoticSkill.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            XmlNode xmlSkillNode = xmlSkillsDocument.SelectSingleNode("/chummer/skills/skill[name = \"" + frmPickExoticSkill.SelectedExoticSkill + "\"]");

            ExoticSkill objSkill = new ExoticSkill(_objCharacter, xmlSkillNode)
            {
                Specific = frmPickExoticSkill.SelectedExoticSkillSpecialisation
            };

            // Karma check needs to come after the skill is created to make sure bonus-based modifiers (e.g. JoAT) get applied properly (since they can potentially trigger off of the specific exotic skill target)
            if (_objCharacter.Created && objSkill.UpgradeKarmaCost > _objCharacter.Karma)
            {
                MessageBox.Show(LanguageManager.GetString("Message_NotEnoughKarma", GlobalOptions.Language));
                return;
            }
            objSkill.Upgrade();
            _objCharacter.SkillsSection.Skills.Add(objSkill);
            string key = objSkill.Name + " (" + objSkill.DisplaySpecializationMethod(GlobalOptions.DefaultLanguage) +
                         ')';

            if (!_objCharacter.SkillsSection.SkillsDictionary.ContainsKey(key))
            {
                _objCharacter.SkillsSection.SkillsDictionary.Add(key, objSkill);
            }
        }
Ejemplo n.º 2
0
        private void btnExotic_Click(object sender, EventArgs e)
        {
            if (_character.Options.KarmaNewActiveSkill > _character.Karma && _character.Created)
            {
                MessageBox.Show(LanguageManager.GetString("Message_NotEnoughKarma", GlobalOptions.Language));
                return;
            }


            XmlDocument          document           = XmlManager.Load("skills.xml");
            frmSelectExoticSkill frmPickExoticSkill = new frmSelectExoticSkill(_character);

            frmPickExoticSkill.ShowDialog(this);

            if (frmPickExoticSkill.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            XmlNode node = document.SelectSingleNode("/chummer/skills/skill[name = \"" + frmPickExoticSkill.SelectedExoticSkill + "\"]");

            ExoticSkill skill = new ExoticSkill(ObjCharacter, node)
            {
                Specific = frmPickExoticSkill.SelectedExoticSkillSpecialisation
            };

            skill.Upgrade();
            ObjCharacter.SkillsSection.Skills.Add(skill);
            ObjCharacter.SkillsSection.SkillsDictionary.Add(skill.Name + " (" + skill.DisplaySpecializationMethod(GlobalOptions.DefaultLanguage) + ')', skill);
        }
Ejemplo n.º 3
0
        private void btnExotic_Click(object sender, EventArgs e)
        {
            ExoticSkill objSkill;
            XmlDocument xmlSkillsDocument = _objCharacter.LoadData("skills.xml");

            using (frmSelectExoticSkill frmPickExoticSkill = new frmSelectExoticSkill(_objCharacter))
            {
                frmPickExoticSkill.ShowDialog(this);

                if (frmPickExoticSkill.DialogResult == DialogResult.Cancel)
                {
                    return;
                }

                XmlNode xmlSkillNode = xmlSkillsDocument.SelectSingleNode("/chummer/skills/skill[name = " + frmPickExoticSkill.SelectedExoticSkill.CleanXPath() + "]");

                objSkill = new ExoticSkill(_objCharacter, xmlSkillNode)
                {
                    Specific = frmPickExoticSkill.SelectedExoticSkillSpecialisation
                };
            }

            // Karma check needs to come after the skill is created to make sure bonus-based modifiers (e.g. JoAT) get applied properly (since they can potentially trigger off of the specific exotic skill target)
            if (_objCharacter.Created && objSkill.UpgradeKarmaCost > _objCharacter.Karma)
            {
                Program.MainForm.ShowMessageBox(LanguageManager.GetString("Message_NotEnoughKarma"));
                return;
            }
            objSkill.Upgrade();
            _objCharacter.SkillsSection.Skills.Add(objSkill);
        }
Ejemplo n.º 4
0
        private void frmSelectSkill_Load(object sender, EventArgs e)
        {
            List <ListItem> lstSkills = new List <ListItem>();
            // Build the list of non-Exotic Skills from the Skills file.
            XmlNodeList objXmlSkillList;

            if (!string.IsNullOrEmpty(_strForceSkill))
            {
                objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[name = \"" + _strForceSkill + "\" and not(exotic) and (" + _objCharacter.Options.BookXPath() + ")]");
            }
            else if (!string.IsNullOrEmpty(_strLimitToCategories))
            {
                objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[" + _strLimitToCategories + " and (" + _objCharacter.Options.BookXPath() + ")]");
            }
            else
            {
                string strFilter = "not(exotic)";
                if (!string.IsNullOrEmpty(_strIncludeCategory))
                {
                    strFilter += " and (";
                    foreach (string strSkillCategory in _strIncludeCategory.SplitNoAlloc(',', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strFilter += "category = \"" + strSkillCategory.Trim() + "\" or ";
                    }
                    // Remove the trailing " or ".
                    strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                    strFilter += ')';
                }
                if (!string.IsNullOrEmpty(_strExcludeCategory))
                {
                    strFilter += " and (";
                    foreach (string strSkillCategory in _strExcludeCategory.SplitNoAlloc(',', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strFilter += "category != \"" + strSkillCategory.Trim() + "\" and ";
                    }
                    // Remove the trailing " and ".
                    strFilter  = strFilter.Substring(0, strFilter.Length - 5);
                    strFilter += ')';
                }
                if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                {
                    strFilter += " and (";
                    foreach (string strSkillGroup in _strIncludeSkillGroup.SplitNoAlloc(',', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strFilter += "skillgroup = \"" + strSkillGroup.Trim() + "\" or ";
                    }
                    // Remove the trailing " or ".
                    strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                    strFilter += ')';
                }
                if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                {
                    strFilter += " and (";
                    foreach (string strSkillGroup in _strExcludeSkillGroup.SplitNoAlloc(',', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strFilter += "skillgroup != \"" + strSkillGroup.Trim() + "\" and ";
                    }
                    // Remove the trailing " and ".
                    strFilter  = strFilter.Substring(0, strFilter.Length - 5);
                    strFilter += ')';
                }
                if (!string.IsNullOrEmpty(LinkedAttribute))
                {
                    strFilter += " and (";
                    foreach (string strAttribute in LinkedAttribute.SplitNoAlloc(',', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strFilter += "attribute = \"" + strAttribute.Trim() + "\" or ";
                    }
                    // Remove the trailing " or ".
                    strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                    strFilter += ')';
                }
                if (!string.IsNullOrEmpty(_strLimitToSkill))
                {
                    strFilter += " and (";
                    foreach (string strSkill in _strLimitToSkill.SplitNoAlloc(',', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strFilter += "name = \"" + strSkill.Trim() + "\" or ";
                    }
                    // Remove the trailing " or ".
                    strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                    strFilter += ')';
                }
                if (!string.IsNullOrEmpty(_strExcludeSkill))
                {
                    strFilter += " and (";
                    foreach (string strSkill in _strExcludeSkill.SplitNoAlloc(',', StringSplitOptions.RemoveEmptyEntries))
                    {
                        strFilter += "name != \"" + strSkill.Trim() + "\" and ";
                    }
                    // Remove the trailing " or ".
                    strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                    strFilter += ')';
                }
                objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[" + strFilter + " and (" + _objCharacter.Options.BookXPath() + ")]");
            }

            // Add the Skills to the list.
            if (objXmlSkillList?.Count > 0)
            {
                foreach (XmlNode objXmlSkill in objXmlSkillList)
                {
                    string strXmlSkillName  = objXmlSkill["name"]?.InnerText;
                    Skill  objExistingSkill = _objCharacter.SkillsSection.GetActiveSkill(strXmlSkillName);
                    if (objExistingSkill == null)
                    {
                        if (_intMinimumRating > 0)
                        {
                            continue;
                        }
                    }
                    else if (objExistingSkill.Rating < _intMinimumRating || objExistingSkill.Rating > _intMaximumRating)
                    {
                        continue;
                    }

                    lstSkills.Add(new ListItem(strXmlSkillName, objXmlSkill["translate"]?.InnerText ?? strXmlSkillName));
                }
            }

            // Add in any Exotic Skills the character has.
            foreach (Skill objSkill in _objCharacter.SkillsSection.Skills)
            {
                if (objSkill.IsExoticSkill)
                {
                    ExoticSkill objExoticSkill = objSkill as ExoticSkill;
                    bool        blnAddSkill    = true;
                    if (objSkill.Rating < _intMinimumRating || objSkill.Rating > _intMaximumRating)
                    {
                        blnAddSkill = false;
                    }
                    else if (!string.IsNullOrEmpty(_strForceSkill))
                    {
                        blnAddSkill = _strForceSkill == objExoticSkill.Name + " (" + objExoticSkill.Specific + ')';
                    }
                    else if (!string.IsNullOrEmpty(_strIncludeCategory))
                    {
                        blnAddSkill = _strIncludeCategory.Contains(objExoticSkill.SkillCategory);
                    }
                    else if (!string.IsNullOrEmpty(_strExcludeCategory))
                    {
                        blnAddSkill = !_strExcludeCategory.Contains(objExoticSkill.SkillCategory);
                    }
                    else if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                    {
                        blnAddSkill = _strIncludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                    }
                    else if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                    {
                        blnAddSkill = !_strExcludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                    }
                    else if (!string.IsNullOrEmpty(_strLimitToSkill))
                    {
                        blnAddSkill = _strLimitToSkill.Contains(objExoticSkill.Name);
                    }
                    else if (!string.IsNullOrEmpty(_strExcludeSkill))
                    {
                        blnAddSkill = !_strExcludeSkill.Contains(objExoticSkill.Name);
                    }

                    if (blnAddSkill)
                    {
                        // Use the translated Exotic Skill name if available.
                        XmlNode objXmlSkill = _objXmlDocument.SelectSingleNode("/chummer/skills/skill[exotic = \"True\" and name = \"" + objExoticSkill.Name + "\"]");
                        lstSkills.Add(new ListItem(objExoticSkill.Name + " (" + objExoticSkill.Specific + ')',
                                                   (objXmlSkill["translate"]?.InnerText ?? objExoticSkill.Name) + LanguageManager.GetString("String_Space") + '(' + objExoticSkill.CurrentDisplaySpecialization + ')'));
                    }
                }
            }

            if (lstSkills.Count <= 0)
            {
                Program.MainForm.ShowMessageBox(this, string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Message_Improvement_EmptySelectionListNamed"), _strSourceName));
                DialogResult = DialogResult.Cancel;
                return;
            }

            lstSkills.Sort(CompareListItems.CompareNames);
            cboSkill.BeginUpdate();
            cboSkill.ValueMember   = nameof(ListItem.Value);
            cboSkill.DisplayMember = nameof(ListItem.Name);
            cboSkill.DataSource    = lstSkills;

            // Select the first Skill in the list.
            cboSkill.SelectedIndex = 0;
            cboSkill.EndUpdate();

            if (cboSkill.Items.Count == 1)
            {
                cmdOK_Click(sender, e);
            }
        }
Ejemplo n.º 5
0
        private void frmSelectSkill_Load(object sender, EventArgs e)
        {
            List <ListItem> lstSkills = new List <ListItem>();

            if (!_blnKnowledgeSkill)
            {
                _objXmlDocument = XmlManager.Instance.Load("skills.xml");

                // Build the list of non-Exotic Skills from the Skills file.
                XmlNodeList objXmlSkillList;
                if (!string.IsNullOrEmpty(_strForceSkill))
                {
                    objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[name = \"" + _strForceSkill + "\" and not(exotic)]");
                }
                else
                {
                    if (!string.IsNullOrEmpty(_strIncludeCategory))
                    {
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[category = \"" + _strIncludeCategory + "\" and not(exotic)]");
                    }
                    else if (!string.IsNullOrEmpty(_strLimitToCategories))
                    {
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[category = " + _strLimitToCategories + "]");
                    }
                    else if (!string.IsNullOrEmpty(_strExcludeCategory))
                    {
                        string[] strExcludes = _strExcludeCategory.Split(',');
                        string   strExclude  = string.Empty;
                        for (int i = 0; i <= strExcludes.Length - 1; i++)
                        {
                            strExclude += "category != \"" + strExcludes[i].Trim() + "\" and ";
                        }
                        // Remove the trailing " and ";
                        strExclude      = strExclude.Substring(0, strExclude.Length - 5);
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[" + strExclude + " and not(exotic)]");
                    }
                    else if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                    {
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[skillgroup = \"" + _strIncludeSkillGroup + "\" and not(exotic)]");
                    }
                    else if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                    {
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[skillgroup != \"" + _strExcludeSkillGroup + "\" and not(exotic)]");
                    }
                    else if (!string.IsNullOrEmpty(LinkedAttribute))
                    {
                        string[] strExcludes = LinkedAttribute.Split(',');
                        string   strExclude  = "not(exotic) and (";
                        for (int i = 0; i <= strExcludes.Length - 1; i++)
                        {
                            strExclude += "attribute = \"" + strExcludes[i].Trim() + "\" or ";
                        }
                        // Remove the trailing " and ";
                        strExclude      = strExclude.Substring(0, strExclude.Length - 4) + ")";
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[" + strExclude + "]");
                    }
                    else if (!string.IsNullOrEmpty(_strLimitToSkill))
                    {
                        string   strFilter = "not(exotic) and (";
                        string[] strValue  = _strLimitToSkill.Split(',');
                        foreach (string strSkill in strValue)
                        {
                            strFilter += "name = \"" + strSkill.Trim() + "\" or ";
                        }
                        // Remove the trailing " or ".
                        strFilter       = strFilter.Substring(0, strFilter.Length - 4);
                        strFilter      += ")";
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[" + strFilter + "]");
                    }
                    else
                    {
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[not(exotic)]");
                    }
                }

                // Add the Skills to the list.
                foreach (XmlNode objXmlSkill in objXmlSkillList)
                {
                    ListItem objItem = new ListItem();
                    objItem.Value = objXmlSkill["name"].InnerText;
                    if (objXmlSkill.Attributes != null)
                    {
                        if (objXmlSkill["translate"] != null)
                        {
                            objItem.Name = objXmlSkill["translate"].InnerText;
                        }
                        else
                        {
                            objItem.Name = objXmlSkill["name"].InnerText;
                        }
                    }
                    else
                    {
                        objItem.Name = objXmlSkill["name"].InnerXml;
                    }
                    lstSkills.Add(objItem);
                }

                // Add in any Exotic Skills the character has.
                foreach (Skill objSkill in _objCharacter.SkillsSection.Skills)
                {
                    if (objSkill.IsExoticSkill)
                    {
                        ExoticSkill objExoticSkill = objSkill as ExoticSkill;
                        bool        blnAddSkill    = true;
                        if (!string.IsNullOrEmpty(_strForceSkill))
                        {
                            blnAddSkill = _strForceSkill == objExoticSkill.Name + " (" + objExoticSkill.Specific + ")";
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(_strIncludeCategory))
                            {
                                blnAddSkill = _strIncludeCategory == objExoticSkill.SkillCategory;
                            }
                            else if (!string.IsNullOrEmpty(_strExcludeCategory))
                            {
                                blnAddSkill = !_strExcludeCategory.Contains(objExoticSkill.SkillCategory);
                            }
                            else if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                            {
                                blnAddSkill = _strIncludeSkillGroup == objExoticSkill.SkillGroup;
                            }
                            else if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                            {
                                blnAddSkill = _strExcludeSkillGroup != objExoticSkill.SkillGroup;
                            }
                            else if (!string.IsNullOrEmpty(_strLimitToSkill))
                            {
                                blnAddSkill = _strLimitToSkill.Contains(objExoticSkill.Name);
                            }
                        }

                        if (blnAddSkill)
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objExoticSkill.Name + " (" + objExoticSkill.Specific + ")";
                            // Use the translated Exotic Skill name if available.
                            XmlNode objXmlSkill =
                                _objXmlDocument.SelectSingleNode("/chummer/skills/skill[exotic = \"Yes\" and name = \"" + objExoticSkill.Name + "\"]");
                            if (objXmlSkill["translate"] != null)
                            {
                                objItem.Name = objXmlSkill["translate"].InnerText + " (" + objExoticSkill.DisplaySpecialization + ")";
                            }
                            else
                            {
                                objItem.Name = objExoticSkill.Name + " (" + objExoticSkill.DisplaySpecialization + ")";
                            }
                            lstSkills.Add(objItem);
                        }
                    }
                }
            }
            else
            {
                // Instead of showing all available Active Skills, show a list of Knowledge Skills that the character currently has.
                foreach (KnowledgeSkill objKnow in _objCharacter.SkillsSection.KnowledgeSkills)
                {
                    ListItem objSkill = new ListItem();
                    objSkill.Value = objKnow.Name;
                    objSkill.Name  = objKnow.DisplayName;
                    lstSkills.Add(objSkill);
                }
            }
            SortListItem objSort = new SortListItem();

            lstSkills.Sort(objSort.Compare);
            cboSkill.BeginUpdate();
            cboSkill.ValueMember   = "Value";
            cboSkill.DisplayMember = "Name";
            cboSkill.DataSource    = lstSkills;

            // Select the first Skill in the list.
            cboSkill.SelectedIndex = 0;
            cboSkill.EndUpdate();

            if (cboSkill.Items.Count == 1)
            {
                cmdOK_Click(sender, e);
            }
        }
Ejemplo n.º 6
0
        private void frmSelectSkill_Load(object sender, EventArgs e)
        {
            List <ListItem> lstSkills = new List <ListItem>();

            if (!_blnKnowledgeSkill)
            {
                // Build the list of non-Exotic Skills from the Skills file.
                XmlNodeList objXmlSkillList;
                if (!string.IsNullOrEmpty(_strForceSkill))
                {
                    objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[name = \"" + _strForceSkill + "\" and not(exotic) and (" + _objCharacter.Options.BookXPath() + ")]");
                }
                else
                {
                    if (!string.IsNullOrEmpty(_strLimitToCategories))
                    {
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[category = " + _strLimitToCategories + " and (" + _objCharacter.Options.BookXPath() + ")]");
                    }
                    else
                    {
                        string strFilter = "not(exotic)";
                        if (!string.IsNullOrEmpty(_strIncludeCategory))
                        {
                            strFilter += " and (";
                            string[] strValue = _strIncludeCategory.Split(',');
                            foreach (string strSkillCategory in strValue)
                            {
                                strFilter += "category = \"" + strSkillCategory.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ')';
                        }
                        if (!string.IsNullOrEmpty(_strExcludeCategory))
                        {
                            strFilter += " and (";
                            string[] strValue = _strExcludeCategory.Split(',');
                            foreach (string strSkillCategory in strValue)
                            {
                                strFilter += "category != \"" + strSkillCategory.Trim() + "\" and ";
                            }
                            // Remove the trailing " and ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 5);
                            strFilter += ')';
                        }
                        if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                        {
                            strFilter += " and (";
                            string[] strValue = _strIncludeSkillGroup.Split(',');
                            foreach (string strSkillGroup in strValue)
                            {
                                strFilter += "skillgroup = \"" + strSkillGroup.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ')';
                        }
                        if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                        {
                            strFilter += " and (";
                            string[] strValue = _strExcludeSkillGroup.Split(',');
                            foreach (string strSkillGroup in strValue)
                            {
                                strFilter += "skillgroup != \"" + strSkillGroup.Trim() + "\" and ";
                            }
                            // Remove the trailing " and ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 5);
                            strFilter += ')';
                        }
                        if (!string.IsNullOrEmpty(LinkedAttribute))
                        {
                            strFilter += " and (";
                            string[] strValue = LinkedAttribute.Split(',');
                            foreach (string strAttribute in strValue)
                            {
                                strFilter += "attribute = \"" + strAttribute.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ')';
                        }
                        if (!string.IsNullOrEmpty(_strLimitToSkill))
                        {
                            strFilter += " and (";
                            string[] strValue = _strLimitToSkill.Split(',');
                            foreach (string strSkill in strValue)
                            {
                                strFilter += "name = \"" + strSkill.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ')';
                        }
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[" + strFilter + " and (" + _objCharacter.Options.BookXPath() + ")]");
                    }
                }

                // Add the Skills to the list.
                foreach (XmlNode objXmlSkill in objXmlSkillList)
                {
                    string strXmlSkillName  = objXmlSkill["name"].InnerText;
                    Skill  objExistingSkill = _objCharacter.SkillsSection.GetActiveSkill(strXmlSkillName);
                    if (objExistingSkill == null)
                    {
                        if (_intMinimumRating > 0)
                        {
                            continue;
                        }
                    }
                    else if (objExistingSkill.Rating < _intMinimumRating || objExistingSkill.Rating > _intMaximumRating)
                    {
                        continue;
                    }
                    lstSkills.Add(new ListItem(strXmlSkillName, objXmlSkill["translate"]?.InnerText ?? strXmlSkillName));
                }

                // Add in any Exotic Skills the character has.
                foreach (Skill objSkill in _objCharacter.SkillsSection.Skills)
                {
                    if (objSkill.IsExoticSkill)
                    {
                        ExoticSkill objExoticSkill = objSkill as ExoticSkill;
                        bool        blnAddSkill    = true;
                        if (objSkill.Rating < _intMinimumRating || objSkill.Rating > _intMaximumRating)
                        {
                            blnAddSkill = false;
                        }
                        else if (!string.IsNullOrEmpty(_strForceSkill))
                        {
                            blnAddSkill = _strForceSkill == objExoticSkill.Name + " (" + objExoticSkill.Specific + ')';
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(_strIncludeCategory))
                            {
                                blnAddSkill = _strIncludeCategory.Contains(objExoticSkill.SkillCategory);
                            }
                            else if (!string.IsNullOrEmpty(_strExcludeCategory))
                            {
                                blnAddSkill = !_strExcludeCategory.Contains(objExoticSkill.SkillCategory);
                            }
                            else if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                            {
                                blnAddSkill = _strIncludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                            }
                            else if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                            {
                                blnAddSkill = !_strExcludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                            }
                            else if (!string.IsNullOrEmpty(_strLimitToSkill))
                            {
                                blnAddSkill = _strLimitToSkill.Contains(objExoticSkill.Name);
                            }
                        }

                        if (blnAddSkill)
                        {
                            // Use the translated Exotic Skill name if available.
                            XmlNode objXmlSkill = _objXmlDocument.SelectSingleNode("/chummer/skills/skill[exotic = \"True\" and name = \"" + objExoticSkill.Name + "\"]");
                            lstSkills.Add(new ListItem(objExoticSkill.Name + " (" + objExoticSkill.Specific + ')',
                                                       (objXmlSkill["translate"]?.InnerText ?? objExoticSkill.Name) + " (" + objExoticSkill.DisplaySpecializationMethod(GlobalOptions.Language) + ')'));
                        }
                    }
                }
            }
            else
            {
                //TODO: This is less robust than it should be. Should be refactored to support the rest of the entries.
                if (!string.IsNullOrWhiteSpace(_strLimitToSkill))
                {
                    string   strFilter = string.Empty;
                    string[] strValue  = _strLimitToSkill.Split(',');
                    for (int i = 0; i < strValue.Length; i++)
                    {
                        strValue[i] = strValue[i].Trim();
                    }
                    Dictionary <string, bool> dicSkillXmlFound = new Dictionary <string, bool>(strValue.Length);
                    foreach (string strLoop in strValue)
                    {
                        // We only care about looking for skills if we're looking for a minimum or maximum rating.
                        if (_intMinimumRating > 0)
                        {
                            if (!_objCharacter.SkillsSection.KnowledgeSkills.Any(objSkill =>
                                                                                 objSkill.Name == strLoop && objSkill.Rating >= _intMinimumRating))
                            {
                                continue;
                            }
                        }

                        if (_objCharacter.SkillsSection.KnowledgeSkills.Any(objSkill => objSkill.Name == strLoop && objSkill.Rating > _intMaximumRating))
                        {
                            continue;
                        }
                        dicSkillXmlFound.Add(strLoop, false);
                        strFilter += "name = \"" + strLoop + "\" or ";
                    }
                    // Remove the trailing " or ".
                    strFilter = strFilter.Substring(0, strFilter.Length - 4);
                    XmlNodeList objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/knowledgeskills/skill[" + strFilter + "]");

                    // Add the Skills to the list.
                    foreach (XmlNode objXmlSkill in objXmlSkillList)
                    {
                        string strXmlSkillName = objXmlSkill["name"].InnerText;
                        dicSkillXmlFound[strXmlSkillName] = true;
                        lstSkills.Add(new ListItem(strXmlSkillName, objXmlSkill["translate"]?.InnerText ?? strXmlSkillName));
                    }
                    foreach (KeyValuePair <string, bool> objLoopEntry in dicSkillXmlFound)
                    {
                        if (!objLoopEntry.Value)
                        {
                            lstSkills.Add(new ListItem(objLoopEntry.Key, objLoopEntry.Key));
                        }
                    }
                }
                else
                {
                    // Instead of showing all available Active Skills, show a list of Knowledge Skills that the character currently has.
                    foreach (KnowledgeSkill objKnow in _objCharacter.SkillsSection.KnowledgeSkills)
                    {
                        if (objKnow.Rating >= _intMinimumRating && objKnow.Rating < _intMaximumRating)
                        {
                            lstSkills.Add(new ListItem(objKnow.Name, objKnow.DisplayNameMethod(GlobalOptions.Language)));
                        }
                    }
                }
            }
            if (lstSkills.Count <= 0)
            {
                MessageBox.Show(LanguageManager.GetString("Message_Improvement_EmptySelectionListNamed", GlobalOptions.Language).Replace("{0}", _strSourceName));
                DialogResult = DialogResult.Cancel;
                return;
            }

            lstSkills.Sort(CompareListItems.CompareNames);
            cboSkill.BeginUpdate();
            cboSkill.ValueMember   = "Value";
            cboSkill.DisplayMember = "Name";
            cboSkill.DataSource    = lstSkills;

            // Select the first Skill in the list.
            cboSkill.SelectedIndex = 0;
            cboSkill.EndUpdate();

            if (cboSkill.Items.Count == 1)
            {
                cmdOK_Click(sender, e);
            }
        }
Ejemplo n.º 7
0
        private void frmSelectSkill_Load(object sender, EventArgs e)
        {
            List <ListItem> lstSkills = new List <ListItem>();

            if (!_blnKnowledgeSkill)
            {
                _objXmlDocument = XmlManager.Instance.Load("skills.xml");
                // Build the list of non-Exotic Skills from the Skills file.
                XmlNodeList objXmlSkillList;
                if (!string.IsNullOrEmpty(_strForceSkill))
                {
                    objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[name = \"" + _strForceSkill + "\" and not(exotic)]");
                }
                else
                {
                    if (!string.IsNullOrEmpty(_strLimitToCategories))
                    {
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[category = " + _strLimitToCategories + "]");
                    }
                    else
                    {
                        string strFilter = "not(exotic)";
                        if (!string.IsNullOrEmpty(_strIncludeCategory))
                        {
                            strFilter += " and (";
                            string[] strValue = _strIncludeCategory.Split(',');
                            foreach (string strSkillCategory in strValue)
                            {
                                strFilter += "category = \"" + strSkillCategory.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ")";
                        }
                        if (!string.IsNullOrEmpty(_strExcludeCategory))
                        {
                            strFilter += " and (";
                            string[] strValue = _strExcludeCategory.Split(',');
                            foreach (string strSkillCategory in strValue)
                            {
                                strFilter += "category != \"" + strSkillCategory.Trim() + "\" and ";
                            }
                            // Remove the trailing " and ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 5);
                            strFilter += ")";
                        }
                        if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                        {
                            strFilter += " and (";
                            string[] strValue = _strIncludeSkillGroup.Split(',');
                            foreach (string strSkillGroup in strValue)
                            {
                                strFilter += "skillgroup = \"" + strSkillGroup.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ")";
                        }
                        if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                        {
                            strFilter += " and (";
                            string[] strValue = _strExcludeSkillGroup.Split(',');
                            foreach (string strSkillGroup in strValue)
                            {
                                strFilter += "skillgroup != \"" + strSkillGroup.Trim() + "\" and ";
                            }
                            // Remove the trailing " and ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 5);
                            strFilter += ")";
                        }
                        if (!string.IsNullOrEmpty(LinkedAttribute))
                        {
                            strFilter += " and (";
                            string[] strValue = LinkedAttribute.Split(',');
                            foreach (string strAttribute in strValue)
                            {
                                strFilter += "attribute = \"" + strAttribute.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ")";
                        }
                        if (!string.IsNullOrEmpty(_strLimitToSkill))
                        {
                            strFilter += " and (";
                            string[] strValue = _strLimitToSkill.Split(',');
                            foreach (string strSkill in strValue)
                            {
                                strFilter += "name = \"" + strSkill.Trim() + "\" or ";
                            }
                            // Remove the trailing " or ".
                            strFilter  = strFilter.Substring(0, strFilter.Length - 4);
                            strFilter += ")";
                        }
                        objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/skills/skill[" + strFilter + "]");
                    }
                }

                // Add the Skills to the list.
                foreach (XmlNode objXmlSkill in objXmlSkillList)
                {
                    string strXmlSkillName = objXmlSkill["name"].InnerText;
                    if (_blnRequireExistingNonzeroRating &&
                        !_objCharacter.SkillsSection.Skills.Any(objSkill => objSkill.Name == strXmlSkillName && objSkill.Rating > 0))
                    {
                        continue;
                    }
                    ListItem objItem = new ListItem();
                    objItem.Value = strXmlSkillName;
                    objItem.Name  = objXmlSkill["translate"]?.InnerText ?? strXmlSkillName;
                    lstSkills.Add(objItem);
                }

                // Add in any Exotic Skills the character has.
                foreach (Skill objSkill in _objCharacter.SkillsSection.Skills)
                {
                    if (objSkill.IsExoticSkill)
                    {
                        ExoticSkill objExoticSkill = objSkill as ExoticSkill;
                        bool        blnAddSkill    = true;
                        if (!string.IsNullOrEmpty(_strForceSkill))
                        {
                            blnAddSkill = _strForceSkill == objExoticSkill.Name + " (" + objExoticSkill.Specific + ")";
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(_strIncludeCategory))
                            {
                                blnAddSkill = _strIncludeCategory.Contains(objExoticSkill.SkillCategory);
                            }
                            else if (!string.IsNullOrEmpty(_strExcludeCategory))
                            {
                                blnAddSkill = !_strExcludeCategory.Contains(objExoticSkill.SkillCategory);
                            }
                            else if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                            {
                                blnAddSkill = _strIncludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                            }
                            else if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                            {
                                blnAddSkill = !_strExcludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                            }
                            else if (!string.IsNullOrEmpty(_strLimitToSkill))
                            {
                                blnAddSkill = _strLimitToSkill.Contains(objExoticSkill.Name);
                            }
                        }

                        if (_blnRequireExistingNonzeroRating && objSkill.Rating <= 0)
                        {
                            blnAddSkill = false;
                        }

                        if (blnAddSkill)
                        {
                            ListItem objItem = new ListItem();
                            objItem.Value = objExoticSkill.Name + " (" + objExoticSkill.Specific + ")";
                            // Use the translated Exotic Skill name if available.
                            XmlNode objXmlSkill =
                                _objXmlDocument.SelectSingleNode("/chummer/skills/skill[exotic = \"Yes\" and name = \"" + objExoticSkill.Name + "\"]");
                            objItem.Name = objXmlSkill["translate"] != null
                                ? objXmlSkill["translate"].InnerText + " (" + objExoticSkill.DisplaySpecialization + ")"
                                : objExoticSkill.Name + " (" + objExoticSkill.DisplaySpecialization + ")";
                            lstSkills.Add(objItem);
                        }
                    }
                }
            }
            else
            {
                //TODO: This is less robust than it should be. Should be refactored to support the rest of the entries.
                if (!string.IsNullOrWhiteSpace(_strLimitToSkill))
                {
                    _objXmlDocument = XmlManager.Instance.Load("skills.xml");
                    string   strFilter = string.Empty;
                    string[] strValue  = _strLimitToSkill.Split(',');
                    strFilter = strValue.Aggregate(strFilter, (current, strSkill) => current + "name = \"" + strSkill.Trim() + "\" or ");
                    // Remove the trailing " or ".
                    strFilter = strFilter.Substring(0, strFilter.Length - 4);
                    XmlNodeList objXmlSkillList = _objXmlDocument.SelectNodes("/chummer/knowledgeskills/skill[" + strFilter + "]");

                    // Add the Skills to the list.
                    foreach (XmlNode objXmlSkill in objXmlSkillList)
                    {
                        string strXmlSkillName = objXmlSkill["name"].InnerText;
                        if (_blnRequireExistingNonzeroRating &&
                            !_objCharacter.SkillsSection.KnowledgeSkills.Any(objSkill => objSkill.Name == strXmlSkillName && objSkill.Rating > 0))
                        {
                            continue;
                        }
                        ListItem objItem = new ListItem();
                        objItem.Value = strXmlSkillName;
                        if (objXmlSkill.Attributes != null)
                        {
                            objItem.Name = objXmlSkill["translate"]?.InnerText ?? strXmlSkillName;
                        }
                        else
                        {
                            objItem.Name = strXmlSkillName;
                        }
                        lstSkills.Add(objItem);
                    }
                }
                else
                {
                    // Instead of showing all available Active Skills, show a list of Knowledge Skills that the character currently has.
                    foreach (KnowledgeSkill objKnow in _objCharacter.SkillsSection.KnowledgeSkills)
                    {
                        if (_blnRequireExistingNonzeroRating && objKnow.Rating <= 0)
                        {
                            continue;
                        }
                        ListItem objSkill = new ListItem();
                        objSkill.Value = objKnow.Name;
                        objSkill.Name  = objKnow.DisplayName;
                        lstSkills.Add(objSkill);
                    }
                }
            }
            if (lstSkills.Count <= 0)
            {
                MessageBox.Show(LanguageManager.Instance.GetString("Message_Improvement_EmptySelectionListNamed").Replace("{0}", _strSourceName));
                DialogResult = DialogResult.Cancel;
                return;
            }

            SortListItem objSort = new SortListItem();

            lstSkills.Sort(objSort.Compare);
            cboSkill.BeginUpdate();
            cboSkill.ValueMember   = "Value";
            cboSkill.DisplayMember = "Name";
            cboSkill.DataSource    = lstSkills;

            // Select the first Skill in the list.
            cboSkill.SelectedIndex = 0;
            cboSkill.EndUpdate();

            if (cboSkill.Items.Count == 1)
            {
                cmdOK_Click(sender, e);
            }
        }
Ejemplo n.º 8
0
        private void SelectSkill_Load(object sender, EventArgs e)
        {
            using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool, out List <ListItem> lstSkills))
            {
                // Build the list of non-Exotic Skills from the Skills file.
                XPathNodeIterator objXmlSkillList;
                if (!string.IsNullOrEmpty(_strForceSkill))
                {
                    objXmlSkillList = _objXmlDocument.Select("/chummer/skills/skill[name = "
                                                             + _strForceSkill.CleanXPath() + " and not(exotic) and ("
                                                             + _objCharacter.Settings.BookXPath() + ")]");
                }
                else if (!string.IsNullOrEmpty(_strLimitToCategories))
                {
                    objXmlSkillList = _objXmlDocument.Select("/chummer/skills/skill[" + _strLimitToCategories + " and ("
                                                             + _objCharacter.Settings.BookXPath() + ")]");
                }
                else
                {
                    string strFilter = string.Empty;
                    using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool, out StringBuilder sbdFilter))
                    {
                        sbdFilter.Append("not(exotic) and (").Append(_objCharacter.Settings.BookXPath()).Append(')');
                        if (!string.IsNullOrEmpty(_strIncludeCategory))
                        {
                            sbdFilter.Append(" and (");
                            foreach (string strSkillCategory in _strIncludeCategory.SplitNoAlloc(
                                         ',', StringSplitOptions.RemoveEmptyEntries))
                            {
                                sbdFilter.Append("category = ").Append(strSkillCategory.Trim().CleanXPath())
                                .Append(" or ");
                            }
                            // Remove the trailing " or ".
                            sbdFilter.Length -= 4;
                            sbdFilter.Append(')');
                        }

                        if (!string.IsNullOrEmpty(_strExcludeCategory))
                        {
                            sbdFilter.Append(" and (");
                            foreach (string strSkillCategory in _strExcludeCategory.SplitNoAlloc(
                                         ',', StringSplitOptions.RemoveEmptyEntries))
                            {
                                sbdFilter.Append("category != ").Append(strSkillCategory.Trim().CleanXPath())
                                .Append(" and ");
                            }
                            // Remove the trailing " and ".
                            sbdFilter.Length -= 5;
                            sbdFilter.Append(')');
                        }

                        if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                        {
                            sbdFilter.Append(" and (");
                            foreach (string strSkillGroup in _strIncludeSkillGroup.SplitNoAlloc(
                                         ',', StringSplitOptions.RemoveEmptyEntries))
                            {
                                sbdFilter.Append("skillgroup = ").Append(strSkillGroup.Trim().CleanXPath())
                                .Append(" or ");
                            }
                            // Remove the trailing " or ".
                            sbdFilter.Length -= 4;
                            sbdFilter.Append(')');
                        }

                        if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                        {
                            sbdFilter.Append(" and (");
                            foreach (string strSkillGroup in _strExcludeSkillGroup.SplitNoAlloc(
                                         ',', StringSplitOptions.RemoveEmptyEntries))
                            {
                                sbdFilter.Append("skillgroup != ").Append(strSkillGroup.Trim().CleanXPath())
                                .Append(" and ");
                            }
                            // Remove the trailing " and ".
                            sbdFilter.Length -= 5;
                            sbdFilter.Append(')');
                        }

                        if (!string.IsNullOrEmpty(LinkedAttribute))
                        {
                            sbdFilter.Append(" and (");
                            foreach (string strAttribute in LinkedAttribute.SplitNoAlloc(
                                         ',', StringSplitOptions.RemoveEmptyEntries))
                            {
                                sbdFilter.Append("attribute = ").Append(strAttribute.Trim().CleanXPath())
                                .Append(" or ");
                            }
                            // Remove the trailing " or ".
                            sbdFilter.Length -= 4;
                            sbdFilter.Append(')');
                        }

                        if (!string.IsNullOrEmpty(_strLimitToSkill))
                        {
                            sbdFilter.Append(" and (");
                            foreach (string strSkill in _strLimitToSkill.SplitNoAlloc(
                                         ',', StringSplitOptions.RemoveEmptyEntries))
                            {
                                sbdFilter.Append("name = ").Append(strSkill.Trim().CleanXPath()).Append(" or ");
                            }
                            // Remove the trailing " or ".
                            sbdFilter.Length -= 4;
                            sbdFilter.Append(')');
                        }

                        if (!string.IsNullOrEmpty(_strExcludeSkill))
                        {
                            sbdFilter.Append(" and (");
                            foreach (string strSkill in _strExcludeSkill.SplitNoAlloc(
                                         ',', StringSplitOptions.RemoveEmptyEntries))
                            {
                                sbdFilter.Append("name != ").Append(strSkill.Trim().CleanXPath()).Append(" and ");
                            }
                            // Remove the trailing " and ".
                            sbdFilter.Length -= 5;
                            sbdFilter.Append(')');
                        }

                        if (sbdFilter.Length > 0)
                        {
                            strFilter = '[' + sbdFilter.ToString() + ']';
                        }
                    }

                    objXmlSkillList = _objXmlDocument.Select("/chummer/skills/skill" + strFilter);
                }

                // Add the Skills to the list.
                if (objXmlSkillList.Count > 0)
                {
                    foreach (XPathNavigator objXmlSkill in objXmlSkillList)
                    {
                        string strXmlSkillName  = objXmlSkill.SelectSingleNodeAndCacheExpression("name")?.Value;
                        Skill  objExistingSkill = _objCharacter.SkillsSection.GetActiveSkill(strXmlSkillName);
                        if (objExistingSkill == null)
                        {
                            if (_intMinimumRating > 0)
                            {
                                continue;
                            }
                        }
                        else if (objExistingSkill.Rating < _intMinimumRating ||
                                 objExistingSkill.Rating > _intMaximumRating)
                        {
                            continue;
                        }

                        lstSkills.Add(new ListItem(strXmlSkillName,
                                                   objXmlSkill.SelectSingleNodeAndCacheExpression("translate")?.Value
                                                   ?? strXmlSkillName));
                    }
                }

                // Add in any Exotic Skills the character has.
                foreach (Skill objSkill in _objCharacter.SkillsSection.Skills)
                {
                    if (objSkill.IsExoticSkill)
                    {
                        ExoticSkill objExoticSkill = objSkill as ExoticSkill;
                        bool        blnAddSkill    = true;
                        if (objSkill.Rating < _intMinimumRating || objSkill.Rating > _intMaximumRating)
                        {
                            blnAddSkill = false;
                        }
                        else if (!string.IsNullOrEmpty(_strForceSkill))
                        {
                            blnAddSkill = _strForceSkill == objExoticSkill.DictionaryKey;
                        }
                        else if (!string.IsNullOrEmpty(_strIncludeCategory))
                        {
                            blnAddSkill = _strIncludeCategory.Contains(objExoticSkill.SkillCategory);
                        }
                        else if (!string.IsNullOrEmpty(_strExcludeCategory))
                        {
                            blnAddSkill = !_strExcludeCategory.Contains(objExoticSkill.SkillCategory);
                        }
                        else if (!string.IsNullOrEmpty(_strIncludeSkillGroup))
                        {
                            blnAddSkill = _strIncludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                        }
                        else if (!string.IsNullOrEmpty(_strExcludeSkillGroup))
                        {
                            blnAddSkill = !_strExcludeSkillGroup.Contains(objExoticSkill.SkillGroup);
                        }
                        else if (!string.IsNullOrEmpty(_strLimitToSkill))
                        {
                            blnAddSkill = _strLimitToSkill.Contains(objExoticSkill.Name);
                        }
                        else if (!string.IsNullOrEmpty(_strExcludeSkill))
                        {
                            blnAddSkill = !_strExcludeSkill.Contains(objExoticSkill.Name);
                        }

                        if (blnAddSkill)
                        {
                            // Use the translated Exotic Skill name if available.
                            XPathNavigator objXmlSkill = _objXmlDocument.SelectSingleNode(
                                "/chummer/skills/skill[exotic = " + bool.TrueString.CleanXPath()
                                + " and name = " + objExoticSkill.Name.CleanXPath()
                                + ']');
                            lstSkills.Add(new ListItem(objExoticSkill.DictionaryKey,
                                                       (objXmlSkill.SelectSingleNodeAndCacheExpression("translate")?.Value
                                                        ?? objExoticSkill.CurrentDisplayName)
                                                       + LanguageManager.GetString("String_Space") + '('
                                                       + objExoticSkill.CurrentDisplaySpecialization + ')'));
                        }
                    }
                }

                if (lstSkills.Count == 0)
                {
                    Program.MainForm.ShowMessageBox(
                        this,
                        string.Format(GlobalSettings.CultureInfo,
                                      LanguageManager.GetString("Message_Improvement_EmptySelectionListNamed"),
                                      _strSourceName));
                    DialogResult = DialogResult.Cancel;
                    return;
                }

                lstSkills.Sort(CompareListItems.CompareNames);
                cboSkill.BeginUpdate();
                cboSkill.PopulateWithListItems(lstSkills);
                // Select the first Skill in the list.
                cboSkill.SelectedIndex = 0;
                cboSkill.EndUpdate();
            }

            if (cboSkill.Items.Count == 1)
            {
                cmdOK_Click(sender, e);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns a current language translation given an improvement name.
        /// </summary>
        /// <param name="strImprovementType"> The selector for the target translation. Often just _strSelect. </param>
        /// <param name="strToTranslate"> The string which to translate. Usually name. Guid in the case of adept powers.</param>
        /// <returns></returns>
        private async ValueTask <string> TranslateField(string strImprovementType, string strToTranslate)
        {
            XPathNavigator objXmlNode;

            switch (strImprovementType)
            {
            case "SelectAttribute":
            case "SelectPhysicalAttribute":
            case "SelectMentalAttribute":
            case "SelectSpecialAttribute":
                return(strToTranslate == "MAGAdept"
                    ? await LanguageManager.GetStringAsync("String_AttributeMAGShort") + await LanguageManager.GetStringAsync("String_Space") + '(' + await LanguageManager.GetStringAsync("String_DescAdept") + ')'
                    : await LanguageManager.GetStringAsync("String_Attribute" + strToTranslate + "Short"));

            case "SelectSkill":
                if (ExoticSkill.IsExoticSkillName(strToTranslate))
                {
                    string[] astrToTranslateParts = strToTranslate.Split('(', StringSplitOptions.RemoveEmptyEntries);
                    astrToTranslateParts[0] = astrToTranslateParts[0].Trim();
                    astrToTranslateParts[1] = astrToTranslateParts[1].Substring(0, astrToTranslateParts[1].Length - 1);

                    objXmlNode = (await _objCharacter.LoadDataXPathAsync("skills.xml")).SelectSingleNode("/chummer/skills/skill[name = " + astrToTranslateParts[0].CleanXPath() + ']');
                    string strFirstPartTranslated = objXmlNode?.SelectSingleNodeAndCacheExpression("translate")?.Value ?? objXmlNode?.SelectSingleNode("name")?.Value ?? astrToTranslateParts[0];

                    return(strFirstPartTranslated + await LanguageManager.GetStringAsync("String_Space") + '(' + await _objCharacter.TranslateExtraAsync(astrToTranslateParts[1]) + ')');
                }
                else
                {
                    objXmlNode = (await _objCharacter.LoadDataXPathAsync("skills.xml")).SelectSingleNode("/chummer/skills/skill[name = " + strToTranslate.CleanXPath() + ']');
                    return(objXmlNode?.SelectSingleNodeAndCacheExpression("translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression("name")?.Value ?? strToTranslate);
                }

            case "SelectKnowSkill":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("skills.xml")).SelectSingleNode("/chummer/knowledgeskills/skill[name = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("translate")?.Value ?? objXmlNode?.SelectSingleNode("name")?.Value ?? strToTranslate);

            case "SelectSkillCategory":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("skills.xml")).SelectSingleNode("/chummer/categories/category[. = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("@translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression(".")?.Value ?? strToTranslate);

            case "SelectSkillGroup":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("skills.xml")).SelectSingleNode("/chummer/skillgroups/name[. = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("@translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression(".")?.Value ?? strToTranslate);

            case "SelectWeaponCategory":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("weapons.xml")).SelectSingleNode("/chummer/categories/category[. = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("@translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression(".")?.Value ?? strToTranslate);

            case "SelectSpellCategory":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("spells.xml")).SelectSingleNode("/chummer/categories/category[. = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("@translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression(".")?.Value ?? strToTranslate);

            case "SelectAdeptPower":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("powers.xml")).SelectSingleNode("/chummer/powers/power[id = " + strToTranslate.CleanXPath() + " or name = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression("name")?.Value ?? strToTranslate);

            case "SelectMetamagic":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("metamagic.xml")).SelectSingleNode("/chummer/metamagics/metamagic[name = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression("name")?.Value ?? strToTranslate);

            case "SelectEcho":
                objXmlNode = (await _objCharacter.LoadDataXPathAsync("echoes.xml")).SelectSingleNode("/chummer/echoes/echo[name = " + strToTranslate.CleanXPath() + ']');
                return(objXmlNode?.SelectSingleNodeAndCacheExpression("translate")?.Value ?? objXmlNode?.SelectSingleNodeAndCacheExpression("name")?.Value ?? strToTranslate);

            default:
                return(strToTranslate);
            }
        }