private MyGuiControlTextbox CreateSeedButton(MyGuiControlList list, string seedValue, float usableWidth)
        {
            var label = AddLabel(MyTexts.GetString(MySpaceTexts.ScreenDebugSpawnMenu_ProceduralSeed), Color.White.ToVector4(), m_scale);
            Controls.Remove(label);
            list.Controls.Add(label);

           var textBox = new MyGuiControlTextbox(m_currentPosition, seedValue, 20, Color.White.ToVector4(), m_scale, MyGuiControlTextboxType.Normal);
            textBox.TextChanged += (MyGuiControlTextbox t) => { seedValue = t.Text; };
            textBox.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            list.Controls.Add(textBox);

            var button = CreateDebugButton(usableWidth, MySpaceTexts.ScreenDebugSpawnMenu_GenerateSeed, (MyGuiControlButton buttonClicked) => { textBox.Text = MyRandom.Instance.Next().ToString(); });
            Controls.Remove(button);
            list.Controls.Add(button);
            return textBox;
        }
        private void CreateSlider(MyGuiControlList list, float usableWidth, float min,float max,ref MyGuiControlSlider slider)
        {
            slider = new MyGuiControlSlider(
               position: m_currentPosition,
               width: 400f / MyGuiConstants.GUI_OPTIMAL_SIZE.X,
               minValue: min,
               maxValue: max,
               labelText: String.Empty,
               labelDecimalPlaces: 4,
               labelScale: 0.75f * m_scale,
               originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
               labelFont: MyFontEnum.Debug);

            slider.DebugScale = m_sliderDebugScale;
            slider.ColorMask = Color.White.ToVector4();
            list.Controls.Add(slider);
        }
        private void ApplyTypeGroupSelectionChange(
            MyGuiControlRadioButtonGroup obj,
            ref bool showsGrid,
            MyGuiControlList targetControlList,
            MyInventoryOwnerTypeEnum? filterType,
            MyGuiControlRadioButtonGroup filterButtonGroup,
            MyGuiControlCheckbox showEmpty,
            MyGuiControlLabel    showEmptyLabel,
            MyGuiControlTextbox blockSearch,
            MyGuiControlButton  blockSearchClear,
            bool isLeftControllist)
        {
            switch (obj.SelectedButton.VisualStyle)
            {
                case MyGuiControlRadioButtonStyleEnum.FilterCharacter:
                    showsGrid = false;

                    showEmpty.Visible        = false;
                    showEmptyLabel.Visible   = false;
                    blockSearch.Visible      = false;
                    blockSearchClear.Visible = false;

                    targetControlList.Position = (isLeftControllist) ? m_leftControlListPosition : m_rightControlListPosition;
                    targetControlList.Size     = m_controlListFullSize;

                    // hack to allow looting, force user on left and interacted corpse on right
                    if (targetControlList == m_leftOwnersControl)
                        CreateInventoryControlInList(m_userAsOwner, targetControlList);
                    else
                        CreateInventoryControlInList(m_interactedAsOwner, targetControlList);
                    break;

                case MyGuiControlRadioButtonStyleEnum.FilterGrid:
                    showsGrid = true;
                    CreateInventoryControlsInList(m_interactedGridOwners, targetControlList, filterType);

                    showEmpty.Visible        = true;
                    showEmptyLabel.Visible   = true;
                    blockSearch.Visible      = true;
                    blockSearchClear.Visible = true;

                    blockSearch.Text = blockSearch.Text;

                    targetControlList.Position = (isLeftControllist) ? m_leftControlListPosWithSearch : m_rightControlListPosWithSearch;
                    targetControlList.Size     = m_controlListSizeWithSearch;
                    break;

                default:
                    Debug.Assert(false, "Invalid branch!");
                    break;
            }
            foreach (var button in filterButtonGroup)
                button.Visible = button.Enabled = showsGrid;

            RefreshSelectedInventoryItem();

            //GR: Do this to return the scrolbar position to zero. Other solution would be to add it to Scrollbar Init but that would cause other bugs so I commented it out for now
            targetControlList.SetScrollBarPage();
        }
        private void CreatePlanetMenu()
        {
            m_currentVoxel = null;
            MyGuiControlList list = new MyGuiControlList(size: new Vector2(SCREEN_SIZE.X,1.0f));

            Vector2 controlPadding = new Vector2(0.02f, 0.02f); // X: Left & Right, Y: Bottom & Top

            float textScale = 0.8f;
            float usableWidth = SCREEN_SIZE.X - HIDDEN_PART_RIGHT - controlPadding.X * 2;

            m_currentPosition = Vector2.Zero;/* -m_size.Value / 2.0f;
            m_currentPosition += controlPadding;*/
            m_scale = textScale;

            var label = AddLabel(MyTexts.GetString(MySpaceTexts.ScreenDebugSpawnMenu_SelectAsteroidType), Vector4.One, m_scale);
            Controls.Remove(label);
            list.Controls.Add(label);

            var combo = AddCombo();
            combo.AddItem(1, MySpaceTexts.ScreenDebugSpawnMenu_PredefinedAsteroids);
            combo.AddItem(2, MySpaceTexts.ScreenDebugSpawnMenu_ProceduralAsteroids);
            combo.AddItem(3, MySpaceTexts.ScreenDebugSpawnMenu_Planets);

            combo.SelectItemByKey(m_asteroid_showPlanet ? 3 : m_asteroid_showPredefinedOrProcedural ? 1 : 2);
            combo.ItemSelected += () => { m_asteroid_showPredefinedOrProcedural = combo.GetSelectedKey() == 1; m_asteroid_showPlanet = combo.GetSelectedKey() == 3; RecreateControls(false); };

            Controls.Remove(combo);
            list.Controls.Add(combo);

            CreatePlanetControls(list, usableWidth);

            AddSeparator(list);
  
            var button = CreateDebugButton(usableWidth, MySpaceTexts.ScreenDebugSpawnMenu_SpawnAsteroid, OnSpawnProceduralAsteroid); 
            Controls.Remove(button);
            list.Controls.Add(button);

            Controls.Add(list);
        }
        private void DisableUnacceptingInventoryControls(MyPhysicalInventoryItem item, MyGuiControlList list)
        {
            foreach (var control in list.Controls.GetVisibleControls())
            {
                if (!control.Enabled)
                    continue;

                var ownerControl = (MyGuiControlInventoryOwner)control;
                var owner = ownerControl.InventoryOwner;
                for (int i = 0; i < owner.InventoryCount; ++i)
                {
                    var inventory = owner.GetInventory(i);
                    if (!inventory.CanItemsBeAdded(0, item.Content.GetId()))
                    {
                        ownerControl.ContentGrids[i].Enabled = false;
                        m_controlsDisabledWhileDragged.Add(ownerControl.ContentGrids[i]);
                    }
                }
            }
        }
        private void CreateInventoryControlInList(MyEntity owner, MyGuiControlList listControl)
        {
            List<MyEntity> inventories = new List<MyEntity>();
            if (owner != null)
                inventories.Add(owner);

            CreateInventoryControlsInList(inventories, listControl);
        }
        private void CreatePlanetCanyonControlls(MyGuiControlList list, float usableWidth)
        {          
            var labelHillTreshold = CreateSliderWithDescription(list, usableWidth, -1.345f, -0.5f, "Planet canyon treshold", ref m_planetCanyonTreshold);
            m_planetCanyonTreshold.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillTreshold.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
            };
            m_planetCanyonTreshold.Value = -0.8f;

            var labelHillBlendTreshold = CreateSliderWithDescription(list, usableWidth, 0f, 1f, "Planet canyon blend size", ref m_planetCanyonBlendTreshold);
            m_planetCanyonBlendTreshold.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillBlendTreshold.Text = MyValueFormatter.GetFormatedFloat(s.Value, 2);
            };
            m_planetCanyonBlendTreshold.Value = 0.1f;

            var labelHillSizeRatio = CreateSliderWithDescription(list, usableWidth, 1.0f, 5.0f, "Planet canyon size ratio", ref m_planetCanyonSizeRatio);
            m_planetCanyonSizeRatio.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillSizeRatio.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
                m_planetCanyonRatioValue = s.Value;
            };
            m_planetCanyonSizeRatio.Value = m_planetCanyonRatioValue;
            m_planetCanyonSizeRatio.ValueChanged += OnPlanetCanyonRatioChanged;

            var labelHillFrequency = CreateSliderWithDescription(list, usableWidth, 0.1f, 3f, "Planet canyon frequency", ref m_planetCanyonFrequency);
            m_planetCanyonFrequency.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillFrequency.Text = MyValueFormatter.GetFormatedFloat(s.Value, 2);
            };
            m_planetCanyonFrequency.Value = 0.11f;

            var labelCanoynNumNoises = CreateSliderWithDescription(list, usableWidth, 1f, 2f, "Planet canyon num noises", ref m_planetCanyonNumNoises);
            m_planetCanyonNumNoises.ValueChanged += (MyGuiControlSlider s) =>
            {
                int value = (int)Math.Ceiling(s.Value);
                labelCanoynNumNoises.Text = value.ToString();
            };
            m_planetCanyonNumNoises.Value = 0.9f;
        }
        public void Init(IMyGuiControlsParent controlsParent, MyEntity thisEntity, MyEntity interactedEntity, MyGridColorHelper colorHelper)
        {
            ProfilerShort.Begin("MyGuiScreenTerminal.ControllerInventory.Init");
            m_userAsEntity = thisEntity;
            m_interactedAsEntity = interactedEntity;
            m_colorHelper = colorHelper;

            m_leftOwnersControl = (MyGuiControlList)controlsParent.Controls.GetControlByName("LeftInventory");
            m_rightOwnersControl = (MyGuiControlList)controlsParent.Controls.GetControlByName("RightInventory");

            m_leftSuitButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftSuitButton");
            m_leftGridButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftGridButton");
            m_leftFilterStorageButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterStorageButton");
            m_leftFilterSystemButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterSystemButton");
            m_leftFilterEnergyButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterEnergyButton");
            m_leftFilterAllButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("LeftFilterAllButton");

            m_rightSuitButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightSuitButton");
            m_rightGridButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightGridButton");
            m_rightFilterStorageButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterStorageButton");
            m_rightFilterSystemButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterSystemButton");
            m_rightFilterEnergyButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterEnergyButton");
            m_rightFilterAllButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("RightFilterAllButton");

            m_throwOutButton = (MyGuiControlButton)controlsParent.Controls.GetControlByName("ThrowOutButton");

            m_hideEmptyLeft         = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("CheckboxHideEmptyLeft");
            m_hideEmptyLeftLabel    = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("LabelHideEmptyLeft");
            m_hideEmptyRight        = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("CheckboxHideEmptyRight");
            m_hideEmptyRightLabel   = (MyGuiControlLabel)controlsParent.Controls.GetControlByName("LabelHideEmptyRight");
            m_blockSearchLeft       = (MyGuiControlTextbox)controlsParent.Controls.GetControlByName("BlockSearchLeft");
            m_blockSearchClearLeft  = (MyGuiControlButton)controlsParent.Controls.GetControlByName("BlockSearchClearLeft");
            m_blockSearchRight      = (MyGuiControlTextbox)controlsParent.Controls.GetControlByName("BlockSearchRight");
            m_blockSearchClearRight = (MyGuiControlButton)controlsParent.Controls.GetControlByName("BlockSearchClearRight");

            m_hideEmptyLeft.Visible         = false;
            m_hideEmptyLeftLabel.Visible    = false;
            m_hideEmptyRight.Visible        = true;
            m_hideEmptyRightLabel.Visible   = true;
            m_blockSearchLeft.Visible       = false;
            m_blockSearchClearLeft.Visible  = false;
            m_blockSearchRight.Visible      = true;
            m_blockSearchClearRight.Visible = true;

            m_hideEmptyLeft.IsCheckedChanged      += HideEmptyLeft_Checked;
            m_hideEmptyRight.IsCheckedChanged     += HideEmptyRight_Checked;
            m_blockSearchLeft.TextChanged         += BlockSearchLeft_TextChanged;
            m_blockSearchClearLeft.ButtonClicked  += BlockSearchClearLeft_ButtonClicked;
            m_blockSearchRight.TextChanged        += BlockSearchRight_TextChanged;
            m_blockSearchClearRight.ButtonClicked += BlockSearchClearRight_ButtonClicked;

            m_leftSuitButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowCharacter);
            m_leftGridButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowConnected);
            m_rightSuitButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowInteracted);
            m_rightGridButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ShowConnected);

            m_leftFilterAllButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterAll);
            m_leftFilterEnergyButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterEnergy);
            m_leftFilterStorageButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterStorage);
            m_leftFilterSystemButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterSystem);

            m_rightFilterAllButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterAll);
            m_rightFilterEnergyButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterEnergy);
            m_rightFilterStorageButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterStorage);
            m_rightFilterSystemButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_FilterSystem);

            m_throwOutButton.SetToolTip(MySpaceTexts.ToolTipTerminalInventory_ThrowOut);
            m_throwOutButton.CueEnum = GuiSounds.None;

            m_leftTypeGroup.Add(m_leftSuitButton);
            m_leftTypeGroup.Add(m_leftGridButton);
            m_rightTypeGroup.Add(m_rightSuitButton);
            m_rightTypeGroup.Add(m_rightGridButton);

            m_leftFilterGroup.Add(m_leftFilterAllButton);
            m_leftFilterGroup.Add(m_leftFilterEnergyButton);
            m_leftFilterGroup.Add(m_leftFilterStorageButton);
            m_leftFilterGroup.Add(m_leftFilterSystemButton);

            m_rightFilterGroup.Add(m_rightFilterAllButton);
            m_rightFilterGroup.Add(m_rightFilterEnergyButton);
            m_rightFilterGroup.Add(m_rightFilterStorageButton);
            m_rightFilterGroup.Add(m_rightFilterSystemButton);

            m_throwOutButton.DrawCrossTextureWhenDisabled = false;
            //m_throwOutButton.Enabled = false;

            // initialize drag and drop
            // maybe this requires screen?
            m_dragAndDrop = new MyGuiControlGridDragAndDrop(MyGuiConstants.DRAG_AND_DROP_BACKGROUND_COLOR,
                                                            MyGuiConstants.DRAG_AND_DROP_TEXT_COLOR,
                                                            0.7f,
                                                            MyGuiConstants.DRAG_AND_DROP_TEXT_OFFSET, true);
            controlsParent.Controls.Add(m_dragAndDrop);

            m_dragAndDrop.DrawBackgroundTexture = false;

            m_throwOutButton.ButtonClicked += throwOutButton_OnButtonClick;
            m_dragAndDrop.ItemDropped += dragDrop_OnItemDropped;

            var thisInventoryOwner = (m_userAsEntity != null && m_userAsEntity.HasInventory) ? m_userAsEntity : null;
            if (thisInventoryOwner != null)
                m_userAsOwner = thisInventoryOwner;

            var targetInventoryOwner = (m_interactedAsEntity != null && m_interactedAsEntity.HasInventory) ? m_interactedAsEntity : null;
            if (targetInventoryOwner != null)
                m_interactedAsOwner = targetInventoryOwner;

            var parentGrid = (m_interactedAsEntity != null) ? m_interactedAsEntity.Parent as MyCubeGrid : null;
            m_interactedGridOwners.Clear();
            if (parentGrid != null)
            {
                var group = MyCubeGridGroups.Static.Logical.GetGroup(parentGrid);
                foreach (var node in group.Nodes)
                {
                    GetGridInventories(node.NodeData, m_interactedGridOwners);
                    node.NodeData.GridSystems.ConveyorSystem.BlockAdded += ConveyorSystem_BlockAdded;
                    node.NodeData.GridSystems.ConveyorSystem.BlockRemoved += ConveyorSystem_BlockRemoved;

                    m_registeredConveyorSystems.Add(node.NodeData.GridSystems.ConveyorSystem);
                }
            }
            
            m_leftTypeGroup.SelectedIndex = 0;
            m_rightTypeGroup.SelectedIndex = (m_interactedAsEntity is MyCharacter) || (m_interactedAsEntity is MyInventoryBagEntity) ? 0 : 1;
            m_leftFilterGroup.SelectedIndex = 0;
            m_rightFilterGroup.SelectedIndex = 0;

            LeftTypeGroup_SelectedChanged(m_leftTypeGroup);
            RightTypeGroup_SelectedChanged(m_rightTypeGroup);
            SetLeftFilter(null);
            SetRightFilter(null);

            m_leftTypeGroup.SelectedChanged += LeftTypeGroup_SelectedChanged;
            m_rightTypeGroup.SelectedChanged += RightTypeGroup_SelectedChanged;

            m_leftFilterAllButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(null); };
            m_leftFilterEnergyButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(MyInventoryOwnerTypeEnum.Energy); };
            m_leftFilterStorageButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(MyInventoryOwnerTypeEnum.Storage); };
            m_leftFilterSystemButton.SelectedChanged += (button) => { if (button.Selected) SetLeftFilter(MyInventoryOwnerTypeEnum.System); };

            m_rightFilterAllButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(null); };
            m_rightFilterEnergyButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(MyInventoryOwnerTypeEnum.Energy); };
            m_rightFilterStorageButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(MyInventoryOwnerTypeEnum.Storage); };
            m_rightFilterSystemButton.SelectedChanged += (button) => { if (button.Selected) SetRightFilter(MyInventoryOwnerTypeEnum.System); };

            if (m_interactedAsEntity == null)
            {
                m_leftGridButton.Enabled = false;
                m_rightGridButton.Enabled = false;
                m_rightTypeGroup.SelectedIndex = 0;
            }

            RefreshSelectedInventoryItem();
            ProfilerShort.End();
        }
        private void CreateInventoryControlInList(IMyInventoryOwner owner, MyGuiControlList listControl)
        {
            List<IMyInventoryOwner> inventories = new List<IMyInventoryOwner>();
            if (owner != null)
                inventories.Add(owner);

            CreateInventoryControlsInList(inventories, listControl);
        }
        private void CreatePlanetHillControlls(MyGuiControlList list, float usableWidth)
        {
            var labelHillTreshold = CreateSliderWithDescription(list, usableWidth, 0f, 2f, "Planet hill treshold", ref m_planetHillTreshold);
            m_planetHillTreshold.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillTreshold.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
            };
            m_planetHillTreshold.Value = 0.5f;

            var labelHillBlendTreshold = CreateSliderWithDescription(list, usableWidth, 0f, 1f, "Planet hill blend size", ref m_planetHillBlendTreshold);
            m_planetHillBlendTreshold.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillBlendTreshold.Text = MyValueFormatter.GetFormatedFloat(s.Value, 2);
            };
            m_planetHillBlendTreshold.Value = 0.4f;

            var labelHillSizeRatio = CreateSliderWithDescription(list, usableWidth, 1f, 5f, "Planet hill size ratio", ref m_planetHillSizeRatio);
            m_planetHillSizeRatio.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillSizeRatio.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
                m_planetHillRatioValue = s.Value;
            };
            m_planetHillSizeRatio.Value = m_planetHillRatioValue;
            m_planetHillSizeRatio.ValueChanged += OnPlanetHillRatioChanged;

            var labelHillFrequency = CreateSliderWithDescription(list, usableWidth, 0.1f, 4f, "Planet hill frequency", ref m_planetHillFrequency);
            m_planetHillFrequency.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelHillFrequency.Text = MyValueFormatter.GetFormatedFloat(s.Value, 2);
            };
            m_planetHillFrequency.Value = 2f;

            var labelHillNumNoises = CreateSliderWithDescription(list, usableWidth, 1f, 4f, "Planet hill num noises", ref m_planetHillNumNoises);
            m_planetHillNumNoises.ValueChanged += (MyGuiControlSlider s) =>
            {
                int value = (int)Math.Ceiling(s.Value);
                labelHillNumNoises.Text = value.ToString();
            };
            m_planetHillNumNoises.Value = 2f;
        }
        public override void RecreateControls(bool contructor)
        {
            base.RecreateControls(contructor);

            ProfilerShort.Begin("MyGuiScreenCubeBuilder.RecreateControls");

            m_gridBlocks.MouseOverIndexChanged += OnGridMouseOverIndexChanged;
            m_gridBlocks.ItemSelected += OnSelectedItemChanged;

            m_blockInfoStyle = new MyGuiControlBlockInfo.MyControlBlockInfoStyle()
			{
				BlockNameLabelFont = MyFontEnum.White,
				EnableBlockTypeLabel = false,
				ComponentsLabelText = MySpaceTexts.HudBlockInfo_Components,
				ComponentsLabelFont = MyFontEnum.Blue,
				InstalledRequiredLabelText = MySpaceTexts.HudBlockInfo_Installed_Required,
				InstalledRequiredLabelFont = MyFontEnum.Blue,
                RequiredLabelText = MyCommonTexts.HudBlockInfo_Required,
				IntegrityLabelFont = MyFontEnum.White,
				IntegrityBackgroundColor = new Vector4(78 / 255.0f, 116 / 255.0f, 137 / 255.0f, 1.0f),
				IntegrityForegroundColor = new Vector4(0.5f, 0.1f, 0.1f, 1),
				IntegrityForegroundColorOverCritical = new Vector4(118 / 255.0f, 166 / 255.0f, 192 / 255.0f, 1.0f),
				LeftColumnBackgroundColor = new Vector4(46 / 255.0f, 76 / 255.0f, 94 / 255.0f, 1.0f),
				TitleBackgroundColor = new Vector4(72 / 255.0f, 109 / 255.0f, 130 / 255.0f, 1.0f),
				ComponentLineMissingFont = MyFontEnum.Red,
				ComponentLineAllMountedFont = MyFontEnum.White,
				ComponentLineAllInstalledFont = MyFontEnum.Blue,
				ComponentLineDefaultFont = MyFontEnum.White,
				ComponentLineDefaultColor = new Vector4(0.6f, 0.6f, 0.6f, 1f),
				ShowAvailableComponents = false,
                EnableBlockTypePanel = false,
			};

            m_rbGridSizeSmall = (MyGuiControlRadioButton)Controls.GetControlByName("GridSizeSmall");
            if(m_rbGridSizeSmall == null) 
                Debug.Fail("Someone changed CubeBuilder.gsc file in Content folder? Please check");

            m_rbGridSizeSmall.HighlightType = MyGuiControlHighlightType.NEVER;
            m_rbGridSizeSmall.SelectedChanged += OnGridSizeSmallSelected;

            m_rbGridSizeLarge = (MyGuiControlRadioButton)Controls.GetControlByName("GridSizeLarge");
            if (m_rbGridSizeLarge == null)
                Debug.Fail("Someone changed CubeBuilder.gsc file in Content folder? Please check");

            m_rbGridSizeLarge.HighlightType = MyGuiControlHighlightType.NEVER;
            m_rbGridSizeLarge.SelectedChanged += OnGridSizeLargeSelected;

            m_rbGroupGridSize = new MyGuiControlRadioButtonGroup { m_rbGridSizeSmall, m_rbGridSizeLarge };
            if (MyCubeBuilder.Static != null)
            {
                m_rbGroupGridSize.SelectedIndex = MyCubeBuilder.Static.CubeBuilderState.CubeSizeMode == MyCubeSize.Small ? 0 : 1;
            }

            MyGuiControlLabel gridSizeLabel = (MyGuiControlLabel)Controls.GetControlByName("GridSizeHintLabel");
            gridSizeLabel.Text = string.Format(MyTexts.GetString(gridSizeLabel.TextEnum), MyGuiSandbox.GetKeyName(MyControlsSpace.CUBE_BUILDER_CUBESIZE_MODE));

            m_blockInfoList = (MyGuiControlList)Controls.GetControlByName("BlockInfoPanel");
            if (m_blockInfoList == null)
                Debug.Fail("Someone changed CubeBuilder.gsc file in Content folder? Please check");



            //m_blockInfoSmall = new MyGuiControlBlockInfo(style, false, false);
            //m_blockInfoSmall.Visible = false;
            //m_blockInfoSmall.IsActiveControl = false;
            //m_blockInfoSmall.BlockInfo = new MyHudBlockInfo();
            //m_blockInfoSmall.Position = new Vector2(0.28f, -0.04f);
            //m_blockInfoSmall.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            //Controls.Add(m_blockInfoSmall);
            //m_blockInfoLarge = new MyGuiControlBlockInfo(style, false, true);
            //m_blockInfoLarge.Visible = false;
            //m_blockInfoLarge.IsActiveControl = false;
            //m_blockInfoLarge.BlockInfo = new MyHudBlockInfo();
            //m_blockInfoLarge.Position = new Vector2(0.28f, -0.06f);
            //m_blockInfoLarge.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            //Controls.Add(m_blockInfoLarge);

            ProfilerShort.End();
        }
        internal MyGuiControlGenericFunctionalBlock(MyTerminalBlock[] blocks) :
            base(canHaveFocus: true,
                  allowFocusingElements: true,
                  isActiveControl: false)
        {
            this.m_currentBlocks = blocks;

            m_separatorList = new MyGuiControlSeparatorList();
            Elements.Add(m_separatorList);

            m_terminalControlList = new MyGuiControlList();
            m_terminalControlList.VisualStyle = MyGuiControlListStyleEnum.Simple;
            m_terminalControlList.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;
            m_terminalControlList.Position = new Vector2(0.1f, 0.1f);
            Elements.Add(m_terminalControlList);

            m_blockPropertiesMultilineText = new MyGuiControlMultilineText(
                position: new Vector2(0.049f, -0.195f),
                size: new Vector2(0.39f, 0.635f),
                font: MyFontEnum.Blue,
                textScale: 0.85f,
                textAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP
                );
            m_blockPropertiesMultilineText.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            m_blockPropertiesMultilineText.Text = new StringBuilder();
            Elements.Add(m_blockPropertiesMultilineText);

            m_transferToCombobox = new MyGuiControlCombobox(
                Vector2.Zero,
                new Vector2(0.15f, 0.1f),
                null, null);
            m_transferToCombobox.ItemSelected += m_transferToCombobox_ItemSelected;
            Elements.Add(m_transferToCombobox);

            m_shareModeCombobox = new MyGuiControlCombobox(
            Vector2.Zero,
            new Vector2(0.25f, 0.1f),
            null, null);
            m_shareModeCombobox.ItemSelected += m_shareModeCombobox_ItemSelected;
            Elements.Add(m_shareModeCombobox);

            m_ownershipLabel = new MyGuiControlLabel(
                Vector2.Zero, null, MyTexts.GetString(MySpaceTexts.BlockOwner_Owner) + ":");
            Elements.Add(m_ownershipLabel);

            m_ownerLabel = new MyGuiControlLabel(
                Vector2.Zero, null, String.Empty);
            Elements.Add(m_ownerLabel);

            m_transferToLabel = new MyGuiControlLabel(
                Vector2.Zero, null, MyTexts.GetString(MySpaceTexts.BlockOwner_TransferTo));
            Elements.Add(m_transferToLabel);

            if (MySession.Static.CreativeMode)
            {
                var topLeftRelative = Vector2.One * -0.5f;
                Vector2 leftColumnSize = new Vector2(0.3f, 0.55f);
                var position = topLeftRelative + new Vector2(leftColumnSize.X + 0.503f, 0.42f);

                m_npcButton = new MyGuiControlButton(
                    position,
                    MyGuiControlButtonStyleEnum.Tiny,
                    new Vector2(0.1f, 0.1f),
                    null, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER, MyTexts.GetString(MyCommonTexts.AddNewNPC), new StringBuilder("+"),
                    MyGuiConstants.DEFAULT_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_ACTIVE, true,
                    OnNewNpcClick, GuiSounds.MouseClick, 0.75f);
                Elements.Add(m_npcButton);
            }


            RecreateBlockControls();
            RecreateOwnershipControls();

            if (m_currentBlocks.Length > 0)
            {
                m_currentBlocks[0].PropertiesChanged += block_PropertiesChanged;
            }

            foreach (var block in m_currentBlocks)
            {
                block.OwnershipChanged += block_OwnershipChanged;
                block.VisibilityChanged += block_VisibilityChanged;
            }

            Sync.Players.IdentitiesChanged += Players_IdentitiesChanged;

            UpdateDetailedInfo();

            Size = new Vector2(0.595f, 0.64f);
        }
        public override void RecreateControls(bool constructor)
        {
            base.RecreateControls(constructor);
            AddCaption(MyTexts.GetString(MyCommonTexts.PerformanceWarningHelpHeader));

            m_warningsList = new MyGuiControlList(position: new Vector2(0f, -0.05f), size: new Vector2(0.92f, 0.7f));
            var m_showWarningsLabel = new MyGuiControlLabel(
                text: MyTexts.GetString(MyCommonTexts.ScreenOptionsGame_EnablePerformanceWarnings), 
                position: new Vector2(-0.17f, 0.35f),
                originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER
                );
            m_showWarningsCheckBox = new MyGuiControlCheckbox(
                toolTip: MyTexts.GetString(MyCommonTexts.ToolTipGameOptionsEnablePerformanceWarnings), 
                position: new Vector2(-0.15f, 0.35f),
                originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER
                );
            m_showWarningsCheckBox.IsChecked = MySandboxGame.Config.EnablePerformanceWarnings;
            m_showWarningsCheckBox.IsCheckedChanged += ShowWarningsChanged;

            var m_showAllLabel = new MyGuiControlLabel(
                text: MyTexts.GetString(MyCommonTexts.PerformanceWarningShowAll),
                position: new Vector2(0.25f, 0.35f),
                originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER
                );
            m_showAllCheckBox = new MyGuiControlCheckbox(
                toolTip: MyTexts.GetString(MyCommonTexts.ToolTipPerformanceWarningShowAll),
                position: new Vector2(0.27f, 0.35f),
                originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER
                );
            m_showAllCheckBox.IsChecked = m_showAll;
            m_showAllCheckBox.IsCheckedChanged += KeepInListChanged;

            m_okButton = new MyGuiControlButton(position: new Vector2(0, 0.42f), text: MyTexts.Get(MyCommonTexts.Ok));
            m_okButton.ButtonClicked += m_okButton_ButtonClicked;

            Controls.Add(m_warningsList);
            Controls.Add(m_showWarningsLabel);
            Controls.Add(m_showWarningsCheckBox);
            Controls.Add(m_showAllLabel);
            Controls.Add(m_showAllCheckBox);
            Controls.Add(m_okButton);

        }
            /// <summary>
            /// Add this area into a list
            /// </summary>
            public void Add(MyGuiControlList list, bool showAll)
            {
                m_header.Position = Vector2.Zero;
                if (m_header.Controls.Count == 0)
                {
                    m_header.Controls.Add(m_titleBackground);
                    m_header.Controls.Add(m_title);
                    m_header.Controls.Add(m_lastOccurence);
                    m_header.Controls.Add(m_separator);
                }

                bool headerAdded = false;
                Warnings.Sort(delegate(WarningLine x, WarningLine y)
                {
                    return x.Warning.Time - y.Warning.Time;
                });
                foreach (var warning in Warnings)
                {
                    if (warning.Warning.Time < 120 || showAll)
                    {
                        if (!headerAdded)
                        {
                            list.Controls.Add(m_header);
                            headerAdded = true;
                        }
                        warning.Prepare();
                        list.Controls.Add(warning.Parent);
                    }
                }
                if (headerAdded && m_graphicsButton != null)
                {
                    list.Controls.Add(m_graphicsButton);
                }
            }
        private void CreatePlanetControls(MyGuiControlList list, float usableWidth)
        {
            var labelDeviation = CreateSliderWithDescription(list, usableWidth, 0f, 1f, "Planet deviation scale", ref m_procAsteroidDeviationScale);
               
            m_procAsteroidDeviationScale.ValueChanged += (MyGuiControlSlider s) =>
            {
                float value = DenormalizeLog(s.Value, MIN_DEVIATION, MAX_DEVIATION);
                labelDeviation.Text = MyValueFormatter.GetFormatedFloat(value * 100.0f, 3) + "%";
                m_planetDeviationScaleValue = value;
            };
            m_procAsteroidDeviationScale.Value = NormalizeLog(0.003f, MIN_DEVIATION, MAX_DEVIATION);
            labelDeviation.Text = MyValueFormatter.GetFormatedFloat(0.003f * 100.0f, 3) + "%";
            m_procAsteroidDeviationScale.ValueChanged += OnPlanetDeviationChanged;

            var asteroidSizeLabel = CreateSliderWithDescription(list, usableWidth, 8000f, 50000f, MyTexts.GetString(MySpaceTexts.ScreenDebugSpawnMenu_ProceduralSize), ref m_procAsteroidSize);

            m_procAsteroidSize.ValueChanged += (MyGuiControlSlider s) => { asteroidSizeLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 0) + "m"; m_procAsteroidSizeValue = s.Value; };
            m_procAsteroidSize.Value = 8000.1f;
            m_procAsteroidSize.ValueChanged += OnPlanetSizeChanged;

            var labelNoise = CreateSliderWithDescription(list, usableWidth, 0.1f, 5f, "Planet structures ratio", ref m_planetStructureRatio);
            m_planetStructureRatio.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelNoise.Text = MyValueFormatter.GetFormatedFloat(s.Value, 2);
            };
            m_planetStructureRatio.Value = 1f;

            var labelNormalNoise = CreateSliderWithDescription(list, usableWidth, 0.1f, 10f, "Planet normal noise ratio", ref m_normalNoiseFrequency);
            m_normalNoiseFrequency.ValueChanged += (MyGuiControlSlider s) =>
            {
                labelNormalNoise.Text = MyValueFormatter.GetFormatedFloat(s.Value, 2);
            };
            m_normalNoiseFrequency.Value = 1f;

            m_procAsteroidSeed = CreateSeedButton(list, m_procAsteroidSeedValue, usableWidth);
        
            var label = AddLabel("Atmosphere", Color.White.ToVector4(), m_scale);
            Controls.Remove(label);
            list.Controls.Add(label);

            m_planetAtmosphere = new MyGuiControlCheckbox(m_currentPosition);
            m_planetAtmosphere.IsChecked = true;
            list.Controls.Add(m_planetAtmosphere);
        }
        private void SearchInList(MyGuiControlTextbox searchText, MyGuiControlList list, bool hideEmpty)
        {
            if (searchText.Text != "")
            {
                String[] tmpSearch = searchText.Text.ToLower().Split(' ');

                foreach (var item in list.Controls)
                {
                    var owner   = (item as MyGuiControlInventoryOwner).InventoryOwner;
                    var tmp     = (owner as MyEntity).DisplayNameText.ToString().ToLower();
                    var add     = true;
                    var isEmpty = true;

                    foreach (var search in tmpSearch)
                    {
                        if (!tmp.Contains(search))
                        {
                            add = false;
                            break;
                        }
                    }

                    if (!add)
                    {
                        for (int i = 0; i < owner.InventoryCount; i++)
                        {
                            System.Diagnostics.Debug.Assert(owner.GetInventory(i) as MyInventory != null, "Null or other inventory type!");

                            foreach (var inventoryItem in (owner.GetInventory(i) as MyInventory).GetItems())
                            {
                                bool matches = true;
                                string inventoryItemName = MyDefinitionManager.Static.GetPhysicalItemDefinition(inventoryItem.Content).DisplayNameText.ToString().ToLower();
                                foreach (var search in tmpSearch)
                                {
                                    if (!inventoryItemName.Contains(search))
                                    {
                                        matches = false;
                                        break;
                                    }
                                }

                                if (matches)
                                {
                                    add = true;
                                    break;
                                }
                            }
                            if (add)
                            {
                                break;
                            }
                        }
                    }

                    if (add)
                    {
                        for (int i = 0; i < owner.InventoryCount; ++i)
                        {
                            if (owner.GetInventory(i).CurrentMass != 0)
                            {
                                isEmpty = false;
                                break;
                            }
                        }
                        item.Visible = (hideEmpty && isEmpty) ? false : true;
                    }
                    else
                        item.Visible = false;
                }
            }
            else
            {
                foreach (var item in list.Controls)
                {
                    bool isEmpty = true;
                    var owner = (item as MyGuiControlInventoryOwner).InventoryOwner;

                    for (int i = 0; i < owner.InventoryCount; ++i)
                    {
                        if (owner.GetInventory(i).CurrentMass != 0)
                        {
                            isEmpty = false;
                            break;
                        }
                    }

                    if (hideEmpty && isEmpty)
                        item.Visible = false;
                    else
                        item.Visible = true;
                }
            }
            list.SetScrollBarPage();
        }
        private void CreateLayersControls(MyGuiControlList list, float usableWidth)
        {
            var button = CreateDebugButton(usableWidth, MySpaceTexts.ScreenDebugSpawnMenu_CreateLayer, OnCreateLayer);
            Controls.Remove(button);
            list.Controls.Add(button);

            button = CreateDebugButton(usableWidth, MySpaceTexts.ScreenDebugSpawnMenu_RemoveLayer, OnRemoveLayer);
            Controls.Remove(button);
            list.Controls.Add(button);

            m_materialLayerDeviationSeed = CreateSeedButton(list, m_materialLayerDeviationSeedValue, usableWidth);

            var layerNoiseLabel = CreateSliderWithDescription(list, usableWidth, 10f, 200.0f, "Layer deviation noise frequency", ref m_materialLayerDeviationNoise);
            m_materialLayerDeviationNoise.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerNoiseLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 2);
            };

            m_layerCombobox = AddCombo();
            m_layerCombobox.ItemSelected += OnLayerCombobox_ItemSelected;
            Controls.Remove(m_layerCombobox);
            list.Controls.Add(m_layerCombobox);

            m_oreComboboxLabel = AddLabel("Layer ore", Vector4.One, m_scale);
            Controls.Remove(m_oreComboboxLabel);
            list.Controls.Add(m_oreComboboxLabel);
            m_oreComboboxLabel.Visible = false;

            m_oreCombobox = AddCombo();
            {
                foreach (var definition in MyDefinitionManager.Static.GetVoxelMaterialDefinitions())
                {
                    m_oreCombobox.AddItem((int)definition.Id.SubtypeId, definition.Id.SubtypeId);
                }
                m_oreCombobox.ItemSelected += OnOreCombobox_ItemSelected;
                m_oreCombobox.SortItemsByValueText();
            }
            m_oreCombobox.Visible = false;
            list.Controls.Add(m_oreCombobox);


            var layerStartLabel = CreateSliderWithDescription(list, usableWidth, -m_procAsteroidSizeValue * m_planetDeviationScaleValue, m_procAsteroidSizeValue * m_planetDeviationScaleValue, "Layer start", ref m_materialLayerStart);
            m_materialLayerStart.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerStartLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 0) + "m";
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].StartHeight = s.Value;
                }

                if (s.Value > m_materialLayerEnd.Value)
                {
                    m_materialLayerEnd.Value = s.Value;
                }
            };

            var layerStartHeigthDeviationLabel = CreateSliderWithDescription(list, usableWidth, 0, 100.0f, "Layer start height deviation", ref m_materialLayerStartHeigthDeviation);
            m_materialLayerStartHeigthDeviation.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerStartHeigthDeviationLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 0) + "m";
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].HeightStartDeviation = s.Value;
                }
            };

            var layerEndLabel = CreateSliderWithDescription(list, usableWidth, -m_procAsteroidSizeValue * m_planetDeviationScaleValue, m_procAsteroidSizeValue * m_planetDeviationScaleValue, "Layer end", ref m_materialLayerEnd);   
            m_materialLayerEnd.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerEndLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 0) + "m";
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].EndHeight = s.Value;
                }
                if (s.Value < m_materialLayerStart.Value)
                {
                    m_materialLayerStart.Value = s.Value;
                }
            };

            var layerHeigthDeviationLabel = CreateSliderWithDescription(list, usableWidth,0, 100.0f, "Layer end height deviation", ref m_materialLayerEndHeigthDeviation);
            m_materialLayerEndHeigthDeviation.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerHeigthDeviationLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 0) + "m";
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].HeightEndDeviation = s.Value;
                }
            };

            var layerAngleStartLabel = CreateSliderWithDescription(list, usableWidth, -1, 1, "Layer angle start", ref m_materialLayerAngleStart);
            m_materialLayerAngleStart.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerAngleStartLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].StartAngle = s.Value;
                }

                if (s.Value > m_materialLayerAngleEnd.Value)
                {
                    m_materialLayerAngleEnd.Value = s.Value;
                }
            };

            var layerStartAngleDeviationLabel = CreateSliderWithDescription(list, usableWidth, 0, 1.0f, "Layer start angle deviation", ref m_materialLayerAngleStartDeviation);
            m_materialLayerAngleStartDeviation.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerStartAngleDeviationLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].AngleStartDeviation = s.Value;
                }
            };

            var layerAngleEndLabel = CreateSliderWithDescription(list, usableWidth, -1, 1, "Layer angle end", ref m_materialLayerAngleEnd);
            m_materialLayerAngleEnd.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerAngleEndLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].EndAngle = s.Value;
                }
                if (s.Value < m_materialLayerAngleStart.Value)
                {
                    m_materialLayerAngleStart.Value = s.Value;
                }
            };

            var layerAngleDeviationLabel = CreateSliderWithDescription(list, usableWidth, 0, 1.0f, "Layer end angle deviation", ref m_materialLayerAngleEndDeviation);
            m_materialLayerAngleEndDeviation.ValueChanged += (MyGuiControlSlider s) =>
            {
                layerAngleDeviationLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 3);
                int currentLayer = m_layerCombobox.GetSelectedIndex();
                if (currentLayer >= 0 && currentLayer < m_materialLayers.Count)
                {
                    m_materialLayers[currentLayer].AngleEndDeviation = s.Value;
                }
            };

        }
        public void Close()
        {
            foreach (var system in m_registeredConveyorSystems)
            {
                system.BlockAdded -= ConveyorSystem_BlockAdded;
                system.BlockRemoved -= ConveyorSystem_BlockRemoved;
            }
            m_registeredConveyorSystems.Clear();
            
            m_leftTypeGroup.Clear();
            m_leftFilterGroup.Clear();
            m_rightTypeGroup.Clear();
            m_rightFilterGroup.Clear();
            m_controlsDisabledWhileDragged.Clear();

            m_leftOwnersControl = null;
            m_leftSuitButton = null;
            m_leftGridButton = null;
            m_leftFilterStorageButton = null;
            m_leftFilterSystemButton = null;
            m_leftFilterEnergyButton = null;
            m_leftFilterAllButton = null;
            m_rightOwnersControl = null;
            m_rightSuitButton = null;
            m_rightGridButton = null;
            m_rightFilterStorageButton = null;
            m_rightFilterSystemButton = null;
            m_rightFilterEnergyButton = null;
            m_rightFilterAllButton = null;
            m_throwOutButton = null;
            m_dragAndDrop = null;
            m_dragAndDropInfo = null;
            m_focusedOwnerControl = null;
            m_focusedGridControl = null;
            m_selectedInventory = null;

            m_hideEmptyLeft.IsCheckedChanged      -= HideEmptyLeft_Checked;
            m_hideEmptyRight.IsCheckedChanged     -= HideEmptyRight_Checked;
            m_blockSearchLeft.TextChanged         -= BlockSearchLeft_TextChanged;
            m_blockSearchClearLeft.ButtonClicked  -= BlockSearchClearLeft_ButtonClicked;
            m_blockSearchRight.TextChanged        -= BlockSearchRight_TextChanged;
            m_blockSearchClearRight.ButtonClicked -= BlockSearchClearRight_ButtonClicked;

            m_hideEmptyLeft         = null;
            m_hideEmptyLeftLabel    = null;
            m_hideEmptyRight        = null;
            m_hideEmptyRightLabel   = null;
            m_blockSearchLeft       = null;
            m_blockSearchClearLeft  = null;
            m_blockSearchRight      = null;
            m_blockSearchClearRight = null;
        }
