Hi, again, lol. Anyway, I was working on a custom action to, well, use a single crafting menu to simulate many different crafting menus. I have text and appearance switching covered fine, but I want to be able to show the current list of categories so that the user doesn't have to go check the inventory manager every time he wants to use the action. I've found some code I think I could use to limit item categories on the fly, but I haven't found the code to gather the category IDs and the names of the categories...
by the way the code I was talking about is:
bool AC.MenuInventoryBox.limitToCategory
If True, only inventory items (InvItem) with a specific category will be displayed
List<int> AC.MenuInventoryBox.categoryIDs = new List<int>()
The category IDs to limit the display of inventory items by, if limitToCategory = True
Anyway, as usual any advice will be greatly appreciated.
Comments
Confusingly, categories in the Inventory Manager are referred to as "bins":
AC.KickStarter.inventoryManager.bins
These are instances of the InvBin class, which stores both an ID and a label.
I think I need some more explanation as to why you'd need to limit by category, though - a Crafting element can only contain the inventory items the player places inside it, so if you limit what items are in the InventoryBox at the time you're also limiting what can go in the Crafting. Custom code could access a given Inventory menu behind the scenes and change what categories it displays.
You can change an InventoryBox element's accepted category / categories by modifying it's categoryIDs list, which is a list of the accepted ID numbers:
MenuInventoryBox myInventoryBox = PlayerMenus.GetElementWithName ("MyMenu", "MyInventory");
myInventoryBox.categoryIDs.Clear ();
myInventoryBox.categoryIDs.Add (2);
That will clear the list and add ID "2" as the only allowed category. You'd need both the "AC" and "System.Collections.Generic" libraries in your script header for it to work, and would need to run that code before turning on the Menu, so that it recalculates everything out of view.
When I use:
MenuInventoryBox myInventoryBox = PlayerMenus.GetElementWithName ("MyMenu", "MyInventory");
I get the error:
CS0266 Cannot implicitly convert type 'AC.MenuElement' to 'AC.MenuInventoryBox'. An explicit conversion exists (are you missing a cast?)
But I found a working code on another thread:
MenuElement inventoryBox = PlayerMenus.GetElementWithName("MyMenu", "MyInventory");
MenuInventoryBox menuInventoryBox = inventoryBox as MenuInventoryBox;
Then you can use:
menuInventoryBox.categoryIDs.Clear ();
menuInventoryBox.categoryIDs.Add (2);
Yes, my mistake. You can do the conversion in one line: