Forum rules - please read before posting.

Switching between Inventory Categories in a Unity UI

Good afternoon, everybody ^_^

So, I've been working on a whodunnit game whose inventory has two item classifications: "Item" and "Profile". The player will access these inventories through a Unity UI, choosing categories by pressing a corresponding button over the inventory box.

I found a useful lead in https://adventurecreator.org/forum/discussion/5700/how-to-get-the-list-of-inventory-category-ids-and-their-names , but the code I made from it doesn't seem to change anything.

public void ItemMode()
{
MenuElement inventorybox = PlayerMenus.GetElementWithName("Inventory", "InventoryBox");
MenuInventoryBox menuInventoryBox = inventorybox as MenuInventoryBox;
menuInventoryBox.categoryIDs.Clear();
menuInventoryBox.categoryIDs.Add(0); // only display entries from the Item category.
// 0 = Item, 1 = Profile

}

I remember reading in the article that you needed to use this code before the menu was opened. Do I need to close the menu, run the code, than open it again? Can I do that scriptside?

Thank you very much for your time. I am so close to getting this built!

Comments

  • Maybe a slightly different approach will get you the same endgame? I saw this post. It might help out.

    https://adventurecreator.org/forum/discussion/4402/multiple-inventories
  • Oh, this looks promising. I'll report later with the results.
    Thank you very much, Amy! o:)

  • Welcome to the community, @CodePrincess.

    Your code is essentially doing the same thing that the Properties box in the Menu Manager controls. While it may be less hassle to simply create two separate InventoryBox elements - each set to show a different category, and then swap their display in/out - it should be possible to alter a single one's display at runtime.

    Likely you just need to call Recalculate to update the menu's display afterwards. Try the following after altering the categoryIDs:

    PlayerMenus.GetMenuWithName ("Inventory").Recalculate ();
    
  • edited January 2020

    Oh! Hello, Chris! It's lovely to meet you! ^_^

    Okay, I tried adding the line you suggested, but there doesn't seem to be any change in the menu's behavior:

    `
    public void ItemMode()
    {
    MenuElement inventorybox = PlayerMenus.GetElementWithName("Inventory", "InventoryBox");
    MenuInventoryBox menuInventoryBox = inventorybox as MenuInventoryBox;
    menuInventoryBox.categoryIDs.Clear();
    menuInventoryBox.categoryIDs.Add(0); // only display entries from the Item category.
    // 0 = Item, 1 = Profile
    PlayerMenus.GetMenuWithName("Inventory").Recalculate();

        Debug.Log("Switched to Item Mode");
    }`
    

    Should I give up now, or are there any other avenues to explore?
    Thank you both again very much. Have a good day!

  • edited January 2020

    It should work - even if this isn't the right code, I'd like for people to be able to configure this if possible.

    I'll try the code and see what's wrong. Is your Menu linked to Unity UI? If so, try switching its Source over to Adventure Creator (temporarily) - does it work then?

    Edit: Your code works on my end. What's your AC version, and let's see a screenshot of your Menu's properties in the Menu Manager. If all else fails, you could try the swapping method above, but this should work too.

  • I'm using version 1.69.5 Okay. I was trying to implement the swapping feature, but now everything's broken. Can I send you a link to my project file? I'm completely helpless.

  • edited January 2020

    By all means, PM me a .zip or .unitypackage file - but please also share steps on how to recreate the issue.

  • Just click "go" and the problems present themselves all at once. Eagerly.
    Looking at what I've made, I wouldn't blame anybody for doubting me when I say I've built my own game from the ground up before. Got it on Steam and everything.

    Thanks again for your patience. I'll be sending you that unity package ASAP.

  • It's sent! If you need anything else, please let me know!

  • No problem. I've replied to you in a PM, but for the sake of anyone having the same issue in the future - the InventoryBox element just needs to have its Limit by category? property checked in the Menu Manager.

  • Well, would you look at that. Everything works!
    Thanks again! You're a Godsend!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.