Пример #19
0
        private void CreateInfoPageControls(MyGuiControlTabPage infoPage)
        {
            infoPage.Name = "PageInfo";
            infoPage.TextEnum = MySpaceTexts.TerminalTab_Info;

            var list = new MyGuiControlList(new Vector2(-0.462f, -0.34f), new Vector2(0.35f, 0.69f));
            //var list = new MyGuiControlMultilineText( new Vector2(-0.462f, -0.34f), new Vector2(0.35f,0.69f), null, MyFontEnum.White, 1, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, new StringBuilder());
            list.Name = "InfoList";
            list.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            infoPage.Controls.Add(list);

            var convertBtn = new MyGuiControlButton();
            convertBtn.TextEnum = MySpaceTexts.TerminalTab_Info_ConvertButton;
            convertBtn.Name = "ConvertBtn";
            infoPage.Controls.Add(convertBtn);

            if (MyFakes.ENABLE_CENTER_OF_MASS)
            {
                var sep = new MyGuiControlSeparatorList();
                sep.AddVertical(new Vector2(0.14f, -0.34f), 0.7f, 0.002f);
                infoPage.Controls.Add(sep);

                var centerBtnLabel = new MyGuiControlLabel(new Vector2(0.15f, -0.32f), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_ShowMassCenter));
                centerBtnLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
                infoPage.Controls.Add(centerBtnLabel);

                var centerBtn = new MyGuiControlCheckbox(new Vector2(0.45f, centerBtnLabel.Position.Y));
                centerBtn.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
                centerBtn.Name = "CenterBtn";
                infoPage.Controls.Add(centerBtn);

            }

            var showGravityGizmoBtnLabel = new MyGuiControlLabel(new Vector2(0.15f, -0.27f), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_ShowGravityGizmo));
            showGravityGizmoBtnLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
            infoPage.Controls.Add(showGravityGizmoBtnLabel);

            var showGravityGizmoBtn = new MyGuiControlCheckbox(new Vector2(0.45f, showGravityGizmoBtnLabel.Position.Y));
            showGravityGizmoBtn.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
            showGravityGizmoBtn.Name = "ShowGravityGizmo";
            infoPage.Controls.Add(showGravityGizmoBtn);

            var showSenzorGizmoBtnLabel = new MyGuiControlLabel(new Vector2(0.15f, -0.22f), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_ShowSenzorGizmo));
            showSenzorGizmoBtnLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
            infoPage.Controls.Add(showSenzorGizmoBtnLabel);

            var showSenzorGizmoBtn = new MyGuiControlCheckbox(new Vector2(0.45f, showSenzorGizmoBtnLabel.Position.Y));
            showSenzorGizmoBtn.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
            showSenzorGizmoBtn.Name = "ShowSenzorGizmo";
            infoPage.Controls.Add(showSenzorGizmoBtn);

            var showAntenaGizmoBtnLabel = new MyGuiControlLabel(new Vector2(0.15f, -0.17f), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_ShowAntenaGizmo));
            showAntenaGizmoBtnLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
            infoPage.Controls.Add(showAntenaGizmoBtnLabel);

            var showAntenaGizmoBtn = new MyGuiControlCheckbox(new Vector2(0.45f, showAntenaGizmoBtnLabel.Position.Y));
            showAntenaGizmoBtn.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
            showAntenaGizmoBtn.Name = "ShowAntenaGizmo";
            infoPage.Controls.Add(showAntenaGizmoBtn);

            CreateAntennaSlider(infoPage, MyTexts.GetString(MySpaceTexts.TerminalTab_Info_FriendlyAntennaRange),"FriendAntennaRange",-0.13f);
            CreateAntennaSlider(infoPage, MyTexts.GetString(MySpaceTexts.TerminalTab_Info_EnemyAntennaRange), "EnemyAntennaRange", -0.01f);
            CreateAntennaSlider(infoPage, MyTexts.GetString(MySpaceTexts.TerminalTab_Info_OwnedAntennaRange), "OwnedAntennaRange", 0.11f);

            var pivotBtnLabel = new MyGuiControlLabel(new Vector2(0.15f, 0.23f), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_PivotBtn));
            pivotBtnLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
            infoPage.Controls.Add(pivotBtnLabel);

            var pivotBtn = new MyGuiControlCheckbox(new Vector2(0.45f, pivotBtnLabel.Position.Y));
            pivotBtn.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
            pivotBtn.Name = "PivotBtn";
            infoPage.Controls.Add(pivotBtn);

            if (MyFakes.ENABLE_TERMINAL_PROPERTIES)
            {
                var nameLabel = new MyGuiControlLabel()
                {
                    Name = "RenameShipLabel",
                    Text = "Ship Name",
                    Position = new Vector2(0.15f, 0.26f)
                };
                var nameTextBox = new MyGuiControlTextbox()
                {
                    Name = "RenameShipText",
                    Position = new Vector2(0.25f, 0.3f),
                    Size = new Vector2(0.2f, 0.005f)
                };

                var renameButton = new MyGuiControlButton()
                {
                    Name = "RenameShipButton",
                    Position = new Vector2(0.38f, 0.3f),
                    Text = "Ok",
                    VisualStyle = MyGuiControlButtonStyleEnum.Tiny,
                };
                infoPage.Controls.Add(nameLabel);
                infoPage.Controls.Add(nameTextBox);
                infoPage.Controls.Add(renameButton);
            }

            var setDestructibleBlocksLabel = new MyGuiControlLabel(new Vector2(0.15f, 0.28f), text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_DestructibleBlocks));
            setDestructibleBlocksLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
            setDestructibleBlocksLabel.Visible = MySession.Static.Settings.ScenarioEditMode || MySession.Static.IsScenario;
            infoPage.Controls.Add(setDestructibleBlocksLabel);

            var setDestructibleBlocksBtn = new MyGuiControlCheckbox(new Vector2(0.45f, setDestructibleBlocksLabel.Position.Y), toolTip: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_DestructibleBlocks_Tooltip));
            setDestructibleBlocksBtn.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
            setDestructibleBlocksBtn.Name = "SetDestructibleBlocks";
            infoPage.Controls.Add(setDestructibleBlocksBtn);
        }
        private void DisableUnreachableInventoryControls(MyInventory srcInventory, MyPhysicalInventoryItem item, MyGuiControlList list)
        {
            bool fromUser = srcInventory.Owner == m_userAsOwner;
            bool fromInteracted = srcInventory.Owner == m_interactedAsOwner;

            // srcEndpoint will be the endpoint from which we search the graph
            var srcInventoryOwner = srcInventory.Owner;
            IMyConveyorEndpointBlock srcEndpoint = null;
            // Search the interacted's graph if we want to transfer from the user
            if (fromUser)
            {
                if (m_interactedAsEntity != null)
                    srcEndpoint = m_interactedAsEntity as IMyConveyorEndpointBlock;
            }
            else if (srcInventoryOwner != null)
            {
                srcEndpoint = srcInventoryOwner as IMyConveyorEndpointBlock;
            }

            IMyConveyorEndpointBlock interactedEndpoint = null;
            if (m_interactedAsEntity != null)
            {
                interactedEndpoint = m_interactedAsEntity as IMyConveyorEndpointBlock;
            }

            if (srcEndpoint != null)
            {
                long ownerId = MySession.Static.LocalPlayerId;
                m_interactedEndpointBlock = interactedEndpoint;
                MyGridConveyorSystem.AppendReachableEndpoints(srcEndpoint.ConveyorEndpoint, ownerId, m_reachableInventoryOwners, item, m_endpointPredicate);
            }

            foreach (var control in list.Controls.GetVisibleControls())
            {
                if (!control.Enabled)
                    continue;

                var ownerControl = (MyGuiControlInventoryOwner)control;
                var owner = ownerControl.InventoryOwner;

                IMyConveyorEndpoint endpoint = null;
                var ownerBlock = owner as IMyConveyorEndpointBlock;
                if (ownerBlock != null)
                    endpoint = ownerBlock.ConveyorEndpoint;

                // TODO: Make some of these as functions so we don't have to call it even when not used due to lazy evaluation
                bool transferIsLocal = owner == srcInventoryOwner;
                bool transferIsClose = (fromUser && owner == m_interactedAsOwner) || (fromInteracted && owner == m_userAsOwner);
                bool transferIsFar = !transferIsLocal && !transferIsClose;
                bool endpointUnreachable = !m_reachableInventoryOwners.Contains(endpoint);
                bool interactedReachable = interactedEndpoint != null && m_reachableInventoryOwners.Contains(interactedEndpoint.ConveyorEndpoint);
                // If interacted is reachable but does not have inventory, than you cant take anything out from it.
                // WARNING: no need for check of null on m_interactedAsEntity, because interactedEndpoint is checked above already (that will be null also if the other is)
                bool toOwnerThroughInteracted = owner == m_userAsOwner && interactedReachable && m_interactedAsEntity.HasInventory;

                if (transferIsFar && endpointUnreachable && !toOwnerThroughInteracted)
                {
                    for (int i = 0; i < owner.InventoryCount; ++i)
                    {
                        if (!ownerControl.ContentGrids[i].Enabled)
                            continue;

                        ownerControl.ContentGrids[i].Enabled = false;
                        m_controlsDisabledWhileDragged.Add(ownerControl.ContentGrids[i]);
                    }
                }
            }

            m_reachableInventoryOwners.Clear();
        }
