public void Close() { m_fetchedStarSytem = null; m_parentScreen = null; m_currentSelectedAsteroid = null; MyPluginDrawSession.Static.RemoveRenderObject(PREVIEW_RENDER_ID); }
public bool OnEditMenuSelectItem(float usableWidth, MyGuiControlParentTableLayout parentTable, MyPluginAdminMenu adminScreen, MySystemAsteroids asteroidObject, MyObjectBuilder_SystemData starSystem) { m_parentScreen = adminScreen; m_currentSelectedAsteroid = asteroidObject; MyGuiControlButton teleportToRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Teleport to sphere", OnTeleportToSphere); parentTable.AddTableRow(teleportToRingButton); MyGuiControlButton deleteRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Remove sphere", OnRemoveSphere); parentTable.AddTableRow(deleteRingButton); parentTable.AddTableSeparator(); var data = MyAsteroidSphereProvider.Static.GetInstanceData(asteroidObject); var sphere = data as MyAsteroidSphereData; m_parentScreen.CameraLookAt(asteroidObject.CenterPosition, (float)sphere.OuterRadius * 2f); RenderSpherePreview(sphere); return(true); }
public bool OnEditMenuSelectItem(float usableWidth, MyGuiControlParentTableLayout parentTable, MyPluginAdminMenu adminScreen, MySystemAsteroids asteroidObject, MyObjectBuilder_SystemData starSystem) { m_parentScreen = adminScreen; m_currentSelectedAsteroid = asteroidObject; m_offset = Vector3D.Zero; m_fetchedStarSytem = starSystem; GenerateRingSettingElements(usableWidth, parentTable); SetSliderValues(m_currentSelectedAsteroid); MyGuiControlButton teleportToRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Teleport to ring", OnTeleportToRing); parentTable.AddTableRow(teleportToRingButton); MyGuiControlButton deleteRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Remove ring", OnRemoveRing); parentTable.AddTableRow(deleteRingButton); MyGuiControlButton editRingButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Edit ring", OnEditRing); parentTable.AddTableRow(editRingButton); parentTable.AddTableSeparator(); var data = MyAsteroidRingProvider.Static.GetInstanceData(asteroidObject); var ring = data as MyAsteroidRingData; m_parentScreen.CameraLookAt(asteroidObject.CenterPosition, (float)ring.Radius * 1.5f); UpdateRingVisual(ring); return(true); }
public bool CreateSpawnMenu(float usableWidth, MyGuiControlParentTableLayout parentTable, MyPluginAdminMenu adminScreen) { m_parentScreen = adminScreen; if (m_fetchedStarSytem == null) { MyGuiControlRotatingWheel loadingWheel = new MyGuiControlRotatingWheel(position: Vector2.Zero); loadingWheel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER; adminScreen.Controls.Add(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); parentTable.AddTableSeparator(); m_radiusSlider = new MyGuiControlClickableSlider(width: usableWidth - 0.1f, minValue: 0, maxValue: 1, labelSuffix: " km", showLabel: true); m_radiusSlider.Enabled = false; m_radiusSlider.ValueChanged += delegate { RenderSpherePreview(GetDataFromGui()); }; parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Radius")); parentTable.AddTableRow(m_radiusSlider); m_widthSlider = new MyGuiControlClickableSlider(null, 0, 1, usableWidth - 0.1f, 0.5f, showLabel: true, labelSuffix: " km"); m_widthSlider.Enabled = false; m_widthSlider.ValueChanged += delegate { RenderSpherePreview(GetDataFromGui()); }; parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Width")); parentTable.AddTableRow(m_widthSlider); m_asteroidSizesSlider = new MyGuiControlRangedSlider(32, 1024, 32, 1024, true, width: usableWidth - 0.1f, showLabel: true); m_asteroidSizesSlider.Enabled = false; parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Asteroid size range")); parentTable.AddTableRow(m_asteroidSizesSlider); 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_spawnButton = MyPluginGuiHelper.CreateDebugButton(usableWidth, "Spawn sphere", 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; MyAsteroidSphereData data; GenerateData(out instance, out data); if (instance == null || data == null) { MyPluginGuiHelper.DisplayError("Could not generate asteroid sphere. No data found.", "Error"); return; } MyAsteroidSphereProvider.Static.AddInstance(instance, data, delegate(bool success) { if (!success) { MyPluginGuiHelper.DisplayError("Sphere 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("Sphere was created successfully.", "Success"); m_parentScreen.ForceFetchStarSystem = true; m_parentScreen.ShouldRecreate = true; } }); }); parentTable.AddTableSeparator(); parentTable.AddTableRow(m_spawnButton); return(true); }
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); }