Forum rules - please read before posting.

Incorporating Inventory Menu into Dialogue Screens

Love working with adventure creator. Long time lurker, first time poster. But I've finally run into a task that seems fairly specific to my needs. In short, the design I'm going for has inventory items appearing on the same UI as conversations, and clicking on the various inventory items activates dialogue in the same way as conversation options do.

I'm after this specific design as I'm making a mystery detective game, and I'm handling clues like suspects and locations as different categories of inventory items. Any help would be much appreciated!

Pictured: Dialogue scene with normal, perfectly functional dialogue in the bottom left, and non-functional "inventory items" on the bottom right.

Comments

  • edited January 2021

    Welcome to the community, @aardvark4lunch.

    It's possible to limit a dialogue option's display to only show when a particular item is held, and options can also be assigned icon textures that match that item.

    The tricky part is getting two different types of option display (text vs icon) to show simultaneously.

    One approach you could try would be to use a separate DialogList element (and Menu) for the "icon" options, and also house those options in a separate Conversation.

    AC lets you manually override which Conversation a DialogList element displays for, so it might be possible to have two Conversations active at a time - each being displayed in a separate menu.

    Try this:

    1) Move your "inventory options" to a separate Conversation, giving them appropriate icons and linking them to inventory items.
    2) Create a second Menu + DialogList element to display this Conversation in.
    3) Set this new Menu's Appear type to Manual, and have it turn on and off (using the Menu: Change state Action) when the original Conversation menu is turned on and off (by assigning ActionLists in that menu's properties panel)
    4) Attach a simple custom script to the second Conversation that causes it to show up in this second menu when the first Conversation is run:

    using UnityEngine;
    using AC;
    
    public class InventoryConversation : MonoBehaviour
    {
    
        public Conversation mainConversation;
    
        private void OnEnable () { EventManager.OnStartConversation += OnStartConversation; }
        private void OnDisable () { EventManager.OnStartConversation -= OnStartConversation; }
    
        void OnStartConversation (Conversation conversation)
        {
            if (conversation == mainConversation)
            {
                MenuDialogList dialogList = PlayerMenus.GetElementWithName ("InventoryConversation", "DialogList") as MenuDialogList;
                dialogList.OverrideConversation = GetComponent <Conversation>();
            }
        }
    
    }
    

    In the Inspector, assign the "main" Conversation that should bring up the second as well.

  • Wow, awesome stuff! You really are a god among men :smiley:
    I'll get started looking into all that now.

    I just had another idea (and I have no idea if this is feasible) but I'm using the Unity UI Prefabs to power the menus through Adventure Creator, and I was wondering if:

    A. A script on a button could get a reference for what inventory item is assigned to it

    B. If that same script could get a reference to who is currently being conversed with.

    C. If through code I could then use inventory item A on hotspot B

  • edited January 2021

    And run something like this psuedo code when you press a button.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class TestButton : MonoBehaviour
    {
        public AC.Hotspot character;
    
        private void OnEnable()
        {
            character = conversationCharacter.GetComponent<AC.Hotspot>();
        }
    
        public void Click()
        {
            character.RunInventoryInteraction(inventoryItemCorrespondingToButton);
        }
    }
    
  • As in, keep icons in an InventoryBox element, and run Hotspot interactions when clicking them?

    That would be possible, yes. If you set the element's Inventory box type setting to Custom Script, then its click handling is left entirely to script.

    Conversations aren't "associated" with a character, though - they're detached from the specific situation they're used for. To work out which character you're talking to, you could move the Conversation component to the NPC's Hotspot, so that they're both the same GameObject.

    To run a Hotspot interaction when clicking an item, you could then use something like this:

    using UnityEngine;
    using AC;
    
    public class ConversationInventoryInteraction : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnMenuElementClick += ElementClick; }
        private void OnDisable () { EventManager.OnMenuElementClick -= ElementClick; }
    
        private void ElementClick (AC.Menu _menu, MenuElement _element, int _slot, int _buttonPressed)
        {
            // Only work during conversation
            if (!KickStarter.playerInput.IsInConversation ()) return;
    
            if (_menu.title == "MyMenu" && _element.title == "MyInventory")
            {
                MenuInventoryBox inventoryBox = _element as MenuInventoryBox;
                InvInstance clickedInstance = inventoryBox.GetInstance (_slot);
    
                if (InvInstance.IsValid (clickedInstance))
                {
                    Hotspot npcHotspot = KickStarter.playerInput.activeConversation.GetComponent <Hotspot>();
                    if (npcHotspot)
                    {
                        npcHotspot.RunInventoryInteraction (clickedInstance);
                    }
                }
            }
        }
    
    }
    

    Change the strings to match your own menu/element, and attach to your UI prefab.

  • Absolute LEGEND works amazing! Been tearing my hair out all day. It works perfectly for handled inventory items, but seems to be having some issues with unhandled (unless I'm doing something wrong which, let's face it. I most likely am.)

    I have this set up on my Cop so when faced with an inventory item he's unfamiliar with he has a specific line of dialogue based on if the item is in the physical, KnowledgePerson, or KnowledgeOther categories. But even though the unhandled item is a KnowledgePerson, it seems to fail all three inventory checks.

  • If you're overriding the click behaviour of the InventoryBox, an item won't become selected automatically upon clicking it. Try inserting the following before the Hotspot's RunInventoryInteraction call:

    KickStarter.runtimeInventory.SelectItem (clickedInstance);
    
  • You're a damn legend, you know that?

    Five star review coming your way! I'll have to send a tip your way too, do you have a donation link?

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.