Ejemplo n.º 1
0
        /// <summary>
        /// Save the Character.
        /// </summary>
        public virtual bool SaveCharacter(bool blnNeedConfirm = true, bool blnDoCreated = false)
        {
            // If the Character does not have a file name, trigger the Save As menu item instead.
            if (string.IsNullOrEmpty(_objCharacter.FileName))
            {
                return(SaveCharacterAs());
            }
            // If the Created is checked, make sure the user wants to actually save this character.
            if (blnDoCreated)
            {
                if (blnNeedConfirm && !ConfirmSaveCreatedCharacter())
                {
                    return(false);
                }
            }

            Cursor = Cursors.WaitCursor;
            if (_objCharacter.Save())
            {
                _blnIsDirty = false;
                GlobalOptions.AddToMRUList(_objCharacter.FileName, "mru", true, true);
                UpdateWindowTitle(false);
                Cursor = Cursors.Default;

                // 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 (blnDoCreated)
                {
                    SaveCharacterAsCreated();
                }

                return(true);
            }
            Cursor = Cursors.Default;
            return(false);
        }
Ejemplo n.º 2
0
        private void tsToggleFav_Click(object sender, EventArgs e)
        {
            TreeNode t = treCharacterList.SelectedNode;

            if (t == null)
            {
                return;
            }
            if (int.TryParse(t.Tag.ToString(), out var intCharacterIndex) && intCharacterIndex >= 0 && intCharacterIndex < _lstCharacterCache.Count)
            {
                CharacterCache objCache = _lstCharacterCache[intCharacterIndex];

                if (objCache == null)
                {
                    return;
                }
                switch (t.Parent.Tag.ToString())
                {
                case "Recent":
                    GlobalOptions.RemoveFromMRUList(objCache.FilePath, "mru", false);
                    GlobalOptions.AddToMRUList(objCache.FilePath, "stickymru");
                    break;

                case "Favourite":
                    GlobalOptions.RemoveFromMRUList(objCache.FilePath, "stickymru", false);
                    GlobalOptions.AddToMRUList(objCache.FilePath);
                    break;

                case "Watch":
                    GlobalOptions.AddToMRUList(objCache.FilePath, "stickymru");
                    break;
                }
                treCharacterList.SelectedNode = t;
            }
        }
