private void okButton_Click(object sender, EventArgs e)
        {
            settings = new Settings();
            List <string> directories = new List <string>();

            StatBlockPath          = statPathBox.Text; directories.Add(StatBlockPath);
            AutoSavePath           = autoPathBox.Text; directories.Add(AutoSavePath);
            LogPath                = logPathBox.Text; directories.Add(LogPath);
            NotesPath              = notesPathBox.Text; directories.Add(NotesPath);
            settings.initEachRound = initOption;
            settings.confirmCrits  = critConfirmBox.Checked;
            settings.brianMode     = brianBox.Checked;

            BattleIO saver = new BattleIO();

            if (saver.ValidateFilePaths(directories))
            {
                settings.UserStatBlockDirectory = StatBlockPath;
                settings.UserAutoSaveDirectory  = AutoSavePath;
                settings.UserLogDirectory       = LogPath;
                settings.UserNotesDirectory     = NotesPath;
                settings.UserSessionDirectory   = SessionPath;
                saver.SaveAutoSettings(settings);
                sendingForm.session.settings = this.settings;
                sendingForm.SetBrianMode();
                this.Close();
            }
            else
            {
                MessageBox.Show("One or more filepaths are invalid. Please make sure all filepaths exist before clicking OK", "Error");
            }
        }
Esempio n. 2
0
        private void LoadButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog load        = new OpenFileDialog();
            string         initialPath = Program.defaultPath + @"\Stat Blocks";

            if (mostRecentPath != "")
            {
                initialPath = mostRecentPath;
            }
            else
            {
                if (parent.session.settings.UserStatBlockDirectory != "")
                {
                    initialPath = parent.session.settings.UserStatBlockDirectory;
                }
            }

            if (!Directory.Exists(initialPath))
            {
                Directory.CreateDirectory(initialPath);
            }
            load.InitialDirectory = initialPath;
            DialogResult confirm = load.ShowDialog();

            if (confirm == DialogResult.OK)
            {
                BattleIO loader     = new BattleIO();
                Fighter  newFighter = loader.LoadStatBlock(load.FileName);

                savePath = load.FileName;

                mostRecentPath = Path.GetDirectoryName(load.FileName);
                LoadFighter(load.FileName);
            }
        }
Esempio n. 3
0
        public void SaveSettings(string path)
        {
            saver = new BattleIO();
            string settingsName = Path.GetDirectoryName(path) + @"\" + Path.GetFileNameWithoutExtension(FilePath) + "_settings.xml";

            saver.SaveObject <Settings>(settings, settingsName);
        }
        public void addDPercentTable(DPercentTable add)
        {
            int dupCount = 0;

            foreach (DPercentTable table in tables)
            {
                if (table.Name == add.Name)
                {
                    dupCount++;
                }
            }
            if (dupCount > 0)
            {
                add.Name += " " + (dupCount + 1).ToString();
            }
            tables.Add(add);
            UpdateTableList();
            tableList.SelectedItem  = add.Name;
            button1.Enabled         = true;
            button2.Enabled         = true;
            npcAttackButton.Enabled = true;

            BattleIO auto = new BattleIO();

            auto.AutoSaveDPercentList(tables, Program.activeSettings);
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (selectedTable != null)
     {
         DialogResult result = MessageBox.Show("Remove " + selectedTable.Name + "?", "Delete Table", MessageBoxButtons.YesNo);
         if (result == DialogResult.Yes)
         {
             int nextIndex = tables.IndexOf(selectedTable) - 1;
             if (nextIndex < 0)
             {
                 nextIndex = 0;
             }
             tables.Remove(selectedTable);
             selectedTable = new DPercentTable();
             UpdateTableList();
             UpdateResultsTable();
             if (nextIndex < tables.Count)
             {
                 tableList.SelectedItem = tables.ElementAt(nextIndex).Name;
             }
             BattleIO auto = new BattleIO();
             auto.AutoSaveDPercentList(tables, Program.activeSettings);
         }
     }
     if (tables.Count <= 0)
     {
         button1.Enabled         = false;
         button2.Enabled         = false;
         npcAttackButton.Enabled = false;
     }
 }
