private void TvTemplates_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { if (!File.Exists(Properties.Settings.Default.SummonsXML)) { MessageBox.Show("XML file was not found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tvTemplates.SelectedNode != null) { if (tvTemplates.SelectedNode.Tag is Summon selSumm) { if (MessageBox.Show(string.Format("Are you sure you want to delete {0} from this list?", ((Summon)tvTemplates.SelectedNode.Tag).Name), "Delete Summon Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes) { Summons summons = Summons.Retrieve(Properties.Settings.Default.SummonsXML); int indexMatch = summons.FindIndex(x => x.Name.ToUpper() == selSumm.Name.ToUpper() && x.SummonSpell.ToUpper() == selSumm.SummonSpell.ToUpper()); if (indexMatch > -1) { summons.RemoveAt(indexMatch); } summons.Save(Properties.Settings.Default.SummonsXML); RefreshSummonPage(); } } } } }
private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { if (!File.Exists(Properties.Settings.Default.SummonsXML)) { MessageBox.Show("XML file was not found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (sittingSummonIndex == 0) { MessageBox.Show("Summon does not exist.", "Summon Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { if (tbName.Text == "") { MessageBox.Show("Summon Name must be filled out", "Summon Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cbSummonSpell.Text == "") { MessageBox.Show("Summon Spell/Category must be specified", "Summon Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List <Size> sizes = Enum.GetValues(typeof(Size)).Cast <Size>().ToList(); int index = sizes.FindIndex(x => x.ToString() == cbSize.SelectedItem.ToString()); Size size = index > -1 ? sizes[index] : DruidAssistant.Size.Medium; Summon updateSummon = new Summon { Index = sittingSummonIndex, SummonSpell = cbSummonSpell.Text, Name = tbName.Text, Abilities = new Abilities((int)nudSTR.Value, (int)nudDEX.Value, (int)nudCON.Value, (int)nudINT.Value, (int)nudWIS.Value, (int)nudCHA.Value), Saves = new Saves((int)nudFort.Value, (int)nudRef.Value, (int)nudWill.Value), Level = (int)nudLevel.Value, HitDie = (int)nudHD.Value, NaturalArmor = (int)nudNatural.Value, BAB = (int)nudBAB.Value, Grapple = (int)nudGrapple.Value, Size = size, Type = tbType.Text, Environment = tbEnvironment.Text, Space = tbSpace.Text, Reach = tbReach.Text, Movement = tbMovement.Text, Skills = rtbSkills.Text.Split(',').ToList(), Feats = tbFeats.Text.Split(',').ToList(), SpecAtks = tbSpecAtks.Text.Split(',').ToList(), SpecQual = tbSpecQual.Text.Split(',').ToList(), Notes = rtbCombat.Text.Split('\r').ToList(), Attacks = Summon.GetAttacks(rtbAttacks.Text), FullAttacks = Summon.GetFullAttacks(rtbFullAttacks.Text) }; Summons summons = Summons.Retrieve(Properties.Settings.Default.SummonsXML); int indexMatch = summons.FindIndex(x => x.Index == sittingSummonIndex); if (indexMatch > -1) { summons[indexMatch] = updateSummon; } else { MessageBox.Show("Summon cannot be found.", "Summon Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } summons.Save(Properties.Settings.Default.SummonsXML); RefreshSummonPage(); } }
private void AddToolStripMenuItem_Click(object sender, EventArgs e) { if (!File.Exists(Properties.Settings.Default.SummonsXML)) { MessageBox.Show("XML file was not found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (tbName.Text == "") { MessageBox.Show("Summon Name must be filled out", "Summon Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cbSummonSpell.Text == "") { MessageBox.Show("Summon Spell/Category must be specified", "Summon Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } List <Size> sizes = Enum.GetValues(typeof(Size)).Cast <Size>().ToList(); int index = sizes.FindIndex(x => x.ToString() == cbSize.SelectedItem.ToString()); Size size = index > -1 ? sizes[index] : DruidAssistant.Size.Medium; Summon addSummon = new Summon { SummonSpell = cbSummonSpell.Text, Name = tbName.Text, Abilities = new Abilities((int)nudSTR.Value, (int)nudDEX.Value, (int)nudCON.Value, (int)nudINT.Value, (int)nudWIS.Value, (int)nudCHA.Value), Saves = new Saves((int)nudFort.Value, (int)nudRef.Value, (int)nudWill.Value), Level = (int)nudLevel.Value, HitDie = (int)nudHD.Value, NaturalArmor = (int)nudNatural.Value, BAB = (int)nudBAB.Value, Grapple = (int)nudGrapple.Value, Size = size, Type = tbType.Text, Environment = tbEnvironment.Text, Space = tbSpace.Text, Reach = tbReach.Text, Movement = tbMovement.Text, Skills = rtbSkills.Text.Split(',').ToList(), Feats = tbFeats.Text.Split(',').ToList(), SpecAtks = tbSpecAtks.Text.Split(',').ToList(), SpecQual = tbSpecQual.Text.Split(',').ToList(), Notes = rtbCombat.Text.Split('\r').ToList(), Attacks = Summon.GetAttacks(rtbAttacks.Text), FullAttacks = Summon.GetFullAttacks(rtbFullAttacks.Text) }; Summons summons = Summons.Retrieve(Properties.Settings.Default.SummonsXML); int indexMatch = summons.FindIndex(x => x.Name.ToUpper() == addSummon.Name.ToUpper() && x.SummonSpell.ToUpper() == addSummon.SummonSpell.ToUpper()); if (indexMatch > -1) { if (MessageBox.Show("Summon of the same name and level already exists\rWould you like to add a duplicate?", "Spell already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { addSummon.Index = summons.Max(x => x.Index) + 1; summons.Add(addSummon); ClearSummonPage(); } } else { addSummon.Index = summons.Max(x => x.Index) + 1; summons.Add(addSummon); ClearSummonPage(); } summons.Save(Properties.Settings.Default.SummonsXML); RefreshSummonPage(); }