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 });
        }
        public void UpdateCubeBlock(MyTerminalBlock block)
        {

            if (block == null)
                return;

            if (m_terminalSystem != null)
            {
                m_terminalSystem.BlockAdded -= TerminalSystem_BlockAdded;
                m_terminalSystem.BlockRemoved -= TerminalSystem_BlockRemoved;
                m_terminalSystem.GroupAdded -= TerminalSystem_GroupAdded;
                m_terminalSystem.GroupRemoved -= TerminalSystem_GroupRemoved;
            }

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

            m_terminalSystem.BlockAdded += TerminalSystem_BlockAdded;
            m_terminalSystem.BlockRemoved += TerminalSystem_BlockRemoved;
            m_terminalSystem.GroupAdded += TerminalSystem_GroupAdded;
            m_terminalSystem.GroupRemoved += TerminalSystem_GroupRemoved;

            SelectBlocks(new MyTerminalBlock[] { block });


        }
        public void Init(IMyGuiControlsParent controlsParent, MyCubeGrid grid)
        {
            if (grid == null)
            {
                ShowError(MySpaceTexts.ScreenTerminalError_ShipNotConnected, controlsParent);
                return;
            }

            grid.RaiseGridChanged();
            m_assemblerKeyCounter = 0;
            m_assemblersByKey.Clear();
            foreach (var block in grid.GridSystems.TerminalSystem.Blocks)
            {
                var assembler = block as MyAssembler;
                if (assembler == null) continue;
                if (!assembler.HasLocalPlayerAccess()) continue;

                m_assemblersByKey.Add(m_assemblerKeyCounter++, assembler);
            }

            m_controlsParent = controlsParent;
            m_terminalSystem = grid.GridSystems.TerminalSystem;

            m_blueprintsArea = (MyGuiControlScrollablePanel)controlsParent.Controls.GetControlByName("BlueprintsScrollableArea");
            m_queueArea = (MyGuiControlScrollablePanel)controlsParent.Controls.GetControlByName("QueueScrollableArea");
            m_inventoryArea = (MyGuiControlScrollablePanel)controlsParent.Controls.GetControlByName("InventoryScrollableArea");
            m_blueprintsBgPanel = controlsParent.Controls.GetControlByName("BlueprintsBackgroundPanel");
            m_blueprintsLabel = controlsParent.Controls.GetControlByName("BlueprintsLabel");
            m_comboboxAssemblers = (MyGuiControlCombobox)controlsParent.Controls.GetControlByName("AssemblersCombobox");
            m_blueprintsGrid = (MyGuiControlGrid)m_blueprintsArea.ScrolledControl;
            m_queueGrid = (MyGuiControlGrid)m_queueArea.ScrolledControl;
            m_inventoryGrid = (MyGuiControlGrid)m_inventoryArea.ScrolledControl;
            m_materialsList = (MyGuiControlComponentList)controlsParent.Controls.GetControlByName("MaterialsList");
            m_repeatCheckbox = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("RepeatCheckbox");
            m_slaveCheckbox = (MyGuiControlCheckbox)controlsParent.Controls.GetControlByName("SlaveCheckbox");
            m_disassembleAllButton = (MyGuiControlButton)controlsParent.Controls.GetControlByName("DisassembleAllButton");
            m_controlPanelButton = (MyGuiControlButton)controlsParent.Controls.GetControlByName("ControlPanelButton");
            m_inventoryButton = (MyGuiControlButton)controlsParent.Controls.GetControlByName("InventoryButton");

            {
                var assemblingButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("AssemblingButton");
                var disassemblingButton = (MyGuiControlRadioButton)controlsParent.Controls.GetControlByName("DisassemblingButton");
                assemblingButton.Key = (int)AssemblerMode.Assembling;
                disassemblingButton.Key = (int)AssemblerMode.Disassembling;
                m_modeButtonGroup.Add(assemblingButton);
                m_modeButtonGroup.Add(disassemblingButton);
            }

            foreach (var entry in m_assemblersByKey)
            {
                if (entry.Value.IsFunctional == false)
                {
                    m_incompleteAssemblerName.Clear();
                    m_incompleteAssemblerName.AppendStringBuilder(entry.Value.CustomName);
                    m_incompleteAssemblerName.AppendStringBuilder(MyTexts.Get(MySpaceTexts.Terminal_BlockIncomplete));
                    m_comboboxAssemblers.AddItem(entry.Key, m_incompleteAssemblerName);
                }
                else
                {
                    m_comboboxAssemblers.AddItem(entry.Key, entry.Value.CustomName);
                }
            }
            m_comboboxAssemblers.ItemSelected += Assemblers_ItemSelected;

            m_comboboxAssemblers.SelectItemByIndex(0);

            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_dragAndDrop.ItemDropped += dragDrop_OnItemDropped;

            RefreshBlueprints();
            Assemblers_ItemSelected();

            RegisterEvents();

            if (m_assemblersByKey.Count == 0)
                ShowError(MySpaceTexts.ScreenTerminalError_NoAssemblers, controlsParent);
        }
        public void Close()
        {
            if (m_terminalSystem != null)
            {
                if (m_blockListbox != null)
                {
                    ClearBlockList();
                    m_blockListbox.ItemsSelected -= blockListbox_ItemSelected;
                }

                m_terminalSystem.BlockAdded -= TerminalSystem_BlockAdded;
                m_terminalSystem.BlockRemoved -= TerminalSystem_BlockRemoved;
                m_terminalSystem.GroupAdded -= TerminalSystem_GroupAdded;
                m_terminalSystem.GroupRemoved -= TerminalSystem_GroupRemoved;
            }

            if (m_tmpGroup != null)
            {
                m_tmpGroup.Blocks.Clear();
            }

            m_controlsParent = null;
            m_blockListbox = null;
            m_blockNameLabel = null;
            m_terminalSystem = null;
            m_currentGroups.Clear();
        }
        internal void Close()
        {
            UnregisterEvents();
            UnregisterAssemblerEvents(m_selectedAssembler);

            m_assemblersByKey.Clear();
            m_blueprintButtonGroup.Clear();
            m_modeButtonGroup.Clear();

            m_selectedAssembler = null;
            m_controlsParent = null;
            m_terminalSystem = null;
            m_comboboxAssemblers = null;

            m_dragAndDrop = null;
            m_dragAndDropInfo = null;
        }