Forum rules - please read before posting.

display multiple elements in the DocumentListMenu

I have a question about the UI.
I'm considering adding a Property to the Document in the Inventory and allowing players to input its contents.

I want to display the Documents in a DocumentListMenu. Is there a way to show both the Document's image and the added Property at the same time?
Since there are many Documents, it needs to be possible to offset them using buttons.

Thanks!

Comments

  • It's possible, but currently most likely through custom script. I'll need to be sure of your intent, however.

    By "list", do you mean to display all Documents, with images and properties for each, in a list - or a list of Document titles, and only show the "selected" Document's image / property?

    If you can share a mockup image of your intention, that'll help clarify the situation.

  • edited January 21

    Thanks for your reply!

    My assumption is that “all image files and properties are listed together.”

    I made a sample image. It's very rough, but...
    Please let me know.

    https://imgur.com/a/6pVb8TP

  • Thanks.

    You'd need to rely on Unity UI for your Menu's Source, and then add each of the "Property" labels as Text components that you can then control through script. These would not need to be linked as Label elements - only the Image components that represent the Document icons. These would all be linked to a single InventoryBox element that shows Collected Documents, which the script would then reference to extract the relevant property data:

    using AC;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class DocumentPropertyLabel : MonoBehaviour
    {
    
        public int slotIndex;
        public Text textBox;
        private const string MenuName = "Documents";
        private const string ElementName = "DocumentList";
        private const string PropertyName = "MyProperty";
        private MenuInventoryBox documentsList;
    
        void Start()
        {
            documentsList = PlayerMenus.GetElementWithName(MenuName, ElementName) as MenuInventoryBox;
        }
    
        void Update()
        {
            var document = documentsList.GetDocument(slotIndex);
            if (document != null)
            {
                textBox.text = document.GetProperty(PropertyName).TextValue;
            }
            else
            {
                textBox.text = string.Empty;
            }
        }
    
    }
    

    This script would be attached and assigned to each Text object, with each having its unique "Slot Index" value set. You can use TextMesh Pro instead of Text if you want. Edit the string variables to match what's in your game and it should pull the property value from each of the Documents and update the UI.

  • Thank you for your reply! I tried it, and it worked!!

    You always give me courage!
    Thank you so much.

  • Excuse me, I have one more question.

    I want to write a process in a script that compares the value of a property added to all documents with a specific value, and if it’s True, it will ‘do something’. Could you give me some hints?

    @ChrisIceBox

  • This'd do it:

    public int GetTotalValue(string propertyName)
    {
        int totalValue = 0;
    
        var documentIDs = KickStarter.runtimeDocuments.GetCollectedDocumentIDs();
        foreach (var ID in documentIDs)
        {
            var documentInstance = KickStarter.runtimeDocuments.GetCollectedDocumentInstance(ID);
            totalValue += documentInstance.Document.GetProperty(propertyName).IntegerValue;
        }
    
        return totalValue;
    }
    
  • It went well!
    Thank you as always.

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.