Exemplo n.º 1
0
		/// <summary>
		/// Load a Character and open the correct window.
		/// </summary>
		/// <param name="strFileName">File to load.</param>
		/// <param name="blnIncludeInMRU">Whether or not the file should appear in the MRU list.</param>
		/// <param name="strNewName">New name for the character.</param>
		/// <param name="blnClearFileName">Whether or not the name of the save file should be cleared.</param>
		public void LoadCharacter(string strFileName, bool blnIncludeInMRU = true, string strNewName = "", bool blnClearFileName = false)
		{
			if (File.Exists(strFileName) && strFileName.EndsWith("chum5"))
			{
				Timekeeper.Start("loading");
				bool blnLoaded = false;
				Character objCharacter = new Character();
				objCharacter.FileName = strFileName;
				Timekeeper.Start("load_file");
				blnLoaded = objCharacter.Load();
				Timekeeper.Finish("load_file");
				Timekeeper.Start("load_free");
				if (!blnLoaded)
					return;

				// If a new name is given, set the character's name to match (used in cloning).
				if (strNewName != "")
					objCharacter.Name = strNewName;
				// Clear the File Name field so that this does not accidentally overwrite the original save file (used in cloning).
				if (blnClearFileName)
					objCharacter.FileName = "";

				// Show the character form.
				if (!objCharacter.Created)
				{
					frmCreate frmCharacter = new frmCreate(objCharacter);
					frmCharacter.MdiParent = this;
					frmCharacter.WindowState = FormWindowState.Maximized;
					frmCharacter.Loading = true;
					frmCharacter.Show();
				}
				else
				{
					frmCareer frmCharacter = new frmCareer(objCharacter);
					frmCharacter.MdiParent = this;
					frmCharacter.WindowState = FormWindowState.Maximized;
					frmCharacter.Loading = true;
					frmCharacter.DiceRollerOpened += objCareer_DiceRollerOpened;
					frmCharacter.DiceRollerOpenedInt += objCareer_DiceRollerOpenedInt;
					frmCharacter.Show();
				}

				if (blnIncludeInMRU)
					GlobalOptions.Instance.AddToMRUList(strFileName);

				objCharacter.CharacterNameChanged += objCharacter_CharacterNameChanged;
				objCharacter_CharacterNameChanged(objCharacter);
			}
			else
			{
				MessageBox.Show(LanguageManager.Instance.GetString("Message_FileNotFound").Replace("{0}", strFileName), LanguageManager.Instance.GetString("MessageTitle_FileNotFound"), MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
Exemplo n.º 2
0
        /// <summary>
        /// Save the Character using the Save As dialogue box.
        /// </summary>
        private bool SaveCharacterAs(bool blnEscapeAfterSave = false)
        {
            bool blnSaved = false;

            // If the Created is checked, make sure the user wants to actually save this character.
            if (chkCharacterCreated.Checked)
            {
                if (!ConfirmSaveCreatedCharacter())
                {
                    chkCharacterCreated.Checked = false;
                    return false;
                }
            }

            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Chummer Files (*.chum)|*.chum|All Files (*.*)|*.*";

            string strShowFileName = "";
            string[] strFile = _objCharacter.FileName.Split(Path.DirectorySeparatorChar);
            strShowFileName = strFile[strFile.Length - 1];

            if (strShowFileName == "")
                strShowFileName = _objCharacter.Alias;

            saveFileDialog.FileName = strShowFileName;

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string strFileName = saveFileDialog.FileName;
                _objCharacter.FileName = strFileName;
                _objCharacter.Save();
                _blnIsDirty = false;
                blnSaved = true;
                GlobalOptions.Instance.AddToMRUList(_objCharacter.FileName);
            }
            if (blnEscapeAfterSave)
                return blnSaved;
            UpdateWindowTitle(false);

            // If this character has just been saved as Created, close this form and re-open the character which will open it in the Career window instead.
            if (blnSaved && chkCharacterCreated.Checked)
            {
                // If the character was built with Karma, record their staring Karma amount (if any).
                if (_objCharacter.BuildMethod == CharacterBuildMethod.Karma)
                {
                    if (_objCharacter.Karma > 0)
                    {
                        ExpenseLogEntry objKarma = new ExpenseLogEntry();
                        objKarma.Create(_objCharacter.Karma, "Starting Karma", ExpenseType.Karma, DateTime.Now);
                        _objCharacter.ExpenseEntries.Add(objKarma);
                    }
                }

                // Create an Expense Entry for Starting Nuyen.
                ExpenseLogEntry objNuyen = new ExpenseLogEntry();
                objNuyen.Create(_objCharacter.Nuyen, "Starting Nuyen", ExpenseType.Nuyen, DateTime.Now);
                _objCharacter.ExpenseEntries.Add(objNuyen);
                _blnSkipToolStripRevert = true;

                frmCareer frmCharacter = new frmCareer(_objCharacter);
                frmCharacter.MdiParent = this.MdiParent;
                frmCharacter.WindowState = FormWindowState.Maximized;
                frmCharacter.Loading = true;
                frmCharacter.Show();
                this.Close();
            }

            return blnSaved;
        }