Esempio n. 6
0
 public SessionController(MainWindow sender)
 {
     isDirty     = false;
     saver       = new BattleIO();
     settings    = new Settings();
     sendingForm = sender;
     startFolder = "";
 }
        public void AutoSave()
        {
            BattleIO auto = new BattleIO();

            if (tables != null)
            {
                auto.AutoSaveDPercentList(tables, Program.activeSettings);
            }
        }
Esempio n. 8
0
        public void LoadSession()
        {
            if (isDirty)
            {
                if (!Exit())
                {
                    return;
                }
            }
            OpenFileDialog load = new OpenFileDialog();

            if (startFolder != "")
            {
                load.InitialDirectory = startFolder;
            }

            load.Filter = "Session File (*.ssn)|*.ssn";
            DialogResult result = load.ShowDialog();

            FilePath = load.FileName;
            SessionDetail.FilePath = load.FileName;

            if (result == DialogResult.OK)
            {
                if (File.Exists(FilePath))
                {
                    saver = new BattleIO();
                    SessionDetail newParent = saver.LoadObject <SessionDetail>(FilePath);
                    if (newParent == null)
                    {
                        sendingForm.WriteToLog("Load failed. Invalid file loaded.");
                    }
                    else
                    {
                        sendingForm.ExtractFields(newParent);
                        if (newParent.combatants.Count > 0)
                        {
                            sendingForm.enableGlobalButtons(); sendingForm.enableTurnButtons();
                        }
                        else
                        {
                            sendingForm.ResetControls();
                        }

                        sendingForm.WriteToLog("===============  SESSION LOADED ON " + DateTime.Now + " ===============");
                        startFolder = Path.GetDirectoryName(FilePath);
                        Program.activeSessionName = Path.GetFileName(FilePath);
                        sendingForm.Text          = Program.ProgramName + " - " + Path.GetFileName(FilePath);

                        isDirty = false;
                    }
                }
            }
        }
Esempio n. 9
0
        private void fileList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (fileList.SelectedIndices.Count > 0)
            {
                int candidateIndex = fileList.SelectedIndices[0];


                if (candidateIndex < notes.Count)
                {
                    if (isDirty)
                    {
                        string title = titleBox.Text;
                        if (title == "")
                        {
                            title = "untitled.txt";
                        }
                        DialogResult result = MessageBox.Show("Save changes to " + title + "?", "Save?", MessageBoxButtons.YesNoCancel);

                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }
                        else if (result == DialogResult.No)
                        {
                            mainTextField.Text = notes.ElementAt(candidateIndex);
                            titleBox.Text      = fileList.SelectedItems[0].Text;
                            isDirty            = false;
                        }
                        else
                        {
                            BattleIO save    = new BattleIO();
                            string   newPath = save.SaveNoteAs(mainTextField.Text);
                            if (newPath != "")
                            {
                                if (!recentPaths.Contains(newPath))
                                {
                                    UpdatePathList(Path.GetDirectoryName(newPath));
                                }
                                mainTextField.Text = notes.ElementAt(candidateIndex);
                                titleBox.Text      = fileList.SelectedItems[0].Text;
                                isDirty            = false;
                            }
                        }
                    }
                    else
                    {
                        mainTextField.Text = notes.ElementAt(candidateIndex);
                        titleBox.Text      = fileList.SelectedItems[0].Text;
                        isDirty            = false;
                    }
                }
            }
        }
