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();
        }
        public void Init(IMyGuiControlsParent controlsParent, MyPlayer controller, MyCubeGrid grid, MyTerminalBlock currentBlock, MyGridColorHelper colorHelper)
        {
            m_controlsParent = controlsParent;
            m_controller = controller;
            m_colorHelper = colorHelper;

            if (grid == null)
            {
                foreach (var control in controlsParent.Controls)
                    control.Visible = false;

                var label = MyGuiScreenTerminal.CreateErrorLabel(MySpaceTexts.ScreenTerminalError_ShipNotConnected, "ErrorMessage");
                controlsParent.Controls.Add(label);
                return;
            }

            m_terminalSystem = grid.GridSystems.TerminalSystem;
            m_tmpGroup = new MyBlockGroup(grid);

            m_blockSearch = (MyGuiControlTextbox)m_controlsParent.Controls.GetControlByName("FunctionalBlockSearch");
            m_blockSearch.TextChanged += blockSearch_TextChanged;
            m_blockSearchClear = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("FunctionalBlockSearchClear");
            m_blockSearchClear.ButtonClicked += blockSearchClear_ButtonClicked;
            m_blockListbox = (MyGuiControlListbox)m_controlsParent.Controls.GetControlByName("FunctionalBlockListbox");
            m_blockNameLabel = (MyGuiControlLabel)m_controlsParent.Controls.GetControlByName("BlockNameLabel");
            m_blockNameLabel.Text = "";
            m_groupName = (MyGuiControlTextbox)m_controlsParent.Controls.GetControlByName("GroupName");
            m_groupName.TextChanged += m_groupName_TextChanged;

            m_showAll = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("ShowAll");
            m_showAll.Selected = m_showAllTerminalBlocks;
            m_showAll.ButtonClicked += showAll_Clicked;
            m_showAll.SetToolTip(MySpaceTexts.Terminal_ShowAllInTerminal);
            m_showAll.IconRotation = 0f;
            m_showAll.Icon = new MyGuiHighlightTexture
                {
                    Normal = @"Textures\GUI\Controls\button_hide.dds",
                    Highlight = @"Textures\GUI\Controls\button_unhide.dds",
                    SizePx = new Vector2(40f, 40f),
                };
            m_showAll.Size = new Vector2(0, 0);

            m_showAll.HighlightType = MyGuiControlHighlightType.FORCED;
            m_showAll.IconOriginAlign = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP;

            m_groupSave = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("GroupSave");
            m_groupSave.TextEnum = MySpaceTexts.TerminalButton_GroupSave;
            m_groupSave.TextAlignment = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER;
            m_groupSave.ButtonClicked += groupSave_ButtonClicked;
            m_groupDelete = (MyGuiControlButton)m_controlsParent.Controls.GetControlByName("GroupDelete");
            m_groupDelete.ButtonClicked += groupDelete_ButtonClicked;
            m_groupDelete.Enabled = false;

            m_blockListbox.ItemsSelected += blockListbox_ItemSelected;

            RefreshBlockList();

            m_terminalSystem.BlockAdded += TerminalSystem_BlockAdded;
            m_terminalSystem.BlockRemoved += TerminalSystem_BlockRemoved;
            m_terminalSystem.GroupAdded += TerminalSystem_GroupAdded;
            m_terminalSystem.GroupRemoved += TerminalSystem_GroupRemoved;
            if (currentBlock != null)
                SelectBlocks(new MyTerminalBlock[] { currentBlock });
        }
 /// <summary>
 /// Do not call directly. Use static Show() method instead.
 /// </summary>
 private MyGuiScreenTerminal() :
     base(position: new Vector2(0.5f, 0.5f),
          backgroundColor: MyGuiConstants.SCREEN_BACKGROUND_COLOR,
          size: new Vector2(0.99f, 0.9f), backgroundTransition: MySandboxGame.Config.UIBkOpacity, guiTransition: MySandboxGame.Config.UIOpacity)
 {
     EnabledBackgroundFade = true;
     m_closeHandler = OnInteractedClose;
     m_colorHelper = new MyGridColorHelper();
 }