Exemplo n.º 1
0
        private void SkillSelectButton_Click(object sender, EventArgs e)
        {
            bool canSelectSkill = true;

            //START Debug Info
            //string debugMessage;

            //debugMessage = "Skill: " + this.skill.name + "\n" +
            //                "XPos: " + this.skill.x + "\n" +
            //                "YPos:" + this.skill.y;
            //;
            //MessageBox.Show(debugMessage);
            //END Debug Info

            // Get the tree control that the clicked button exists in
            TreeTableLayoutPanel treeControl = (this.Parent as SkillSelectPanel).treeControl;

            // Get the current control that will be replaced with the newly-selected one
            Control btnSkill = treeControl.GetControlFromPosition(this.skill.x, this.skill.y);

            // Since the Mastery Tree has 3 shared General Rows with the same Skills, check that the chosen skill isn't already assigned in a different General Row
            if (treeControl.tree.name == "Mastery")
            {
                canSelectSkill = CanSelectSkill(treeControl, this.skill);
            }

            // See if we've discovered that we cannot select this Skill
            if (!canSelectSkill)
            {
                // Explain to the user that they cannot select this Skill because it's already been selected in a different General Row
                MessageBox.Show("Skill '" + this.skill.name + "' has already been selected.", "Skill Selection Error");

                // Hide the SkillSelectPanel
                this.Parent.Hide();

                // Get out of this method, we don't need to do anything else here
                return;
            }

            // Incase there's a skill at this position already, subtract the level of the skill from the build before we remove it
            if (canSelectSkill && btnSkill is SkillButton)
            {
                // Get the skill that was previously selected at this location
                SkillButton btnPreviousSkill = (btnSkill as SkillButton);

                // Create a new button to hold the selected Skill and change it on the tree
                (this.Parent as SkillSelectPanel).ChangeSelectedSkill(btnPreviousSkill, new SkillButton(this.skill, treeControl, this.skillTooltipPanel, form));
            }
            else if (canSelectSkill && btnSkill is MultiSkillSelectButton)
            {
                // No skill has yet been selected at this position
                MultiSkillSelectButton btnMultiSkillSelect = (btnSkill as MultiSkillSelectButton);

                // Create a new button to hold the selected Skill and change it on the tree
                (this.Parent as SkillSelectPanel).ChangeSelectedSkill(btnMultiSkillSelect, new SkillButton(this.skill, treeControl, this.skillTooltipPanel, form));
            }
            else if (!(btnSkill is SkillButton) && !(btnSkill is MultiSkillSelectButton))
            {
                // Display error for unknown control type found (ie. user clicked an unknown control type on the Tree to bring up the skill select panel and click a SkillSelectButton
                Alerts.DisplayError("SkillSelectButton_Click: Unknown control type found.  The control type of '" + btnSkill.GetType().ToString() + "' is not being accounted for or has a click event on it that needs to be removed.");
                return;
            }
        }
Exemplo n.º 2
0
        private void BtnPastebinShare_Click(object sender, EventArgs e)
        {
            // Generate a Pastebin URL of the current Build for the user to share
            string        buildAsText;
            string        pasteUrl;
            XmlSerializer serializer;
            var           client = new PasteBinClient(PasteBinClient.PBType.BuildShare);

            // Optional; will publish as a guest if not logged in; could enable this to see how many pastes people are using but
            //   this exposes username/password since it's on Github
            //client.Login(userName, password); //this'll set User Key

            serializer = new XmlSerializer((this.ParentForm as BuildShareForm).ParentForm.build.GetType());

            try
            {
                // Save the build to a string format
                using (StringWriter writer = new StringWriter())
                {
                    serializer.Serialize(writer, (this.ParentForm as BuildShareForm).ParentForm.build);
                    buildAsText = writer.ToString();
                }
            }
            catch (Exception ex)
            {
                // Display error that the build could not be serialized to be shared via Pastebin
                Alerts.DisplayError("PastebinShare:  Unable to serialize the build to be shared with Pastebin." + Environment.NewLine + ex.ToString());
                return;
            }

            // Setup the data for the Pastebin
            var entry = new PasteBinEntry
            {
                Title      = "ChroniCalc Build Share",
                Text       = buildAsText,
                Expiration = PasteBinExpiration.Never,
                Private    = false,
                Format     = "xml"
            };

            try
            {
                // Call through the Pastebin API to get the URL
                pasteUrl = client.Paste(entry);

                // Show the Pastebin URL in the textbox
                txtPastebinShare.Text = pasteUrl;
            }
            catch (System.Net.WebException)
            {
                MessageBox.Show("Unable to reach Pastebin.  This function is not currently available.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (PasteBinApiException ex)
            {
                MessageBox.Show("Unable to retrieve Build URL from Pastebin.  This function is not currently available." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                // Something else happened and we're not sure what, so provide error details to the user to pass along to me
                throw new EChroniCalcException("PasteBinShare: Unable to reach Pastebin." + Environment.NewLine + ex.Message);
            }
        }