Example #1
0
        /// <summary>
        /// Rebuilds the UI of the menu, by replacing the combo box at the top, with
        /// a new one with new selectable options, and checks, if a plugin menu should be shown and when yes,
        /// which one, otherwise shows the corresponding vanilla menu
        /// </summary>
        /// <param name="constructor">Whether this is run from constructor</param>
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);

            MyGuiControlCombobox modeCombo = GetCombo();

            int oldCount = modeCombo.GetItemsCount();

            if (MySession.Static.IsUserSpaceMaster(Sync.MyId) && MySession.Static.IsUserAdmin(Sync.MyId))
            {
                modeCombo.AddItem(oldCount, "SEWorldGenPlugin - Rings");
                modeCombo.AddItem(oldCount + 1, "SEWorldGenPlugin - Planets");
            }

            MyGuiControlCombobox newCombo = AddCombo();

            int count = modeCombo.GetItemsCount();

            for (int i = 0; i < count; i++)
            {
                var item = modeCombo.GetItemByIndex(i);
                newCombo.AddItem(item.Key, item.Value);
            }

            newCombo.Position = modeCombo.Position;
            newCombo.SelectItemByKey(m_currentKey);
            Controls[Controls.IndexOf(modeCombo)] = newCombo;
            Controls.Remove(modeCombo);

            newCombo.ItemSelected += delegate
            {
                m_currentKey = newCombo.GetSelectedKey();
                if (newCombo.GetSelectedKey() >= oldCount)
                {
                    RecreateControls(false);
                }
                else
                {
                    m_attachedEntity = 0L;
                    m_selectedPlanet = null;
                    modeCombo.SelectItemByKey(newCombo.GetSelectedKey());
                    RecreateControls(false);
                }
            };
            if (newCombo.GetSelectedKey() == oldCount)
            {
                ClearControls();
                CheckBuildPluginControls(BuildRingMenu);
            }
            else if (newCombo.GetSelectedKey() == oldCount + 1)
            {
                ClearControls();
                CheckBuildPluginControls(BuildPlanetMenu);
            }
        }
        public static List <MyGuiControlCombobox.Item> ItemsAsList(this MyGuiControlCombobox combo)
        {
            var list = new List <MyGuiControlCombobox.Item>();

            for (var i = 0; i < combo.GetItemsCount(); i++)
            {
                list.Add(combo.GetItemByIndex(i));
            }

            return(list);
        }