Пример #1
0
        private void FavoriteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Spells spells     = Spells.Retrieve(Properties.Settings.Default.SpellsXML);
            Spell  thisSpell  = (Spell)((TreeView)((ContextMenuStrip)((ToolStripMenuItem)sender).GetCurrentParent()).SourceControl).SelectedNode.Tag; //((TreeView)((ContextMenuStrip)((ToolStripMenuItem)sender).GetCurrentParent().tvSpells).SelectedNode.Tag;
            int    indexMatch = spells.FindIndex(x => x.Name.ToUpper() == thisSpell.Name.ToUpper() && x.Level.ToUpper() == thisSpell.Level.ToUpper());

            if (indexMatch > -1)
            {
                if (spells[indexMatch].Favorited)
                {
                    spells[indexMatch].Favorited = false;
                }
                else if (!spells[indexMatch].Favorited)
                {
                    spells[indexMatch].Favorited = true;
                }
                else
                {
                    spells[indexMatch].Favorited = true;
                }

                spells.Save(Properties.Settings.Default.SpellsXML);
            }

            RefreshSpellPage(GetSpellNodesExpansion());
        }
Пример #2
0
        private void TvSpells_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                if (!File.Exists(Properties.Settings.Default.SpellsXML))
                {
                    MessageBox.Show("XML file was not found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (tvSpells.SelectedNode != null)
                {
                    if (tvSpells.SelectedNode.Tag is Spell selSpell)
                    {
                        if (MessageBox.Show(string.Format("Are you sure you want to delete {0} from this list?", ((Spell)tvSpells.SelectedNode.Tag).Name), "Delete Summon Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
                        {
                            Spells spells     = Spells.Retrieve(Properties.Settings.Default.SpellsXML);
                            int    indexMatch = spells.FindIndex(x => x.Name.ToUpper() == selSpell.Name.ToUpper() && x.Level.ToUpper() == selSpell.Level.ToUpper());

                            if (indexMatch > -1)
                            {
                                spells.RemoveAt(indexMatch);
                            }

                            spells.Save(Properties.Settings.Default.SpellsXML);
                            RefreshSpellPage(GetSpellNodesExpansion());
                        }
                    }
                }
            }
        }
Пример #3
0
        private void SaveSpellToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!File.Exists(Properties.Settings.Default.SpellsXML))
            {
                MessageBox.Show("XML file was not found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (sittingSpellID == 0)
            {
                MessageBox.Show("Spell does not exist.", "Spell Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                if (tbSpellName.Text == "")
                {
                    MessageBox.Show("Spell Name must be filled out", "Spell Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (!Regex.IsMatch(tbSpellLevel.Text, "[0-9]{1}"))
                {
                    MessageBox.Show("Spell Level must be a number 0 - 9", "Spell Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                Spell updateSpell = new Spell
                {
                    Index           = sittingSpellID,
                    Favorited       = chkFavoriteSpell.Checked,
                    Name            = tbSpellName.Text,
                    Class           = tbSpellClass.Text,
                    Level           = tbSpellLevel.Text,
                    Domain          = tbSpellDomain.Text,
                    Components      = tbSpellComponents.Text,
                    Casting         = tbSpellCastingTime.Text,
                    Range           = tbSpellRange.Text,
                    Target          = tbSpellTarget.Text,
                    Effect          = tbSpellEffect.Text,
                    Duration        = tbSpellDuration.Text,
                    SavingThrow     = tbSpellSaving.Text,
                    SpellResistance = tbSpellResistance.Text,
                    SourceBook      = tbSource.Text,
                    Description     = rtbSpellDescription.Text,
                    PersonalNotes   = rtbPersonalNotes.Text
                };

                Spells spells     = Spells.Retrieve(Properties.Settings.Default.SpellsXML);
                int    indexMatch = spells.FindIndex(x => x.Index == sittingSpellID);

                if (indexMatch > -1)
                {
                    spells[indexMatch] = updateSpell;
                }
                else
                {
                    MessageBox.Show("Spell cannot be found.", "Spell Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                spells.Save(Properties.Settings.Default.SpellsXML);
                RefreshSpellPage(GetSpellNodesExpansion());
            }
        }
Пример #4
0
        private void AddSpellToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!File.Exists(Properties.Settings.Default.SpellsXML))
            {
                MessageBox.Show("XML file was not found.", "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tbSpellName.Text == "")
            {
                MessageBox.Show("Spell Name must be filled out", "Spell Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!Regex.IsMatch(tbSpellLevel.Text, "[0-9]{1}"))
            {
                MessageBox.Show("Spell Level must be a number 0 - 9", "Spell Update Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Spell addSpell = new Spell
            {
                Favorited       = chkFavoriteSpell.Checked,
                Name            = tbSpellName.Text,
                Class           = tbSpellClass.Text,
                Level           = tbSpellLevel.Text,
                Domain          = tbSpellDomain.Text,
                Components      = tbSpellComponents.Text,
                Casting         = tbSpellCastingTime.Text,
                Range           = tbSpellRange.Text,
                Target          = tbSpellTarget.Text,
                Effect          = tbSpellEffect.Text,
                Duration        = tbSpellDuration.Text,
                SavingThrow     = tbSpellSaving.Text,
                SpellResistance = tbSpellResistance.Text,
                SourceBook      = tbSource.Text,
                Description     = rtbSpellDescription.Text,
                PersonalNotes   = rtbPersonalNotes.Text
            };

            Spells spells     = Spells.Retrieve(Properties.Settings.Default.SpellsXML);
            int    indexMatch = spells.FindIndex(x => x.Name.ToUpper() == addSpell.Name.ToUpper() && x.Level.ToUpper() == addSpell.Level.ToUpper());

            if (indexMatch > -1)
            {
                if (MessageBox.Show("Spell of the same name and level already exists\rWould you like to add a duplicate?", "Spell already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    addSpell.Index = spells.Max(x => x.Index) + 1;
                    spells.Add(addSpell);
                    ClearSpellPage();
                }
            }
            else
            {
                addSpell.Index = spells.Max(x => x.Index) + 1;
                spells.Add(addSpell);
                ClearSpellPage();
            }
            rtbSpellText.Clear();
            spells.Save(Properties.Settings.Default.SpellsXML);
            RefreshSpellPage(GetSpellNodesExpansion());
        }