예제 #1
0
        /// <summary>
        /// Loads all planets that are in the world
        /// </summary>
        private void LoadPlanetsInWorld(string selectPlanet = null)
        {
            m_planetListBox.Items.Clear();
            List <MyEntityList.MyEntityListInfoItem> planets = MyEntityList.GetEntityList(MyEntityList.MyEntityTypeEnum.Planets);

            foreach (var item in planets)
            {
                string name = item.DisplayName.Substring(0, item.DisplayName.LastIndexOf("-")).Replace("_", " ").Trim();

                SystemGenerator.Static.GetObject(name, delegate(bool success, MySystemItem obj)
                {
                    if (success)
                    {
                        if (obj.Type == SystemObjectType.PLANET)
                        {
                            m_planetListBox.Items.Add(new MyGuiControlListbox.Item(new StringBuilder(name), null, null, Tuple.Create(obj, item)));
                            if (selectPlanet != null && name.Equals(selectPlanet))
                            {
                                m_planetListBox.SelectSingleItem(m_planetListBox.Items[m_planetListBox.Items.Count - 1]);
                                PlanetListItemClicked(m_planetListBox);
                            }
                        }
                    }
                });
            }
        }
예제 #2
0
        private void LoadPlanetsInWorld()
        {
            List <MyEntityList.MyEntityListInfoItem> planets = MyEntityList.GetEntityList(MyEntityList.MyEntityTypeEnum.Planets);

            foreach (var item in planets)
            {
                string name = item.DisplayName.Replace("_", " ");

                if (name.StartsWith("Moon "))
                {
                    continue;
                }

                m_planetListBox.Items.Add(new MyGuiControlListbox.Item(new StringBuilder(name), null, null, item));
            }
        }
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            if (!MySettingsSession.Static.IsEnabled())
            {
                return;
            }

            CheckIntegrityOfSystem();

            List <MyEntityList.MyEntityListInfoItem> planets = MyEntityList.GetEntityList(MyEntityList.MyEntityTypeEnum.Planets);

            foreach (var p in planets)
            {
                var  e      = MyEntities.GetEntityById(p.EntityId) as MyPlanet;
                bool exists = false;

                foreach (var obj in StarSystem.GetAllObjects())
                {
                    if (obj is MySystemPlanet)
                    {
                        if ((obj as MySystemPlanet).EntityId == p.EntityId)
                        {
                            exists = true;
                        }
                    }
                }
                if (!exists)
                {
                    MySystemPlanet vanillaPlanet = new MySystemPlanet();
                    vanillaPlanet.CenterPosition = e.PositionComp.GetPosition();
                    vanillaPlanet.Diameter       = e.MaximumRadius * 2;
                    vanillaPlanet.DisplayName    = GetPlanetNameForPlanetStorageName(e.StorageName);
                    vanillaPlanet.Generated      = true;
                    vanillaPlanet.EntityId       = p.EntityId;

                    StarSystem.CenterObject.ChildObjects.Add(vanillaPlanet);
                }
            }
            AddAllPersistentGps();
        }
        /// <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;
        }