Пример #21
0
        private void CreateInventoryPageControls(MyGuiControlTabPage page)
        {
            page.Name      = "PageInventory";
            page.TextEnum  = MySpaceTexts.Inventory;
            page.TextScale = 0.9f;

            #region Left radio buttons
            var leftRadioCharacter = new MyGuiControlRadioButton()
            {
                Position = new Vector2(-0.465f, -0.36f),
                Size = new Vector2(0.056875f, 0.0575f),
                Name = "LeftSuitButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterCharacter
            };
            var leftRadioGrid = new MyGuiControlRadioButton()
            {
                Position = new Vector2(-0.405f, -0.36f),
                Size = new Vector2(0.056875f, 0.0575f),
                Name = "LeftGridButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterGrid
            };
            var leftRadioStorage = new MyGuiControlRadioButton()
            {
                Position = new Vector2(-0.175f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "LeftFilterStorageButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterStorage
            };
            var leftRadioSystem = new MyGuiControlRadioButton()
            {
                Position = new Vector2(-0.125f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "LeftFilterSystemButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterSystem
            };
            var leftRadioEnergy = new MyGuiControlRadioButton()
            {
                Position = new Vector2(-0.075f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "LeftFilterEnergyButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterEnergy
            };
            var leftRadioAll = new MyGuiControlRadioButton()
            {
                Position = new Vector2(-0.025f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "LeftFilterAllButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterAll
            };
            #endregion

            #region Left search filters
            var blockSearchLeft = new MyGuiControlTextbox()
            {
                Position = new Vector2(-0.465f, -0.283f),
                Size = new Vector2(0.288f, 0.052f),
                Name = "BlockSearchLeft",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER
            };
            var blockSearchClearLeft = new MyGuiControlButton()
            {
                Position = new Vector2(-0.2f, -0.283f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "BlockSearchClearLeft",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                VisualStyle = MyGuiControlButtonStyleEnum.Close,
                ActivateOnMouseRelease = true
            };
            var hideEmptyLeft = new MyGuiControlCheckbox()
            {
                Position = new Vector2(-0.025f, -0.283f),
                Name = "CheckboxHideEmptyLeft",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER
            };
            var hideEmptyLeftLabel = new MyGuiControlLabel()
            {
                Position = new Vector2(-0.155f, -0.283f),
                Name = "LabelHideEmptyLeft",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                TextEnum = MySpaceTexts.HideEmpty
            };
            #endregion

            var leftList = new MyGuiControlList()
            {
                Position = new Vector2(-0.465f, -0.26f),
                Size = new Vector2(0.44f, 0.616f),
                Name = "LeftInventory",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP
            };

            page.Controls.Add(leftRadioCharacter);
            page.Controls.Add(leftRadioGrid);
            page.Controls.Add(leftRadioStorage);
            page.Controls.Add(leftRadioSystem);
            page.Controls.Add(leftRadioEnergy);
            page.Controls.Add(leftRadioAll);

            page.Controls.Add(blockSearchLeft);
            page.Controls.Add(blockSearchClearLeft);
            page.Controls.Add(hideEmptyLeft);
            page.Controls.Add(hideEmptyLeftLabel);
            page.Controls.Add(leftList);

            #region Right radio buttons
            var rightRadioCharacter = new MyGuiControlRadioButton()
            {
                Position = new Vector2(0.025f, -0.36f),
                Size = new Vector2(0.056875f, 0.0575f),
                Name = "RightSuitButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterCharacter
            };
            var rightRadioGrid = new MyGuiControlRadioButton()
            {
                Position = new Vector2(0.085f, -0.36f),
                Size = new Vector2(0.056875f, 0.0575f),
                Name = "RightGridButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterGrid
            };
            var rightRadioStorage = new MyGuiControlRadioButton()
            {
                Position = new Vector2(0.315f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "RightFilterStorageButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterStorage
            };
            var rightRadioSystem = new MyGuiControlRadioButton()
            {
                Position = new Vector2(0.365f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "RightFilterSystemButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterSystem
            };
            var rightRadioEnergy = new MyGuiControlRadioButton()
            {
                Position = new Vector2(0.415f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "RightFilterEnergyButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterEnergy
            };
            var rightRadioAll = new MyGuiControlRadioButton()
            {
                Position = new Vector2(0.465f, -0.36f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "RightFilterAllButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP,
                Key = 0,
                VisualStyle = MyGuiControlRadioButtonStyleEnum.FilterAll
            };
            #endregion

            #region Right search filters
            var blockSearchRight = new MyGuiControlTextbox()
            {
                Position = new Vector2(0.025f, -0.283f),
                Size = new Vector2(0.288f, 0.052f),
                Name = "BlockSearchRight",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
            };
            var blockSearchClearRight = new MyGuiControlButton()
            {
                Position = new Vector2(0.29f, -0.283f),
                Size = new Vector2(0.045f, 0.05666667f),
                Name = "BlockSearchClearRight",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                VisualStyle = MyGuiControlButtonStyleEnum.Close,
                ActivateOnMouseRelease = true
            };
            var hideEmptyRight = new MyGuiControlCheckbox()
            {
                Position = new Vector2(0.465f, -0.283f),
                Name = "CheckboxHideEmptyRight",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER
            };
            var hideEmptyRightLabel = new MyGuiControlLabel()
            {
                Position = new Vector2(0.335f, -0.283f),
                Name = "LabelHideEmptyRight",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                TextEnum = MySpaceTexts.HideEmpty
            };
            #endregion

            var rightList = new MyGuiControlList()
            {
                Position = new Vector2(0.465f, -0.295f),
                Size = new Vector2(0.44f, 0.65f),
                Name = "RightInventory",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP
            };

            page.Controls.Add(rightRadioCharacter);
            page.Controls.Add(rightRadioGrid);
            page.Controls.Add(rightRadioStorage);
            page.Controls.Add(rightRadioSystem);
            page.Controls.Add(rightRadioEnergy);
            page.Controls.Add(rightRadioAll);

            page.Controls.Add(blockSearchRight);
            page.Controls.Add(blockSearchClearRight);
            page.Controls.Add(hideEmptyRight);
            page.Controls.Add(hideEmptyRightLabel);
            page.Controls.Add(rightList);

            var trash = new MyGuiControlButton()
            {
                Position = new Vector2(0f, 0.355f),
                Size = new Vector2(0.044375f, 0.13666667f),
                Name = "ThrowOutButton",
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_BOTTOM,
                TextEnum = MySpaceTexts.Afterburner,
                TextScale = 0f,
                TextAlignment = 0f,
                DrawCrossTextureWhenDisabled = true,
                VisualStyle = MyGuiControlButtonStyleEnum.InventoryTrash,
                ActivateOnMouseRelease = true
            };
            page.Controls.Add(trash);
        }
        private void CreateInventoryControlsInList(List<MyEntity> owners, MyGuiControlList listControl, MyInventoryOwnerTypeEnum? filterType = null)
        {
            if (listControl.Controls.Contains(m_focusedOwnerControl))
                m_focusedOwnerControl = null;

            List<MyGuiControlBase> inventoryControlList = new List<MyGuiControlBase>();

            foreach (var owner in owners)
            {
                if (!(owner != null && owner.HasInventory))
                    continue;

                if (filterType.HasValue && (owner as MyEntity).InventoryOwnerType() != filterType)
                    continue;

                Vector4 labelColor = Color.White.ToVector4();
                if (owner is MyCubeBlock)
                {
                    labelColor = m_colorHelper.GetGridColor((owner as MyCubeBlock).CubeGrid).ToVector4();
                }

                var ownerControl = new MyGuiControlInventoryOwner(owner, labelColor);
                ownerControl.Size = new Vector2(listControl.Size.X - 0.045f, ownerControl.Size.Y);
                ownerControl.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
                foreach (var grid in ownerControl.ContentGrids)
                {
                    grid.ItemSelected += grid_ItemSelected;
                    grid.ItemDragged += grid_ItemDragged;
                    grid.ItemDoubleClicked += grid_ItemDoubleClicked;
                    grid.ItemClicked += grid_ItemClicked;
                }
                ownerControl.SizeChanged += inventoryControl_SizeChanged;
                ownerControl.InventoryContentsChanged += ownerControl_InventoryContentsChanged;

                if (owner is MyCubeBlock)
                    ownerControl.Enabled = (owner as MyCubeBlock).IsFunctional;

                // Put inventory of interacted block or character on first position.
                if (owner == m_interactedAsOwner ||
                    owner == m_userAsOwner)
                {
                    inventoryControlList.Insert(0, ownerControl);
                }
                else
                {
                    //sort by name (Inventory filters ticket)
                    inventoryControlList.Add(ownerControl);
                }
            
            }
            listControl.InitControls(inventoryControlList);
        }
        private void RecreateServerLimitInfo(MyGuiControlList list)
        {
            var identity = MySession.Static.Players.TryGetIdentity(MySession.Static.LocalPlayerId);
            int built;

            if (MySession.Static.MaxBlocksPerPlayer > 0 || MySession.Static.BlockTypeLimits.Keys.Count > 0)
            {
                MyGuiControlLabel totalBlocksLabel = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_Overview), textScale: 1.3f);
                list.Controls.Add(totalBlocksLabel);
            }

            if (MySession.Static.MaxBlocksPerPlayer > 0)
            {
                MyGuiControlLabel totalBlocksLabel = new MyGuiControlLabel(text: String.Format("{0} {1}/{2} {3}", MyTexts.Get(MySpaceTexts.TerminalTab_Info_YouBuilt), identity.BlocksBuilt, MySession.Static.MaxBlocksPerPlayer + identity.BlockLimitModifier, MyTexts.Get(MySpaceTexts.TerminalTab_Info_BlocksLower)));
                list.Controls.Add(totalBlocksLabel);
            }
            foreach (var blockType in MySession.Static.BlockTypeLimits)
            {
                identity.BlockTypeBuilt.TryGetValue(blockType.Key, out built);
                var definition = Sandbox.Definitions.MyDefinitionManager.Static.TryGetDefinitionGroup(blockType.Key);
                if (definition == null)
                    continue;
                MyGuiControlLabel blockTypeLabel = new MyGuiControlLabel(text: String.Format("{0} {1}/{2} {3}", MyTexts.Get(MySpaceTexts.TerminalTab_Info_YouBuilt), built, MySession.Static.GetBlockTypeLimit(blockType.Key), definition.Any.DisplayNameText));
                list.Controls.Add(blockTypeLabel);
            }

            foreach (var grid in m_infoGrids)
            {
                grid.OnAuthorshipChanged -= grid_OnAuthorshipChanged;
            }

            m_infoGrids.Clear();
            identity.LockBlocksBuiltByGrid.AcquireExclusive();
            for (int i = 0; i < identity.BlocksBuiltByGrid.Count; i++)
            {
                var grid = identity.BlocksBuiltByGrid.ElementAt(i);
                MyGuiControlParent panel = new MyGuiControlParent();

                if (m_infoGrids.Count == 0)
                {
                    MyGuiControlSeparatorList infoSeparator = new MyGuiControlSeparatorList();
                    infoSeparator.AddHorizontal(new Vector2(-0.2f, -0.052f), 0.4f, width: 0.004f);
                    panel.Controls.Add(infoSeparator);
                }

                MyGuiControlLabel gridNameLabel = new MyGuiControlLabel(text: grid.Key.DisplayName, textScale: 0.9f);
                MyGuiControlLabel gridBlockCountLabel = new MyGuiControlLabel(text: String.Format("{0} {1}", grid.Value, MyTexts.Get(MySpaceTexts.TerminalTab_Info_BlocksLower)), textScale: 0.9f);
                MyGuiControlLabel assignLabel = new MyGuiControlLabel(text: MyTexts.GetString(MySpaceTexts.TerminalTab_Info_Assign), originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER, textScale: 0.9f);
                MyGuiControlCombobox assignCombobox = new MyGuiControlCombobox(originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER, size: new Vector2(0.11f, 0.008f));
                MyGuiControlSeparatorList lineSeparator = new MyGuiControlSeparatorList();

                gridNameLabel.Position = new Vector2(-0.15f, -0.025f);
                gridBlockCountLabel.Position = new Vector2(-0.15f, 0.000f);
                assignLabel.Position = new Vector2(0.035f, 0.025f);
                assignCombobox.Position = new Vector2(0.15f, 0.025f);

                assignCombobox.ItemSelected += delegate()
                {
                    assignCombobox_ItemSelected(grid.Key, m_playerIds[(int)assignCombobox.GetSelectedKey()]);
                };

                m_playerIds.Clear();
                foreach (var player in MySession.Static.Players.GetOnlinePlayers())
                {
                    if (MySession.Static.LocalHumanPlayer != player)
                    {
                        assignCombobox.AddItem(m_playerIds.Count, player.DisplayName);
                        m_playerIds.Add(player.Id);
                    }
                }
                lineSeparator.AddHorizontal(new Vector2(-0.15f, 0.05f), 0.3f, width: 0.002f);

                panel.Controls.Add(gridNameLabel);
                panel.Controls.Add(gridBlockCountLabel);
                panel.Controls.Add(assignLabel);
                panel.Controls.Add(assignCombobox);
                panel.Controls.Add(lineSeparator);

                if (MySession.Static.EnableRemoteBlockRemoval)
                {
                    MyGuiControlLabel deleteOwnedBlocksLabel = new MyGuiControlLabel(
                        text: MyTexts.GetString(MySpaceTexts.buttonRemove), 
                        originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER, 
                        textScale: 0.9f);
                    MyGuiControlButton deleteOwnedBlocksButton = new MyGuiControlButton(
                        text: new StringBuilder("X"), 
                        onButtonClick: deleteOwnedBlocksButton_ButtonClicked, 
                        buttonIndex: m_infoGrids.Count, 
                        visualStyle: MyGuiControlButtonStyleEnum.SquareSmall, 
                        originAlign: VRage.Utils.MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER);
                    deleteOwnedBlocksLabel.Position = new Vector2(0.11f, -0.02f);
                    deleteOwnedBlocksButton.Position = new Vector2(0.15f, -0.02f);
                    panel.Controls.Add(deleteOwnedBlocksLabel);
                    panel.Controls.Add(deleteOwnedBlocksButton);
                }

                grid.Key.OnAuthorshipChanged += grid_OnAuthorshipChanged;

                m_infoGrids.Add(grid.Key);

                panel.Size = new Vector2(panel.Size.X, 0.09f);
                list.Controls.Add(panel);
            }
            identity.LockBlocksBuiltByGrid.ReleaseExclusive();
        }
        internal MyGuiControlGenericFunctionalBlock(MyTerminalBlock[] blocks) :
            base(canHaveFocus: true,
                 allowFocusingElements: true,
                 isActiveControl: false)
        {
            this.m_currentBlocks = blocks;

            m_separatorList = new MyGuiControlSeparatorList();
            Elements.Add(m_separatorList);

            m_terminalControlList             = new MyGuiControlList();
            m_terminalControlList.VisualStyle = MyGuiControlListStyleEnum.Simple;
            m_terminalControlList.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_TOP;
            m_terminalControlList.Position    = new Vector2(0.1f, 0.1f);
            Elements.Add(m_terminalControlList);

            m_blockPropertiesMultilineText = new MyGuiControlMultilineText(
                position: new Vector2(0.049f, -0.195f),
                size: new Vector2(0.39f, 0.635f),
                font: MyFontEnum.Blue,
                textScale: 0.85f,
                textAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                textBoxAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP
                );
            m_blockPropertiesMultilineText.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            m_blockPropertiesMultilineText.Text        = new StringBuilder();
            Elements.Add(m_blockPropertiesMultilineText);

            m_transferToCombobox = new MyGuiControlCombobox(
                Vector2.Zero,
                new Vector2(0.15f, 0.1f),
                null, null);
            m_transferToCombobox.ItemSelected += m_transferToCombobox_ItemSelected;
            Elements.Add(m_transferToCombobox);

            m_shareModeCombobox = new MyGuiControlCombobox(
                Vector2.Zero,
                new Vector2(0.25f, 0.1f),
                null, null);
            m_shareModeCombobox.ItemSelected += m_shareModeCombobox_ItemSelected;
            Elements.Add(m_shareModeCombobox);

            m_ownershipLabel = new MyGuiControlLabel(
                Vector2.Zero, null, MyTexts.GetString(MySpaceTexts.BlockOwner_Owner) + ":");
            Elements.Add(m_ownershipLabel);

            m_ownerLabel = new MyGuiControlLabel(
                Vector2.Zero, null, String.Empty);
            Elements.Add(m_ownerLabel);

            m_transferToLabel = new MyGuiControlLabel(
                Vector2.Zero, null, MyTexts.GetString(MySpaceTexts.BlockOwner_TransferTo));
            Elements.Add(m_transferToLabel);

            if (MySession.Static.CreativeMode)
            {
                var     topLeftRelative = Vector2.One * -0.5f;
                Vector2 leftColumnSize  = new Vector2(0.3f, 0.55f);
                var     position        = topLeftRelative + new Vector2(leftColumnSize.X + 0.503f, 0.42f);

                m_npcButton = new MyGuiControlButton(
                    position,
                    MyGuiControlButtonStyleEnum.Tiny,
                    new Vector2(0.1f, 0.1f),
                    null, MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER, MyTexts.GetString(MyCommonTexts.AddNewNPC), new StringBuilder("+"),
                    MyGuiConstants.DEFAULT_TEXT_SCALE, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_ACTIVE, true,
                    OnNewNpcClick, GuiSounds.MouseClick, 0.75f);
                Elements.Add(m_npcButton);
            }


            RecreateBlockControls();
            RecreateOwnershipControls();

            if (m_currentBlocks.Length > 0)
            {
                m_currentBlocks[0].PropertiesChanged += block_PropertiesChanged;
            }

            foreach (var block in m_currentBlocks)
            {
                block.OwnershipChanged  += block_OwnershipChanged;
                block.VisibilityChanged += block_VisibilityChanged;
            }

            Sync.Players.IdentitiesChanged += Players_IdentitiesChanged;

            UpdateDetailedInfo();

            Size = new Vector2(0.595f, 0.64f);
        }
        protected virtual void BuildControls()
        {
            Vector2 buttonSize = MyGuiConstants.BACK_BUTTON_SIZE;
            Vector2 buttonsOrigin = m_size.Value / 2 - new Vector2(0.65f, 0.1f);

            AddCaption(MySpaceTexts.ScreenCaptionScenario);

            //RIGHT:
            int numControls = 0;

            var nameLabel = MakeLabel(MySpaceTexts.Name);
            var descriptionLabel = MakeLabel(MySpaceTexts.Description);
            var difficultyLabel = MakeLabel(MySpaceTexts.Difficulty);
            var onlineModeLabel = MakeLabel(MySpaceTexts.WorldSettings_OnlineMode);
            m_maxPlayersLabel = MakeLabel(MySpaceTexts.MaxPlayers);

            float width = 0.284375f + 0.025f;

            m_nameTextbox = new MyGuiControlTextbox(maxLength: MySession.MAX_NAME_LENGTH);
            m_descriptionTextbox = new MyGuiControlTextbox(maxLength: MySession.MAX_DESCRIPTION_LENGTH);
            m_difficultyCombo = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_difficultyCombo.AddItem((int)0, MySpaceTexts.DifficultyEasy);
            m_difficultyCombo.AddItem((int)1, MySpaceTexts.DifficultyNormal);
            m_difficultyCombo.AddItem((int)2, MySpaceTexts.DifficultyHard);

            m_onlineMode = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_maxPlayersSlider = new MyGuiControlSlider(
                position: Vector2.Zero,
                width: m_onlineMode.Size.X,
                minValue: 2,
                maxValue: 16,
                labelText: new StringBuilder("{0}").ToString(),
                labelDecimalPlaces: 0,
                labelSpaceWidth: 0.05f,
                intValue: true
                );

            m_scenarioTypesList = new MyGuiControlList();


            //BUTTONS
            m_removeButton = new MyGuiControlButton(position: buttonsOrigin, size: buttonSize, text: MyTexts.Get(MySpaceTexts.buttonRemove), 
                onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_publishButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(0.01f + m_removeButton.Size.X, 0f), size: buttonSize, text: MyTexts.Get(MySpaceTexts.buttonPublish), 
                onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_createButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(2*(0.01f + m_removeButton.Size.X), 0f), size: buttonSize, text: MyTexts.Get(MySpaceTexts.buttonCreateNew), 
                onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_browseWorkshopButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(3*(0.01f + m_removeButton.Size.X), 0f), size: buttonSize, text: MyTexts.Get(MySpaceTexts.buttonBrowseWorkshop), 
                onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);

            m_refreshButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(0.0f, m_removeButton.Size.Y+0.01f), size: buttonSize, text: MyTexts.Get(MySpaceTexts.buttonRefresh), 
                onButtonClick: OnRefreshButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_openInWorkshopButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2((0.01f + m_removeButton.Size.X), m_removeButton.Size.Y + 0.01f), size: buttonSize, text: MyTexts.Get(MySpaceTexts.buttonOpenInWorkshop), 
                onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_okButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(2 * (0.01f + m_removeButton.Size.X), m_removeButton.Size.Y + 0.01f), size: buttonSize, text: MyTexts.Get(MySpaceTexts.Ok), 
                onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_cancelButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(3 * (0.01f + m_removeButton.Size.X), m_removeButton.Size.Y + 0.01f), size: buttonSize, text: MyTexts.Get(MySpaceTexts.Cancel), 
                onButtonClick: OnCancelButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);

            m_onlineMode.ItemSelected += OnOnlineModeSelect;
            m_onlineMode.AddItem((int)MyOnlineModeEnum.OFFLINE, MySpaceTexts.WorldSettings_OnlineModeOffline);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PRIVATE, MySpaceTexts.WorldSettings_OnlineModePrivate);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.FRIENDS, MySpaceTexts.WorldSettings_OnlineModeFriends);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PUBLIC, MySpaceTexts.WorldSettings_OnlineModePublic);


            m_nameTextbox.TextChanged += m_nameTextbox_TextChanged;

            // Add controls in pairs; label first, control second. They will be laid out automatically this way.
            Controls.Add(nameLabel);
            Controls.Add(m_nameTextbox);
            //m_nameTextbox.Enabled = false;
            Controls.Add(descriptionLabel);
            Controls.Add(m_descriptionTextbox);
            //m_descriptionTextbox.Enabled = false;
            Controls.Add(difficultyLabel);
            Controls.Add(m_difficultyCombo);
            m_difficultyCombo.Enabled = false;

            Controls.Add(onlineModeLabel);
            Controls.Add(m_onlineMode);
            m_onlineMode.Enabled = false;
            Controls.Add(m_maxPlayersLabel);
            Controls.Add(m_maxPlayersSlider);


            float labelSize = 0.12f;

            float MARGIN_TOP = 0.1f;
            float MARGIN_LEFT = 0.42f;// m_isNewGame ? 0.315f : 0.08f;

            // Automatic layout.
            Vector2 originL, originC;
            Vector2 controlsDelta = new Vector2(0f, 0.052f);
            float rightColumnOffset;
            originL = -m_size.Value / 2 + new Vector2(MARGIN_LEFT, MARGIN_TOP);
            originC = originL + new Vector2(labelSize, 0f);
            rightColumnOffset = originC.X + m_onlineMode.Size.X - labelSize - 0.017f;

            foreach (var control in Controls)
            {
                control.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
                if (control is MyGuiControlLabel)
                    control.Position = originL + controlsDelta * numControls;
                else
                    control.Position = originC + controlsDelta * numControls++;
            }
            //BRIEFING:
            //var textBackgroundPanel = AddCompositePanel(MyGuiConstants.TEXTURE_RECTANGLE_DARK, new Vector2(0f,0f), new Vector2(0.43f, 0.422f), MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
            //textBackgroundPanel.InnerHeight = 6;
            MyGuiControlParent briefing = new MyGuiControlParent();//new Vector2(0f, 0f), new Vector2(0.43f, 0.422f));

            var briefingScrollableArea = new MyGuiControlScrollablePanel(
                scrolledControl: briefing)
            {
                Name = "BriefingScrollableArea",
                ScrollbarVEnabled = true,
                Position = new Vector2(-0.02f, -0.12f),
                Size = new Vector2(0.43f, 0.422f),
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                BackgroundTexture = MyGuiConstants.TEXTURE_SCROLLABLE_LIST,
                ScrolledAreaPadding = new MyGuiBorderThickness(0.005f),
            };
            Controls.Add(briefingScrollableArea);
            //inside scrollable area:
            m_descriptionBox = AddMultilineText(offset: new Vector2(0.0f, 0.0f), size: new Vector2(1f, 1f), selectable: false);
            briefing.Controls.Add(m_descriptionBox);

            //LEFT:
            m_scenarioTable = new MyGuiControlTable();
            m_scenarioTable.Position = new Vector2(-0.42f, -0.5f+MARGIN_TOP);
            m_scenarioTable.Size = new Vector2(0.38f, 1.8f);
            m_scenarioTable.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
            m_scenarioTable.VisibleRowsCount = 20;
            m_scenarioTable.ColumnsCount = 2;
            m_scenarioTable.SetCustomColumnWidths(new float[] { 0.085f, 0.905f });
            m_scenarioTable.SetColumnName(1, MyTexts.Get(MySpaceTexts.Name));
            m_scenarioTable.ItemSelected += OnTableItemSelected;
            //m_scenarioTable.ItemDoubleClicked += OnTableItemConfirmedOrDoubleClick;
            //m_scenarioTable.ItemConfirmed += OnTableItemConfirmedOrDoubleClick;
            Controls.Add(m_scenarioTable);
            //BUTTONS:
            Controls.Add(m_removeButton);
            m_removeButton.Enabled = false;
            Controls.Add(m_publishButton);
            m_publishButton.Enabled = false;
            Controls.Add(m_createButton);
            m_createButton.Enabled = false;
            Controls.Add(m_browseWorkshopButton);
            m_browseWorkshopButton.Enabled = false;
            Controls.Add(m_refreshButton);
            Controls.Add(m_openInWorkshopButton);
            m_openInWorkshopButton.Enabled = false;
            Controls.Add(m_okButton);
            Controls.Add(m_cancelButton);

            CloseButtonEnabled = true;

            SetDefaultValues();
        }
        private void CreatePlanetControls(MyGuiControlList list, float usableWidth)
        {   
            var asteroidSizeLabel = CreateSliderWithDescription(list, usableWidth, 8000f, 120000f, MyTexts.GetString(MySpaceTexts.ScreenDebugSpawnMenu_ProceduralSize), ref m_procAsteroidSize);

            m_procAsteroidSize.ValueChanged += (MyGuiControlSlider s) => { asteroidSizeLabel.Text = MyValueFormatter.GetFormatedFloat(s.Value, 0) + "m"; m_procAsteroidSizeValue = s.Value; };
            m_procAsteroidSize.Value = 8000.1f;

            m_procAsteroidSeed = CreateSeedButton(list, m_procAsteroidSeedValue, usableWidth);  
        }
        protected virtual void BuildControls()
        {
            Vector2 buttonSize = MyGuiConstants.BACK_BUTTON_SIZE;
            Vector2 buttonsOrigin = m_size.Value / 2 - new Vector2(0.23f, 0.03f);

            if (m_isNewGame)
                AddCaption(MyCommonTexts.ScreenCaptionCustomWorld);
            else
                AddCaption(MyCommonTexts.ScreenCaptionEditSettings);

            int numControls = 0;

            var nameLabel = MakeLabel(MyCommonTexts.Name);
            var descriptionLabel = MakeLabel(MyCommonTexts.Description);
            var gameModeLabel = MakeLabel(MyCommonTexts.WorldSettings_GameMode);
            var onlineModeLabel = MakeLabel(MyCommonTexts.WorldSettings_OnlineMode);
            m_maxPlayersLabel = MakeLabel(MyCommonTexts.MaxPlayers);
            var environmentLabel = MakeLabel(MySpaceTexts.WorldSettings_EnvironmentHostility);
            var scenarioLabel = MakeLabel(MySpaceTexts.WorldSettings_Scenario);
            var soundModeLabel = MakeLabel(MySpaceTexts.WorldSettings_SoundMode);

            float width = 0.284375f + 0.025f;

            m_nameTextbox = new MyGuiControlTextbox(maxLength: MySession.MAX_NAME_LENGTH);
            m_descriptionTextbox = new MyGuiControlTextbox(maxLength: MySession.MAX_DESCRIPTION_LENGTH);
            m_onlineMode = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_environment = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_maxPlayersSlider = new MyGuiControlSlider(
                position: Vector2.Zero,
                width: m_onlineMode.Size.X,
                minValue: 2,
                maxValue: 16,
                labelText: new StringBuilder("{0}").ToString(),
                labelDecimalPlaces: 0,
                labelSpaceWidth: 0.05f,
                intValue: true
                );



            m_asteroidAmountLabel = MakeLabel(MySpaceTexts.Asteroid_Amount);
            m_asteroidAmountCombo = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));

            m_asteroidAmountCombo.ItemSelected += m_asteroidAmountCombo_ItemSelected;
            m_soundModeCombo = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));

            m_scenarioTypesList = new MyGuiControlList();

            // Ok/Cancel
            m_okButton = new MyGuiControlButton(position: buttonsOrigin - new Vector2(0.01f, 0f), size: buttonSize, text: MyTexts.Get(MyCommonTexts.Ok), onButtonClick: OnOkButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM);
            m_cancelButton = new MyGuiControlButton(position: buttonsOrigin + new Vector2(0.01f, 0f), size: buttonSize, text: MyTexts.Get(MyCommonTexts.Cancel), onButtonClick: OnCancelButtonClick, originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM);

            m_creativeModeButton = new MyGuiControlButton(visualStyle: MyGuiControlButtonStyleEnum.Small, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MyCommonTexts.WorldSettings_GameModeCreative), onButtonClick: OnCreativeClick);
            m_creativeModeButton.SetToolTip(MySpaceTexts.ToolTipWorldSettingsModeCreative);
            m_survivalModeButton = new MyGuiControlButton(visualStyle: MyGuiControlButtonStyleEnum.Small, highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MyCommonTexts.WorldSettings_GameModeSurvival), onButtonClick: OnSurvivalClick);
            m_survivalModeButton.SetToolTip(MySpaceTexts.ToolTipWorldSettingsModeSurvival);

            m_onlineMode.ItemSelected += OnOnlineModeSelect;
            m_onlineMode.AddItem((int)MyOnlineModeEnum.OFFLINE, MyCommonTexts.WorldSettings_OnlineModeOffline);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PRIVATE, MyCommonTexts.WorldSettings_OnlineModePrivate);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.FRIENDS, MyCommonTexts.WorldSettings_OnlineModeFriends);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PUBLIC, MyCommonTexts.WorldSettings_OnlineModePublic);

            m_environment.AddItem((int)MyEnvironmentHostilityEnum.SAFE, MySpaceTexts.WorldSettings_EnvironmentHostilitySafe);
            m_environment.AddItem((int)MyEnvironmentHostilityEnum.NORMAL, MySpaceTexts.WorldSettings_EnvironmentHostilityNormal);
            m_environment.AddItem((int)MyEnvironmentHostilityEnum.CATACLYSM, MySpaceTexts.WorldSettings_EnvironmentHostilityCataclysm);
            m_environment.AddItem((int)MyEnvironmentHostilityEnum.CATACLYSM_UNREAL, MySpaceTexts.WorldSettings_EnvironmentHostilityCataclysmUnreal);
            m_environment.ItemSelected += HostilityChanged;

            m_soundModeCombo.AddItem((int)MySoundModeEnum.Arcade, MySpaceTexts.WorldSettings_ArcadeSound);
            m_soundModeCombo.AddItem((int)MySoundModeEnum.Realistic, MySpaceTexts.WorldSettings_RealisticSound);

            if (m_isNewGame)
            {
                m_scenarioTypesGroup = new MyGuiControlRadioButtonGroup();
                m_scenarioTypesGroup.SelectedChanged += scenario_SelectedChanged;
                foreach (var scenario in MyDefinitionManager.Static.GetScenarioDefinitions())
                {
                    if (!scenario.Public && !MyFakes.ENABLE_NON_PUBLIC_SCENARIOS)
                        continue;

                    var button = new MyGuiControlScenarioButton(scenario);
                    m_scenarioTypesGroup.Add(button);
                    m_scenarioTypesList.Controls.Add(button);
                }
            }

            m_nameTextbox.SetToolTip(string.Format(MyTexts.GetString(MyCommonTexts.ToolTipWorldSettingsName), MySession.MIN_NAME_LENGTH, MySession.MAX_NAME_LENGTH));
            m_descriptionTextbox.SetToolTip(MyTexts.GetString(MyCommonTexts.ToolTipWorldSettingsDescription));
            m_environment.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsEnvironment));
            m_onlineMode.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsOnlineMode));
            m_maxPlayersSlider.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsMaxPlayer));
            m_asteroidAmountCombo.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsAsteroidAmount));
            m_soundModeCombo.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettingsSoundMode));

            m_nameTextbox.TextChanged += m_nameTextbox_TextChanged;
            m_soundModeCombo.ItemSelected += m_soundModeCombo_ItemSelected;

            var advanced = new MyGuiControlButton(highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MySpaceTexts.WorldSettings_Advanced), onButtonClick: OnAdvancedClick);

