Пример #1
0
        public bool RefreshInventory(string search = "", int searchField = -1)
        {
            var listViewRows = new List <ListViewItem>();
            var containerID  = containersListBox.SelectedItem.ToString();

            containerGroupBox.Visible = true;
            containerGroupBox.Text    = containerID;
            if (containerID == "Player Inventory")
            {
                containerID = "1";
            }
            ItemData activeItemEdit = null;

            if (inventoryListView.SelectedItems.Count > 0)
            {
                activeItemEdit = (ItemData)inventoryListView.SelectedItems[0].Tag;
            }

            ListViewItem selectItem = null;

            foreach (ItemData item in activeSaveFile.GetInventory(ulong.Parse(containerID)).Items)
            {
                var row = new string[] { item.ItemGameName, "", item.ItemName, "", "1", item.ItemGameDescription };

                if (item.ItemGameName.Length < 1)
                {
                    row[0] = "Unknown";
                }

                if (item.Data.GetType() == typeof(ItemData.SimpleItemData))
                {
                    row[4] = ((ItemData.SimpleItemData)item.Data).Quantity.ToString();
                    row[1] = "[S] ";
                }
                else if (item.Data.GetType() == typeof(ItemData.ModableItemWithQuantityData))
                {
                    row[4] = ((ItemData.ModableItemWithQuantityData)item.Data).Quantity.ToString();
                    row[1] = "[M+] ";
                }
                else
                {
                    row[1] = "[M] ";
                }

                var id = item.ItemTdbId.ToString();
                if (itemClasses.ContainsKey(id))
                {
                    row[1] += itemClasses[id];
                }
                else
                {
                    row[1] += "Unknown";
                }

                if (search != "")
                {
                    if (searchField > -1)
                    {
                        if (!row[searchField].ToLower().Contains(search.ToLower()))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        var containsSearchString = false;
                        foreach (string rowItem in row)
                        {
                            if (rowItem.ToLower().Contains(search.ToLower()))
                            {
                                containsSearchString = true;
                                break;
                            }
                        }
                        if (!containsSearchString)
                        {
                            continue;
                        }
                    }
                }

                var newItem = new ListViewItem(row);
                newItem.Tag = item;

                if (activeItemEdit == item)
                {
                    newItem.Selected = true;
                    selectItem       = newItem;
                }

                listViewRows.Add(newItem);
                if (item.ItemGameName == "Eddies" && containerID == "1")
                {
                    moneyUpDown.Value   = ((ItemData.SimpleItemData)item.Data).Quantity;
                    moneyUpDown.Enabled = true;
                }
            }

            foreach (KeyValuePair <CyberCAT.Core.Classes.DumpedClasses.GameItemID, string> equipInfo in activeSaveFile.GetEquippedItems().Reverse())
            {
                var equippedItem = listViewRows.Where(x => ((ItemData)x.Tag).ItemTdbId.Id == equipInfo.Key.Id.Id).FirstOrDefault();

                if (equippedItem != null)
                {
                    equippedItem.SubItems[3].Text = equipInfo.Value;
                    equippedItem.BackColor        = Color.FromArgb(248, 248, 248);
                    listViewRows.Remove(equippedItem);
                    listViewRows.Insert(0, equippedItem);
                }
            }

            inventoryListView.BeginUpdate();
            inventoryListView.ListViewItemSorter = null;

            inventoryListView.Items.Clear();
            inventoryListView.Items.AddRange(listViewRows.ToArray());

            inventoryListView.ListViewItemSorter = inventoryColumnSorter;
            inventoryListView.Sort();
            inventoryListView.EndUpdate();

            if (selectItem != null)
            {
                inventoryListView.EnsureVisible(inventoryListView.Items.IndexOf(selectItem));
            }

            return(true);
        }