예제 #1
0
        private void UpdateTrees()
        {
            ClearTalentPickerItems();
            if (Talents != null)
            {
                _treeNames = new List <string>((string[])Talents.GetType().GetField("TreeNames").GetValue(Talents));
                talentTree1.CharacterClass = _character.Class;
                talentTree1.TreeName       = _treeNames[0];
                tabPageTree1.Text          = _treeNames[0];
                talentTree2.CharacterClass = _character.Class;
                talentTree2.TreeName       = _treeNames[1];
                tabPageTree2.Text          = _treeNames[1];
                talentTree3.CharacterClass = _character.Class;
                talentTree3.TreeName       = _treeNames[2];
                tabPageTree3.Text          = _treeNames[2];

                TalentTree currentTree;

                List <GlyphDataAttribute> majors   = new List <GlyphDataAttribute>();
                List <GlyphDataAttribute> minors   = new List <GlyphDataAttribute>();
                List <string>             relevant = Calculations.GetModel(Character.CurrentModel).GetRelevantGlyphs();

                foreach (PropertyInfo pi in Talents.GetType().GetProperties())
                {
                    TalentDataAttribute[] talentDatas = pi.GetCustomAttributes(typeof(TalentDataAttribute), true) as TalentDataAttribute[];
                    if (talentDatas.Length > 0)
                    {
                        TalentDataAttribute talentData = talentDatas[0];
                        switch (talentData.Tree)
                        {
                        case 0: currentTree = talentTree1; break;

                        case 1: currentTree = talentTree2; break;

                        default: currentTree = talentTree3; break;
                        }
                        TalentItem item = new TalentItem(currentTree, talentData.Name, talentData.Row - 1, talentData.Column - 1, talentData.Index, LineWrapDescription(talentData.Description), talentData.Icon,
                                                         (int)pi.GetValue(Talents, null), talentData.MaxPoints, talentData.Prerequisite >= 0 ? _talentPickerItems[talentData.Prerequisite] : null);
                        _talentPickerItems[talentData.Index] = item;
                        currentTree.AddTalent(item);

                        item.CurrentRankChanged += new EventHandler(item_CurrentRankChanged);
                    }

                    GlyphDataAttribute[] glyphDatas = pi.GetCustomAttributes(typeof(GlyphDataAttribute), true) as GlyphDataAttribute[];
                    if (glyphDatas.Length > 0)
                    {
                        GlyphDataAttribute glyphData = glyphDatas[0];
                        if (glyphData.Major)
                        {
                            majors.Add(glyphData);
                        }
                        else
                        {
                            minors.Add(glyphData);
                        }
                    }
                }

                tabPageGlyphs.SuspendLayout();

                foreach (Control c in grpMajorGlyph.Controls)
                {
                    c.Dispose();
                }
                grpMajorGlyph.Controls.Clear();

                int count = 0;
                foreach (GlyphDataAttribute glyph in majors)
                {
                    if (relevant == null || relevant.Contains(glyph.Name))
                    {
                        CheckBox cb = new CheckBox();
                        grpMajorGlyph.Controls.Add(cb);
                        cb.AutoSize = true;
                        cb.Text     = glyph.Name;
                        cb.Tag      = glyph.Index;
                        cb.Checked  = Talents.GlyphData[glyph.Index];
                        cb.UseVisualStyleBackColor = true;
                        cb.Location        = new Point(8, 17 + 21 * count);
                        cb.CheckedChanged += new EventHandler(this.glyph_ValueChanged);
                        tooltipGlyph.SetToolTip(cb, glyph.Description);
                        count++;
                    }
                }
                if (count == 0)
                {
                    grpMajorGlyph.Hide();
                }
                else
                {
                    grpMajorGlyph.Show();
                }
                count = 0;

                foreach (Control c in grpMinorGlyph.Controls)
                {
                    c.Dispose();
                }
                grpMinorGlyph.Controls.Clear();

                foreach (GlyphDataAttribute glyph in minors)
                {
                    if (relevant == null || relevant.Contains(glyph.Name))
                    {
                        CheckBox cb = new CheckBox();
                        grpMinorGlyph.Controls.Add(cb);
                        cb.AutoSize = true;
                        cb.Text     = glyph.Name;
                        cb.Tag      = glyph.Index;
                        cb.Checked  = Talents.GlyphData[glyph.Index];
                        cb.UseVisualStyleBackColor = true;
                        cb.Location        = new Point(6, 19 + 23 * count);
                        cb.CheckedChanged += new EventHandler(this.glyph_ValueChanged);
                        tooltipGlyph.SetToolTip(cb, glyph.Description);
                        count++;
                    }
                }

                if (count == 0)
                {
                    grpMinorGlyph.Hide();
                }
                else
                {
                    grpMinorGlyph.Show();
                }

                tabPageGlyphs.ResumeLayout();

                talentTree1.Redraw();
                talentTree2.Redraw();
                talentTree3.Redraw();
                item_CurrentRankChanged(null, null);
            }
        }