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);
        }
Exemplo n.º 2
0
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            var caption = AddCaption("SEWorldGenPlugin world settings");

            caption.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;
            caption.Position    = new Vector2(0, SIZE.Y / -2 + PADDING.Y);

            MyGuiControlButton OkButton = new MyGuiControlButton(null, VRage.Game.MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM, null, VRage.MyTexts.Get(MyCommonTexts.Ok), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_ACTIVE, OkButtonClicked);

            OkButton.Position = new Vector2(0, SIZE.Y / 2 - PADDING.Y);
            Controls.Add(OkButton);

            MyGuiControlSeparatorList separators = new MyGuiControlSeparatorList();

            separators.AddHorizontal(SIZE / -2 + PADDING + new Vector2(0, caption.Size.Y) + CHILD_MARGINS_VERT, SIZE.X - 2 * PADDING.X);
            separators.AddHorizontal(new Vector2(SIZE.X / -2 + PADDING.X, SIZE.Y / 2 - PADDING.Y - OkButton.Size.Y) - CHILD_MARGINS_VERT, SIZE.X - 2 * PADDING.X);
            Controls.Add(separators);

            MyGuiControlParentTableLayout parent = new MyGuiControlParentTableLayout(2);

            parent.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;

            //Generate rows for parent layout containing settings

            var systemGenLabel       = new MyGuiControlLabel(null, null, "Generator mode");
            var asteroidGenLabel     = new MyGuiControlLabel(null, null, "Asteroid generator mode");
            var enableVanillaLabel   = new MyGuiControlLabel(null, null, "Use vanilla planets");
            var planetCountLabel     = new MyGuiControlLabel(null, null, "Planet count");
            var asteroidCountLabel   = new MyGuiControlLabel(null, null, "Asteroid object count");
            var oribtDistanceLabel   = new MyGuiControlLabel(null, null, "Orbit distances");
            var asteroidDensityLabel = new MyGuiControlLabel(null, null, "Asteroid density");
            var worldSizeLabel       = new MyGuiControlLabel(null, null, "World size");
            var planetSizeCapLabel   = new MyGuiControlLabel(null, null, "Planet size cap");
            var planetSizeMultLabel  = new MyGuiControlLabel(null, null, "Planet size multiplier");
            var planetMoonPropLabel  = new MyGuiControlLabel(null, null, "Planet moon probability");
            var planetRingPropLabel  = new MyGuiControlLabel(null, null, "Planet ring probability");
            var planetMoonCountLabel = new MyGuiControlLabel(null, null, "Planet moon count");
            var planetGpsModeLabel   = new MyGuiControlLabel(null, null, "Planet gps mode");
            var moonGpsModeLabel     = new MyGuiControlLabel(null, null, "Moon gps mode");
            var asteroidGpsModeLabel = new MyGuiControlLabel(null, null, "Asteroid gps mode");

            m_systemGeneratorCombo = new MyGuiControlCombobox(null, null);
            m_systemGeneratorCombo.SetToolTip(MyPluginTexts.TOOLTIPS.SYS_GEN_MODE_COMBO);
            m_systemGeneratorCombo.AddItem((long)SystemGenerationMethod.FULL_RANDOM, "Full random");
            m_systemGeneratorCombo.AddItem((long)SystemGenerationMethod.UNIQUE, "Unique");
            m_systemGeneratorCombo.AddItem((long)SystemGenerationMethod.MANDATORY_FIRST, "Mandatory first");
            m_systemGeneratorCombo.AddItem((long)SystemGenerationMethod.MANDATORY_ONLY, "Mandatory only");

            m_systemGeneratorCombo.Size = new Vector2(0.25f, m_systemGeneratorCombo.Size.Y);

            parent.AddTableRow(systemGenLabel, m_systemGeneratorCombo);

            m_asteroidGeneratorCombo = new MyGuiControlCombobox();
            m_asteroidGeneratorCombo.SetToolTip(MyPluginTexts.TOOLTIPS.ASTEROID_GEN_MODE_COMBO);
            m_asteroidGeneratorCombo.AddItem((long)AsteroidGenerationMethod.PLUGIN, "Plugin");
            m_asteroidGeneratorCombo.AddItem((long)AsteroidGenerationMethod.VANILLA, "Vanilla");
            m_asteroidGeneratorCombo.AddItem((long)AsteroidGenerationMethod.BOTH, "Combined");
            m_asteroidGeneratorCombo.ItemSelected += delegate
            {
                m_asteroidGPSModeCombo.Enabled  = m_asteroidGPSModeCombo.GetSelectedIndex() != (long)AsteroidGenerationMethod.VANILLA;
                m_asteroidDensitySlider.Enabled = m_asteroidGPSModeCombo.GetSelectedIndex() != (long)AsteroidGenerationMethod.VANILLA;
            };

            m_asteroidGeneratorCombo.Size = new Vector2(0.25f, m_asteroidGeneratorCombo.Size.Y);

            parent.AddTableRow(asteroidGenLabel, m_asteroidGeneratorCombo);

            m_enableVanillaPlanetsCheckbox = new MyGuiControlCheckbox();
            m_enableVanillaPlanetsCheckbox.SetToolTip(MyPluginTexts.TOOLTIPS.VANILLA_PLANETS_CHECK);

            parent.AddTableRow(enableVanillaLabel, m_enableVanillaPlanetsCheckbox);

            m_planetCountSlider = new MyGuiControlRangedSlider(0, 50, 5, 15, true, width: 0.25f);
            m_planetCountSlider.SetToolTip(MyPluginTexts.TOOLTIPS.PLANET_COUNT_SLIDER);

            parent.AddTableRow(planetCountLabel, m_planetCountSlider);

            m_asteroidCountSlider = new MyGuiControlRangedSlider(0, 50, 5, 15, true, width: 0.25f);
            m_asteroidCountSlider.SetToolTip(MyPluginTexts.TOOLTIPS.ASTEROID_COUNT_SLIDER);

            parent.AddTableRow(asteroidCountLabel, m_asteroidCountSlider);

            m_orbitDistancesSlider = new MyGuiControlRangedSlider(100, 10000000, 40000, 1000000, width: 0.25f, useLogScale: true);
            m_orbitDistancesSlider.SetToolTip(MyPluginTexts.TOOLTIPS.ORBIT_DISTANCE_SLIDER);

            parent.AddTableRow(oribtDistanceLabel, m_orbitDistancesSlider);

            m_asteroidDensitySlider = new MyGuiControlClickableSlider(minValue: 0, maxValue: 1, defaultValue: 0.6f, width: 0.25f, showLabel: true);
            m_asteroidDensitySlider.SetToolTip(MyPluginTexts.TOOLTIPS.ASTEROID_DENS_SLIDER);

            parent.AddTableRow(asteroidDensityLabel, m_asteroidDensitySlider);

            m_worldSizeSlider = new MyGuiControlClickableSlider(minValue: -1, maxValue: 1000000000, defaultValue: -1, width: 0.25f, showLabel: true, labelSuffix: " Km");
            m_worldSizeSlider.SetToolTip(MyPluginTexts.TOOLTIPS.WORLD_SIZE_SLIDER);
            m_worldSizeSlider.OnLabelUpdate += delegate(MyGuiControlLabel l)
            {
                if (m_worldSizeSlider.Value < 0)
                {
                    l.Text = "Infinite";
                }
            };

            parent.AddTableRow(worldSizeLabel, m_worldSizeSlider);

            m_planetSizeCapSlider = new MyGuiControlClickableSlider(minValue: 1, maxValue: 2400000, defaultValue: 1200000, intValue: true, width: 0.25f, showLabel: true, labelSuffix: " m");
            m_planetSizeCapSlider.SetToolTip(MyPluginTexts.TOOLTIPS.PLANET_SIZE_CAP_SLIDER);

            parent.AddTableRow(planetSizeCapLabel, m_planetSizeCapSlider);

            m_planetSizeMultSlider = new MyGuiControlClickableSlider(minValue: 0.1f, maxValue: 10, defaultValue: 2, width: 0.25f, showLabel: true);
            m_planetSizeMultSlider.SetToolTip(MyPluginTexts.TOOLTIPS.PLANET_SIZE_MULT);

            parent.AddTableRow(planetSizeMultLabel, m_planetSizeMultSlider);

            m_planetMoonBasePropSlider = new MyGuiControlClickableSlider(minValue: 0f, maxValue: 1f, defaultValue: 0.5f, width: 0.25f, showLabel: true);
            m_planetMoonBasePropSlider.SetToolTip(MyPluginTexts.TOOLTIPS.PLANET_MOON_PROP);

            parent.AddTableRow(planetMoonPropLabel, m_planetMoonBasePropSlider);

            m_planetRingBasePropSlider = new MyGuiControlClickableSlider(minValue: 0f, maxValue: 1f, defaultValue: 0.5f, width: 0.25f, showLabel: true);
            m_planetRingBasePropSlider.SetToolTip(MyPluginTexts.TOOLTIPS.PLANET_RING_PROP);

            parent.AddTableRow(planetRingPropLabel, m_planetRingBasePropSlider);

            m_planetMoonMinMaxSlider = new MyGuiControlRangedSlider(1, 50, 1, 25, true, showLabel: true, width: 0.25f);
            m_planetMoonMinMaxSlider.SetToolTip(MyPluginTexts.TOOLTIPS.PLANET_MOON_COUNT);

            parent.AddTableRow(planetMoonCountLabel, m_planetMoonMinMaxSlider);

            m_planetGPSModeCombo = new MyGuiControlCombobox();
            m_planetGPSModeCombo.SetToolTip(MyPluginTexts.TOOLTIPS.PLANET_GPS_COMBO);
            m_planetGPSModeCombo.AddItem((long)MyGPSGenerationMode.DISCOVERY, "Discovery");
            m_planetGPSModeCombo.AddItem((long)MyGPSGenerationMode.PERSISTENT, "Persistent");
            m_planetGPSModeCombo.AddItem((long)MyGPSGenerationMode.NONE, "None");

            m_planetGPSModeCombo.Size = new Vector2(0.25f, m_planetGPSModeCombo.Size.Y);

            parent.AddTableRow(planetGpsModeLabel, m_planetGPSModeCombo);

            m_moonGPSModeCombo = new MyGuiControlCombobox();
            m_moonGPSModeCombo.SetToolTip(MyPluginTexts.TOOLTIPS.MOON_GPS_COMBO);
            m_moonGPSModeCombo.AddItem((long)MyGPSGenerationMode.DISCOVERY, "Discovery");
            m_moonGPSModeCombo.AddItem((long)MyGPSGenerationMode.PERSISTENT, "Persistent");
            m_moonGPSModeCombo.AddItem((long)MyGPSGenerationMode.NONE, "None");

            m_moonGPSModeCombo.Size = new Vector2(0.25f, m_moonGPSModeCombo.Size.Y);

            parent.AddTableRow(moonGpsModeLabel, m_moonGPSModeCombo);

            m_asteroidGPSModeCombo = new MyGuiControlCombobox();
            m_asteroidGPSModeCombo.SetToolTip(MyPluginTexts.TOOLTIPS.ASTEROID_GPS_COMBO);
            m_asteroidGPSModeCombo.AddItem((long)MyGPSGenerationMode.DISCOVERY, "Discovery");
            m_asteroidGPSModeCombo.AddItem((long)MyGPSGenerationMode.PERSISTENT, "Persistent");
            m_asteroidGPSModeCombo.AddItem((long)MyGPSGenerationMode.NONE, "None");

            m_asteroidGPSModeCombo.Size = new Vector2(0.25f, m_asteroidGPSModeCombo.Size.Y);

            parent.AddTableRow(asteroidGpsModeLabel, m_asteroidGPSModeCombo);

            parent.ApplyRows();

            Vector2 start = SIZE / -2 + PADDING + new Vector2(0, caption.Size.Y) + CHILD_MARGINS_VERT * 2;
            Vector2 end   = new Vector2(SIZE.X / 2 - PADDING.X, SIZE.Y / 2 - PADDING.Y - OkButton.Size.Y) - CHILD_MARGINS_VERT * 2;

            MyGuiControlScrollablePanel scrollPane = new MyGuiControlScrollablePanel(parent);

            scrollPane.OriginAlign       = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            scrollPane.ScrollbarVEnabled = true;
            scrollPane.Size     = end - start;
            scrollPane.Position = start;

            Controls.Add(scrollPane);
        }
        /// <summary>
        /// Generates the specific gui elements to set ring data and puts them into the parent table
        /// </summary>
        /// <param name="usableWidth">Usable width for gui elements</param>
        /// <param name="parentTable">Parent table</param>
        private void GenerateRingSettingElements(float usableWidth, MyGuiControlParentTableLayout parentTable)
        {
            m_radiusSlider               = new MyGuiControlClickableSlider(width: usableWidth - 0.1f, minValue: 0, maxValue: 1, labelSuffix: " km", showLabel: true);
            m_radiusSlider.Enabled       = false;
            m_radiusSlider.ValueChanged += delegate
            {
                UpdateRingVisual(GetAsteroidDataFromGui());
            };

            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
            {
                UpdateRingVisual(GetAsteroidDataFromGui());
            };

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Width"));
            parentTable.AddTableRow(m_widthSlider);

            m_heightSlider               = new MyGuiControlClickableSlider(null, 0, 1, usableWidth - 0.1f, 0.5f, showLabel: true, labelSuffix: " km");
            m_heightSlider.Enabled       = false;
            m_heightSlider.ValueChanged += delegate
            {
                UpdateRingVisual(GetAsteroidDataFromGui());
            };

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Height"));
            parentTable.AddTableRow(m_heightSlider);

            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_angleXSlider               = new MyGuiControlClickableSlider(null, -90, 90, usableWidth - 0.1f, defaultValue: 0, intValue: true, showLabel: true, labelSuffix: "°");
            m_angleXSlider.Enabled       = false;
            m_angleXSlider.ValueChanged += delegate
            {
                UpdateRingVisual(GetAsteroidDataFromGui());
            };

            m_angleYSlider               = new MyGuiControlClickableSlider(null, -90, 90, usableWidth - 0.1f, defaultValue: 0, intValue: true, showLabel: true, labelSuffix: "°");
            m_angleYSlider.Enabled       = false;
            m_angleYSlider.ValueChanged += delegate
            {
                UpdateRingVisual(GetAsteroidDataFromGui());
            };

            m_angleZSlider               = new MyGuiControlClickableSlider(null, -90, 90, usableWidth - 0.1f, defaultValue: 0, intValue: true, showLabel: true, labelSuffix: "°");
            m_angleZSlider.Enabled       = false;
            m_angleZSlider.ValueChanged += delegate
            {
                UpdateRingVisual(GetAsteroidDataFromGui());
            };

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Angle X Axis"));
            parentTable.AddTableRow(m_angleXSlider);

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Angle Y Axis"));
            parentTable.AddTableRow(m_angleYSlider);

            parentTable.AddTableRow(new MyGuiControlLabel(null, null, "Angle Z Axis"));
            parentTable.AddTableRow(m_angleZSlider);
        }