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); }
/// <summary> /// Runs on click of the parent item box. Sets the ranges for the sliders and resets the values. /// </summary> /// <param name="box">The listbox which calls this method on item clicked</param> private void OnParentItemClicked(MyGuiControlListbox box) { if (box.SelectedItems.Count > 0) { m_spawnButton.Enabled = true; m_radiusSlider.Enabled = true; m_widthSlider.Enabled = true; m_asteroidSizesSlider.Enabled = true; m_nameBox.Enabled = true; var parent = box.SelectedItems[box.SelectedItems.Count - 1].UserData as MySystemObject; var settings = MySettingsSession.Static.Settings.GeneratorSettings; if (parent == m_fetchedStarSytem.CenterObject) { m_radiusSlider.MinValue = settings.MinMaxOrbitDistance.Min / 1000; m_radiusSlider.MaxValue = settings.WorldSize < 0 ? int.MaxValue / 1000 : settings.WorldSize / 1000; m_radiusSlider.Value = m_radiusSlider.MinValue + (m_radiusSlider.MaxValue - m_radiusSlider.MinValue) / 2; m_widthSlider.MinValue = settings.MinMaxOrbitDistance.Min / 2000; m_widthSlider.MaxValue = settings.MinMaxOrbitDistance.Min / 1000; m_widthSlider.Value = m_radiusSlider.MinValue + (m_radiusSlider.MaxValue - m_radiusSlider.MinValue) / 2; m_asteroidSizesSlider.SetValues(32, 1024); m_parentScreen.CameraLookAt(Vector3D.Zero, new Vector3D(0, 0, m_radiusSlider.Value * 2000)); RenderSpherePreview(GetDataFromGui()); return; } else { if (parent.Type == MySystemObjectType.PLANET || parent.Type == MySystemObjectType.MOON) { var planet = parent as MySystemPlanet; List <MyEntityList.MyEntityListInfoItem> planets = MyEntityList.GetEntityList(MyEntityList.MyEntityTypeEnum.Planets); MyPlanet planetEntity = null; foreach (var p in planets) { var e = MyEntities.GetEntityById(p.EntityId) as MyPlanet; if (e.EntityId == planet.EntityId) { planetEntity = MyEntities.GetEntityById(p.EntityId) as MyPlanet; } } if (planetEntity != null) { m_radiusSlider.MinValue = planetEntity.AverageRadius / 1000; m_radiusSlider.MaxValue = (float)planet.Diameter / 1000; m_radiusSlider.Value = m_radiusSlider.MinValue + (m_radiusSlider.MaxValue - m_radiusSlider.MinValue) / 2; m_widthSlider.MinValue = (planetEntity.MaximumRadius - planetEntity.MinimumRadius) / 1000; m_widthSlider.MaxValue = (float)planet.Diameter / 5000f; m_widthSlider.Value = m_widthSlider.MinValue + (m_widthSlider.MaxValue - m_widthSlider.MinValue) / 2; m_asteroidSizesSlider.SetValues(32, 1024); m_parentScreen.CameraLookAt(planet.CenterPosition, (float)planet.Diameter * 2f); RenderSpherePreview(GetDataFromGui()); return; } } } } m_radiusSlider.Enabled = false; m_asteroidSizesSlider.Enabled = false; m_nameBox.Enabled = false; m_spawnButton.Enabled = false; m_widthSlider.Enabled = false; }
/// <summary> /// Runs on click of the parent item box. Sets the ranges for the sliders and resets the values. /// </summary> /// <param name="box">The listbox which calls this method on item clicked</param> private void OnParentItemClicked(MyGuiControlListbox box) { if (box.SelectedItems.Count > 0) { m_spawnRingButton.Enabled = true; m_zoomInButton.Enabled = m_snapToParent; m_offsetToCoordButton.Enabled = false; m_offset = Vector3D.Zero; var parent = box.SelectedItems[box.SelectedItems.Count - 1].UserData as MySystemObject; var settings = MySettingsSession.Static.Settings.GeneratorSettings; if (parent == m_fetchedStarSytem.CenterObject) { m_radiusSlider.MinValue = settings.MinMaxOrbitDistance.Min / 1000; m_radiusSlider.MaxValue = settings.WorldSize < 0 ? int.MaxValue / 1000 : settings.WorldSize / 1000; m_radiusSlider.Value = m_radiusSlider.MinValue + (m_radiusSlider.MaxValue - m_radiusSlider.MinValue) / 2; m_radiusSlider.Enabled = true; m_widthSlider.MinValue = settings.MinMaxOrbitDistance.Min / 2000; m_widthSlider.MaxValue = settings.MinMaxOrbitDistance.Max / 1000; m_widthSlider.Value = m_widthSlider.MinValue + (m_widthSlider.MaxValue - m_widthSlider.MinValue) / 2; m_widthSlider.Enabled = true; m_heightSlider.MinValue = m_widthSlider.MinValue / 10; m_heightSlider.MaxValue = m_widthSlider.MaxValue / 10; m_heightSlider.Value = m_heightSlider.MinValue + (m_heightSlider.MaxValue - m_heightSlider.MinValue) / 2; m_heightSlider.Enabled = true; m_asteroidSizesSlider.Enabled = true; m_asteroidSizesSlider.SetValues(32, 1024); m_angleXSlider.Enabled = true; m_angleXSlider.Value = 0; m_angleYSlider.Enabled = true; m_angleYSlider.Value = 0; m_angleZSlider.Enabled = true; m_angleZSlider.Value = 0; m_offsetToCoordButton.Enabled = true; if (m_snapToParent) { m_parentScreen.CameraLookAt(Vector3D.Zero, new Vector3D(0, 0, m_radiusSlider.Value * 2000)); } UpdateRingVisual(GenerateAsteroidRing()); return; } if (parent.Type != MySystemObjectType.PLANET && parent.Type != MySystemObjectType.MOON) { return; } var planet = parent as MySystemPlanet; m_radiusSlider.MinValue = (int)planet.Diameter / 1000 * 0.75f; m_radiusSlider.MaxValue = (int)planet.Diameter / 1000 * 2f; m_radiusSlider.Value = m_radiusSlider.MinValue + (m_radiusSlider.MaxValue - m_radiusSlider.MinValue) / 2; m_radiusSlider.Enabled = true; m_widthSlider.MinValue = (int)planet.Diameter / 1000 / 20f; m_widthSlider.MaxValue = (int)planet.Diameter / 1000 / 1.25f; m_widthSlider.Value = m_widthSlider.MinValue + (m_widthSlider.MaxValue - m_widthSlider.MinValue) / 2; m_widthSlider.Enabled = true; m_heightSlider.MinValue = m_widthSlider.MinValue / 10; m_heightSlider.MaxValue = m_widthSlider.MaxValue / 10; m_heightSlider.Value = m_heightSlider.MinValue + (m_heightSlider.MaxValue - m_heightSlider.MinValue) / 2; m_heightSlider.Enabled = true; m_asteroidSizesSlider.Enabled = true; m_asteroidSizesSlider.SetValues(32, 1024); m_angleXSlider.Enabled = true; m_angleXSlider.Value = 0; m_angleYSlider.Enabled = true; m_angleYSlider.Value = 0; m_angleZSlider.Enabled = true; m_angleZSlider.Value = 0; m_nameBox.SetText(new StringBuilder("")); if (m_snapToParent) { m_parentScreen.CameraLookAt(planet.CenterPosition, (float)planet.Diameter * 2f); } UpdateRingVisual(GenerateAsteroidRing()); } else { m_radiusSlider.Enabled = false; m_widthSlider.Enabled = false; m_heightSlider.Enabled = false; m_asteroidSizesSlider.Enabled = false; m_angleXSlider.Enabled = false; m_angleYSlider.Enabled = false; m_angleZSlider.Enabled = false; m_spawnRingButton.Enabled = false; } }
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); }