#if !XB1 // XB1_NOWORKSHOP
            var mods = new MyGuiControlButton(highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MyCommonTexts.WorldSettings_Mods), onButtonClick: OnModsClick);
#endif // !XB1

            m_worldGeneratorButton = new MyGuiControlButton(highlightType: MyGuiControlHighlightType.WHEN_ACTIVE, text: MyTexts.Get(MySpaceTexts.WorldSettings_WorldGenerator), onButtonClick: OnWorldGeneratorClick);

            // Add controls in pairs; label first, control second. They will be laid out automatically this way.
            Controls.Add(nameLabel);
            Controls.Add(m_nameTextbox);
            Controls.Add(descriptionLabel);
            Controls.Add(m_descriptionTextbox);

            Controls.Add(gameModeLabel);
            Controls.Add(m_creativeModeButton);

            if (MyFakes.ENABLE_NEW_SOUNDS)
            {
                Controls.Add(soundModeLabel);
                Controls.Add(m_soundModeCombo);
            }

            Controls.Add(onlineModeLabel);
            Controls.Add(m_onlineMode);
            Controls.Add(m_maxPlayersLabel);
            Controls.Add(m_maxPlayersSlider);

            if (MyFakes.ENABLE_METEOR_SHOWERS)
            {
                Controls.Add(environmentLabel);
                Controls.Add(m_environment);
            }

            if (m_isNewGame && MyFakes.ENABLE_PLANETS == false)
            {
                Controls.Add(m_asteroidAmountLabel);
                Controls.Add(m_asteroidAmountCombo);
            }

            var autoSaveLabel = MakeLabel(MyCommonTexts.WorldSettings_AutoSave);
            m_autoSave = new MyGuiControlCheckbox();
            m_autoSave.SetToolTip(new StringBuilder().AppendFormat(MyCommonTexts.ToolTipWorldSettingsAutoSave, MyObjectBuilder_SessionSettings.DEFAULT_AUTOSAVE_IN_MINUTES).ToString());
            Controls.Add(autoSaveLabel);
            Controls.Add(m_autoSave);

            var scenarioEditModeLabel = MakeLabel(MySpaceTexts.WorldSettings_ScenarioEditMode);
            m_scenarioEditMode = new MyGuiControlCheckbox();
            m_scenarioEditMode.SetToolTip(MyTexts.GetString(MySpaceTexts.ToolTipWorldSettings_ScenarioEditMode));

            Controls.Add(scenarioEditModeLabel);
            Controls.Add(m_scenarioEditMode);

