コード例 #1
0
ファイル: TalentsForm.cs プロジェクト: gaknoia/babbot
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (cbWoWVersion.SelectedItem == null)
            {
                ShowErrorMessage("WoW Version not selected");
                return;
            }

            // Check learning order
            int[] ls = null;
            if (tbLearningOrder.Text.Equals(""))
                ls = new int[] {1, 2, 3};
            else
            {
                string[] lorder = tbLearningOrder.Text.Split(',');
                int ll = lorder.Length;
                if (ll > 3)
                {
                    ShowErrorMessage("Invalid learning sequence '" + tbLearningOrder.Text +
                    "'. Number of tabs exceed 3");
                    return;
                }

                // convert each tab to int
                ls = new int[ll];

                try
                {
                    for (int i = 0; i < ll; i++)
                        ls[i] = Convert.ToInt32(lorder[i]);
                } catch {
                    ShowErrorMessage("Invalid Tab Id parameter in learning sequence '" +
                        tbLearningOrder.Text + "'");
                    return;
                }
            }

            // Finally process URL
            try
            {
                string url = tbTalentURL.Text;
                // Check for class id
                Match m = trex.Match(url);

                if (m.Success && (m.Groups.Count == 3))
                {
                    string s = m.Groups[1].ToString();
                    byte cid = Convert.ToByte(s);
                    string ts = m.Groups[2].ToString();

                    // string response = ReadURL(url);

                    // Find class
                    WoWVersion cur_version = (WoWVersion) cbWoWVersion.SelectedItem;
                    CharClass cc = cur_version.Classes.FindClassByArmoryId(cid);

                    // Check if Class defined
                    if (cc == null)
                    {
                        ShowErrorMessage("Unable find class for Armory ID " + cid);
                        return;
                    }

                    // Check size of talents
                    int cc_total = cc.TotalTalentSum;
                    if (cc_total != ts.Length)
                    {
                        ShowErrorMessage("Length of talent's URL parameter " + ts.Length +
                            " different from class parameter length " + cc_total +
                            " configured in WoWData.xml");
                        return;
                    }

                    byte[] tabs_len = cc.Tabs;

                    // Convert talent list to byte array
                    byte[] tlist = new byte[cc_total];
                    for (int i = 0; i < cc_total; i++)
                        tlist[i] = Convert.ToByte(ts.Substring(i, 1));

                    byte num = cur_version.TalentConfig.StartLevel;

                    // Select class
                    cbClass.SelectedItem = cc;
                    cbClass.Enabled = false;

                    // Clear CurTalents
                    if (CurTalents == null)
                        CurTalents = new Talents();
                    else
                        btnReset_Click(sender, e);

                    BindLevels();

                    for (int i = 0; i < ls.Length; i++)
                    {
                        int cur_tab_id = ls[i];
                        int offset = 0;
                        for (int j = 0; j < cur_tab_id - 1; j++)
                            offset += tabs_len[j];

                        int cur_tab_len = tabs_len[cur_tab_id - 1];
                        for (int j = 0; j < cur_tab_len; j++)
                        {
                            byte ct = tlist[offset + j];
                            // Added current talent with all ranks
                            for (int k = 1; k <= ct; k++)
                            {
                                CurTalents.AddLevel(new Level(num, cur_tab_id, j + 1, k));
                                num++;
                                RefreshLevelList();
                            }
                        }
                    }
                } else {
                    ShowErrorMessage(string.Format(
                        "Invalid URL. '{0}' excpected", trex.ToString()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable read URL: " + ex.Message);
            }
        }
コード例 #2
0
ファイル: TalentsForm.cs プロジェクト: gaknoia/babbot
        private void cbTalentTemplates_SelectedIndexChanged(object sender, EventArgs e)
        {
            CurTalents = (Talents)cbTalentTemplates.SelectedItem;
            // Doesn't make sence process if tallent not selected
            if (CurTalents == null)
                return;

            if (CurTalents.WoWVersion != null)
                cbWoWVersion.SelectedItem =
                    DataManager.FindWoWVersionByName(CurTalents.WoWVersion);
            else
                cbWoWVersion.SelectedItem = null;

            SelectClass();

            tbDescription.Text = CurTalents.Description;
            tbTalentURL.Text = CurTalents.URL;
            tbLearningOrder.Text = CurTalents.LearningOrder;

            // Clear binding
            if (lbLevelList.DataSource != null)
                lbLevelList.DataSource = null;

            lbLevelList.Items.Clear();

            BindLevels();

            lbLevelList.SelectedIndex = 0;

            IsChanged = false;
            CheckSaveBtn();
        }
コード例 #3
0
ファイル: TalentsForm.cs プロジェクト: gaknoia/babbot
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int num = 10;
            int tab = 1;
            int talent = 1;
            int rank = 1;

            // Find last item
            if ((CurTalents != null) && (CurTalents.Levels.Count > 0))
            {
                Level last = (Level)CurTalents.Levels[CurTalents.Levels.Count - 1];

                num = last.Num + 1;
                tab = last.TabId;
                talent = last.TalentId;

                if (last.Rank < numRank.Maximum)
                    rank = last.Rank + 1;
                else
                    talent++;
            }

            Level l  = new Level(num , tab, talent, rank);

            bool is_new = (CurTalents == null);
            if (is_new)
            {
                // Don't forget add .xml extension for new file
                CurTalents = new Talents(cbTalentTemplates.Text + ".xml",
                                        tbTalentURL.Text, tbDescription.Text);
                BindLevels();
            }

            CurTalents.AddLevel(l);

            RefreshLevelList();
            lbLevelList.SelectedIndex = lbLevelList.Items.Count - 1;

            RegisterChange();
        }