/// <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(); }
public bool CreateSpawnMenu(float usableWidth, MyGuiControlParentTableLayout parentTable, MyPluginAdminMenu adminScreen) { m_parentScreen = adminScreen; m_offset = Vector3D.Zero; m_currentSelectedAsteroid = null; if (m_fetchedStarSytem == null) { MyGuiControlRotatingWheel m_loadingWheel = new MyGuiControlRotatingWheel(position: Vector2.Zero); m_loadingWheel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER; adminScreen.Controls.Add(m_loadingWheel); MyStarSystemGenerator.Static.GetStarSystem(delegate(MyObjectBuilder_SystemData starSystem) { m_fetchedStarSytem = starSystem; adminScreen.ShouldRecreate = true; }); return(true); } MyGuiControlLabel label = new MyGuiControlLabel(null, null, "Parent objects"); parentTable.AddTableRow(label); m_parentObjectListBox = new MyGuiControlListbox(); m_parentObjectListBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder("System center"), userData: m_fetchedStarSytem.CenterObject)); m_parentObjectListBox.VisibleRowsCount = 8; m_parentObjectListBox.Size = new Vector2(usableWidth, m_parentObjectListBox.Size.Y); m_parentObjectListBox.SelectAllVisible(); m_parentObjectListBox.ItemsSelected += OnParentItemClicked; foreach (var obj in m_fetchedStarSytem.CenterObject.GetAllChildren()) { if (obj.Type == MySystemObjectType.PLANET || obj.Type == MySystemObjectType.MOON) { m_parentObjectListBox.Add(new MyGuiControlListbox.Item(new System.Text.StringBuilder(obj.DisplayName), userData: obj)); } } parentTable.AddTableRow(m_parentObjectListBox); var row = new MyGuiControlParentTableLayout(2, false, Vector2.Zero); m_snapToParentCheck = new MyGuiControlCheckbox(); m_snapToParentCheck.IsChecked = m_snapToParent; m_snapToParentCheck.IsCheckedChanged += delegate { m_snapToParent = m_snapToParentCheck.IsChecked; m_zoomInButton.Enabled = m_snapToParent; }; row.AddTableRow(m_snapToParentCheck, new MyGuiControlLabel(null, null, "Snap camera to parent")); row.ApplyRows(); parentTable.AddTableRow(row); parentTable.AddTableSeparator(); GenerateRingSettingElements(usableWidth, parentTable); m_nameBox = new MyGuiControlTextbox(); m_nameBox.Size = new Vector2(usableWidth, m_nameBox.Size.Y); parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Name")); parentTable.AddTableRow(m_nameBox); m_zoomInButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Zoom to ring", delegate { if (m_snapToParent) { m_parentScreen.CameraLookAt(GenerateAsteroidRing().CenterPosition, new Vector3D(0, 0, (m_radiusSlider.Value + m_widthSlider.Value) * 2000)); } }); parentTable.AddTableRow(m_zoomInButton); m_offsetToCoordButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Offset to coordinate", delegate { var coordMessage = new MyGuiScreenDialogCoordinate("Enter coordinate to offset the center of the ring from its parent"); coordMessage.OnConfirmed += delegate(Vector3D coord) { m_offset = coord; UpdateRingVisual(GenerateAsteroidRing()); }; MyGuiSandbox.AddScreen(coordMessage); }); parentTable.AddTableRow(m_offsetToCoordButton); m_spawnRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Add ring", delegate { StringBuilder name = new StringBuilder(); m_nameBox.GetText(name); if (name.Length < 4) { MyPluginGuiHelper.DisplayError("Name must be at least 4 letters long", "Error"); return; } MySystemAsteroids instance; MyAsteroidRingData ring; GenerateAsteroidData(out ring, out instance); if (ring == null || instance == null) { MyPluginGuiHelper.DisplayError("Could not generate asteroid ring. No data found.", "Error"); return; } MyAsteroidRingProvider.Static.AddInstance(instance, ring, delegate(bool success) { if (!success) { MyPluginGuiHelper.DisplayError("Ring could not be added, because an object with the same id already exists. This error should not occour, so please try again.", "Error"); } else { MyPluginGuiHelper.DisplayMessage("Ring was created successfully.", "Success"); m_parentScreen.ForceFetchStarSystem = true; m_parentScreen.ShouldRecreate = true; } }); }); parentTable.AddTableRow(m_spawnRingButton); return(true); }