private void gamesListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gamesListBox.SelectedIndex != -1)
            {
                ulong sizeInBytes;

                WorldItem worldItem = (WorldItem)gamesListBox.Items[gamesListBox.SelectedIndex];
                ((MyConfigDedicated <T>)MySandboxGame.ConfigDedicated).LoadWorld = worldItem.SessionPath;

                var loadPath = worldItem.SessionPath;
                MyObjectBuilder_Checkpoint checkpoint = MyLocalCache.LoadCheckpoint(loadPath, out sizeInBytes);

                m_selectedSessionSettings = checkpoint.Settings;

                if (m_selectedSessionSettings != null && battleButton.Checked)
                {
                    MyBattleHelper.FillDefaultBattleServerSettings(m_selectedSessionSettings, true);
                }

                MySandboxGame.ConfigDedicated.Mods.Clear();
                foreach (var mod in checkpoint.Mods)
                {
                    if (mod.PublishedFileId != 0)
                    {
                        MySandboxGame.ConfigDedicated.Mods.Add(mod.PublishedFileId);
                    }
                }

                modIdsTextBox.Text = string.Join(Environment.NewLine, MySandboxGame.ConfigDedicated.Mods.ToArray());

                FillSessionSettingsItems();
            }
        }
        private void startButton_Click(object sender, EventArgs e)
        {
            if (m_selectedSessionSettings == null)
            {
                return;
            }

            if (MyFakes.ENABLE_BATTLE_SYSTEM && battleButton.Checked && m_selectedSessionSettings != null)
            {
                MyBattleHelper.FillDefaultBattleServerSettings(m_selectedSessionSettings, true);
            }

            saveConfigButton_Click(sender, e);

            if (m_isService) // Service
            {
                RefreshWorldsList();
                if (startGameButton.Checked)
                {
                    // fix for new game selected - new game will be started and not last saved game instead
                    MyLocalCache.SaveLastSessionInfo("");
                }
                startService();
            }
            else // Local / Console
            {
                // When running without host process, console is not properly attached on debug (no console output)
                string[] cmdLine = Environment.GetCommandLineArgs();
                Process.Start(cmdLine[0].Replace(".vshost.exe", ".exe"), ((cmdLine.Length > 1) ? cmdLine[1] : "") + " -console -ignorelastsession");
                Close();
            }
        }
        void OnReplace(MyGuiControlButton button)
        {
            if (m_selectedItem == null)
            {
                return;
            }

            MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                       buttonType : MyMessageBoxButtonsType.YES_NO,
                                       styleEnum : MyMessageBoxStyleEnum.Info,
                                       messageCaption : MyTexts.Get(MySpaceTexts.BlueprintsMessageBoxTitle_Replace),
                                       messageText : MyTexts.Get(MySpaceTexts.BlueprintsMessageBoxDesc_Replace),
                                       callback : delegate(MyGuiScreenMessageBox.ResultEnum callbackReturn)
            {
                if (callbackReturn == MyGuiScreenMessageBox.ResultEnum.YES)
                {
                    string name = m_selectedItem.Text.ToString();
                    var path    = Path.Combine(m_localBlueprintFolder, name, "bp.sbc");
                    if (File.Exists(path))
                    {
                        var oldBlueprint = LoadPrefab(path);
                        MyCubeBuilder.Static.Clipboard.CopiedGrids[0].DisplayName = name;
                        oldBlueprint.ShipBlueprints[0].CubeGrids = MyCubeBuilder.Static.Clipboard.CopiedGrids.ToArray();

                        if (MyFakes.ENABLE_BATTLE_SYSTEM)
                        {
                            oldBlueprint.ShipBlueprints[0].Points = MyBattleHelper.GetBattlePoints(oldBlueprint.ShipBlueprints[0].CubeGrids);
                        }

                        SavePrefabToFile(oldBlueprint, replace: true);
                        RefreshBlueprintList();
                    }
                }
            }));
        }
        public void CreateFromClipboard(bool withScreenshot = false, bool replace = false)
        {
            if (MyCubeBuilder.Static.Clipboard.CopiedGridsName == null)
            {
                return;
            }
            string name    = MyUtils.StripInvalidChars(MyCubeBuilder.Static.Clipboard.CopiedGridsName);
            string newName = name;
            string path    = Path.Combine(m_localBlueprintFolder, name);
            int    index   = 1;

            while (MyFileSystem.DirectoryExists(path))
            {
                newName = name + "_" + index;
                path    = Path.Combine(m_localBlueprintFolder, newName);
                index++;
            }
            string imagePath = Path.Combine(path, "thumb.png");

            if (withScreenshot)
            {
                TakeScreenshot(newName);
            }

            var prefab = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            prefab.Id           = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), MyUtils.StripInvalidChars(name));
            prefab.CubeGrids    = MyCubeBuilder.Static.Clipboard.CopiedGrids.ToArray();
            prefab.RespawnShip  = false;
            prefab.DisplayName  = MySteam.UserName;
            prefab.OwnerSteamId = MySteam.UserId;
            if (MyFakes.ENABLE_BATTLE_SYSTEM)
            {
                prefab.Points = MyBattleHelper.GetBattlePoints(prefab.CubeGrids);
            }
            prefab.CubeGrids[0].DisplayName = name;

            var definitions = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            definitions.ShipBlueprints    = new MyObjectBuilder_ShipBlueprintDefinition[1];
            definitions.ShipBlueprints[0] = prefab;

            SavePrefabToFile(definitions, replace: replace);
            RefreshBlueprintList();
        }
        private void startButton_Click(object sender, EventArgs e)
        {
            if (MyFakes.ENABLE_BATTLE_SYSTEM && battleButton.Checked && m_selectedSessionSettings != null)
            {
                MyBattleHelper.FillDefaultBattleServerSettings(m_selectedSessionSettings);
            }

            saveConfigButton_Click(sender, e);

            if (m_isService) // Service
            {
                startService();
            }
            else // Local / Console
            {
                string[] cmdLine = Environment.GetCommandLineArgs();
                Process.Start(cmdLine[0], ((cmdLine.Length > 1) ? cmdLine[1] : "") + " -console -ignorelastsession");
                Close();
            }
        }
Exemple #6
0
        private void startButton_Click(object sender, EventArgs e)
        {
            if (MyFakes.ENABLE_BATTLE_SYSTEM && battleButton.Checked && m_selectedSessionSettings != null)
            {
                MyBattleHelper.FillDefaultBattleServerSettings(m_selectedSessionSettings, true);
            }

            saveConfigButton_Click(sender, e);

            if (m_isService) // Service
            {
                startService();
            }
            else // Local / Console
            {
                // When running without host process, console is not properly attached on debug (no console output)
                string[] cmdLine = Environment.GetCommandLineArgs();
                Process.Start(cmdLine[0].Replace(".vshost.exe", ".exe"), ((cmdLine.Length > 1) ? cmdLine[1] : "") + " -console -ignorelastsession");
                Close();
            }
        }
        private void startTypeRadio_CheckedChanged(object sender, EventArgs e)
        {
            if (!m_canChangeStartType)
            {
                return;
            }

            startGameButton.Enabled = true;

            tableLayoutPanel1.Show();
            newGameSettingsPanel.Show();

            if (loadGameButton.Checked)
            {
                if (MyFakes.ENABLE_BATTLE_SYSTEM)
                {
                    FillWorldsList();
                }

                if (gamesListBox.Items.Count > 0)
                {
                    gamesListBox.Enabled = true;
                    //tableLayoutPanel1.Enabled = false;
                    newGameSettingsPanel.Enabled = false;
                    if (gamesListBox.SelectedIndex == -1)
                    {
                        gamesListBox.SelectedIndex = 0;
                    }
                }
                else
                {
                    startGameButton.Checked = true;
                    gamesListBox.Enabled    = false;
                    //tableLayoutPanel1.Enabled = true;
                    newGameSettingsPanel.Enabled = true;

                    MySandboxGame.ConfigDedicated.Load();
                    m_selectedSessionSettings = MySandboxGame.ConfigDedicated.SessionSettings;
                }

                if (m_selectedSessionSettings != null)
                {
                    m_selectedSessionSettings.Battle = false;
                }
            }
            else
            {
                if (MyFakes.ENABLE_BATTLE_SYSTEM && battleButton.Checked)
                {
                    FillBattlesList();

                    tableLayoutPanel1.Hide();
                    newGameSettingsPanel.Hide();

                    if (gamesListBox.Items.Count > 0)
                    {
                        gamesListBox.Enabled = true;
                        if (gamesListBox.SelectedIndex == -1)
                        {
                            gamesListBox.SelectedIndex = 0;
                        }
                    }
                    else
                    {
                        startGameButton.Enabled      = false;
                        gamesListBox.Enabled         = false;
                        newGameSettingsPanel.Enabled = true;

                        MySandboxGame.ConfigDedicated.Load();
                        m_selectedSessionSettings = MySandboxGame.ConfigDedicated.SessionSettings;
                    }

                    if (m_selectedSessionSettings != null)
                    {
                        MyBattleHelper.FillDefaultBattleServerSettings(m_selectedSessionSettings, true);
                    }
                }
                else
                {
                    gamesListBox.SelectedIndex = -1;
                    gamesListBox.Enabled       = false;
                    //tableLayoutPanel1.Enabled = true;
                    newGameSettingsPanel.Enabled = true;

                    MySandboxGame.ConfigDedicated.Load();
                    m_selectedSessionSettings = MySandboxGame.ConfigDedicated.SessionSettings;

                    //enable tool shake needs to be true for new world, but false for old saved worlds.
                    m_selectedSessionSettings.EnableToolShake = true;

                    m_selectedSessionSettings.EnableFlora       = (MyPerGameSettings.Game == GameEnum.SE_GAME) && MyFakes.ENABLE_PLANETS;
                    m_selectedSessionSettings.EnableSunRotation = MyPerGameSettings.Game == GameEnum.SE_GAME;
                    m_selectedSessionSettings.CargoShipsEnabled = !MyFakes.ENABLE_PLANETS;
                    m_selectedSessionSettings.EnableCyberhounds = false;
                    m_selectedSessionSettings.EnableSpiders     = true;

                    m_selectedSessionSettings.Battle = false;
                }
            }

            FillSessionSettingsItems();
        }