Ejemplo n.º 1
0
        private void btnKnowledge_Click(object sender, EventArgs e)
        {
            if (_character.Created)
            {
                List <ListItem> lstDefaultKnowledgeSkills = KnowledgeSkill.DefaultKnowledgeSkills(GlobalOptions.Language).ToList();
                lstDefaultKnowledgeSkills.Sort(CompareListItems.CompareNames);
                frmSelectItem form = new frmSelectItem
                {
                    Description   = LanguageManager.GetString("Label_Options_NewKnowledgeSkill", GlobalOptions.Language),
                    DropdownItems = lstDefaultKnowledgeSkills
                };

                if (form.ShowDialog() == DialogResult.OK)
                {
                    KnowledgeSkill skill = new KnowledgeSkill(ObjCharacter)
                    {
                        WriteableName = form.SelectedItem
                    };

                    ObjCharacter.SkillsSection.KnowledgeSkills.Add(skill);
                }
            }
            else
            {
                ObjCharacter.SkillsSection.KnowledgeSkills.Add(new KnowledgeSkill(ObjCharacter));
            }
        }
Ejemplo n.º 2
0
        private async void btnKnowledge_Click(object sender, EventArgs e)
        {
            if (_objCharacter.Created)
            {
                string strSelectedSkill;

                string strDescription = await LanguageManager.GetStringAsync("Label_Options_NewKnowledgeSkill");

                using (ThreadSafeForm <SelectItem> form = await ThreadSafeForm <SelectItem> .GetAsync(() => new SelectItem
                {
                    Description = strDescription
                }))
                {
                    form.MyForm.SetDropdownItemsMode(_objCharacter.SkillsSection.MyDefaultKnowledgeSkills);
                    if (await form.ShowDialogSafeAsync(_objCharacter) != DialogResult.OK)
                    {
                        return;
                    }
                    strSelectedSkill = form.MyForm.SelectedItem;
                }

                KnowledgeSkill skill = new KnowledgeSkill(_objCharacter)
                {
                    WritableName = strSelectedSkill
                };

                if (_objCharacter.SkillsSection.HasAvailableNativeLanguageSlots &&
                    (skill.IsLanguage || string.IsNullOrEmpty(skill.Type)))
                {
                    DialogResult eDialogResult = Program.ShowMessageBox(this,
                                                                        string.Format(GlobalSettings.CultureInfo,
                                                                                      await LanguageManager.GetStringAsync("Message_NewNativeLanguageSkill"),
                                                                                      1 + await ImprovementManager.ValueOfAsync(
                                                                                          _objCharacter, Improvement.ImprovementType.NativeLanguageLimit),
                                                                                      skill.WritableName),
                                                                        await LanguageManager.GetStringAsync("Tip_Skill_NativeLanguage"), MessageBoxButtons.YesNoCancel);
                    switch (eDialogResult)
                    {
                    case DialogResult.Cancel:
                        return;

                    case DialogResult.Yes:
                    {
                        if (!skill.IsLanguage)
                        {
                            skill.Type = "Language";
                        }
                        skill.IsNativeLanguage = true;
                        break;
                    }
                    }
                }

                await _objCharacter.SkillsSection.KnowledgeSkills.AddAsync(skill);
            }
            else
            {
                await _objCharacter.SkillsSection.KnowledgeSkills.AddAsync(new KnowledgeSkill(_objCharacter));
            }
        }
Ejemplo n.º 3
0
        private void btnKnowledge_Click(object sender, EventArgs e)
        {
            if (_objCharacter.Created)
            {
                List <ListItem> lstDefaultKnowledgeSkills = KnowledgeSkill.DefaultKnowledgeSkills().ToList();
                lstDefaultKnowledgeSkills.Sort(CompareListItems.CompareNames);
                using (frmSelectItem form = new frmSelectItem
                {
                    Description = LanguageManager.GetString("Label_Options_NewKnowledgeSkill")
                })
                {
                    form.SetDropdownItemsMode(lstDefaultKnowledgeSkills);

                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    KnowledgeSkill skill = new KnowledgeSkill(_objCharacter)
                    {
                        WriteableName = form.SelectedItem
                    };

                    _objCharacter.SkillsSection.KnowledgeSkills.Add(skill);
                }
            }
            else
            {
                _objCharacter.SkillsSection.KnowledgeSkills.Add(new KnowledgeSkill(_objCharacter));
            }
        }
Ejemplo n.º 4
0
        private void btnKnowledge_Click(object sender, EventArgs e)
        {
            if (_character.Created)
            {
                frmSelectItem form = new frmSelectItem
                {
                    Description   = LanguageManager.GetString("Label_Options_NewKnowledgeSkill", GlobalOptions.Language),
                    DropdownItems = KnowledgeSkill.DefaultKnowledgeSkills(GlobalOptions.Language)
                };

                if (form.ShowDialog() == DialogResult.OK)
                {
                    KnowledgeSkill skill = new KnowledgeSkill(ObjCharacter)
                    {
                        WriteableName = form.SelectedItem
                    };
                    skill.LoadDefaultType(skill.Name);


                    ObjCharacter.SkillsSection.KnowledgeSkills.Add(skill);
                }
            }
            else
            {
                ObjCharacter.SkillsSection.KnowledgeSkills.Add(new KnowledgeSkill(ObjCharacter));
            }
        }
Ejemplo n.º 5
0
        private void btnKnowledge_Click(object sender, EventArgs e)
        {
            if (_objCharacter.Created)
            {
                using (frmSelectItem form = new frmSelectItem
                {
                    Description = LanguageManager.GetString("Label_Options_NewKnowledgeSkill")
                })
                {
                    form.SetDropdownItemsMode(KnowledgeSkill.DefaultKnowledgeSkills);

                    if (form.ShowDialog(Program.MainForm) != DialogResult.OK)
                    {
                        return;
                    }
                    KnowledgeSkill skill = new KnowledgeSkill(_objCharacter)
                    {
                        WriteableName = form.SelectedItem
                    };

                    if (_objCharacter.SkillsSection.HasAvailableNativeLanguageSlots && (skill.IsLanguage || string.IsNullOrEmpty(skill.Type)))
                    {
                        DialogResult eDialogResult = Program.MainForm.ShowMessageBox(this,
                                                                                     string.Format(GlobalOptions.CultureInfo, LanguageManager.GetString("Message_NewNativeLanguageSkill"),
                                                                                                   1 + ImprovementManager.ValueOf(_objCharacter, Improvement.ImprovementType.NativeLanguageLimit), skill.WriteableName),
                                                                                     LanguageManager.GetString("Tip_Skill_NativeLanguage"), MessageBoxButtons.YesNoCancel);
                        if (eDialogResult == DialogResult.Cancel)
                        {
                            return;
                        }
                        if (eDialogResult == DialogResult.Yes)
                        {
                            if (!skill.IsLanguage)
                            {
                                skill.Type = "Language";
                            }
                            skill.IsNativeLanguage = true;
                        }
                    }

                    _objCharacter.SkillsSection.KnowledgeSkills.Add(skill);
                }
            }
            else
            {
                _objCharacter.SkillsSection.KnowledgeSkills.Add(new KnowledgeSkill(_objCharacter));
            }
        }
Ejemplo n.º 6
0
        private void btnKnowledge_Click(object sender, EventArgs e)
        {
            if (_character.Created)
            {
                frmSelectItem form = new frmSelectItem();
                form.Description   = LanguageManager.Instance.GetString("Label_Options_NewKnowledgeSkill");
                form.DropdownItems = KnowledgeSkill.DefaultKnowledgeSkillCatagories;

                if (form.ShowDialog() == DialogResult.OK)
                {
                    KnowledgeSkill skill = new KnowledgeSkill(ObjCharacter);
                    skill.WriteableName = form.SelectedItem;


                    ObjCharacter.SkillsSection.KnowledgeSkills.Add(skill);
                }
            }
            else
            {
                ObjCharacter.SkillsSection.KnowledgeSkills.Add(new KnowledgeSkill(ObjCharacter));
            }
        }
Ejemplo n.º 7
0
        public static bool TestNodeRequirements(XmlNode node, Character character, out string name,
                                                string strIgnoreQuality        = "", XmlDocument objMetatypeDocument = null, XmlDocument objCritterDocument = null,
                                                XmlDocument objQualityDocument = null)
        {
            XmlNode nameNode;

            switch (node.Name)
            {
            case "attribute":
                // Check to see if an Attribute meets a requirement.
                CharacterAttrib objAttribute =
                    character.GetAttribute(node["name"].InnerText);
                name = $"\n\t{objAttribute.DisplayAbbrev} {node["total"].InnerText}";
                return(objAttribute.TotalValue >=
                       Convert.ToInt32(node["total"].InnerText));

            case "attributetotal":
                // Check if the character's Attributes add up to a particular total.
                string strAttributes = Character.AttributeStrings.Aggregate(node["attributes"].InnerText,
                                                                            (current, strAttribute) => current.Replace(strAttribute, character.GetAttribute(strAttribute).DisplayAbbrev));
                name          = $"\n\t{strAttributes} {node["val"].InnerText}";
                strAttributes = Character.AttributeStrings.Aggregate(node["attributes"].InnerText,
                                                                     (current, strAttribute) => current.Replace(strAttribute, character.GetAttribute(strAttribute).Value.ToString()));
                XmlDocument     objXmlDocument = new XmlDocument();
                XPathNavigator  nav            = objXmlDocument.CreateNavigator();
                XPathExpression xprAttributes  = nav.Compile(strAttributes);
                return(Convert.ToInt32(nav.Evaluate(xprAttributes)) >= Convert.ToInt32(node["val"].InnerText));

            case "careerkarma":
                // Check Career Karma requirement.
                name = "\n\t" + LanguageManager.Instance.GetString("Message_SelectQuality_RequireKarma")
                       .Replace("{0}", node.InnerText);
                return(character.CareerKarma >= Convert.ToInt32(node.InnerText));

            case "critterpower":
                // Run through all of the Powers the character has and see if the current required item exists.
                if (character.CritterEnabled && character.CritterPowers != null)
                {
                    CritterPower critterPower = character.CritterPowers.FirstOrDefault(p => p.Name == node.InnerText);
                    if (critterPower != null)
                    {
                        name = critterPower.DisplayNameShort;
                        return(true);
                    }
                    XmlDocument critterPowers = XmlManager.Instance.Load("critterpowers.xml");
                    nameNode =
                        critterPowers.SelectSingleNode($"/chummer/powers/power[name = \"{node.InnerText}\"]");
                    name = nameNode["translate"] != null
                                                        ? "\n\t" + nameNode["translate"].InnerText
                                                        : "\n\t" + node.InnerText;
                    name += $" ({LanguageManager.Instance.GetString("Tab_Critter")})";
                    return(false);
                }
                break;

            case "bioware":
            case "cyberware":
            {
                int count = node.Attributes?["count"] != null?Convert.ToInt32(node.Attributes?["count"].InnerText) : 1;

                name  = null;
                name += node.Name == "cyberware"
                                                ? "\n\t" + LanguageManager.Instance.GetString("Label_Cyberware") + node.InnerText
                                                : "\n\t" + LanguageManager.Instance.GetString("Label_Bioware") + node.InnerText;
                return
                    (character.Cyberware.Count(
                         objCyberware =>
                         objCyberware.Name == node.InnerText && node.Attributes?["select"] == null ||
                         node.Attributes?["select"] != null && node.Attributes?["select"].InnerText == objCyberware.Location) >= count);
            }

            case "biowarecontains":
            case "cyberwarecontains":
            {
                int count = node.Attributes?["count"] != null?Convert.ToInt32(node.Attributes?["count"].InnerText) : 1;

                name  = null;
                name += node.Name == "cyberware"
                                                        ? "\n\t" + LanguageManager.Instance.GetString("Label_Cyberware") + node.InnerText
                                                        : "\n\t" + LanguageManager.Instance.GetString("Label_Bioware") + node.InnerText;
                Improvement.ImprovementSource source = Improvement.ImprovementSource.Cyberware;
                if (node.Name == "biowarecontains")
                {
                    source = Improvement.ImprovementSource.Bioware;
                }
                return(character.Cyberware.Count(objCyberware =>
                                                 objCyberware.SourceType == source && objCyberware.Name.Contains(node.InnerText) && node.Attributes?["select"] == null ||
                                                 node.Attributes?["select"] != null && node.Attributes?["select"].InnerText == objCyberware.Location) >= count);
            }

            case "damageresistance":
                // Damage Resistance must be a particular value.
                ImprovementManager objImprovementManager = new ImprovementManager(character);
                name = "\n\t" + LanguageManager.Instance.GetString("String_DamageResistance");
                return(character.BOD.TotalValue + objImprovementManager.ValueOf(Improvement.ImprovementType.DamageResistance) >=
                       Convert.ToInt32(node.InnerText));

            case "ess":
                if (node.Attributes["grade"] != null)
                {
                    decimal decGrade =
                        character.Cyberware.Where(
                            objCyberware =>
                            objCyberware.Grade.Name ==
                            node.Attributes?["grade"].InnerText)
                        .Sum(objCyberware => objCyberware.CalculatedESS);
                    if (node.InnerText.StartsWith("-"))
                    {
                        // Essence must be less than the value.
                        name = "\n\t" +
                               LanguageManager.Instance.GetString(
                            "Message_SelectQuality_RequireESSGradeBelow")
                               .Replace("{0}", node.InnerText)
                               .Replace("{1}", node.Attributes["grade"].InnerText)
                               .Replace("{2}", decGrade.ToString(CultureInfo.InvariantCulture));
                        return(decGrade <
                               Convert.ToDecimal(node.InnerText.Replace("-", string.Empty), GlobalOptions.InvariantCultureInfo));
                    }
                    // Essence must be equal to or greater than the value.
                    name = "\n\t" +
                           LanguageManager.Instance.GetString(
                        "Message_SelectQuality_RequireESSGradeAbove")
                           .Replace("{0}", node.InnerText)
                           .Replace("{1}", node.Attributes["grade"].InnerText)
                           .Replace("{2}", decGrade.ToString(CultureInfo.InvariantCulture));
                    return(decGrade >= Convert.ToDecimal(node.InnerText, GlobalOptions.InvariantCultureInfo));
                }
                // Check Essence requirement.
                if (node.InnerText.StartsWith("-"))
                {
                    // Essence must be less than the value.
                    name = "\n\t" +
                           LanguageManager.Instance.GetString(
                        "Message_SelectQuality_RequireESSBelow")
                           .Replace("{0}", node.InnerText)
                           .Replace("{1}", character.Essence.ToString(CultureInfo.InvariantCulture));
                    return(character.Essence <
                           Convert.ToDecimal(node.InnerText.Replace("-", string.Empty), GlobalOptions.InvariantCultureInfo));
                }
                // Essence must be equal to or greater than the value.
                name = "\n\t" +
                       LanguageManager.Instance.GetString(
                    "Message_SelectQuality_RequireESSAbove")
                       .Replace("{0}", node.InnerText)
                       .Replace("{1}", character.Essence.ToString(CultureInfo.InvariantCulture));
                return(character.Essence >= Convert.ToDecimal(node.InnerText, GlobalOptions.InvariantCultureInfo));

            case "group":
                // Check that clustered options are present (Magical Tradition + Skill 6, for example)
                string result = string.Empty;
                if (node.ChildNodes.Cast <XmlNode>().Any(childNode => !TestNodeRequirements(childNode, character, out result, strIgnoreQuality,
                                                                                            objMetatypeDocument,
                                                                                            objCritterDocument, objQualityDocument)))
                {
                    name = result;
                    return(false);
                }
                name = result;
                return(true);

            case "initiategrade":
                // Character's initiate grade must be higher than or equal to the required value.
                name = "\n\t" + LanguageManager.Instance.GetString("String_InitiateGrade") + " >= " + node.InnerText;
                return(character.InitiateGrade >= Convert.ToInt32(node.InnerText));

            case "martialtechnique":
                // Character needs a specific Martial Arts technique.
                XmlNode martialDoc = XmlManager.Instance.Load("martialarts.xml");
                nameNode = martialDoc.SelectSingleNode($"/chummer/techniques/technique[name = \"{node.InnerText}\"]");
                name     = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_MartialArt")})";
                return(character.MartialArts.Any(martialart => martialart.Advantages.Any(technique => technique.Name == node.InnerText)));

            case "metamagic":
                XmlNode metamagicDoc = XmlManager.Instance.Load("metamagic.xml");
                nameNode =
                    metamagicDoc.SelectSingleNode($"/chummer/metamagics/metamagic[name = \"{node.InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_Metamagic")})";
                return(character.Metamagics.Any(objMetamagic => objMetamagic.Name == node.InnerText));

            case "metamagicart":
            case "art":
                XmlNode metamagicArtDoc = XmlManager.Instance.Load("metamagic.xml");
                nameNode =
                    metamagicArtDoc.SelectSingleNode($"/chummer/arts/art[name = \"{node.InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_Art")})";
                if (character.Options.IgnoreArt)
                {
                    if (node.Name == "art")
                    {
                        return(true);
                    }
                    foreach (Metamagic metamagic in character.Metamagics)
                    {
                        XmlNode metaNode =
                            metamagicArtDoc.SelectSingleNode($"/chummer/metamagics/metamagic[name = \"{metamagic.Name}\"]/required");
                        if (metaNode?.InnerXml.Contains($"<art>{node.InnerText}</art>") == true)
                        {
                            return(metaNode.InnerXml.Contains($"<art>{node.InnerText}</art>"));
                        }
                        metaNode =
                            metamagicArtDoc.SelectSingleNode($"/chummer/metamagics/metamagic[name = \"{metamagic.Name}\"]/forbidden");
                        if (metaNode?.InnerXml.Contains($"<art>{node.InnerText}</art>") == true)
                        {
                            return(metaNode.InnerXml.Contains($"<art>{node.InnerText}</art>"));
                        }
                    }
                    return(false);
                }
                return(character.Arts.Any(art => art.Name == node.InnerText));

            case "metatype":
                // Check the Metatype restriction.
                nameNode =
                    objMetatypeDocument.SelectSingleNode($"/chummer/metatypes/metatype[name = \"{node.InnerText}\"]") ??
                    objCritterDocument.SelectSingleNode($"/chummer/metatypes/metatype[name = \"{node.InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_Metatype")})";
                return(node.InnerText == character.Metatype);

            case "metatypecategory":
                // Check the Metatype Category restriction.
                nameNode =
                    objMetatypeDocument.SelectSingleNode($"/chummer/categories/category[. = \"{node.InnerText}\"]") ??
                    objCritterDocument.SelectSingleNode($"/chummer/categories/category[. = \"{node.InnerText}\"]");
                name = nameNode?.Attributes["translate"] != null
                                                ? "\n\t" + nameNode.Attributes["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += LanguageManager.Instance.GetString("String_MetatypeCategory");
                return(node.InnerText == character.MetatypeCategory);

            case "metavariant":
                // Check the Metavariant restriction.
                nameNode =
                    objMetatypeDocument.SelectSingleNode($"/chummer/metavariants/metavariant[name = \"{node.InnerText}\"]") ??
                    objCritterDocument.SelectSingleNode($"/chummer/metavariants/metavariant[name = \"{node.InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_Metavariant")})";
                return(node.InnerText == character.Metavariant);

            case "power":
                // Run through all of the Powers the character has and see if the current required item exists.
                Power power = character.Powers.FirstOrDefault(p => p.Name == node.InnerText);
                if (power != null)
                {
                    name = power.DisplayNameShort;
                    return(true);
                }
                XmlDocument xmlPowers = XmlManager.Instance.Load("powers.xml");
                nameNode =
                    xmlPowers.SelectSingleNode($"/chummer/powers/power[name = \"{node.InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("Tab_Adept")})";
                return(false);

            case "quality":
                Quality quality =
                    character.Qualities.FirstOrDefault(q => q.Name == node.InnerText && q.Name != strIgnoreQuality);
                if (quality != null)
                {
                    name = quality.DisplayNameShort;
                    return(true);
                }
                // ReSharper disable once RedundantIfElseBlock (Suppresses node warning)
                else
                {
                    nameNode =
                        objQualityDocument.SelectSingleNode($"/chummer/qualities/quality[name = \"{node.InnerText}\"]");
                    name = nameNode?["translate"] != null
                                                        ? "\n\t" + nameNode["translate"].InnerText
                                                        : "\n\t" + node.InnerText;
                    name += $" ({LanguageManager.Instance.GetString("String_Quality")})";
                    return(false);
                }

            case "skill":
                // Check if the character has the required Skill.
                if (node["type"] != null)
                {
                    KnowledgeSkill s = character.SkillsSection.KnowledgeSkills
                                       .Where(objSkill => objSkill.Name == node["name"]?.InnerText &&
                                              (node["spec"] == null ||
                                               objSkill.Specializations.Any(objSpec => objSpec.Name == node["spec"]?.InnerText)))
                                       .FirstOrDefault(objSkill => objSkill.LearnedRating >= Convert.ToInt32(node["val"]?.InnerText));

                    if (s != null)
                    {
                        name = s.DisplayName;
                        if (node["spec"] != null)
                        {
                            name += $" ({node["spec"].InnerText})";
                        }
                        if (node["val"] != null)
                        {
                            name += $" {node["val"].InnerText}";
                        }
                        return(true);
                    }
                }
                else
                {
                    Skill s = character.SkillsSection.Skills
                              .Where(objSkill => objSkill.Name == node["name"]?.InnerText &&
                                     (node["spec"] == null ||
                                      objSkill.Specializations.Any(objSpec => objSpec.Name == node["spec"]?.InnerText)))
                              .FirstOrDefault(objSkill => objSkill.LearnedRating >= Convert.ToInt32(node["val"]?.InnerText));

                    if (s != null)
                    {
                        name = s.DisplayName;
                        if (node["spec"] != null)
                        {
                            name += $" ({node["spec"].InnerText})";
                        }
                        if (node["val"] != null)
                        {
                            name += $" {node["val"].InnerText}";
                        }
                        return(true);
                    }
                }
                XmlDocument xmlSkills = XmlManager.Instance.Load("skills.xml");
                nameNode =
                    xmlSkills.SelectSingleNode($"/chummer/skills/skill[name = \"{node["name"].InnerText}\"]");
                name = nameNode?["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node["name"].InnerText;
                if (node["spec"] != null)
                {
                    name += $" ({node["spec"].InnerText})";
                }
                if (node["val"] != null)
                {
                    name += $" {node["val"].InnerText}";
                }
                name += $" ({LanguageManager.Instance.GetString("Tab_Skills")})";
                return(false);

            case "skillgrouptotal":
                {
                    // Check if the total combined Ratings of Skill Groups adds up to a particular total.
                    int    intTotal  = 0;
                    var    strGroups = node["skillgroups"].InnerText.Split('+');
                    string outString = "\n\t";
                    for (int i = 0; i <= strGroups.Length - 1; i++)
                    {
                        foreach (SkillGroup objGroup in character.SkillsSection.SkillGroups)
                        {
                            if (objGroup.Name == strGroups[i])
                            {
                                outString += objGroup.DisplayName + ", ";
                                intTotal  += objGroup.Rating;
                                break;
                            }
                        }
                    }
                    name  = outString;
                    name += $" ({LanguageManager.Instance.GetString("String_ExpenseSkillGroup")})";
                    return(intTotal >= Convert.ToInt32(node["val"].InnerText));
                }

            case "spell":
                // Check for a specific Spell.
                XmlDocument xmlSpell = XmlManager.Instance.Load("spells.xml");
                nameNode =
                    xmlSpell.SelectSingleNode($"/chummer/spells/spell[name = \"{node.InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_DescSpell")})";
                return(character.Spells.Any(spell => spell.Name == node.InnerText));

            case "spellcategory":
                // Check for a specified amount of a particular Spell category.
                XmlDocument xmlSpells = XmlManager.Instance.Load("spells.xml");
                nameNode =
                    xmlSpells.SelectSingleNode($"/chummer/categories/category[. = \"{node["name"].InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_SpellCategory")})";
                return(character.Spells.Count(objSpell => objSpell.Category == node["name"].InnerText) >= Convert.ToInt32(node["count"].InnerText));

            case "spelldescriptor":
                // Check for a specified amount of a particular Spell Descriptor.
                name = "\n\t" + LanguageManager.Instance.GetString("Label_Descriptors") + " >= " + node["count"].InnerText;
                return(character.Spells.Count(objSpell => objSpell.Descriptors.Contains(node["name"].InnerText)) >= Convert.ToInt32(node["count"].InnerText));

            case "streetcredvsnotoriety":
                // Street Cred must be higher than Notoriety.
                name = "\n\t" + LanguageManager.Instance.GetString("String_StreetCred") + " >= " +
                       LanguageManager.Instance.GetString("String_Notoriety");
                return(character.StreetCred >= character.Notoriety);

            case "tradition":
                // Character needs a specific Tradition.
                XmlDocument xmlTradition = XmlManager.Instance.Load("traditions.xml");
                nameNode =
                    xmlTradition.SelectSingleNode($"/chummer/traditions/tradition[name = \"{node.InnerText}\"]");
                name = nameNode["translate"] != null
                                                ? "\n\t" + nameNode["translate"].InnerText
                                                : "\n\t" + node.InnerText;
                name += $" ({LanguageManager.Instance.GetString("String_Tradition")})";
                return(character.MagicTradition == node.InnerText);

            default:
                Utils.BreakIfDebug();
                break;
            }
            name = node.InnerText;
            return(false);
        }
