Пример #1
0
        private void pictureBox_Click(object sender, EventArgs e)
        {
            LOG.Debug("pictureBox_Click");
            bool       isCommanderSkill = false;
            PictureBox box = (PictureBox)sender;

            if (box.AccessibleDescription == null || box.AccessibleDescription.Equals(""))
            {
                try
                {
                    if (box.Parent.Name.Equals("panelFlags"))
                    {
                        LOG.Debug("panelFlags");
                        int count = int.Parse(combatFlagsCount.Text);
                        if (box.AccessibleRole == AccessibleRole.Alert)
                        {
                            count++;
                            if (count > 8)
                            {
                                throw new AllocatingException("You can only select 8 combat flags");
                            }
                            combatFlagsCount.Text = count.ToString();
                        }
                    }
                    else
                    {
                        LOG.Debug("CommanderSkill = true");
                        isCommanderSkill = true;
                        AddSkillPoints(box.AccessibleName);
                    }
                    box.AccessibleDescription = "X";
                    if (isCommanderSkill)
                    {
                        Skill currentSkill = FindSkillByAccessibleName(box.AccessibleName);
                        if (currentSkill != null)
                        {
                            foreach (Perk perk in currentSkill.Perks)
                            {
                                bmHandler.ApplyValue(perk.ID, perk.Value);
                            }
                        }
                    }
                    else
                    {
                        bmHandler.ApplyValue(box.AccessibleName);
                    }
                }
                catch (AllocatingException ae)
                {
                    LOG.Info("User tried to allocate more skillpoints or flags than allowed");
                    MessageBox.Show(ae.Message, "Error allocating skillpoints/flags", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    box.AccessibleDescription = "";
                }
                catch (Exception ex)
                {
                    LOG.Error(ex.Message);
                    MessageBox.Show(ex.Message, "Error allocating skillpoints/flags", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    box.AccessibleDescription = "";
                }
            }
            else
            {
                if (box.Parent.Name.Equals("panelFlags"))
                {
                    if (box.AccessibleRole == AccessibleRole.Alert)
                    {
                        int count = int.Parse(combatFlagsCount.Text);
                        count--;
                        combatFlagsCount.Text = count.ToString();
                    }
                }
                else
                {
                    isCommanderSkill = true;
                    RemoveSkillPoints(box.AccessibleName);
                }
                box.AccessibleDescription = "";
                if (isCommanderSkill)
                {
                    Skill currentSkill = FindSkillByAccessibleName(box.AccessibleName);
                    if (currentSkill != null)
                    {
                        foreach (Perk perk in currentSkill.Perks)
                        {
                            bmHandler.RemoveValue(perk.ID, perk.Value);
                        }
                    }
                }
                else
                {
                    bmHandler.RemoveValue(box.AccessibleName);
                }
            }
            box.Refresh();
        }