public void close(TabPlayer tab)
        {
            DialogResult result = MessageBox.Show("Do you wish to save file " + tab.fileName + " before closing?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            switch (result)
            {
                case DialogResult.Yes:
                    save(tab);
                    tabs.TabPages.Remove(tab);
                    break;

                case DialogResult.No:
                    tabs.TabPages.Remove(tab);
                    break;

                default:
                    break;
            }
        }
Esempio n. 2
0
 public void addTab(TabPlayer tab)
 {
     Controls.Add(tab);
 }
        private void save(TabPlayer tab)
        {
            statusBar.setText("Saving...");

            bool success = false;
            string name = tab.fileName;
            string path = tab.path;

            try
            {
                backupFile(path);

                if (!name.EndsWith(".ttp"))
                {
                    name += ".ttp";
                }

                //NEED TO CHECK SKILLS TO REMOVE DEFAULTS!!!
                PlayerDataFile copy = tab.playerDataFile.clone();
                Dictionary<int, Skill> newSkillDictionary = new Dictionary<int, Skill>();

                foreach (int key in copy.skills.skillDictionary.Keys)
                {
                    Skill skill = null;
                    copy.skills.skillDictionary.TryGetValue(key, out skill);

                    if (!BinderSkill.isDefaultValues(skill))
                    {
                        newSkillDictionary.Add(key, skill);
                    }
                }

                copy.skills.skillDictionary = newSkillDictionary;

                copy.Write(path);

                success = true;
            }

            catch (Exception e)
            {
                Log.writeError(e);
                MessageBox.Show("Failed to save file " + name + ". " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            statusBar.reset();

            if (success)
            {
                MessageBox.Show("File " + tab.fileName + " saved!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }