private void ItemIcon_SetItemIndex(On.RoR2.UI.ItemIcon.orig_SetItemIndex orig, ItemIcon self, ItemIndex newItemIndex, int newItemCount) { orig(self, newItemIndex, newItemCount); var shouldDisplay = newItemIndex == itemDef.itemIndex && newItemCount > 0; var fillIcon = self.GetComponent <MysticsItemsSuperIdolHUDIcon>(); if (shouldDisplay != fillIcon) { if (shouldDisplay) { var itemInventoryDisplay = self.GetComponentInParent <ItemInventoryDisplay>(); if (itemInventoryDisplay && itemInventoryDisplay.inventory) { var master = itemInventoryDisplay.inventory.GetComponent <CharacterMaster>(); if (master) { fillIcon = self.gameObject.AddComponent <MysticsItemsSuperIdolHUDIcon>(); fillIcon.master = master; fillIcon.fillAmount = CalculateIdolBonus(master, newItemCount); } } } else { UnityEngine.Object.Destroy(fillIcon); fillIcon = null; } } if (shouldDisplay && fillIcon) { fillIcon.itemCount = newItemCount; fillIcon.UpdateTransform(); } }