Exemplo n.º 1
0
        /// <summary>
        /// Saves a specific tab to specified location.
        /// </summary>
        /// <param name="tab">Tab to save</param>
        /// <param name="path">Path of the location to save the tab to</param>
        public void Save(PlayerTab tab, string path)
        {
            mainWindow.focusDummy.Focus();

            bottomStatusBar.SetText("Saving...");

            try {
                BackupFile(path);

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

                PlayerDataFile playerDataFile = tab.playerDataFile.Clone();

                PostProcess(playerDataFile);

                playerDataFile.Write(path);

                tab.path     = path;
                tab.fileName = path.Substring(path.LastIndexOf('\\') + 1);

                MessageBox.Show(string.Format("File {0} saved!", path.Substring(path.LastIndexOf('\\') + 1)), "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception e) {
                ErrorHandler.HandleError(string.Format("Failed to save file {0}. {1}", path.Substring(path.LastIndexOf('\\') + 1), e.Message), e, true, tab.path);
            }

            bottomStatusBar.Reset();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens a file.
        /// </summary>
        /// <param name="fileName">File to open</param>
        /// <param name="playerDataFile">Holds all the ttp info of a file</param>
        /// <param name="selectedIndex">Tab index to be selected after opening</param>
        private void OpenFile(string fileName, PlayerDataFile playerDataFile, int selectedIndex)
        {
            ItemStack[] inventory = playerDataFile.inventory;
            ItemStack[] bag       = playerDataFile.bag;

            List <string> devItems = new List <string>();

            for (int i = 0; i < bag.Length; i++)
            {
                ItemData devItem = ItemData.GetDevItemById(bag[i].itemValue.type.Get());
                if (devItem != null)
                {
                    devItems.Add(string.Format("{0} at position: row {1}, column {2}\n", devItem.name, (i / 8) + 1, (i % 8) + 1));
                }
            }

            for (int i = 0; i < inventory.Length; i++)
            {
                ItemData devItem = ItemData.GetDevItemById(inventory[i].itemValue.type.Get());
                if (devItem != null)
                {
                    devItems.Add(string.Format("{0} at position: row 5, column {1}\n", devItem.name, i + 1));
                }
            }

            if (devItems.Count == 0)
            {
                try {
                    PlayerTab tab = new PlayerTab(playerDataFile, fileName, selectedIndex);
                    playerTabControl.AddTab(tab);
                }
                catch (Exception e) {
                    ErrorHandler.HandleError(string.Format("Failed to open file {0}. {1}", fileName, e.Message), e, true, fileName);
                }
            }
            else
            {
                // Split the full path into an array where the last element will be the short filename
                string[] fullPathFileNameArray = fileName.Split('\\');

                // Capture the short filename from the last element of the array
                string shortFileName = fullPathFileNameArray[fullPathFileNameArray.Length - 1];
                string text          = string.Format("Player file {0} has the following developer items in their inventory:\n\n", shortFileName);

                for (int i = 0; i < devItems.Count; i++)
                {
                    text += devItems[i] + "\n";
                }

                text += "\nPlease remove these items before continuing.";

                MessageBox.Show(text, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reloads a tab. Useful for testing.
        /// </summary>
        /// <param name="tab">Tab to reload</param>
        public void Reload(PlayerTab tab)
        {
            bottomStatusBar.SetText("Reloading...");

            string path          = tab.path;
            int    selectedIndex = tab.ttpFileTabControl.SelectedIndex;

            playerTabControl.TabPages.Remove(tab);
            OpenFile(path, new PlayerDataFile(path), selectedIndex);

            bottomStatusBar.Reset();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Closes a specific tab.
        /// </summary>
        /// <param name="tab">Tab to close</param>
        public void Close(PlayerTab tab)
        {
            DialogResult result = MessageBox.Show(string.Format("Do you wish to save file {0} before closing?", tab.fileName), "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            switch (result)
            {
            case DialogResult.Yes:
                Save(tab);
                playerTabControl.TabPages.Remove(tab);
                break;

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

            default:
                break;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Saves a specific tab.
 /// </summary>
 /// <param name="tab">Tab to save</param>
 public void Save(PlayerTab tab)
 {
     Save(tab, tab.path);
 }
 /// <summary>
 /// Adds a tab.
 /// </summary>
 /// <param name="tab">Tab to add</param>
 public void AddTab(PlayerTab tab)
 {
     Controls.Add(tab);
 }