示例#1
0
        private void btnQuickStart_Click(object sender, EventArgs e)
        {
            var status = new Status
            {
                Progress  = 0d,
                Message   = "Initializing",
                Exception = null,
            };

            string[] warnings = new string[0];
            Thread   t        = new Thread(new ThreadStart(() =>
            {
#if RELEASE
                try
                {
#endif
                bool doOrDie = true;
                if (Mod.Current == null)
                {
                    status.Message = "Loading mod";
                    Mod.Load(null, true, status, 0.5);
                    if (Mod.Errors.Any())
                    {
                        Action a = delegate()
                        {
                            doOrDie = this.ShowChildForm(new ModErrorsForm()) == System.Windows.Forms.DialogResult.OK;
                        };
                        this.Invoke(a);
                    }
                }
                if (doOrDie)
                {
                    status.Message = "Setting up game";
                    var setup      = GameSetup.Load(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "GameSetups", "Quickstart.gsu"));
                    warnings       = setup.Warnings.ToArray();
                    if (warnings.Any())
                    {
                        MessageBox.Show(warnings.First(), "Game Setup Error");
                    }
                    else
                    {
                        var dlg = new OpenFileDialog();
                        dlg.InitialDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Empires");
                        dlg.Filter           = "Empires (*.emp)|*.emp";
                        var result           = dlg.ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            // replace existing first player with selected empire
                            var et = EmpireTemplate.Load(dlg.FileName);
                            setup.EmpireTemplates.RemoveAt(0);
                            setup.EmpireTemplates.Insert(0, et);

                            // set race trait points to however many were spent
                            setup.EmpirePoints = et.PointsSpent;
                        }

                        status.Message = "Setting up galaxy";
                        Galaxy.Initialize(setup, null, status, 1.0);
                        var name       = Galaxy.Current.Name;
                        var turn       = Galaxy.Current.TurnNumber;
                        status.Message = "Loading game";
                        Galaxy.Load(name + "_" + turn + "_0001.gam");
                    }
                }
#if RELEASE
            }
                                                           catch (Exception ex)
            {
                status.Exception = ex;
            }
#endif
            }));

            t.Name = "Game Setup";
            t.SetApartmentState(ApartmentState.STA);

            this.ShowChildForm(new StatusForm(t, status));

            if (status.Exception == null && !warnings.Any())
            {
                Design.ImportFromLibrary();
                var game = new MainGameForm(false, true);
                this.ShowChildForm(game);
                game.FormClosed += (s, args) =>
                {
                    game.Dispose();
                    Show();
                };
                Hide();
            }
        }