Ejemplo n.º 8
0
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            this.skill = skill;
            InitializeComponent();

            //Display
            lblModifiedRating.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.DisplayPool), false, DataSourceUpdateMode.OnPropertyChanged);

            cboType.DataSource    = KnowledgeSkill.KnowledgeTypes;
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataBindings.Add("SelectedValue", skill, nameof(KnowledgeSkill.Type), false, DataSourceUpdateMode.OnPropertyChanged);


            if (skill.CharacterObject.Created)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;

                lblRating.Visible = true;
                lblRating.DataBindings.Add("Text", skill, nameof(Skill.Rating), false, DataSourceUpdateMode.OnPropertyChanged);

                cboType.Enabled = false;

                lblName.Visible = true;
                lblName.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);

                lblSpec.Visible  = true;
                lblSpec.Text     = string.Join(", ", skill.Specializations.Select(x => x.Name));
                cboSkill.Visible = false;
                chkKarma.Visible = false;
                cboSpec.Visible  = false;

                lblModifiedRating.Location = new Point(294 - 30, 4);

                btnAddSpec.Visible        = true;
                btnCareerIncrease.Visible = true;

                lblSpec.DataBindings.Add("Text", skill, nameof(Skill.DisplaySpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
            }
            else
            {
                //Up down boxes
                nudKarma.DataBindings.Add("Value", skill, nameof(Skill.Karma), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("Value", skill, nameof(Skill.Base), false, DataSourceUpdateMode.OnPropertyChanged);

                nudSkill.DataBindings.Add("Enabled", skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints), false, DataSourceUpdateMode.OnPropertyChanged);

                if (skill.CharacterObject.BuildMethod.HaveSkillPoints() || skill.CharacterObject.Options.FreeKarmaKnowledge)
                {
                    chkKarma.DataBindings.Add("Checked", skill, nameof(Skill.BuyWithKarma), false,
                                              DataSourceUpdateMode.OnPropertyChanged);
                }
                else
                {
                    chkKarma.Visible = false;
                }

                cboSkill.DataSource    = skill.KnowledgeSkillCatagories;
                cboSkill.DisplayMember = nameof(ListItem.Name);
                cboSkill.ValueMember   = nameof(ListItem.Value);
                cboSkill.SelectedIndex = -1;
                cboSkill.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);

                //dropdown/spec
                cboSpec.DataSource    = skill.CGLSpecializations;
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.SelectedIndex = -1;

                cboSpec.DataBindings.Add("Enabled", skill, nameof(Skill.Leveled), false, DataSourceUpdateMode.OnPropertyChanged);
                cboSpec.DataBindings.Add("Text", skill, nameof(Skill.Specialization), false, DataSourceUpdateMode.OnPropertyChanged);

                skill.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == nameof(Skill.CGLSpecializations))
                    {
                        cboSpec.DataSource       = null;
                        cboSpec.DataSource       = skill.CGLSpecializations;
                        cboSpec.DisplayMember    = nameof(ListItem.Name);
                        cboSpec.ValueMember      = nameof(ListItem.Value);
                        cboSpec.MaxDropDownItems = Math.Max(1, skill.CGLSpecializations.Count);
                    }
                };
            }

            if (skill.ForcedName)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;
                cboSkill.Enabled = false;
                cboSpec.DataBindings.Clear();
                cboSpec.Enabled           = false;
                btnAddSpec.Enabled        = false;
                btnCareerIncrease.Enabled = false;

                lblRating.Visible = true;
                lblRating.Text    = skill.CyberwareRating().ToString();

                cmdDelete.Visible = false;
            }
            else
            {
                cmdDelete.Click += (sender, args) => { skill.CharacterObject.SkillsSection.KnowledgeSkills.Remove(skill); };
            }
        }
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            if (skill == null)
            {
                return;
            }
            _objGraphics        = CreateGraphics();
            _skill              = skill;
            _tmrNameChangeTimer = new Timer {
                Interval = 1000
            };
            _tmrNameChangeTimer.Tick += NameChangeTimer_Tick;
            InitializeComponent();
            KnowledgeSkillControl_DpiChangedAfterParent(null, EventArgs.Empty);
            this.UpdateLightDarkMode();
            this.TranslateWinForm();

            SuspendLayout();

            lblModifiedRating.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.DisplayPool));
            lblModifiedRating.DoOneWayDataBinding("ToolTipText", _skill, nameof(KnowledgeSkill.PoolToolTip));

            cmdDelete.DoOneWayDataBinding("Visible", _skill, nameof(Skill.AllowDelete));

            cboType.BeginUpdate();
            cboType.DataSource    = null;
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataSource    = KnowledgeSkill.KnowledgeTypes;
            cboType.DoDatabinding("SelectedValue", _skill, nameof(KnowledgeSkill.Type));
            cboType.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.AllowTypeChange));
            cboType.EndUpdate();

            lblName.DoOneWayNegatableDatabinding("Visible", _skill, nameof(Skill.AllowNameChange));
            lblName.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
            lblName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));

            cboName.BeginUpdate();
            cboName.DoOneWayDataBinding("Visible", _skill, nameof(Skill.AllowNameChange));
            cboName.DataSource    = null;
            cboName.DisplayMember = nameof(ListItem.Name);
            cboName.ValueMember   = nameof(ListItem.Value);
            cboName.DataSource    = KnowledgeSkill.DefaultKnowledgeSkills;
            cboName.SelectedIndex = -1;
            cboName.Text          = _skill.WriteableName;
            cboName.EndUpdate();
            _blnUpdatingName = false;

            if (_skill.CharacterObject.Created)
            {
                lblRating = new Label
                {
                    Anchor      = AnchorStyles.Right,
                    AutoSize    = true,
                    MinimumSize = new Size((int)(25 * _objGraphics.DpiX / 96.0f), 0),
                    Name        = "lblRating",
                    Text        = "00",
                    TextAlign   = ContentAlignment.MiddleCenter
                };
                btnCareerIncrease = new ButtonWithToolTip
                {
                    Anchor                  = AnchorStyles.Right,
                    AutoSize                = true,
                    AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                    Image                   = Resources.add,
                    Margin                  = new Padding(3, 0, 3, 0),
                    Name                    = "btnCareerIncrease",
                    Padding                 = new Padding(1),
                    UseVisualStyleBackColor = true
                };
                btnCareerIncrease.Click += btnCareerIncrease_Click;

                lblRating.DoOneWayNegatableDatabinding("Visible", _skill, nameof(KnowledgeSkill.IsNativeLanguage));
                lblRating.DoOneWayDataBinding("Text", _skill, nameof(Skill.Rating));

                btnCareerIncrease.DoOneWayDataBinding("Visible", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                btnCareerIncrease.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanUpgradeCareer));
                btnCareerIncrease.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.UpgradeToolTip));

                lblRating.UpdateLightDarkMode();
                lblRating.TranslateWinForm();
                btnCareerIncrease.UpdateLightDarkMode();
                btnCareerIncrease.TranslateWinForm();
                tlpMain.Controls.Add(lblRating, 1, 0);
                tlpMain.Controls.Add(btnCareerIncrease, 2, 0);

                lblSpec = new Label
                {
                    Anchor    = AnchorStyles.Left,
                    AutoSize  = true,
                    Name      = "lblSpec",
                    Text      = "[SPEC]",
                    TextAlign = ContentAlignment.MiddleLeft
                };
                btnAddSpec = new ButtonWithToolTip
                {
                    Anchor                  = AnchorStyles.Right,
                    AutoSize                = true,
                    AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                    Image                   = Resources.add,
                    Margin                  = new Padding(3, 0, 3, 0),
                    Name                    = "btnAddSpec",
                    Padding                 = new Padding(1),
                    UseVisualStyleBackColor = true
                };
                btnAddSpec.Click += btnAddSpec_Click;

                lblSpec.DoOneWayNegatableDatabinding("Visible", _skill, nameof(KnowledgeSkill.IsNativeLanguage));
                lblSpec.DoOneWayDataBinding("Text", _skill, nameof(Skill.CurrentDisplaySpecialization));

                btnAddSpec.DoOneWayDataBinding("Visible", _skill, nameof(Skill.CanHaveSpecs));
                btnAddSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanAffordSpecialization));
                btnAddSpec.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.AddSpecToolTip));

                lblSpec.UpdateLightDarkMode();
                lblSpec.TranslateWinForm();
                btnAddSpec.UpdateLightDarkMode();
                btnAddSpec.TranslateWinForm();
                tlpMiddle.SetColumnSpan(lblSpec, 2);
                tlpMiddle.Controls.Add(lblSpec, 1, 0);
                tlpMiddle.Controls.Add(btnAddSpec, 3, 0);
            }
            else
            {
                nudSkill = new NumericUpDownEx
                {
                    Anchor              = AnchorStyles.Right,
                    AutoSize            = true,
                    InterceptMouseWheel = NumericUpDownEx.InterceptMouseWheelMode.WhenMouseOver,
                    Margin              = new Padding(3, 2, 3, 2),
                    Maximum             = new decimal(new[] { 99, 0, 0, 0 }),
                    Name = "nudSkill"
                };
                nudKarma = new NumericUpDownEx
                {
                    Anchor              = AnchorStyles.Right,
                    AutoSize            = true,
                    InterceptMouseWheel = NumericUpDownEx.InterceptMouseWheelMode.WhenMouseOver,
                    Margin              = new Padding(3, 2, 3, 2),
                    Maximum             = new decimal(new[] { 99, 0, 0, 0 }),
                    Name = "nudKarma"
                };

                nudSkill.DoOneWayDataBinding("Visible", _skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints));
                nudSkill.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                nudSkill.DoDatabinding("Value", _skill, nameof(Skill.Base));
                nudSkill.DoOneWayDataBinding("InterceptMouseWheel", _skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode));
                nudKarma.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                nudKarma.DoDatabinding("Value", _skill, nameof(Skill.Karma));
                nudKarma.DoOneWayDataBinding("InterceptMouseWheel", _skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode));

                nudSkill.UpdateLightDarkMode();
                nudSkill.TranslateWinForm();
                nudKarma.UpdateLightDarkMode();
                nudKarma.TranslateWinForm();
                tlpMain.Controls.Add(nudSkill, 1, 0);
                tlpMain.Controls.Add(nudKarma, 2, 0);

                chkNativeLanguage = new ColorableCheckBox(components)
                {
                    Anchor             = AnchorStyles.Left,
                    AutoSize           = true,
                    DefaultColorScheme = true,
                    Margin             = new Padding(3, 0, 3, 0),
                    Name = "chkNativeLanguage",
                    Tag  = "Skill_NativeLanguageLong",
                    Text = "Native",
                    UseVisualStyleBackColor = true
                };
                cboSpec = new ElasticComboBox
                {
                    Anchor            = AnchorStyles.Left | AnchorStyles.Right,
                    AutoCompleteMode  = AutoCompleteMode.Suggest,
                    FormattingEnabled = true,
                    Margin            = new Padding(3, 0, 3, 0),
                    Name    = "cboSpec",
                    TabStop = false
                };
                chkKarma = new ColorableCheckBox(components)
                {
                    Anchor             = AnchorStyles.Left,
                    AutoSize           = true,
                    DefaultColorScheme = true,
                    Name = "chkKarma",
                    UseVisualStyleBackColor = true
                };

                chkNativeLanguage.DoOneWayDataBinding("Visible", _skill, nameof(Skill.IsLanguage));
                chkNativeLanguage.Enabled = _skill.IsNativeLanguage || _skill.CharacterObject.SkillsSection.HasAvailableNativeLanguageSlots;
                chkNativeLanguage.DoDatabinding("Checked", _skill, nameof(Skill.IsNativeLanguage));

                cboSpec.BeginUpdate();
                cboSpec.DataSource    = null;
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.DataSource    = _skill.CGLSpecializations;
                cboSpec.SelectedIndex = -1;
                cboSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanHaveSpecs));
                cboSpec.DoDatabinding("Text", _skill, nameof(Skill.Specialization));
                cboSpec.EndUpdate();

                chkKarma.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanHaveSpecs));
                chkKarma.DoDatabinding("Checked", _skill, nameof(Skill.BuyWithKarma));

                chkNativeLanguage.UpdateLightDarkMode();
                chkNativeLanguage.TranslateWinForm();
                cboSpec.UpdateLightDarkMode();
                cboSpec.TranslateWinForm();
                chkKarma.UpdateLightDarkMode();
                chkKarma.TranslateWinForm();
                tlpMiddle.Controls.Add(chkNativeLanguage, 1, 0);
                tlpMiddle.Controls.Add(cboSpec, 2, 0);
                tlpMiddle.Controls.Add(chkKarma, 3, 0);
            }

            if (_skill.ForcedName)
            {
                this.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.Enabled));
            }

            ResumeLayout();

            _skill.PropertyChanged += Skill_PropertyChanged;
            _skill.CharacterObject.SkillsSection.PropertyChanged += OnSkillsSectionPropertyChanged;
        }
