void newGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewGame frmNewGame = new FormNewGame())
            {
                DialogResult result = frmNewGame.ShowDialog();

                if (result == DialogResult.OK && frmNewGame.RolePlayingGame != null)
                {
                    FolderBrowserDialog folderDialog = new FolderBrowserDialog();

                    folderDialog.Description  = "Select folder to create game in.";
                    folderDialog.SelectedPath = Application.StartupPath;

                    DialogResult folderResult = folderDialog.ShowDialog();

                    if (folderResult == DialogResult.OK)
                    {
                        try
                        {
                            gamePath  = Path.Combine(folderDialog.SelectedPath, "Game");
                            classPath = Path.Combine(gamePath, "Classes");
                            itemPath  = Path.Combine(gamePath, "Items");
                            keyPath   = Path.Combine(gamePath, "Keys");
                            chestPath = Path.Combine(gamePath, "Chests");
                            skillPath = Path.Combine(gamePath, "Skills");

                            if (Directory.Exists(gamePath))
                            {
                                throw new Exception("Selected directory already exists.");
                            }

                            Directory.CreateDirectory(gamePath);
                            Directory.CreateDirectory(classPath);
                            Directory.CreateDirectory(itemPath + @"\Armor");
                            Directory.CreateDirectory(itemPath + @"\Shield");
                            Directory.CreateDirectory(itemPath + @"\Weapon");
                            Directory.CreateDirectory(keyPath);
                            Directory.CreateDirectory(chestPath);
                            Directory.CreateDirectory(skillPath);

                            rolePlayingGame = frmNewGame.RolePlayingGame;

                            XnaSerializer.Serialize <RolePlayingGame>(gamePath + @"\Game.xml",
                                                                      rolePlayingGame);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            return;
                        }

                        classesToolStripMenuItem.Enabled = true;
                        itemsToolStripMenuItem.Enabled   = true;
                        keysToolStripMenuItem.Enabled    = true;
                        chestsToolStripMenuItem.Enabled  = true;
                        skillsToolStripMenuItem.Enabled  = true;
                    }
                }
            }
        }
Beispiel #2
0
        void newGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewGame frmNewGame = new FormNewGame())
            {
                DialogResult result = frmNewGame.ShowDialog();

                if (result == DialogResult.OK && frmNewGame.RolePlayingGame != null)
                {
                    FolderBrowserDialog folderDialog = new FolderBrowserDialog();

                    folderDialog.Description = "Select directory to create folder in";
                    folderDialog.SelectedPath = Application.StartupPath;

                    DialogResult folderResult = folderDialog.ShowDialog();

                    if (folderResult == DialogResult.OK)
                    {
                        try
                        {
                            gamePath = Path.Combine(folderDialog.SelectedPath, "Game");
                            classPath = Path.Combine(gamePath, "Classes");
                            itemPath = Path.Combine(gamePath, "Items");
                            keyPath = Path.Combine(gamePath, "Keys");
                            chestPath = Path.Combine(gamePath, "Chests");
                            skillPath = Path.Combine(gamePath, "Skills");

                            if (Directory.Exists(gamePath))
                            {
                                throw new Exception("Folder already exists.");
                            }

                            Directory.CreateDirectory(gamePath);
                            Directory.CreateDirectory(classPath);
                            Directory.CreateDirectory(itemPath + @"\Armor");
                            Directory.CreateDirectory(itemPath + @"\Shield");
                            Directory.CreateDirectory(itemPath + @"\Weapon");
                            Directory.CreateDirectory(keyPath);
                            Directory.CreateDirectory(chestPath);
                            Directory.CreateDirectory(skillPath);

                            rolePlayingGame = frmNewGame.RolePlayingGame;
                            XnaSerializer.Serialize<RolePlayingGame>(gamePath + @"\Game.xml", rolePlayingGame);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            return;
                        }

                        classesToolStripMenuItem.Enabled = true;
                        itemsToolStripMenuItem.Enabled = true;
                        keysToolStripMenuItem.Enabled = true;
                        chestsToolStripMenuItem.Enabled = true;
                        skillsToolStripMenuItem.Enabled = true;
                    }
                }
            }
        }
Beispiel #3
0
        private void NewGameMenuItemClick(object sender, EventArgs e)
        {
            using (var newGameForm = new FormNewGame())
            {
                DialogResult result = newGameForm.ShowDialog();
                if (result != DialogResult.OK || newGameForm.RolePlayingGame == null)
                    return;

                var folderBrowser = new FolderBrowserDialog
                {
                    Description = "Select folder to create game in.",
                    SelectedPath = Application.StartupPath
                };

                result = folderBrowser.ShowDialog();

                if (result != DialogResult.OK)
                    return;

                try
                {
                    _rpg = newGameForm.RolePlayingGame;

                    _gamePath = Path.Combine(folderBrowser.SelectedPath, GameFolder);

                    if (Directory.Exists(_gamePath))
                    {
                        MessageBox.Show("Target directory already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    Directory.CreateDirectory(_gamePath);
                    Directory.CreateDirectory(ClassPath);
                    Directory.CreateDirectory(ArmorPath);
                    Directory.CreateDirectory(ShieldPath);
                    Directory.CreateDirectory(WeaponPath);
                    Directory.CreateDirectory(KeyPath);
                    Directory.CreateDirectory(ContainerPath);
                    Directory.CreateDirectory(SkillPath);

                    Serializer.Serialize(_rpg, GameFilePath);

                    ExportMenuItem.Enabled = true;
                    ClassesMenuItem.Enabled = true;
                    ItemsMenuItem.Enabled = true;
                    KeysMenuItem.Enabled = true;
                    ContainersMenuItem.Enabled = true;

                    SetTitle(_rpg.Name);
                    StatusBar.Text = _gamePath;
                }
                catch (IOException ex)
                {
                    MessageBox.Show(
                        "IO operation failed when creating game files. IOException thrown with message: " + ex.Message +
                        "\n\nStack Trace:\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }