/// <summary>
        /// Spawns a planet in the system
        /// </summary>
        /// <param name="planet">Planet to spawn</param>
        /// <param name="position">Position to spawn at</param>
        private void SpawnPlanet(MySystemObject planet, Vector3D position)
        {
            if (planet.Type == MySystemObjectType.PLANET)
            {
                MySystemPlanet p = planet as MySystemPlanet;
                p.CenterPosition = position;

                MyStarSystemGenerator.Static.AddObjectToSystem(p, callback : delegate(bool success)
                {
                    if (!success)
                    {
                        MyPluginGuiHelper.DisplayError("Planet could not be spawned, because an object with the same id already exists. This error should not occour, so please try again.", "Error");
                    }
                });
            }
        }
        /// <summary>
        /// Action to spawn a planet
        /// </summary>
        /// <param name="coordSpawn">If the planet should be spawned at coordinates instead of direct placement</param>
        private void OnSpawnPlanet(bool coordSpawn = false)
        {
            StringBuilder name = new StringBuilder();

            m_nameBox.GetText(name);
            if (name.ToString().Trim().Length <= 3)
            {
                MyPluginGuiHelper.DisplayError("The name must be at least 4 letters long", "Error");
                return;
            }

            if (coordSpawn)
            {
                MyGuiScreenDialogCoordinate coordinateInput = new MyGuiScreenDialogCoordinate("Planet coordinate");

                coordinateInput.OnConfirmed += delegate(Vector3D coord)
                {
                    MySystemPlanet p = new MySystemPlanet()
                    {
                        CenterPosition = coord,
                        SubtypeId      = ((MyPlanetGeneratorDefinition)m_planetDefList.GetLastSelected().UserData).Id.SubtypeId.ToString(),
                        Generated      = false,
                        DisplayName    = name.ToString().Trim(),
                        Diameter       = m_planetSizeSlider.Value
                    };

                    SpawnPlanet(p, coord);
                };

                MyGuiSandbox.AddScreen(coordinateInput);
                return;
            }

            float          size   = m_planetSizeSlider.Value;
            MySystemPlanet planet = new MySystemPlanet()
            {
                CenterPosition = Vector3D.Zero,
                SubtypeId      = ((MyPlanetGeneratorDefinition)m_planetDefList.GetLastSelected().UserData).Id.SubtypeId.ToString(),
                Generated      = false,
                DisplayName    = name.ToString().Trim(),
                Diameter       = size
            };

            MyPluginItemsClipboard.Static.Activate(planet, SpawnPlanet, size);

            CloseScreenNow();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Opens the dialog to add a subtype id to the given table
        /// </summary>
        /// <param name="table">Table to add item to</param>
        /// <param name="addAction">Action, which should add the id to the settings file</param>
        private void OpenEnterIdDialog(MyGuiControlTable table, Action <string> addAction)
        {
            MyGuiScreenDialogText inputBox = new MyGuiScreenDialogText();

            inputBox.OnConfirmed += delegate(string text)
            {
                if (Regex.Match(text, ILLEGAL_XML).Success)
                {
                    MyPluginGuiHelper.DisplayError("The entered subtype id contains invalid characters (& < >).", "Error, invalid character");
                    return;
                }

                var row = new MyGuiControlTable.Row(text);
                row.AddCell(new MyGuiControlTable.Cell(text));

                table.Add(row);
                addAction(text);
            };
            MyGuiSandbox.AddScreen(inputBox);
        }