public void Close() { m_fetchedStarSytem = null; m_parentScreen = null; m_currentSelectedAsteroid = null; MyPluginDrawSession.Static.RemoveRenderObject(PREVIEW_RENDER_ID); }
/// <summary> /// Creates all GPSs that are persistent. /// </summary> private void AddAllPersistentGps() { var settings = MySettingsSession.Static.Settings.GeneratorSettings.GPSSettings; foreach (var item in StarSystem.GetAllObjects()) { switch (item.Type) { case MySystemObjectType.MOON: if (settings.MoonGPSMode == MyGPSGenerationMode.PERSISTENT || settings.MoonGPSMode == MyGPSGenerationMode.PERSISTENT_HIDDEN) { MyGPSManager.Static.AddPersistentGps(item.DisplayName, MOON_GPS_COLOR, item.CenterPosition, item.Id, settings.MoonGPSMode == MyGPSGenerationMode.PERSISTENT_HIDDEN); } break; case MySystemObjectType.PLANET: if (settings.PlanetGPSMode == MyGPSGenerationMode.PERSISTENT || settings.PlanetGPSMode == MyGPSGenerationMode.PERSISTENT_HIDDEN) { MyGPSManager.Static.AddPersistentGps(item.DisplayName, PLANET_GPS_COLOR, item.CenterPosition, item.Id, settings.PlanetGPSMode == MyGPSGenerationMode.PERSISTENT_HIDDEN); } break; case MySystemObjectType.ASTEROIDS: if (settings.AsteroidGPSMode == MyGPSGenerationMode.PERSISTENT || settings.AsteroidGPSMode == MyGPSGenerationMode.PERSISTENT_HIDDEN) { MySystemAsteroids asteroid = item as MySystemAsteroids; MyAbstractAsteroidObjectProvider provider = null; if (MyAsteroidObjectsManager.Static.AsteroidObjectProviders.TryGetValue(asteroid.AsteroidTypeName, out provider)) { var shape = provider.GetAsteroidObjectShape(asteroid); if (shape == null) { break; } MyGPSManager.Static.AddPersistentGps(item.DisplayName, RING_GPS_COLOR, shape.GetPointInShape(true), item.Id, settings.AsteroidGPSMode == MyGPSGenerationMode.PERSISTENT_HIDDEN); } } break; } } }
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); }
private void GenerateData(out MySystemAsteroids instance, out MyAsteroidSphereData data) { if (m_parentObjectListBox.SelectedItems.Count <= 0) { instance = null; data = null; return; } var selectedParent = m_parentObjectListBox.SelectedItems[m_parentObjectListBox.SelectedItems.Count - 1]; var parentItem = selectedParent.UserData as MySystemObject; StringBuilder name = new StringBuilder(); m_nameBox.GetText(name); instance = new MySystemAsteroids(); instance.AsteroidTypeName = MyAsteroidSphereProvider.TYPE_NAME; instance.CenterPosition = parentItem.CenterPosition; instance.AsteroidSize = new MySerializableMinMax((int)m_asteroidSizesSlider.CurrentMin, (int)m_asteroidSizesSlider.CurrentMax); instance.ParentId = parentItem.Id; instance.DisplayName = name.ToString(); data = GetDataFromGui(); }
/// <summary> /// Generates the whole data for the currently edited asteroid ring from the values in the spawn menu /// </summary> /// <param name="ringData">The out value for the ring data</param> /// <param name="systemObject">The out value for the system object</param> private void GenerateAsteroidData(out MyAsteroidRingData ringData, out MySystemAsteroids systemObject) { if (m_parentObjectListBox.SelectedItems.Count <= 0) { ringData = null; systemObject = null; return; } var selectedParent = m_parentObjectListBox.SelectedItems[m_parentObjectListBox.SelectedItems.Count - 1]; var parentItem = selectedParent.UserData as MySystemObject; StringBuilder name = new StringBuilder(); m_nameBox.GetText(name); systemObject = new MySystemAsteroids(); systemObject.AsteroidTypeName = MyAsteroidRingProvider.Static.GetTypeName(); systemObject.CenterPosition = parentItem.CenterPosition + m_offset; systemObject.AsteroidSize = new MySerializableMinMax((int)m_asteroidSizesSlider.CurrentMin, (int)m_asteroidSizesSlider.CurrentMax); systemObject.DisplayName = name.ToString(); systemObject.ParentId = parentItem.Id; ringData = GenerateAsteroidRing(); }
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 override void UpdateGpsForPlayer(MyEntityTracker entity) { if (!(entity.Entity is MyCharacter)) { return; } var settings = MySettingsSession.Static.Settings.GeneratorSettings.GPSSettings; if (settings.AsteroidGPSMode != MyGPSGenerationMode.DISCOVERY) { return; } var objects = MyStarSystemGenerator.Static.StarSystem.GetAllObjects(); MyCharacter player = entity.Entity as MyCharacter; foreach (var obj in objects) { if (obj.Type != MySystemObjectType.ASTEROIDS) { continue; } MySystemAsteroids asteroid = obj as MySystemAsteroids; Vector3D entityPosition = player.PositionComp.GetPosition(); var provider = MyAsteroidObjectsManager.Static.AsteroidObjectProviders[asteroid.AsteroidTypeName]; IMyAsteroidObjectShape shape = provider.GetAsteroidObjectShape(asteroid); if (shape == null) { continue; } if (shape.Contains(entityPosition) != ContainmentType.Disjoint) { MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id); } Vector3D closestPos = shape.GetClosestPoint(entityPosition); double distance = Vector3D.Subtract(entityPosition, closestPos).Length(); if (distance > 5000000) { MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id); } else if (distance > 5) { if (MyGPSManager.Static.DynamicGpsExists(asteroid.Id, player.GetPlayerIdentityId())) { MyGPSManager.Static.ModifyDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId(), asteroid.Id); continue; } MyGPSManager.Static.AddDynamicGps(asteroid.DisplayName, Color.Yellow, closestPos, player.GetPlayerIdentityId(), asteroid.Id); } else { MyGPSManager.Static.RemoveDynamicGps(player.GetPlayerIdentityId(), asteroid.Id); } } }
/// <summary> /// Returns the associated asteroid data provided by this class for the given asteroid object instance, /// if the instance is of type of this provider /// </summary> /// <param name="instance">Instance to get data for</param> /// <returns>The data associated or null</returns> public abstract object GetInstanceData(MySystemAsteroids instance);
/// <summary> /// Tries to load the given asteroid /// </summary> public abstract bool TryLoadObject(MySystemAsteroids asteroid);
/// <summary> /// Tries to remove the given asteroid instance from this provider /// </summary> /// <param name="systemInstance">Instance to remove</param> /// <returns>True, if removed</returns> public abstract bool RemoveInstance(MySystemAsteroids systemInstance);
/// <summary> /// Returns the shape for the given asteroid object /// </summary> /// <param name="instance">The system object instance for the corresponding asteroid</param> /// <returns>The asteroid shape for the asteroid object</returns> public abstract IMyAsteroidObjectShape GetAsteroidObjectShape(MySystemAsteroids instance);
/// <summary> /// Converts an asteroid object name to a file name. /// </summary> /// <param name="obj">The asteroid object</param> /// <returns>The file name for the asteroid object</returns> protected string GetFileName(MySystemAsteroids obj) { return((obj.DisplayName + obj.Id.ToString()).Replace(" ", "_") + ".roid"); }
/// <summary> /// Sets all slider values to reflect the instance asteroid object /// </summary> /// <param name="instance">The instance of the asteroid object</param> private void SetSliderValues(MySystemAsteroids instance) { if (instance.AsteroidTypeName != MyAsteroidRingProvider.TYPE_NAME) { return; } MyAsteroidRingData data = MyAsteroidRingProvider.Static.GetInstanceData(instance) as MyAsteroidRingData; var planet = m_fetchedStarSytem.GetObjectById(instance.ParentId) as MySystemPlanet; if (planet == null) { var settings = MySettingsSession.Static.Settings.GeneratorSettings; 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; return; } m_radiusSlider.MinValue = (int)planet.Diameter / 1000 * 0.75f; m_radiusSlider.MaxValue = (int)planet.Diameter / 1000 * 2f; m_radiusSlider.Value = (float)data.Radius / 1000; m_radiusSlider.Enabled = true; m_widthSlider.MinValue = (int)planet.Diameter / 1000 / 20f; m_widthSlider.MaxValue = (int)planet.Diameter / 1000 / 1.25f; m_widthSlider.Value = (float)data.Width / 1000; m_widthSlider.Enabled = true; m_heightSlider.MinValue = m_widthSlider.MinValue / 10; m_heightSlider.MaxValue = m_widthSlider.MaxValue / 10; m_heightSlider.Value = (float)data.Height / 1000; m_heightSlider.Enabled = true; m_asteroidSizesSlider.Enabled = true; m_asteroidSizesSlider.SetValues(instance.AsteroidSize.Min, instance.AsteroidSize.Max); m_angleXSlider.Enabled = true; m_angleXSlider.Value = (float)data.AngleDegrees.x; m_angleYSlider.Enabled = true; m_angleYSlider.Value = (float)data.AngleDegrees.y; m_angleZSlider.Enabled = true; m_angleZSlider.Value = (float)data.AngleDegrees.z; }
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); }