private Control MakeActiveSkill(Skill arg)
 {
     SkillControl2 control = new SkillControl2(arg);
     controls.Add(control);
     control.CustomAttributeChanged += Control_CustomAttributeChanged;
     return control;
 }
Beispiel #2
0
        /// <summary>
        /// Load a skill from a xml node from a saved .chum5 file
        /// </summary>
        /// <param name="n">The XML node describing the skill</param>
        /// <param name="character">The character this skill belongs to</param>
        /// <returns></returns>
        public static Skill Load(Character character, XmlNode n)
        {
            if (n["suid"] == null)
            {
                return(null);
            }

            Guid        suid;
            XmlDocument skills = XmlManager.Instance.Load("skills.xml");

            if (!Guid.TryParse(n["suid"].InnerText, out suid))
            {
                return(null);
            }
            Skill skill;

            if (suid != Guid.Empty)
            {
                XmlNode node = skills.SelectSingleNode($"/chummer/skills/skill[id = '{n["suid"].InnerText}']");

                if (node == null)
                {
                    return(null);
                }

                if (node["exotic"]?.InnerText == "Yes")
                {
                    ExoticSkill exotic = new ExoticSkill(character, node);
                    exotic.Load(n);
                    skill = exotic;
                }
                else
                {
                    skill = new Skill(character, node);
                }
            }
            else             //This is ugly but i'm not sure how to make it pretty
            {
                if (n["forced"] != null)
                {
                    skill = new KnowledgeSkill(character, n["name"].InnerText);
                }
                else
                {
                    KnowledgeSkill knoSkill = new KnowledgeSkill(character);
                    knoSkill.Load(n);
                    skill = knoSkill;
                }
            }

            XmlElement element = n["guid"];

            if (element != null)
            {
                skill.Id = Guid.Parse(element.InnerText);
            }

            n.TryGetField("karma", out skill._karma);
            n.TryGetField("base", out skill._base);
            n.TryGetField("buywithkarma", out skill._buyWithKarma);
            n.TryGetField("notes", out skill._strNotes);

            foreach (XmlNode spec in n.SelectNodes("specs/spec"))
            {
                skill.Specializations.Add(SkillSpecialization.Load(spec));
            }
            XmlNode objCategoryNode = skills.SelectSingleNode($"/chummer/categories/category[. = '{skill.SkillCategory}']");

            if (objCategoryNode != null && objCategoryNode.Attributes?["translate"] != null)
            {
                skill.DisplayCategory = objCategoryNode.Attributes["translate"].InnerText;
            }

            return(skill);
        }
Beispiel #3
0
        /// <summary>
        /// Loads skill saved in legacy format
        /// </summary>
        /// <param name="character"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Skill LegacyLoad(Character character, XmlNode n)
        {
            Guid  suid;
            Skill skill;

            n.TryGetField("id", Guid.TryParse, out suid, Guid.NewGuid());

            int baseRating  = int.Parse(n["base"].InnerText);
            int fullRating  = int.Parse(n["rating"].InnerText);
            int karmaRating = fullRating - baseRating;              //Not reading karma directly as career only increases rating

            if (n.TryCheckValue("knowledge", "True"))
            {
                Skills.KnowledgeSkill kno = new KnowledgeSkill(character);
                kno.WriteableName = n["name"].InnerText;
                kno.Base          = baseRating;
                kno.Karma         = karmaRating;

                kno.Type = n["skillcategory"].InnerText;

                skill = kno;
            }
            else
            {
                XmlNode data =
                    XmlManager.Instance.Load("skills.xml").SelectSingleNode($"/chummer/skills/skill[id = '{suid}']");

                //Some stuff apparently have a guid of 0000-000... (only exotic?)
                if (data == null)
                {
                    data = XmlManager.Instance.Load("skills.xml")
                           .SelectSingleNode($"/chummer/skills/skill[name = '{n["name"].InnerText}']");
                }


                skill        = Skill.FromData(data, character);
                skill._base  = baseRating;
                skill._karma = karmaRating;

                ExoticSkill exoticSkill = skill as ExoticSkill;
                if (exoticSkill != null)
                {
                    string name = n.SelectSingleNode("skillspecializations/skillspecialization/name")?.InnerText ?? "";
                    //don't need to do more load then.

                    exoticSkill.Specific = name;
                    return(skill);
                }

                skill._buyWithKarma = n.TryCheckValue("buywithkarma", "True");
            }

            var v = from XmlNode node
                    in n.SelectNodes("skillspecializations/skillspecialization")
                    select SkillSpecialization.Load(node);

            var q = v.ToList();

            if (q.Count != 0)
            {
                skill.Specializations.AddRange(q);
            }

            return(skill);
        }