Ejemplo n.º 10
0
        public KnowledgeSkillControl(KnowledgeSkill objSkill)
        {
            if (objSkill == null)
            {
                return;
            }
            _objSkill = objSkill;
            InitializeComponent();
            SuspendLayout();
            tlpMain.SuspendLayout();
            tlpMiddle.SuspendLayout();
            try
            {
                lblModifiedRating.DoOneWayDataBinding("Text", objSkill, nameof(KnowledgeSkill.DisplayPool));
                lblModifiedRating.DoOneWayDataBinding("ToolTipText", objSkill, nameof(KnowledgeSkill.PoolToolTip));

                cmdDelete.DoOneWayDataBinding("Visible", objSkill, nameof(Skill.AllowDelete));

                cboType.BeginUpdate();
                cboType.PopulateWithListItems(objSkill.CharacterObject.SkillsSection.MyKnowledgeTypes);
                cboType.DoDataBinding("SelectedValue", objSkill, nameof(KnowledgeSkill.Type));
                cboType.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.AllowTypeChange));
                cboType.EndUpdate();

                lblName.DoOneWayNegatableDataBinding("Visible", objSkill, nameof(Skill.AllowNameChange));
                lblName.DoOneWayDataBinding("Text", objSkill, nameof(KnowledgeSkill.WritableName));
                lblName.DoOneWayDataBinding("ForeColor", objSkill, nameof(Skill.PreferredColor));

                cboName.BeginUpdate();
                cboName.PopulateWithListItems(objSkill.CharacterObject.SkillsSection.MyDefaultKnowledgeSkills);
                cboName.SelectedIndex = -1;
                cboName.Text          = objSkill.WritableName;
                cboName.DoOneWayDataBinding("Visible", objSkill, nameof(Skill.AllowNameChange));
                cboName.EndUpdate();
                _blnUpdatingName    = false;
                _tmrNameChangeTimer = new Timer {
                    Interval = 1000
                };
                _tmrNameChangeTimer.Tick += NameChangeTimer_Tick;

                if (objSkill.CharacterObject.Created)
                {
                    lblRating = new Label
                    {
                        Anchor    = AnchorStyles.Right,
                        AutoSize  = true,
                        Margin    = new Padding(3, 6, 3, 6),
                        Name      = "lblRating",
                        Text      = "00",
                        TextAlign = ContentAlignment.MiddleCenter
                    };
                    btnCareerIncrease = new ButtonWithToolTip
                    {
                        Anchor                  = AnchorStyles.Right,
                        AutoSize                = true,
                        AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                        ImageDpi96              = Resources.add,
                        ImageDpi192             = Resources.add1,
                        MinimumSize             = new Size(24, 24),
                        Name                    = "btnCareerIncrease",
                        Padding                 = new Padding(1),
                        UseVisualStyleBackColor = true
                    };
                    btnCareerIncrease.Click += btnCareerIncrease_Click;

                    lblRating.DoOneWayNegatableDataBinding("Visible", objSkill, nameof(KnowledgeSkill.IsNativeLanguage));
                    lblRating.DoOneWayDataBinding("Text", objSkill, nameof(Skill.Rating));

                    btnCareerIncrease.DoOneWayDataBinding("Visible", objSkill, nameof(KnowledgeSkill.AllowUpgrade));
                    btnCareerIncrease.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanUpgradeCareer));
                    btnCareerIncrease.DoOneWayDataBinding("ToolTipText", objSkill, nameof(Skill.UpgradeToolTip));

                    tlpMain.Controls.Add(lblRating, 1, 0);
                    tlpMain.Controls.Add(btnCareerIncrease, 2, 0);

                    lblSpec = new Label
                    {
                        Anchor    = AnchorStyles.Left,
                        AutoSize  = true,
                        Margin    = new Padding(3, 6, 3, 6),
                        Name      = "lblSpec",
                        Text      = "[SPEC]",
                        TextAlign = ContentAlignment.MiddleLeft
                    };
                    btnAddSpec = new ButtonWithToolTip
                    {
                        Anchor                  = AnchorStyles.Right,
                        AutoSize                = true,
                        AutoSizeMode            = AutoSizeMode.GrowAndShrink,
                        ImageDpi96              = Resources.add,
                        ImageDpi192             = Resources.add1,
                        MinimumSize             = new Size(24, 24),
                        Name                    = "btnAddSpec",
                        Padding                 = new Padding(1),
                        UseVisualStyleBackColor = true
                    };
                    btnAddSpec.Click += btnAddSpec_Click;

                    lblSpec.DoOneWayDataBinding("Text", objSkill, nameof(Skill.CurrentDisplaySpecialization));

                    btnAddSpec.DoOneWayDataBinding("Visible", objSkill, nameof(Skill.CanHaveSpecs));
                    btnAddSpec.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanAffordSpecialization));
                    btnAddSpec.DoOneWayDataBinding("ToolTipText", objSkill, nameof(Skill.AddSpecToolTip));

                    tlpMiddle.SetColumnSpan(lblSpec, 2);
                    tlpMiddle.Controls.Add(lblSpec, 1, 0);
                    tlpMiddle.Controls.Add(btnAddSpec, 3, 0);
                }
                else
                {
                    nudSkill = new NumericUpDownEx
                    {
                        Anchor              = AnchorStyles.Right,
                        AutoSize            = true,
                        InterceptMouseWheel = NumericUpDownEx.InterceptMouseWheelMode.WhenMouseOver,
                        Margin              = new Padding(3, 2, 3, 2),
                        Maximum             = new decimal(new[] { 99, 0, 0, 0 }),
                        Name = "nudSkill"
                    };
                    nudKarma = new NumericUpDownEx
                    {
                        Anchor              = AnchorStyles.Right,
                        AutoSize            = true,
                        InterceptMouseWheel = NumericUpDownEx.InterceptMouseWheelMode.WhenMouseOver,
                        Margin              = new Padding(3, 2, 3, 2),
                        Maximum             = new decimal(new[] { 99, 0, 0, 0 }),
                        Name = "nudKarma"
                    };

                    nudSkill.DoOneWayDataBinding("Visible", objSkill.CharacterObject.SkillsSection,
                                                 nameof(SkillsSection.HasKnowledgePoints));
                    nudSkill.DoOneWayDataBinding("Enabled", objSkill, nameof(KnowledgeSkill.AllowUpgrade));
                    nudSkill.DoDataBinding("Value", objSkill, nameof(Skill.Base));
                    nudSkill.InterceptMouseWheel = GlobalSettings.InterceptMode;
                    nudKarma.DoOneWayDataBinding("Enabled", objSkill, nameof(KnowledgeSkill.AllowUpgrade));
                    nudKarma.DoDataBinding("Value", objSkill, nameof(Skill.Karma));
                    nudKarma.InterceptMouseWheel = GlobalSettings.InterceptMode;

                    tlpMain.Controls.Add(nudSkill, 1, 0);
                    tlpMain.Controls.Add(nudKarma, 2, 0);

                    chkNativeLanguage = new ColorableCheckBox(components)
                    {
                        Anchor             = AnchorStyles.Left,
                        AutoSize           = true,
                        DefaultColorScheme = true,
                        Margin             = new Padding(3, 4, 3, 4),
                        Name = "chkNativeLanguage",
                        Tag  = "Skill_NativeLanguageLong",
                        Text = "Native",
                        UseVisualStyleBackColor = true
                    };
                    cboSpec = new ElasticComboBox
                    {
                        Anchor            = AnchorStyles.Left | AnchorStyles.Right,
                        AutoCompleteMode  = AutoCompleteMode.Suggest,
                        FormattingEnabled = true,
                        Margin            = new Padding(3, 0, 3, 0),
                        Name    = "cboSpec",
                        TabStop = false
                    };
                    chkKarma = new ColorableCheckBox(components)
                    {
                        Anchor             = AnchorStyles.Left,
                        AutoSize           = true,
                        DefaultColorScheme = true,
                        Margin             = new Padding(3, 4, 3, 4),
                        Name = "chkKarma",
                        UseVisualStyleBackColor = true
                    };

                    chkNativeLanguage.DoOneWayDataBinding("Visible", objSkill, nameof(Skill.IsLanguage));
                    chkNativeLanguage.Enabled = objSkill.IsNativeLanguage ||
                                                objSkill.CharacterObject.SkillsSection.HasAvailableNativeLanguageSlots;
                    chkNativeLanguage.DoDataBinding("Checked", objSkill, nameof(Skill.IsNativeLanguage));

                    cboSpec.BeginUpdate();
                    cboSpec.PopulateWithListItems(objSkill.CGLSpecializations);
                    cboSpec.EndUpdate();
                    cboSpec.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanHaveSpecs));
                    cboSpec.Text         = objSkill.CurrentDisplaySpecialization;
                    cboSpec.TextChanged += cboSpec_TextChanged;
                    _blnUpdatingSpec     = false;
                    _tmrSpecChangeTimer  = new Timer {
                        Interval = 1000
                    };
                    _tmrSpecChangeTimer.Tick += SpecChangeTimer_Tick;

                    chkKarma.DoOneWayDataBinding("Enabled", objSkill, nameof(Skill.CanHaveSpecs));
                    chkKarma.DoDataBinding("Checked", objSkill, nameof(Skill.BuyWithKarma));

                    tlpMiddle.Controls.Add(chkNativeLanguage, 1, 0);
                    tlpMiddle.Controls.Add(cboSpec, 2, 0);
                    tlpMiddle.Controls.Add(chkKarma, 3, 0);

                    // Hacky way of fixing a weird UI issue caused by items of a combobox only being populated from the DataSource after the combobox is added
                    _blnUpdatingSpec = true;
                    cboSpec.Text     = objSkill.CurrentDisplaySpecialization;
                    _blnUpdatingSpec = false;
                }

                if (objSkill.ForcedName)
                {
                    this.DoOneWayDataBinding("Enabled", objSkill, nameof(KnowledgeSkill.Enabled));
                }

                AdjustForDpi();
                this.UpdateLightDarkMode();
                this.TranslateWinForm(blnDoResumeLayout: false);
            }
            finally
            {
                tlpMiddle.ResumeLayout();
                tlpMain.ResumeLayout();
                ResumeLayout(true);
                objSkill.PropertyChanged += Skill_PropertyChanged;
                objSkill.CharacterObject.SkillsSection.PropertyChanged += OnSkillsSectionPropertyChanged;
            }
        }
