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 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();
        }