#if !XB1 // XB1_NOWORKSHOP
            if (!MyFakes.XB1_PREVIEW)
                if (MyFakes.ENABLE_WORKSHOP_MODS)
                    Controls.Add(mods);
#endif // !XB1

            Controls.Add(advanced);

            if (m_isNewGame && MyFakes.ENABLE_PLANETS == true)
            {
                Controls.Add(m_worldGeneratorButton);
            }

            float labelSize = 0.20f;

            float MARGIN_TOP = 0.12f;
            float MARGIN_BOTTOM = 0.12f;
            float MARGIN_LEFT = m_isNewGame ? 0.315f : 0.08f;
            float MARGIN_RIGHT = m_isNewGame ? 0.075f : 0.045f;

            // Automatic layout.
            Vector2 originL, originC;
            Vector2 controlsDelta = new Vector2(0f, 0.052f);
            float rightColumnOffset;
            originL = -m_size.Value / 2 + new Vector2(MARGIN_LEFT, MARGIN_TOP);
            originC = originL + new Vector2(labelSize, 0f);
            rightColumnOffset = originC.X + m_onlineMode.Size.X - labelSize - 0.017f;

            foreach (var control in Controls)
            {
                control.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER;
                if (control is MyGuiControlLabel)
                    control.Position = originL + controlsDelta * numControls;
                else
                    control.Position = originC + controlsDelta * numControls++;
            }

            Controls.Add(m_survivalModeButton);
            m_survivalModeButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_CENTER;
            m_survivalModeButton.Position = m_creativeModeButton.Position + new Vector2(m_onlineMode.Size.X, 0);

            if (m_isNewGame)
            {
                Vector2 scenarioPosition = new Vector2(-0.375f, nameLabel.Position.Y);

                m_nameTextbox.Size = m_onlineMode.Size;
                m_descriptionTextbox.Size = m_nameTextbox.Size;

                scenarioLabel.Position = scenarioPosition;

                m_scenarioTypesList.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;
                m_scenarioTypesList.Position = scenarioLabel.Position + new Vector2(0, 0.02f);
                m_scenarioTypesList.Size = new Vector2(0.19f, m_size.Value.Y - MARGIN_BOTTOM - MARGIN_TOP);
                Controls.Add(scenarioLabel);
                Controls.Add(m_scenarioTypesList);

                MyGuiControlSeparatorList m_verticalLine = new MyGuiControlSeparatorList();
                Vector2 position = nameLabel.Position + new Vector2(-0.025f, -0.02f);
                m_verticalLine.AddVertical(position, m_size.Value.Y - MARGIN_BOTTOM - MARGIN_TOP + 0.04f);
                Controls.Add(m_verticalLine);
            }

            var pos2 = advanced.Position;
            //pos2.X = m_isNewGame ? 0.160f : 0.0f;
            pos2.X = Size.HasValue ? Size.Value.X / 2.0f - advanced.Size.X - MARGIN_RIGHT : 0.0f;
            advanced.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            advanced.Position = pos2;

#if !XB1 // XB1_NOWORKSHOP
            mods.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            mods.Position = advanced.Position - new Vector2(advanced.Size.X + 0.017f, 0);
#endif // !XB1

            m_worldGeneratorButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
            m_worldGeneratorButton.Position = advanced.Position - new Vector2(advanced.Size.X + 0.017f, -0.06f);

            if (MyFakes.XB1_PREVIEW)
            {
                var pos2p = m_worldGeneratorButton.Position;
                pos2p.X = Size.HasValue ? Size.Value.X / 2.0f - m_worldGeneratorButton.Size.X - MARGIN_RIGHT : 0.0f;
                m_worldGeneratorButton.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                m_worldGeneratorButton.Position = pos2p;

                advanced.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM;
                if (m_isNewGame)
                {
                    advanced.Position = m_worldGeneratorButton.Position - new Vector2(m_worldGeneratorButton.Size.X + 0.017f, 0);
                }
                else
                {
                    advanced.Position = m_worldGeneratorButton.Position - new Vector2(m_worldGeneratorButton.Size.X + 0.017f, 0.008f);
                }
            }

            Controls.Add(m_okButton);
            Controls.Add(m_cancelButton);

            CloseButtonEnabled = true;
        }
        private MyGuiControlLabel CreateSliderWithDescription(MyGuiControlList list, float usableWidth,float min,float max, string description,ref MyGuiControlSlider slider)
        {
            var label = AddLabel(description, Vector4.One, m_scale);
            Controls.Remove(label);
            list.Controls.Add(label);

            CreateSlider(list, usableWidth, min, max, ref slider);

            var labelNoise = AddLabel("", Vector4.One, m_scale);
            Controls.Remove(labelNoise);
            list.Controls.Add(labelNoise);
            return labelNoise;
        }
        protected override void BuildControls()
        {
            base.BuildControls();

            Vector2 buttonSize = MyGuiConstants.BACK_BUTTON_SIZE;
            Vector2 buttonsOrigin = m_size.Value / 2 - new Vector2(0.65f, 0.1f);

            var difficultyLabel = MakeLabel(MySpaceTexts.Difficulty);
            var onlineModeLabel = MakeLabel(MyCommonTexts.WorldSettings_OnlineMode);
            m_maxPlayersLabel = MakeLabel(MyCommonTexts.MaxPlayers);

            float width = 0.284375f + 0.025f;

            m_difficultyCombo = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_difficultyCombo.Enabled = false;
            m_difficultyCombo.AddItem((int)0, MySpaceTexts.DifficultyEasy);
            m_difficultyCombo.AddItem((int)1, MySpaceTexts.DifficultyNormal);
            m_difficultyCombo.AddItem((int)2, MySpaceTexts.DifficultyHard);

            m_onlineMode = new MyGuiControlCombobox(size: new Vector2(width, 0.04f));
            m_onlineMode.Enabled = false;
            m_onlineMode.ItemSelected += OnOnlineModeSelect;
            m_onlineMode.AddItem((int)MyOnlineModeEnum.OFFLINE, MyCommonTexts.WorldSettings_OnlineModeOffline);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PRIVATE, MyCommonTexts.WorldSettings_OnlineModePrivate);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.FRIENDS, MyCommonTexts.WorldSettings_OnlineModeFriends);
            m_onlineMode.AddItem((int)MyOnlineModeEnum.PUBLIC, MyCommonTexts.WorldSettings_OnlineModePublic);

            m_maxPlayersSlider = new MyGuiControlSlider(
                position: Vector2.Zero,
                width: m_onlineMode.Size.X,
                minValue: 2,
                maxValue: 16,
                labelText: new StringBuilder("{0}").ToString(),
                labelDecimalPlaces: 0,
                labelSpaceWidth: 0.05f,
                intValue: true
                );

            m_scenarioTypesList = new MyGuiControlList();

            //BUTTONS
            m_removeButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.buttonRemove), onButtonClick: OnOkButtonClick);