Ejemplo n.º 3
0
        private void treCharacterList_DragDrop(object sender, DragEventArgs e)
        {
            // Do not allow the root element to be moved.
            if (treCharacterList.SelectedNode == null || treCharacterList.SelectedNode.Level == 0 || treCharacterList.SelectedNode.Parent.Tag.ToString() == "Watch")
            {
                return;
            }

            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                TreeView treSenderView = sender as TreeView;
                if (treSenderView == null)
                {
                    return;
                }
                Point    pt = treSenderView.PointToClient(new Point(e.X, e.Y));
                TreeNode nodDestinationNode = treSenderView.GetNodeAt(pt);
                if (nodDestinationNode.Level > 0)
                {
                    nodDestinationNode = nodDestinationNode.Parent;
                }
                string strDestinationNode = nodDestinationNode.Tag.ToString();
                if (strDestinationNode != "Watch")
                {
                    TreeNode nodNewNode = e.Data.GetData("System.Windows.Forms.TreeNode") as TreeNode;
                    if (nodNewNode == null)
                    {
                        return;
                    }

                    if (nodNewNode.Level == 0 || nodNewNode.Parent == nodDestinationNode)
                    {
                        return;
                    }
                    if (int.TryParse(nodNewNode.Tag.ToString(), out int intCharacterIndex) && intCharacterIndex >= 0 && intCharacterIndex < _lstCharacterCache.Count)
                    {
                        CharacterCache objCache = _lstCharacterCache[intCharacterIndex];

                        if (objCache == null)
                        {
                            return;
                        }
                        switch (strDestinationNode)
                        {
                        case "Recent":
                            GlobalOptions.RemoveFromMRUList(objCache.FilePath, "stickymru", false);
                            GlobalOptions.AddToMRUList(objCache.FilePath);
                            break;

                        case "Favourite":
                            GlobalOptions.RemoveFromMRUList(objCache.FilePath, "mru", false);
                            GlobalOptions.AddToMRUList(objCache.FilePath, "stickymru");
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void mnuStickyMRU_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                string strFileName = ((ToolStripMenuItem)sender).Text;

                GlobalOptions.RemoveFromMRUList(strFileName, "stickymru", false);
                GlobalOptions.AddToMRUList(strFileName);
            }
        }
Ejemplo n.º 5
0
        private void mnuMRU_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                string strFileName = ((ToolStripMenuItem)sender).Text;
                strFileName = strFileName.Substring(3, strFileName.Length - 3).Trim();

                GlobalOptions.RemoveFromMRUList(strFileName);
                GlobalOptions.AddToMRUList(strFileName, "stickymru");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Open the correct windows for a list of characters (not thread-safe).
        /// </summary>
        /// <param name="lstCharacters">Characters for which windows should be opened.</param>
        public void OpenCharacterList(IEnumerable <Character> lstCharacters, bool blnIncludeInMRU = true)
        {
            if (lstCharacters == null)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            foreach (Character objCharacter in lstCharacters)
            {
                if (objCharacter == null)
                {
                    continue;
                }
                Timekeeper.Start("load_event_time");
                // Show the character form.
                if (!objCharacter.Created)
                {
                    frmCreate frmCharacter = new frmCreate(objCharacter)
                    {
                        MdiParent   = this,
                        WindowState = FormWindowState.Maximized,
                        Loading     = true
                    };
                    frmCharacter.Show();
                }
                else
                {
                    frmCareer frmCharacter = new frmCareer(objCharacter)
                    {
                        MdiParent   = this,
                        WindowState = FormWindowState.Maximized,
                        Loading     = true
                    };
                    frmCharacter.DiceRollerOpened    += objCareer_DiceRollerOpened;
                    frmCharacter.DiceRollerOpenedInt += objCareer_DiceRollerOpenedInt;
                    frmCharacter.Show();
                }

                if (blnIncludeInMRU)
                {
                    GlobalOptions.AddToMRUList(objCharacter.FileName);
                }

                objCharacter.CharacterNameChanged += objCharacter_CharacterNameChanged;
                objCharacter_CharacterNameChanged(objCharacter);
                Timekeeper.Finish("load_event_time");
            }

            Cursor = Cursors.Default;
        }
Ejemplo n.º 7
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");
                Cursor.Current = Cursors.WaitCursor;
                bool      blnLoaded    = false;
                Character objCharacter = new Character();
                objCharacter.FileName = strFileName;

                XmlDocument objXmlDocument = new XmlDocument();
                //StreamReader is used to prevent encoding errors
                using (StreamReader sr = new StreamReader(strFileName, true))
                {
                    try
                    {
                        objXmlDocument.Load(sr);
                    }
                    catch (XmlException ex)
                    {
                        MessageBox.Show(LanguageManager.GetString("Message_FailedLoad").Replace("{0}", ex.Message), LanguageManager.GetString("MessageTitle_FailedLoad"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                XmlNode objXmlCharacter = objXmlDocument.SelectSingleNode("/character");
                if (!string.IsNullOrEmpty(objXmlCharacter?["appversion"]?.InnerText))
                {
                    Version verSavedVersion;
                    Version verCorrectedVersion;
                    string  strVersion = objXmlCharacter["appversion"].InnerText;
                    if (strVersion.StartsWith("0."))
                    {
                        strVersion = strVersion.Substring(2);
                    }
                    Version.TryParse(strVersion, out verSavedVersion);
                    Version.TryParse("5.188.34", out verCorrectedVersion);
                    if (verCorrectedVersion != null && verSavedVersion != null)
                    {
                        int intResult = verSavedVersion.CompareTo(verCorrectedVersion);
                        //Check for typo in Corrupter quality and correct it
                        if (intResult == -1)
                        {
                            File.WriteAllText(strFileName, Regex.Replace(File.ReadAllText(strFileName), "Corruptor", "Corrupter"));
                        }
                    }
                }

                Timekeeper.Start("load_file");
                blnLoaded = objCharacter.Load();
                Timekeeper.Finish("load_file");
                Timekeeper.Start("load_free");
                if (!blnLoaded)
                {
                    Cursor.Current = Cursors.Default;
                    return;
                }

                // If a new name is given, set the character's name to match (used in cloning).
                if (!string.IsNullOrEmpty(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 = string.Empty;
                }

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

                if (blnIncludeInMRU)
                {
                    GlobalOptions.AddToMRUList(strFileName);
                }

                objCharacter.CharacterNameChanged += objCharacter_CharacterNameChanged;
                objCharacter_CharacterNameChanged(objCharacter);
                Cursor.Current = Cursors.Default;
            }
            else
            {
                MessageBox.Show(LanguageManager.GetString("Message_FileNotFound").Replace("{0}", strFileName), LanguageManager.GetString("MessageTitle_FileNotFound"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }