private void SetRightFilter(MyInventoryOwnerTypeEnum? filterType)
 {
     m_rightFilterType = filterType;
     if (m_rightShowsGrid)
     {
         CreateInventoryControlsInList(m_interactedGridOwners, m_rightOwnersControl, m_rightFilterType);
         m_blockSearchRight.Text = m_blockSearchRight.Text;
     }
     RefreshSelectedInventoryItem();
 }
        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 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);
        }