Forum rules - please read before posting.

Inventory Item Close up

Hello again, in my 2D game, I have implemented a feature where I can right-click to examine an inventory item - the setup is almost identical to that of 'The Chamber' (https://adventurecreator.org/downloads). What I'm trying to achieve is displaying a larger image of an inventory item upon examination. I am wondering, is there a way to have different images for the ItemGraphic in the InvenItemCloseup menu and the Main Graphic (in the AC Game Editor - Inventory)? I have noticed a "Linked prefab" field in the Inventory Manager panel, but I'm uncertain about its functionality. Any guidance or useful references for handling menus would be greatly appreciated. Thank you in advance!

Comments

  • Currently, it'd involve scripting - but I am looking into ways to improve this.

    In the meantime, here is an alternative script to The Chamber's NewItemMenuSetup script that exposes a list of item textures that you can assign in its Inspector:

    using UnityEngine;
    using AC;
    
    public class NewItemMenuSetup_Alternative : MonoBehaviour
    {
    
        private const string menuName = "NewItem";
        private const string inventoryMenuName = "Inventory";
        private const string nameElement = "ItemName";
        private const string graphicElement = "ItemGraphic";
    
        [SerializeField] private ItemGraphic[] itemGraphics = new ItemGraphic[0];
    
        private void OnEnable ()
        {
            EventManager.OnInventoryAdd += OnInventoryAdd;
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
            EventManager.OnMenuTurnOff += OnMenuTurnOff;
        }
    
        private void OnDisable ()
        {
            EventManager.OnInventoryAdd -= OnInventoryAdd;
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
            EventManager.OnMenuTurnOff -= OnMenuTurnOff;
        }
    
    
        private void OnInventoryAdd (InvItem invItem, int count)
        {
            Menu newItemMenu = PlayerMenus.GetMenuWithName (menuName);
    
            MenuLabel itemNameLabel = newItemMenu.GetElementWithName (nameElement) as MenuLabel;
            itemNameLabel.label = invItem.GetLabel (Options.GetLanguage ());
            itemNameLabel.UpdateLabelText ();
    
            Texture2D tex = null;
            foreach (ItemGraphic itemGraphic in itemGraphics)
            {
                if (itemGraphic.itemID == invItem.id)
                {
                    MenuGraphic menuGraphic = newItemMenu.GetElementWithName (graphicElement) as MenuGraphic;
                    menuGraphic.SetNormalGraphicTexture (itemGraphic.graphic);
                    break;
                }
            }
    
            newItemMenu.TurnOn ();
        }
    
    
        private void OnMenuTurnOn (Menu menu, bool isInstant)
        {
            if (menu.title == menuName)
            {
                PlayerMenus.GetMenuWithName (inventoryMenuName).ignoreMouseClicks = true;
                KickStarter.playerInput.dragOverrideInput = "DragOverride";
                KickStarter.stateHandler.SetInteractionSystem (false);
            }
        }
    
    
        private void OnMenuTurnOff (Menu menu, bool isInstant)
        {
            if (menu.title == menuName)
            {
                PlayerMenus.GetMenuWithName (inventoryMenuName).ignoreMouseClicks = false;
                KickStarter.playerInput.dragOverrideInput = string.Empty;
                KickStarter.stateHandler.SetInteractionSystem (true);
            }
        }
    
        [System.Serializable]
        private class ItemGraphic
        {
    
            public int itemID;
            public Texture2D graphic;
    
        }
    
    }
    
  • Chris, I can't thank you enough. Your code is working perfectly and was exactly what I was looking for. Your dedication to continuously improve Adventure Creator is truly appreciated. Once again, my sincerest thanks for your help!

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.