#if !XB1 // XB1_NOWORKSHOP
            m_publishButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.buttonPublish), onButtonClick: OnPublishButtonClick);
#else // XB1
            m_publishButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.buttonPublish), onButtonClick: OnOkButtonClick);
#endif // XB1
            m_editButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.buttonEdit), onButtonClick: OnEditButtonClick);
            m_browseWorkshopButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.buttonBrowseWorkshop), onButtonClick: OnBrowseWorkshopClick);

            m_refreshButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.buttonRefresh), onButtonClick: OnRefreshButtonClick);
            m_openInWorkshopButton = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.buttonOpenInWorkshop), onButtonClick: OnOkButtonClick);

            m_removeButton.Enabled = false;
            m_publishButton.Enabled = false;
            m_editButton.Enabled = false;
            m_openInWorkshopButton.Enabled = false;
            CloseButtonEnabled = true;

            //m_nameTextbox.TextChanged += m_nameTextbox_TextChanged;

            m_sideMenuLayout.Add(difficultyLabel, MyAlignH.Left, MyAlignV.Top, 2, 0);
            m_sideMenuLayout.Add(m_difficultyCombo, MyAlignH.Left, MyAlignV.Top, 2, 1);
            m_sideMenuLayout.Add(onlineModeLabel, MyAlignH.Left, MyAlignV.Top, 3, 0);
            m_sideMenuLayout.Add(m_onlineMode, MyAlignH.Left, MyAlignV.Top, 3, 1);
            m_sideMenuLayout.Add(m_maxPlayersLabel, MyAlignH.Left, MyAlignV.Top, 4, 0);
            m_sideMenuLayout.Add(m_maxPlayersSlider, MyAlignH.Left, MyAlignV.Top, 4, 1);

            m_buttonsLayout.Add(m_removeButton, MyAlignH.Left, MyAlignV.Top, 0, 0);
            if (!MyFakes.XB1_PREVIEW)
            {
                m_buttonsLayout.Add(m_publishButton, MyAlignH.Left, MyAlignV.Top, 0, 1);
            }
            m_buttonsLayout.Add(m_editButton, MyAlignH.Left, MyAlignV.Top, 0, 2);
            if (!MyFakes.XB1_PREVIEW)
            {
                m_buttonsLayout.Add(m_browseWorkshopButton, MyAlignH.Left, MyAlignV.Top, 0, 3);
            }
            m_buttonsLayout.Add(m_refreshButton, MyAlignH.Left, MyAlignV.Top, 1, 0);
            if (!MyFakes.XB1_PREVIEW)
            {
                m_buttonsLayout.Add(m_openInWorkshopButton, MyAlignH.Left, MyAlignV.Top, 1, 1);
            }
        }
        private static void AddSeparator(MyGuiControlList list)
        {
            var separator = new MyGuiControlSeparatorList();
            separator.Size = new Vector2(1, 0.01f);
            separator.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP;
            separator.AddHorizontal(Vector2.Zero, 1);

            list.Controls.Add(separator);
        }
Пример #31
0
        private void InitCampaignList()
        {
            Vector2 originL = -m_size.Value / 2 + new Vector2(0.07f, MARGIN_TOP);

            m_campaignTypesGroup = new MyGuiControlRadioButtonGroup();
            m_campaignTypesGroup.SelectedChanged += CampaignSelectionChanged;

            m_campaignList = new MyGuiControlList
            {
              OriginAlign  = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
              Position = originL,
              Size = new Vector2(0.19f, m_size.Value.Y - 0.03f - MARGIN_TOP),
            };

            var separator = new MyGuiControlSeparatorList()
            {
                Size = new Vector2(0.03f, m_campaignList.Size.Y),
                OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP,
                Position = m_campaignList.Position + new Vector2(m_campaignList.Size.X + 0.015f, 0f)
            };
            separator.AddVertical(new Vector2(0f, -m_campaignList.Size.Y/2), separator.Size.Y);

            Controls.Add(separator);
            Controls.Add(m_campaignList);
        }