Esempio n. 10
0
        private void Save(Fighter newFighter)
        {
            SaveFileDialog save = new SaveFileDialog();

            save.DefaultExt = ".bin";
            string initialPath = Program.defaultPath + @"\Stat Blocks";

            if (mostRecentPath != "")
            {
                initialPath = mostRecentPath;
            }
            else
            {
                if (parent.session.settings.UserStatBlockDirectory != "")
                {
                    initialPath = parent.session.settings.UserStatBlockDirectory;
                }
            }

            if (!Directory.Exists(initialPath))
            {
                Directory.CreateDirectory(initialPath);
            }
            save.InitialDirectory = initialPath;


            if (newFighter != null)
            {
                if (!saved)
                {
                    DialogResult confirm = save.ShowDialog();
                    if (confirm == DialogResult.OK)
                    {
                        savePath = save.FileName;
                        BattleIO saver = new BattleIO();
                        saver.SaveStatBlock(savePath, newFighter);
                        saved          = true;
                        mostRecentPath = Path.GetDirectoryName(save.FileName);
                    }
                }
                else
                {
                    BattleIO saver = new BattleIO();
                    saver.SaveStatBlock(savePath, newFighter);
                }
            }
        }
Esempio n. 11
0
        private void Save(bool SaveAs)
        {
            if (SaveAs)
            {
                BattleIO save    = new BattleIO();
                string   newPath = save.SaveNoteAs(mainTextField.Text);
                if (newPath != "")
                {
                    if (!recentPaths.Contains(newPath))
                    {
                        UpdatePathList(Path.GetDirectoryName(newPath));
                        LoadFiles(Path.GetDirectoryName(newPath));
                    }
                }
                isDirty = false;
            }
            else
            {
                string newPath = filePath + @"\" + titleBox.Text;
                if (newPath.Split('.').Length > 1)
                {
                    if (newPath.Split('.').Last <string>() != "txt")
                    {
                        newPath += ".txt";
                    }
                }
                if (Directory.GetFiles(filePath).Contains(newPath))
                {
                    BattleIO save = new BattleIO();
                    save.SaveNote(mainTextField.Text, newPath);
                    LoadFiles(Path.GetDirectoryName(newPath));
                }
                else
                {
                    BattleIO save = new BattleIO();
                    newPath = save.SaveNoteAs(mainTextField.Text);
                    if (!recentPaths.Contains(newPath) && newPath != "")
                    {
                        UpdatePathList(Path.GetDirectoryName(newPath));
                        LoadFiles(Path.GetDirectoryName(newPath));
                    }
                }

                isDirty = false;
            }
        }
Esempio n. 12
0
        private string LoadNote(string path)
        {
            if (isDirty)
            {
                string title = titleBox.Text;
                if (title == "")
                {
                    title = "untitled.txt";
                }
                DialogResult result = MessageBox.Show("Save changes to " + title + "?", "Save?", MessageBoxButtons.YesNoCancel);

                if (result == DialogResult.Cancel)
                {
                    return("");
                }
                else if (result == DialogResult.No)
                {
                    BattleIO load   = new BattleIO();
                    string   output = load.LoadNote(path);
                    return(output);
                }
                else
                {
                    BattleIO save    = new BattleIO();
                    string   newPath = save.SaveNoteAs(mainTextField.Text);

                    if (newPath != "")
                    {
                        BattleIO load   = new BattleIO();
                        string   output = load.LoadNote(path);
                        return(output);
                    }
                    else
                    {
                        return("");
                    }
                }
            }
            else
            {
                BattleIO load   = new BattleIO();
                string   output = load.LoadNote(path);
                return(output);
            }
        }
Esempio n. 13
0
        private void newNoteButton_Click(object sender, EventArgs e)
        {
            if (isDirty)
            {
                string title = titleBox.Text;
                if (title == "")
                {
                    title = "untitled.txt";
                }
                DialogResult result = MessageBox.Show("Save changes to " + title + "?", "Save?", MessageBoxButtons.YesNoCancel);

                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else if (result == DialogResult.No)
                {
                    mainTextField.Clear();
                    titleBox.Clear();
                    isDirty = false;
                }
                else
                {
                    BattleIO save    = new BattleIO();
                    string   newPath = "";
                    newPath = save.SaveNoteAs(mainTextField.Text);
                    if (newPath != "")
                    {
                        if (!recentPaths.Contains(newPath))
                        {
                            UpdatePathList(Path.GetDirectoryName(newPath));
                        }
                    }
                    mainTextField.Clear();
                    titleBox.Clear();
                    isDirty = false;
                }
            }
            else
            {
                mainTextField.Clear();
                titleBox.Clear();
                isDirty = false;
            }
        }
