Forum rules - please read before posting.

Change graphic for inventory items that can have multiple carried?

edited March 2023 in Technical Q&A

Hi all,

I was wondering if it is possible to change the graphics for inventory items that can have multiple being carried.

The inventory item of "multiple being carried" is 5 berries in my case, so each time the player picks up a berry, I want the graphic to be updated.

E.g.:
When the player has 1 of this item, the graphic shows only one berry and the label is "1 berry".
When the player has 2 of this item, the graphic is updated to show two berries (separate png file that I have) and the label is "2 berries".
...
When the player has 5 of this item, the graphic is updated to show 5 items (another separate png file) an the label says "5 berries".

With that being said, is it possible to accomplish this?
Thank you!

Comments

  • It's possible with scripting. I've added a script to handle this on the AC wiki here:
    https://adventure-creator.fandom.com/wiki/Changing_item_graphics_with_amount

  • Thank you so much! Will take a look :)

  • @ChrisIceBox
    Is there a way I could manipulate the script so that the cursor changes as well?

    I noticed that the count near the cursor is appearing correctly, but only the default graphic shows up in the inventory box and the cursor.

  • Ah nevermind, just realized I could add
    invInstance.CursorIcon.texture = ag.texture;

    One other thing that came up though -- is it possible to change the label as well, like above?

    I noticed that the label does not change as the amounts increase, although the graphics are changing correctly!

    Any help is appreciated, thank you!

  • Currently not - you'd have to update the label of the original Item itself.

    I shall look into how this might be added, however.

  • Got it, thanks for the heads up!

  • OK - v1.77.0 is out, and I've included a similar "ItemLabel" property to the InvInstance class that you can use to override an item's name:

    int count = invInstance.Count;
    if (count == 1) invInstance.ItemLabel = "1 apple";
    else invInstance.ItemLabel = count + " apples";
    
  • Ooh thank you so much! Really appreciate it! :)

  • Is v1.77.0 a stable release by any chance? Was checking for Adventure Creator updates, but it's showing v1.76.3 only it seems.

    Thanks!

  • v1.77.1 is now the latest, and should indeed be stable. If you encounter issues, however, just let me know.

  • Thanks for the heads up!
    Ah, would I have to upgrade to v1.76.3 before upgrading to v1.77.1, or could this be done directly?

    My current version is v1.76.2, this is the screenshot that I am getting.

  • You can upgrade directly to v1.77.1 - try it now, just be sure to backup your project first.

  • Great, thank you so much! Looks like it shows up as v1.77.1!

  • edited July 2023

    Hi Chris!

    Just following up on this -- I have just downloaded v1.77.4, and I added this functionality in the MultipleItemGraphics script.

    It seems that the message (for "ITEM LABEL MULTIPLE") is printing out on the console, but the image still shows up as "Tomatoes" instead of "3 Tomatoes".

    Might there be something I missed?

    This is a screenshot of how it looks right now: https://drive.google.com/file/d/1W1438aoibL6Ieh7Xm3jyw0Hccp5bMA2v/view?usp=sharing

    I am attaching the relevant code snippet below.

    `private void UpdateGraphics()
    {
    foreach (InvInstance invInstance in KickStarter.runtimeInventory.PlayerInvCollection.InvInstances)
    {
    if (invInstance.ItemID != itemID) continue;
    int count = invInstance.Count;

            foreach (AlternativeGraphic ag in alternativeGraphics)
            {
                if (count == ag.minCount)
                {
                    //updates the cursor texture when selected
                    invInstance.Tex = ag.texture;
                    invInstance.CursorIcon.texture = ag.texture;
    
                    //updates the inventory box texture 
                    KickStarter.runtimeInventory.GetItem(itemID).tex = ag.texture;
    
                    Debug.Log("the count is " + count + " graphics is " + invInstance.Tex.name);
    
                    //set new cursor offsets if they exist
                    if (ag.xOffset != 0)
                    {
                        invInstance.CursorIcon.clickOffset.x = ag.xOffset;
                    }
    
                    if(ag.yOffset != 0)
                    {
                        invInstance.CursorIcon.clickOffset.y = ag.yOffset;
                    }
    
                    if (count == 1)
                    {
                        invInstance.ItemLabel = "1 " + invInstance.ItemLabel;
                        Debug.Log("ITEM LABEL SINGULAR " + invInstance.ItemLabel);
                    }
                    else
                    {
                        invInstance.ItemLabel = count + " " + invInstance.ItemLabel;
                        Debug.Log("ITEM LABEL MULTIPLE " + invInstance.ItemLabel);
                    }
    
    
    
                    PlayerMenus.ResetInventoryBoxes();
                    //return;
                }
            }`
    
  • I see nothing wrong - when are you calling the function, and what is your Menu's Source set to?

    Does the item have an "Active" texture assigned in its properties? That will override the "Main" graphic when selected.

  • The graphics are fine from what I can tell -- I think it's the label that's the only issue.

    The source for the Hotspot menu is set to Adventure Creator.

  • Ah - sorry, I misread the issue.

    Is the label wrong only when hovering over the item with the cursor, or when selected and hovering over other items/Hotspots?

  • No worries!
    I think it's during both from what I can tell -- the stray 3 shows up even when selecting the tomatoes, and the label is also not updated with the amount when hovering over it.

  • edited July 2023

    The stray 3 can be hidden by setting the Size field in the Cursor Manager's Count display style section, in the "Inventory cursor" panel, to zero.

    I've recreated the label issue - I'll issue a fix in the upcoming v1.78 release, thanks.

  • Got it, thank you!

    Thank you so much! :)
    Will keep my eyes peeled!

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.