Beispiel #4
0
        public SkillControl2(Skill skill)
        {
            this._skill = skill;
            InitializeComponent();

            DataBindings.Add("Enabled", skill, nameof(Skill.Enabled), false, DataSourceUpdateMode.OnPropertyChanged);

            //Display
            if (!skill.Default)
            {
                lblName.Font = new Font(lblName.Font, FontStyle.Italic);
            }
            if (!String.IsNullOrWhiteSpace(_skill.Notes))
            {
                lblName.ForeColor = Color.SaddleBrown;
            }

            lblName.DataBindings.Add("Text", skill, nameof(Skill.DisplayName));

            skill.PropertyChanged += Skill_PropertyChanged;

            _attributeActive = skill.AttributeObject;
            _attributeActive.PropertyChanged += AttributeActiveOnPropertyChanged;
            Skill_PropertyChanged(null, null);  //if null it updates all

            _normal = btnAttribute.Font;
            _italic = new Font(_normal, FontStyle.Italic);
            if (skill.CharacterObject.Created)
            {
                lblModifiedRating.Location = new Point(256 - 13, 4);

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

                btnCareerIncrease.Visible = true;
                btnCareerIncrease.DataBindings.Add("Enabled", skill, nameof(Skill.CanUpgradeCareer), false,
                    DataSourceUpdateMode.OnPropertyChanged);
                nudSkill.Visible = false;
                nudKarma.Visible = false;
                chkKarma.Visible = false;

                cboSpec.Visible = false;

                lblCareerSpec.DataBindings.Add("Text", skill, nameof(skill.DisplaySpecialization), false, DataSourceUpdateMode.OnPropertyChanged);
                lblCareerSpec.Visible = true;

                lblAttribute.Visible = false;  //Was true, cannot think it should be

                btnAttribute.DataBindings.Add("Text", skill, nameof(Skill.DisplayAttribute));
                btnAttribute.Visible = true;

                SetupDropdown();
            }
            else
            {
                lblAttribute.DataBindings.Add("Text", skill, nameof(Skill.DisplayAttribute));

                //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, nameof(Skill.BaseUnlocked), false,
                    DataSourceUpdateMode.OnPropertyChanged);
                nudKarma.DataBindings.Add("Enabled", skill, nameof(Skill.KarmaUnlocked), false,
                    DataSourceUpdateMode.OnPropertyChanged);

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

                if (skill.IsExoticSkill)
                {
                    cboSpec.Enabled = false;
                    cboSpec.DataBindings.Add("Text", skill, nameof(Skill.DisplaySpecialization), false, DataSourceUpdateMode.OnPropertyChanged);

                }
                else
                {
                    //dropdown/spec
                    cboSpec.DataSource = skill.CGLSpecializations;
                    cboSpec.DisplayMember = nameof(ListItem.Name);
                    cboSpec.ValueMember = nameof(ListItem.Value);
                    cboSpec.DataBindings.Add("Enabled", skill, nameof(Skill.CanHaveSpecs), false,
                        DataSourceUpdateMode.OnPropertyChanged);
                    cboSpec.SelectedIndex = -1;

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

                }
            }

            //Delete button
            if (skill.AllowDelete)
            {
                cmdDelete.Visible = true;
                cmdDelete.Click += (sender, args) => { skill.CharacterObject.SkillsSection.Skills.Remove(skill); };

                if (skill.CharacterObject.Created)
                {
                    btnAddSpec.Location = new Point(btnAddSpec.Location.X - cmdDelete.Width, btnAddSpec.Location.Y);
                }
            }
        }