Esempio n. 14
0
        private bool Save()
        {
            SaveFileDialog saveBox = new SaveFileDialog();

            saveBox.Filter = "Session File (*.ssn)|*.ssn";
            if (startFolder != "")
            {
                saveBox.InitialDirectory = startFolder;
            }
            saveBox.FileName = Program.activeSessionName;
            DialogResult result = saveBox.ShowDialog();

            if (result == DialogResult.OK)
            {
                saver       = new BattleIO();
                FilePath    = saveBox.FileName;
                startFolder = Path.GetDirectoryName(FilePath);
                Program.activeSessionName = Path.GetFileName(FilePath);
                SessionDetail sessionData = new SessionDetail();
                sessionData.CopySessionFieldsFromWindow(sendingForm, Program.activeSessionName);
                //List<SerializableObject> saveableData = SerializableObject.PackageObjectList(sessionData);
                if (saver.SaveObject <SessionDetail>(sessionData, FilePath))
                {
                    sendingForm.WriteToLog("Session Saved as \"" + FilePath + "\"");

                    SaveSettings(FilePath);
                    isDirty          = false;
                    sendingForm.Text = Program.ProgramName + " - " + Path.GetFileName(FilePath);
                    return(true);
                }
                else
                {
                    sendingForm.WriteToLog("Save failed. Check the log for details.");
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 15
0
 public void SaveSession(bool SaveAs)
 {
     if (FilePath == null)
     {
         FilePath = SessionDetail.FilePath;
     }
     if (File.Exists(FilePath) && !SaveAs)
     {
         SessionDetail sessionData = new SessionDetail();
         sessionData.CopySessionFieldsFromWindow(sendingForm, Program.activeSessionName);
         saver = new BattleIO();
         saver.SaveObject <SessionDetail>(sessionData, FilePath);
         sendingForm.WriteToLog("Session Saved as \"" + FilePath + "\"");
         sendingForm.Text = Program.ProgramName + " - " + Program.activeSessionName;
         isDirty          = false;
     }
     else
     {
         Save();
     }
 }
Esempio n. 16
0
        private void LoadFighter(string path)
        {
            BattleIO loader     = new BattleIO();
            Fighter  newFighter = loader.LoadStatBlock(path);

            savePath = path;

            mostRecentPath        = Path.GetDirectoryName(path);
            userPopulated         = false;
            nameBox.Text          = newFighter.Name;
            HPValBox.Text         = newFighter.HP.ToString();
            multBox.Text          = newFighter.HPMult.ToString();
            addBox.Text           = newFighter.HPAdd.ToString();
            dBox.Text             = newFighter.HPDieType.ToString();
            ACValBox.Text         = newFighter.AC.ToString();
            FFBox.Text            = newFighter.FlatFootedAC.ToString();
            touchBox.Text         = newFighter.TouchAC.ToString();
            InitBox.Text          = newFighter.InitBonus.ToString();
            CMBBox.Text           = newFighter.CMB.ToString();
            CMDBox.Text           = newFighter.CMD.ToString();
            fortBox.Text          = newFighter.fort.ToString();
            refBox.Text           = newFighter.reflex.ToString();
            willBox.Text          = newFighter.will.ToString();
            attacks               = newFighter.attacks;
            attackCountLabel.Text = newFighter.attacks.Count + " attacks.";
            skillCountLabel.Text  = newFighter.skills.Count + " skills.";
            skillList             = newFighter.skills;
            strBox.Text           = newFighter.Str.ToString();
            dexBox.Text           = newFighter.Dex.ToString();
            conBox.Text           = newFighter.Con.ToString();
            intBox.Text           = newFighter.Int.ToString();
            wisBox.Text           = newFighter.Wis.ToString();
            chaBox.Text           = newFighter.Cha.ToString();
            srBox.Text            = newFighter.SpellResist.ToString();
            drBox.Text            = newFighter.DamageReduce.ToString();
            bioBox.Text           = newFighter.Notes;
            userPopulated         = true;
            saved = true;
        }