private void SetPickupOptionsHook(
            On.RoR2.UI.PickupPickerPanel.orig_SetPickupOptions orig,
            PickupPickerPanel self,
            PickupPickerController.Option[] options
            )
        {
            orig.Invoke(self, options);

            if (options.Length < 1)
            {
                return;
            }

            ReadOnlyCollection <MPButton> elements =
                self.GetFieldValue <UIElementAllocator <MPButton> >("buttonAllocator").elements;

            Inventory inventory = LocalUserManager.GetFirstLocalUser().cachedMasterController.master.inventory;

            for (int i = 0; i < options.Length; i++)
            {
                Transform parent           = elements[i].transform;
                PickupDef pickupDefinition = PickupCatalog.GetPickupDef(options[i].pickupIndex);
                ItemIndex itemIndex        = pickupDefinition.itemIndex;
                int       itemCount        = !itemIndex.Equals(ItemIndex.None) ? inventory.GetItemCount(itemIndex) : 0;

                if (pickupDefinition.equipmentIndex.Equals(EquipmentIndex.None))
                {
                    CreateNumberLabel(parent, itemIndex, itemCount);
                }

                if (EnableTooltip.Value)
                {
                    CreateTooltip(parent, pickupDefinition, itemCount);
                }
            }
        }
Пример #2
0
        public void PickupPickerPanel_SetPickupOptions(On.RoR2.UI.PickupPickerPanel.orig_SetPickupOptions orig, RoR2.UI.PickupPickerPanel self, RoR2.PickupPickerController.Option[] options)
        {
            if (options == null || options.Length == 0)
            {
                orig(self, options);
                return;
            }


            self.buttonAllocator.AllocateElements(0);
            optionMap[0] = -1;
            switch (self.pickerController.contextString)
            {
            case "ARTIFACT_COMMAND_CUBE_INTERACTION_PROMPT":
                if (mod.config.CommandResizeCommandWindow.Value)
                {
                    self.transform.Find("MainPanel").GetComponent <RectTransform>().sizeDelta = new Vector2(576, 166 + (82 * (float)Math.Ceiling(options.Length / 5f)));
                }

                if (mod.config.CommandRemoveBackgroundBlur.Value)
                {
                    self.transform.GetComponent <LeTai.Asset.TranslucentImage.TranslucentImage>().enabled = false;
                }
                if (mod.config.SortingSortItemsCommand.Value)
                {
                    sortOrder = mod.config.SortingSortOrderCommand.Value;
                    break;
                }
                goto default;

            case "SCRAPPER_CONTEXT":
                if (mod.config.SortingSortItemsScrapper.Value)
                {
                    sortOrder = mod.config.SortingSortOrderScrapper.Value;
                    break;
                }
                goto default;

            default:
                orig(self, options);
                return;
            }


            Inventory inventory = LocalUserManager.GetFirstLocalUser().cachedMasterController.master.inventory;

            if (PickupCatalog.GetPickupDef(options[0].pickupIndex).equipmentIndex != EquipmentIndex.None)
            {
                foreach (RoR2.PickupPickerController.Option option in options)
                {
                    availableIndex[(int)PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex] = option.available;
                }

                List <EquipmentIndex> sortedItems = mod.itemSorting.sortItems(options.Select(option => PickupCatalog.GetPickupDef(option.pickupIndex).equipmentIndex).ToList(), sortOrder);

                sortedItems.Select(equipemntIndex => new RoR2.PickupPickerController.Option {
                    pickupIndex = PickupCatalog.FindPickupIndex(equipemntIndex), available = availableIndex[(int)equipemntIndex]
                }).ToArray().CopyTo(sortedOptions, 0);;
                sortedOptions.Select(option => Array.IndexOf(options, option)).ToArray().CopyTo(optionMap, 0);
                options = sortedOptions.Take(options.Length).ToArray();
            }
            else if (PickupCatalog.GetPickupDef(options[0].pickupIndex).itemIndex != ItemIndex.None)
            {
                bool[] availableIndex = new bool[ItemCatalog.itemCount];
                foreach (RoR2.PickupPickerController.Option option in options)
                {
                    availableIndex[(int)PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex] = option.available;
                }

                List <ItemIndex> sortedItems = mod.itemSorting.sortItems(options.Select(option => PickupCatalog.GetPickupDef(option.pickupIndex).itemIndex).ToList(), inventory, sortOrder);

                sortedItems.Select(itemIndex => new RoR2.PickupPickerController.Option {
                    pickupIndex = PickupCatalog.FindPickupIndex(itemIndex), available = availableIndex[(int)itemIndex]
                }).ToArray().CopyTo(sortedOptions, 0);
                sortedOptions.Select(option => Array.IndexOf(options, option)).ToArray().CopyTo(optionMap, 0);
                options = sortedOptions.Take(options.Length).ToArray();
            }

            orig(self, options);
        }