Ejemplo n.º 11
0
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            _skill = skill;
            InitializeComponent();

            //Display
            lblModifiedRating.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.DisplayPool), false, DataSourceUpdateMode.OnPropertyChanged);

            List <ListItem> lstTypes = KnowledgeSkill.KnowledgeTypes(GlobalOptions.Language).ToList();

            lstTypes.Sort(CompareListItems.CompareNames);

            cboType.BeginUpdate();
            cboSkill.BeginUpdate();
            cboSpec.BeginUpdate();
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataSource    = lstTypes;
            cboType.DataBindings.Add("SelectedValue", skill, nameof(KnowledgeSkill.Type), false, DataSourceUpdateMode.OnPropertyChanged);

            if (skill.CharacterObject.Created)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;

                lblRating.Visible = true;
                lblRating.DataBindings.Add("Text", skill, nameof(Skill.Rating), false, DataSourceUpdateMode.OnPropertyChanged);

                //New knowledge skills start at 0. Leave the Type selector unlocked until they spend Karma on the skill.
                cboType.Enabled = (skill.Karma == 0 && skill.Base == 0 || string.IsNullOrWhiteSpace(_skill.Type));

                lblName.Visible = true;
                lblName.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);

                lblSpec.Visible  = true;
                lblSpec.Text     = string.Join(", ", skill.Specializations.Select(x => x.Name));
                cboSkill.Visible = false;
                chkKarma.Visible = false;
                cboSpec.Visible  = false;

                lblModifiedRating.Location = new Point(294 - 30, 4);

                btnAddSpec.Visible = true;
                btnAddSpec.DataBindings.Add("Enabled", skill, nameof(Skill.CanAffordSpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
                btnCareerIncrease.Visible = true;
                btnCareerIncrease.DataBindings.Add("Enabled", skill, nameof(Skill.CanUpgradeCareer), false,
                                                   DataSourceUpdateMode.OnPropertyChanged);
                lblSpec.DataBindings.Add("Text", skill, nameof(Skill.DisplaySpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
            }
            else
            {
                //Up down boxes
                nudKarma.DataBindings.Add("Value", skill, nameof(Skill.Karma), false, DataSourceUpdateMode.OnPropertyChanged);
                nudKarma.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                nudSkill.DataBindings.Add("Value", skill, nameof(Skill.Base), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("Enabled", skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                chkKarma.DataBindings.Add("Checked", skill, nameof(Skill.BuyWithKarma), false,
                                          DataSourceUpdateMode.OnPropertyChanged);
                cboSkill.DisplayMember = nameof(ListItem.Name);
                cboSkill.ValueMember   = nameof(ListItem.Value);
                List <ListItem> lstDefaultKnowledgeSkills = KnowledgeSkill.DefaultKnowledgeSkills(GlobalOptions.Language).ToList();
                lstDefaultKnowledgeSkills.Sort(CompareListItems.CompareNames);
                cboSkill.DataSource    = lstDefaultKnowledgeSkills;
                cboSkill.SelectedIndex = -1;
                cboSkill.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);

                //dropdown/spec
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.DataSource    = skill.CGLSpecializations;
                cboSpec.SelectedIndex = -1;

                cboSpec.DataBindings.Add("Enabled", skill, nameof(Skill.Leveled), false, DataSourceUpdateMode.OnPropertyChanged);
                cboSpec.DataBindings.Add("Text", skill, nameof(Skill.Specialization), false, DataSourceUpdateMode.OnPropertyChanged);

                skill.PropertyChanged += (sender, args) =>
                {
                    if (args.PropertyName == nameof(Skill.CGLSpecializations))
                    {
                        cboSpec.DataSource       = null;
                        cboSpec.DisplayMember    = nameof(ListItem.Name);
                        cboSpec.ValueMember      = nameof(ListItem.Value);
                        cboSpec.DataSource       = skill.CGLSpecializations;
                        cboSpec.MaxDropDownItems = Math.Max(1, skill.CGLSpecializations.Count);
                    }
                };
            }

            if (skill.ForcedName)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;
                cboSkill.Enabled = false;
                cboSpec.DataBindings.Clear();
                cboSpec.Enabled           = false;
                btnAddSpec.Enabled        = false;
                btnCareerIncrease.Enabled = false;

                lblRating.Visible = true;
                lblRating.Text    = skill.CyberwareRating.ToString();

                cmdDelete.Visible = false;
            }
            else
            {
                cmdDelete.Click += (sender, args) => { skill.CharacterObject.SkillsSection.KnowledgeSkills.Remove(skill); };
            }
            cboType.EndUpdate();
            cboSkill.EndUpdate();
            cboSpec.EndUpdate();
        }
Ejemplo n.º 12
0
        private async void btnKnowledge_Click(object sender, EventArgs e)
        {
            if (_objCharacter.Created)
            {
                string strSelectedSkill = string.Empty;

                Form frmToUse = ParentForm ?? Program.MainForm;

                DialogResult eResult = await frmToUse.DoThreadSafeFunc(async x =>
                {
                    using (SelectItem form = new SelectItem
                    {
                        Description = await LanguageManager.GetStringAsync("Label_Options_NewKnowledgeSkill")
                    })
                    {
                        form.SetDropdownItemsMode(_objCharacter.SkillsSection.MyDefaultKnowledgeSkills);

                        await form.ShowDialogSafeAsync(x);

                        if (form.DialogResult == DialogResult.OK)
                        {
                            strSelectedSkill = form.SelectedItem;
                        }
                        return(form.DialogResult);
                    }
                });

                if (eResult != DialogResult.OK)
                {
                    return;
                }

                KnowledgeSkill skill = new KnowledgeSkill(_objCharacter)
                {
                    WritableName = strSelectedSkill
                };

                if (_objCharacter.SkillsSection.HasAvailableNativeLanguageSlots &&
                    (skill.IsLanguage || string.IsNullOrEmpty(skill.Type)))
                {
                    DialogResult eDialogResult = Program.ShowMessageBox(this,
                                                                        string.Format(GlobalSettings.CultureInfo,
                                                                                      await LanguageManager.GetStringAsync("Message_NewNativeLanguageSkill"),
                                                                                      1 + ImprovementManager.ValueOf(
                                                                                          _objCharacter, Improvement.ImprovementType.NativeLanguageLimit),
                                                                                      skill.WritableName),
                                                                        await LanguageManager.GetStringAsync("Tip_Skill_NativeLanguage"), MessageBoxButtons.YesNoCancel);
                    switch (eDialogResult)
                    {
                    case DialogResult.Cancel:
                        return;

                    case DialogResult.Yes:
                    {
                        if (!skill.IsLanguage)
                        {
                            skill.Type = "Language";
                        }
                        skill.IsNativeLanguage = true;
                        break;
                    }
                    }
                }

                _objCharacter.SkillsSection.KnowledgeSkills.Add(skill);
            }
            else
            {
                _objCharacter.SkillsSection.KnowledgeSkills.Add(new KnowledgeSkill(_objCharacter));
            }
        }
Ejemplo n.º 13
0
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            if (skill == null)
            {
                return;
            }
            _skill = skill;
            InitializeComponent();

            LanguageManager.TranslateWinForm(GlobalOptions.Language, this);

            //Display
            lblModifiedRating.DoDatabinding("Text", skill, nameof(KnowledgeSkill.DisplayPool));
            lblModifiedRating.DoDatabinding("ToolTipText", skill, nameof(KnowledgeSkill.PoolToolTip));

            List <ListItem> lstTypes = KnowledgeSkill.KnowledgeTypes().ToList();

            lstTypes.Sort(CompareListItems.CompareNames);

            cboType.BeginUpdate();
            cboSkill.BeginUpdate();
            cboSpec.BeginUpdate();
            cboType.DataSource    = lstTypes;
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataBindings.Add("SelectedValue", skill, nameof(KnowledgeSkill.Type), false, DataSourceUpdateMode.OnPropertyChanged);

            nudSkill.Visible = !skill.CharacterObject.Created && skill.CharacterObject.SkillsSection.HasKnowledgePoints;
            nudKarma.Visible = !skill.CharacterObject.Created;
            chkKarma.Visible = !skill.CharacterObject.Created;
            cboSpec.Visible  = !skill.CharacterObject.Created;
            //cboType.Visible = !skill.CharacterObject.Created;

            btnCareerIncrease.Visible = skill.CharacterObject.Created;
            lblSpec.Visible           = skill.CharacterObject.Created;
            btnAddSpec.Visible        = skill.CharacterObject.Created;
            lblRating.Visible         = skill.CharacterObject.Created;

            if (skill.CharacterObject.Created)
            {
                nudKarma.Visible = false;
                nudSkill.Visible = false;

                lblRating.Visible = true;
                lblRating.DataBindings.Add("Text", skill, nameof(Skill.Rating), false, DataSourceUpdateMode.OnPropertyChanged);

                //New knowledge skills start at 0. Leave the Type selector unlocked until they spend Karma on the skill.
                cboType.Enabled = (skill.Karma == 0 && skill.Base == 0 || string.IsNullOrWhiteSpace(_skill.Type));

                lblName.Visible = true;
                lblName.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);
                lblName.DataBindings.Add("ForeColor", skill, nameof(Skill.PreferredColor));
                lblName.DataBindings.Add("ToolTipText", skill, nameof(Skill.HtmlSkillToolTip));

                lblSpec.Visible = true;
                lblSpec.DataBindings.Add("Text", skill, nameof(Skill.CurrentDisplaySpecialization), false, DataSourceUpdateMode.OnPropertyChanged);

                cboSkill.Visible = false;
                chkKarma.Visible = false;
                cboSpec.Visible  = false;

                lblModifiedRating.Location = new Point(294 - 30, 4);

                btnAddSpec.DataBindings.Add("Enabled", skill, nameof(Skill.CanAffordSpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
                btnAddSpec.DataBindings.Add("Visible", skill, nameof(Skill.CanHaveSpecs), false, DataSourceUpdateMode.OnPropertyChanged);
                btnAddSpec.DataBindings.Add("ToolTipText", skill, nameof(Skill.AddSpecToolTip), false, DataSourceUpdateMode.OnPropertyChanged);
                btnCareerIncrease.DataBindings.Add("Enabled", skill, nameof(Skill.CanUpgradeCareer), false, DataSourceUpdateMode.OnPropertyChanged);
                btnCareerIncrease.DataBindings.Add("ToolTipText", skill, nameof(Skill.UpgradeToolTip), false, DataSourceUpdateMode.OnPropertyChanged);
            }
            else
            {
                //Up down boxes
                nudKarma.DataBindings.Add("Value", skill, nameof(Skill.Karma), false, DataSourceUpdateMode.OnPropertyChanged);
                nudKarma.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                nudSkill.DataBindings.Add("Value", skill, nameof(Skill.Base), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("Enabled", skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints), false, DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.DataBindings.Add("InterceptMouseWheel", skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode), false, DataSourceUpdateMode.OnPropertyChanged);

                chkKarma.DataBindings.Add("Checked", skill, nameof(Skill.BuyWithKarma), false,
                                          DataSourceUpdateMode.OnPropertyChanged);
                List <ListItem> lstDefaultKnowledgeSkills = KnowledgeSkill.DefaultKnowledgeSkills().ToList();
                lstDefaultKnowledgeSkills.Sort(CompareListItems.CompareNames);
                cboSkill.DataSource    = lstDefaultKnowledgeSkills;
                cboSkill.DisplayMember = nameof(ListItem.Name);
                cboSkill.ValueMember   = nameof(ListItem.Value);
                cboSkill.SelectedIndex = -1;
                cboSkill.DataBindings.Add("Text", skill, nameof(KnowledgeSkill.WriteableName), false, DataSourceUpdateMode.OnPropertyChanged);
                cboSkill.DataBindings.Add(new NegatableBinding("Enabled", skill, nameof(KnowledgeSkill.ForcedName), true));

                //dropdown/spec
                cboSpec.DataSource    = skill.CGLSpecializations;
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.SelectedIndex = -1;

                cboSpec.DataBindings.Add("Enabled", skill, nameof(Skill.CanHaveSpecs), false, DataSourceUpdateMode.OnPropertyChanged);
                cboSpec.DataBindings.Add("Text", skill, nameof(Skill.Specialization), false, DataSourceUpdateMode.OnPropertyChanged);

                skill.PropertyChanged += Skill_PropertyChanged;
            }

            cmdDelete.DataBindings.Add("Visible", skill, nameof(Skill.AllowDelete), false, DataSourceUpdateMode.OnPropertyChanged);
            cmdDelete.Click += (sender, args) =>
            {
                if (!skill.CharacterObject.ConfirmDelete(LanguageManager.GetString("Message_DeleteKnowledgeSkill",
                                                                                   GlobalOptions.Language)))
                {
                    return;
                }
                skill.UnbindSkill();
                skill.CharacterObject.SkillsSection.KnowledgeSkills.Remove(skill);
            };
            if (skill.ForcedName)
            {
                DataBindings.Add("Enabled", skill, nameof(KnowledgeSkill.Enabled), false, DataSourceUpdateMode.OnPropertyChanged);
                if (!skill.CharacterObject.Created)
                {
                    cboType.Enabled = string.IsNullOrEmpty(_skill.Type);
                }
            }
            if (!skill.AllowUpgrade)
            {
                nudKarma.Visible          = false;
                nudSkill.Visible          = false;
                cboSkill.Enabled          = false;
                chkKarma.Visible          = false;
                btnAddSpec.Enabled        = false;
                btnCareerIncrease.Enabled = false;

                if (!skill.CharacterObject.Created)
                {
                    lblRating.Visible = true;
                    lblRating.DataBindings.Add("Text", skill, nameof(Skill.Rating), false, DataSourceUpdateMode.OnPropertyChanged);
                }
            }
            cboType.EndUpdate();
            cboSkill.EndUpdate();
            cboSpec.EndUpdate();
        }
Ejemplo n.º 14
0
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            if (skill == null)
            {
                return;
            }
            _skill = skill;
            InitializeComponent();

            this.TranslateWinForm();

            lblModifiedRating.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.DisplayPool));
            lblModifiedRating.DoOneWayDataBinding("ToolTipText", _skill, nameof(KnowledgeSkill.PoolToolTip));

            cmdDelete.DoOneWayDataBinding("Visible", _skill, nameof(Skill.AllowDelete));

            cboType.BeginUpdate();
            cboType.DataSource    = null;
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataSource    = KnowledgeSkill.KnowledgeTypes;
            cboType.DoDatabinding("SelectedValue", _skill, nameof(KnowledgeSkill.Type));
            cboType.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.AllowTypeChange));
            cboType.EndUpdate();

            lblName.DoOneWayNegatableDatabinding("Visible", _skill, nameof(Skill.AllowNameChange));
            lblName.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
            lblName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));

            cboName.BeginUpdate();
            cboName.DoOneWayDataBinding("Visible", _skill, nameof(Skill.AllowNameChange));
            cboName.DataSource    = null;
            cboName.DisplayMember = nameof(ListItem.Name);
            cboName.ValueMember   = nameof(ListItem.Value);
            cboName.DataSource    = KnowledgeSkill.DefaultKnowledgeSkills;
            cboName.SelectedIndex = -1;
            cboName.DoDatabinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
            cboName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));
            cboName.EndUpdate();

            if (_skill.CharacterObject.Created)
            {
                flpButtonsCreate.Visible = false;
                tlpSpecsCreate.Visible   = false;
                flpButtonsCareer.Dock    = DockStyle.Fill;
                tlpSpecsCareer.Dock      = DockStyle.Fill;

                lblRating.DoOneWayNegatableDatabinding("Visible", _skill, nameof(KnowledgeSkill.IsNativeLanguage));
                lblRating.DoOneWayDataBinding("Text", _skill, nameof(Skill.Rating));
                lblSpec.DoOneWayNegatableDatabinding("Visible", _skill, nameof(KnowledgeSkill.IsNativeLanguage));
                lblSpec.DoOneWayDataBinding("Text", _skill, nameof(Skill.CurrentDisplaySpecialization));

                btnCareerIncrease.DoOneWayDataBinding("Visible", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                btnCareerIncrease.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanUpgradeCareer));
                btnCareerIncrease.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.UpgradeToolTip));

                btnAddSpec.DoOneWayDataBinding("Visible", _skill, nameof(Skill.CanHaveSpecs));
                btnAddSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanAffordSpecialization));
                btnAddSpec.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.AddSpecToolTip));
            }
            else
            {
                flpButtonsCareer.Visible = false;
                tlpSpecsCareer.Visible   = false;
                flpButtonsCreate.Dock    = DockStyle.Fill;
                tlpSpecsCreate.Dock      = DockStyle.Fill;

                nudSkill.DoOneWayDataBinding("Visible", _skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints));
                nudSkill.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                nudSkill.DoDatabinding("Value", _skill, nameof(Skill.Base));
                nudSkill.DoOneWayDataBinding("InterceptMouseWheel", _skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode));
                nudKarma.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.AllowUpgrade));
                nudKarma.DoDatabinding("Value", _skill, nameof(Skill.Karma));
                nudKarma.DoOneWayDataBinding("InterceptMouseWheel", _skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode));

                chkNativeLanguage.DoOneWayDataBinding("Visible", _skill, nameof(Skill.IsLanguage));
                chkNativeLanguage.Enabled = _skill.IsNativeLanguage || _skill.CharacterObject.SkillsSection.HasAvailableNativeLanguageSlots;
                chkNativeLanguage.DoDatabinding("Checked", _skill, nameof(Skill.IsNativeLanguage));

                cboSpec.BeginUpdate();
                cboSpec.DataSource    = null;
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.DataSource    = _skill.CGLSpecializations;
                cboSpec.SelectedIndex = -1;
                cboSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanHaveSpecs));
                cboSpec.DoDatabinding("Text", _skill, nameof(Skill.Specialization));
                cboSpec.EndUpdate();
                chkKarma.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanHaveSpecs));
                chkKarma.DoDatabinding("Checked", _skill, nameof(Skill.BuyWithKarma));
            }

            if (_skill.ForcedName)
            {
                this.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.Enabled));
            }

            _skill.PropertyChanged += Skill_PropertyChanged;
            _skill.CharacterObject.SkillsSection.PropertyChanged += OnSkillsSectionPropertyChanged;
        }
