/// <summary> /// Retreives the world settings set in this gui screen for the plugin /// </summary> /// <returns>An object builder containing the currently set world settings</returns> public MyObjectBuilder_WorldSettings GetSettings() { MyObjectBuilder_WorldSettings settings = new MyObjectBuilder_WorldSettings(); settings.GeneratorSettings.SystemGenerator = (SystemGenerationMethod)m_systemGeneratorCombo.GetSelectedKey(); settings.GeneratorSettings.AsteroidGenerator = (AsteroidGenerationMethod)m_asteroidGeneratorCombo.GetSelectedKey(); settings.GeneratorSettings.AllowVanillaPlanets = m_enableVanillaPlanetsCheckbox.IsChecked; settings.GeneratorSettings.MinMaxPlanets = new MySerializableMinMax((long)m_planetCountSlider.CurrentMin, (long)m_planetCountSlider.CurrentMax); settings.GeneratorSettings.MinMaxAsteroidObjects = new MySerializableMinMax((long)m_asteroidCountSlider.CurrentMin, (long)m_asteroidCountSlider.CurrentMax); settings.GeneratorSettings.MinMaxOrbitDistance = new MySerializableMinMax((long)(m_orbitDistancesSlider.CurrentMin * 1000), (long)(m_orbitDistancesSlider.CurrentMax * 1000)); settings.GeneratorSettings.AsteroidDensity = m_asteroidDensitySlider.Value; settings.GeneratorSettings.WorldSize = m_worldSizeSlider.Value >= 0 ? (long)(m_worldSizeSlider.Value * 1000) : -1; settings.GeneratorSettings.PlanetSettings.PlanetSizeCap = (int)m_planetSizeCapSlider.Value; settings.GeneratorSettings.PlanetSettings.PlanetSizeMultiplier = m_planetSizeMultSlider.Value; settings.GeneratorSettings.PlanetSettings.BaseMoonProbability = m_planetMoonBasePropSlider.Value; settings.GeneratorSettings.PlanetSettings.BaseRingProbability = m_planetRingBasePropSlider.Value; settings.GeneratorSettings.PlanetSettings.MinMaxMoons = new MySerializableMinMax((long)m_planetMoonMinMaxSlider.CurrentMin, (long)m_planetMoonMinMaxSlider.CurrentMax); settings.GeneratorSettings.GPSSettings.PlanetGPSMode = (MyGPSGenerationMode)m_planetGPSModeCombo.GetSelectedKey(); settings.GeneratorSettings.GPSSettings.MoonGPSMode = (MyGPSGenerationMode)m_moonGPSModeCombo.GetSelectedKey(); settings.GeneratorSettings.GPSSettings.AsteroidGPSMode = (MyGPSGenerationMode)m_asteroidGPSModeCombo.GetSelectedKey(); return(settings); }
/// <summary> /// Loads the savefile of the plugin settings of the world and stores it /// int the Settings member variable /// </summary> public override void LoadData() { MyPluginLog.Log("Loading Session settings data"); Static = this; if (MyFileUtils.FileExistsInWorldStorage(FILE_NAME)) { Settings = MyFileUtils.ReadXmlFileFromWorld <MyObjectBuilder_WorldSettings>(FILE_NAME); MyPluginLog.Log("Session settings read from file"); } else { MyPluginLog.Log("Session settings do not exist, creating new ones."); if (MySettings.Static == null) { var s = new MySettings(); s.LoadSettings(); } if (MySettings.Static.SessionSettings != null) { Settings = MySettings.Static.SessionSettings; } else { Settings = new MyObjectBuilder_WorldSettings(); } MySettings.Static.SessionSettings = null; } MyPluginLog.Log("Loading Session settings data completed"); }
/// <summary> /// Sets the settings for this menu screen to display. /// </summary> /// <param name="worldSettings">The world settings to display</param> public void SetSettings(MyObjectBuilder_WorldSettings worldSettings) { m_systemGeneratorCombo.SelectItemByKey((long)worldSettings.GeneratorSettings.SystemGenerator); m_asteroidGeneratorCombo.SelectItemByKey((long)worldSettings.GeneratorSettings.AsteroidGenerator); m_enableVanillaPlanetsCheckbox.IsChecked = worldSettings.GeneratorSettings.AllowVanillaPlanets; m_planetCountSlider.SetValues(worldSettings.GeneratorSettings.MinMaxPlanets.Min, worldSettings.GeneratorSettings.MinMaxPlanets.Max); m_asteroidCountSlider.SetValues(worldSettings.GeneratorSettings.MinMaxAsteroidObjects.Min, worldSettings.GeneratorSettings.MinMaxAsteroidObjects.Max); m_orbitDistancesSlider.SetValues(worldSettings.GeneratorSettings.MinMaxOrbitDistance.Min / 1000, worldSettings.GeneratorSettings.MinMaxOrbitDistance.Max / 1000); m_asteroidDensitySlider.Value = worldSettings.GeneratorSettings.AsteroidDensity; if (worldSettings.GeneratorSettings.WorldSize >= 0) { m_worldSizeSlider.Value = worldSettings.GeneratorSettings.WorldSize / 1000; } else { m_worldSizeSlider.Value = -1; } m_planetSizeCapSlider.Value = worldSettings.GeneratorSettings.PlanetSettings.PlanetSizeCap; m_planetSizeMultSlider.Value = worldSettings.GeneratorSettings.PlanetSettings.PlanetSizeMultiplier; m_planetMoonBasePropSlider.Value = worldSettings.GeneratorSettings.PlanetSettings.BaseMoonProbability; m_planetRingBasePropSlider.Value = worldSettings.GeneratorSettings.PlanetSettings.BaseRingProbability; m_planetMoonMinMaxSlider.SetValues(worldSettings.GeneratorSettings.PlanetSettings.MinMaxMoons.Min, worldSettings.GeneratorSettings.PlanetSettings.MinMaxMoons.Max); m_planetGPSModeCombo.SelectItemByKey((long)worldSettings.GeneratorSettings.GPSSettings.PlanetGPSMode); m_asteroidGPSModeCombo.SelectItemByKey((long)worldSettings.GeneratorSettings.GPSSettings.AsteroidGPSMode); m_moonGPSModeCombo.SelectItemByKey((long)worldSettings.GeneratorSettings.GPSSettings.MoonGPSMode); }
private static void GetSettingsClient(MyObjectBuilder_WorldSettings settings) { if (Sync.IsServer) { return; } Static.Settings = settings; }
/// <summary> /// Unloads the used data of this session component. /// </summary> protected override void UnloadData() { MyPluginLog.Log("Unloading Session settings data"); if (Sync.IsServer) { MyFileUtils.WriteXmlFileToWorld(Settings, FILE_NAME); } Settings = null; MySettings.Static.SessionSettings = null; MyPluginLog.Log("Unloading Session settings data completed"); }
/// <summary> /// Loads values from the folder of the world, which is currently edited. Used for editing world settings. /// </summary> private void LoadValues() { var path = Path.Combine(MyFileSystem.SavesPath, Checkpoint.SessionName.Replace(":", "-")); if (MyFileUtils.FileExistsInPath(path, MySettingsSession.FILE_NAME, typeof(PluginWorldSettings))) { PlSettings = MyFileUtils.ReadXmlFileFromPath <MyObjectBuilder_WorldSettings>(path, MySettingsSession.FILE_NAME, typeof(PluginWorldSettings)); } else { PlSettings = new MyObjectBuilder_WorldSettings(); } m_enablePlugin.IsChecked = PlSettings.Enabled; }
/// <summary> /// Builds the controls for the gui screen by first building the base /// controls and then adding the checkbox to enable the plugin and a button to edit /// its settings for the world, also initializes an instance of plugin settings to edit. /// Adds a new delegate to the create world button, to transfere the set plugin settings /// to the plugins settings session component. /// </summary> protected override void BuildControls() { base.BuildControls(); Vector2 vector = -m_size.Value / 2f + new Vector2(m_isNewGame ? (MARGIN_LEFT_LIST + MyGuiConstants.LISTBOX_WIDTH + MARGIN_LEFT_INFO) : MARGIN_LEFT_LIST, m_isNewGame ? (MARGIN_TOP + 0.015f) : (MARGIN_TOP - 0.105f)); Vector2 value = new Vector2(0f, 0.052f); Vector2 vector2 = m_size.Value / 2f - vector; vector2.X -= MARGIN_RIGHT + 0.005f; vector2.Y -= MARGIN_BOTTOM; Vector2 vector3 = vector2 * (m_isNewGame ? 0.339f : 0.329f); Vector2 vector4 = vector2 - vector3; m_enablePluginLabel = new MyGuiControlLabel(null, null, "Enable SEWorldGenPlugin"); m_enablePlugin = new MyGuiControlCheckbox(); m_enablePlugin.SetToolTip("Enable the SEWorldGenPlugin for this world"); m_enablePlugin.IsCheckedChanged = (Action <MyGuiControlCheckbox>) Delegate.Combine(m_enablePlugin.IsCheckedChanged, (Action <MyGuiControlCheckbox>) delegate(MyGuiControlCheckbox s) { if (PlSettings != null) { PlSettings.Enabled = s.IsChecked; m_pluginSettingsButton.Enabled = m_enablePlugin.IsChecked; } }); m_enablePlugin.IsChecked = false; m_pluginSettingsButton = new MyGuiControlButton(null, MyGuiControlButtonStyleEnum.Small, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, new StringBuilder("Plugin settings"), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_ACTIVE, OnSettingsClick); Controls.Add(m_enablePluginLabel); Controls.Add(m_enablePlugin); Controls.Add(m_pluginSettingsButton); m_enablePluginLabel.Position = vector + value * 5; m_enablePluginLabel.PositionY += MyGuiConstants.BACK_BUTTON_SIZE.Y * 2; m_pluginSettingsButton.Enabled = m_enablePlugin.IsChecked; m_enablePlugin.Position = GetControlPosition(); m_enablePlugin.PositionY = m_enablePluginLabel.PositionY; m_enablePlugin.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER; m_pluginSettingsButton.Position = m_enablePlugin.Position; m_pluginSettingsButton.PositionX += m_enablePlugin.Size.X + 0.009f; m_pluginSettingsButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER; foreach (var c in Controls) { if (c is MyGuiControlButton) { MyGuiControlButton b = (MyGuiControlButton)c; if (b.Text == MyTexts.GetString(MyCommonTexts.Start) || b.Text == MyTexts.GetString(MyCommonTexts.Ok)) { if (!m_enablePlugin.IsChecked) { PlSettings = new MyObjectBuilder_WorldSettings(); PlSettings.Enabled = m_enablePlugin.IsChecked; } if (m_isNewGame) { b.ButtonClicked += delegate { MySettings.Static.SessionSettings = PlSettings; MyPluginLog.Log("Settings: " + PlSettings.ToString()); }; } else { b.ButtonClicked += delegate { var name = Checkpoint.SessionName; var path = Path.Combine(MyFileSystem.SavesPath, name.Replace(":", "-")); MyFileUtils.WriteXmlFileToPath(PlSettings, path, MySettingsSession.FILE_NAME, typeof(PluginWorldSettings)); }; } } } } if (m_isNewGame) { PlSettings = new MyObjectBuilder_WorldSettings(); } else { LoadValues(); } }
/// <summary> /// Callback for the confirm button in the plugin settings menu, /// to get the new settings back. /// </summary> private void Settings_OnOkButtonClick() { PlSettings = SettingsGui.GetSettings(); PlSettings.Enabled = m_enablePlugin.IsChecked; }