Ejemplo n.º 1
0
        public void LoadInventoryData()
        {
            //This assumes items can't be added to the inventory while the inventory is open. It's probably possible that a mod could add items while
            //the inventory is open. If it turns out to be an issue, this code can be updated to retrieve the entire list every frame, but that seems
            //overkill for now - this should probably work for most realistic cases.
            if (this.InventoryList.Count <= 0)
            {
                GameObject playerCurrentBody = XRLCore.Core?.Game?.Player?.Body;
                Inventory  inventory         = playerCurrentBody?.GetPart("Inventory") as Inventory;
                if (inventory == null)
                {
                    return;
                }
                List <GameObject> objects = inventory.GetObjectsDirect();
                for (int i = 0; i < objects.Count; i++)
                {
                    GameObject item = objects[i];
                    if (!item.HasTag("HiddenInInventory"))
                    {
                        //removed filter string handling, because if the player removes the filter after we do this, we won't have all the items saved in our List<GameObject>

                        //if (InventoryScreen.filterString == string.Empty || ConsoleLib.Console.ColorUtility.StripFormatting(item.DisplayName).ToLower().Contains(InventoryScreen.filterString.ToLower()))
                        //{
                        this.InventoryList.Add(item);
                        //}
                    }
                }
                this.InventoryList.Sort(InventoryScreen.displayNameSorter);

                foreach (GameObject item in this.InventoryList)
                {
                    string strippedConstrainedName = item.GetCachedDisplayNameStripped().Substring(0, Math.Min(item.GetCachedDisplayNameStripped().Length, 60)).PadRight(60);
                    if (!this.CachedValuePerLbStrings.ContainsKey(strippedConstrainedName))
                    {
                        this.CachedValuePerLbStrings.Add(strippedConstrainedName, this.GetItemValueString(item));
                    }
                }
            }
        }