Ejemplo n.º 15
0
        public KnowledgeSkillControl(KnowledgeSkill skill)
        {
            if (skill == null)
            {
                return;
            }
            _skill = skill;
            InitializeComponent();

            this.TranslateWinForm();

            lblModifiedRating.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.DisplayPool));
            lblModifiedRating.DoOneWayDataBinding("ToolTipText", _skill, nameof(KnowledgeSkill.PoolToolTip));

            cmdDelete.DoOneWayDataBinding("Visible", _skill, nameof(Skill.AllowDelete));

            cboType.BeginUpdate();
            cboType.DataSource    = null;
            cboType.DisplayMember = nameof(ListItem.Name);
            cboType.ValueMember   = nameof(ListItem.Value);
            cboType.DataSource    = KnowledgeSkill.KnowledgeTypes;
            cboType.DoDatabinding("SelectedValue", _skill, nameof(KnowledgeSkill.Type));

            if (_skill.CharacterObject.Created)
            {
                //New knowledge_skills start at 0. Leave the Type selector unlocked until they spend Karma on the_skill.
                cboType.Enabled = (_skill.Karma == 0 && _skill.Base == 0 && !_skill.ForcedName) || string.IsNullOrWhiteSpace(_skill.Type);
            }
            if (_skill.ForcedName)
            {
                this.DoOneWayDataBinding("Enabled", _skill, nameof(KnowledgeSkill.Enabled));
                if (!_skill.CharacterObject.Created)
                {
                    cboType.Enabled = string.IsNullOrEmpty(_skill.Type);
                }
            }
            cboType.EndUpdate();

            if (_skill.CharacterObject.Created || !_skill.AllowUpgrade)
            {
                flpButtonsCreate.Visible = false;
                tlpSpecsCreate.Visible   = false;
                flpButtonsCareer.Dock    = DockStyle.Fill;
                tlpSpecsCareer.Dock      = DockStyle.Fill;

                lblRating.DoOneWayDataBinding("Text", _skill, nameof(Skill.Rating));
                lblSpec.DoOneWayDataBinding("Text", _skill, nameof(Skill.CurrentDisplaySpecialization));

                if (_skill.AllowUpgrade)
                {
                    if (_skill.Karma == 0 && _skill.Base == 0 && !_skill.ForcedName)
                    {
                        lblName.Visible = false;
                        cboName.BeginUpdate();
                        cboName.DataSource    = null;
                        cboName.DisplayMember = nameof(ListItem.Name);
                        cboName.ValueMember   = nameof(ListItem.Value);
                        cboName.DataSource    = KnowledgeSkill.DefaultKnowledgeSkills;
                        cboName.SelectedIndex = -1;
                        cboName.DoDatabinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
                        cboName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));
                        cboName.EndUpdate();
                    }
                    else
                    {
                        cboName.Visible = false;
                        lblName.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
                        lblName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));
                    }
                    btnCareerIncrease.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanUpgradeCareer));
                    btnCareerIncrease.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.UpgradeToolTip));

                    btnAddSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanAffordSpecialization));
                    btnAddSpec.DoOneWayDataBinding("Visible", _skill, nameof(Skill.CanHaveSpecs));
                    btnAddSpec.DoOneWayDataBinding("ToolTipText", _skill, nameof(Skill.AddSpecToolTip));
                }
                else
                {
                    btnCareerIncrease.Visible = false;
                    btnAddSpec.Visible        = false;
                }
            }
            else
            {
                flpButtonsCareer.Visible = false;
                tlpSpecsCareer.Visible   = false;
                flpButtonsCreate.Dock    = DockStyle.Fill;
                tlpSpecsCreate.Dock      = DockStyle.Fill;

                if (!_skill.ForcedName)
                {
                    lblName.Visible = false;
                    cboName.BeginUpdate();
                    cboName.DataSource    = null;
                    cboName.DisplayMember = nameof(ListItem.Name);
                    cboName.ValueMember   = nameof(ListItem.Value);
                    cboName.DataSource    = KnowledgeSkill.DefaultKnowledgeSkills;
                    cboName.SelectedIndex = -1;
                    cboName.DoDatabinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
                    cboName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));
                    cboName.EndUpdate();
                }
                else
                {
                    cboName.Visible = false;
                    lblName.DoOneWayDataBinding("Text", _skill, nameof(KnowledgeSkill.WriteableName));
                    lblName.DoOneWayDataBinding("ForeColor", _skill, nameof(Skill.PreferredColor));
                }

                nudSkill.DoOneWayDataBinding("Visible", _skill.CharacterObject.SkillsSection, nameof(SkillsSection.HasKnowledgePoints));
                nudSkill.DoDatabinding("Value", _skill, nameof(Skill.Base));
                nudSkill.DoOneWayDataBinding("InterceptMouseWheel", _skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode));
                nudKarma.DoDatabinding("Value", _skill, nameof(Skill.Karma));
                nudKarma.DoOneWayDataBinding("InterceptMouseWheel", _skill.CharacterObject.Options, nameof(CharacterOptions.InterceptMode));

                cboSpec.BeginUpdate();
                cboSpec.DataSource    = null;
                cboSpec.DisplayMember = nameof(ListItem.Name);
                cboSpec.ValueMember   = nameof(ListItem.Value);
                cboSpec.DataSource    = _skill.CGLSpecializations;
                cboSpec.SelectedIndex = -1;
                cboSpec.DoOneWayDataBinding("Enabled", _skill, nameof(Skill.CanHaveSpecs));
                cboSpec.DoDatabinding("Text", _skill, nameof(Skill.Specialization));
                cboSpec.EndUpdate();
                chkKarma.DoDatabinding("Checked", _skill, nameof(Skill.BuyWithKarma));
            }

            _skill.PropertyChanged += Skill_PropertyChanged;
        }