attributes view on different panels

manscom

Member
i have successfully setup to show different attributes on the item view slot for my inventory just like the tutorial video shown. i also want to do it on other panels like hotbar, crafting, etc, but those panels' item slot look different and even some are action buttons, so i try the same method but not work. Because I am not a very good at coding so i am very afraid to edit the scripts. I have tried my best to take some pictures for your references to show you there are two situations I am not able to set it up. Please teach me how to do it.

Thank You!
 

Attachments

  • problem 1.zip
    1,007.2 KB · Views: 1
  • problem 2.zip
    442.5 KB · Views: 2
For problem 1, the issue is that the Item Info set to that Item View does not come from an inventory. The item views are directly set from the Recipe. Usually I set the Inventory directly but it seems that that's not the case for Recipes.

Until I find a better solution you can replace the InventoryAmountItemView by this:
C#:
/// <summary>
/// An Item View component that compares the item amount with an amount from an inventory.
/// </summary>
public class InventoryAmountItemView : ItemViewModule, IInventoryDependent
{
    [Tooltip("The amount text.")]
    [SerializeField] protected Text m_AmountText;
    [Tooltip("The ID of the Inventory to get the amount from.")]
    [SerializeField] protected uint m_InventoryID = 1;
    [Tooltip("Use the Inventory ID to get the Inventory or get it from the Item Info.")]
    [SerializeField] protected bool m_UseInventoryID = false;
    public Inventory Inventory { get; set; }
    /// <summary>
    /// Set the value.
    /// </summary>
    /// <param name="info">The item info.</param>
    public override void SetValue(ItemInfo info)
    {
        if (Inventory == null) {
            if (m_UseInventoryID) {
                Inventory = InventorySystemManager.GetInventoryIdentifier(m_InventoryID)?.Inventory;
            } else {
                Inventory = info.Inventory as Inventory;
            }
            
        }
        if (Inventory == null) {
            Debug.LogWarning("Inventory is missing from component.", gameObject);
            Clear();
            return;
        }
        var inventoryAmount = Inventory.GetItemAmount(info.Item.ItemDefinition, false, false);
        m_AmountText.text = $"{inventoryAmount}";
    }
    /// <summary>
    /// Clear the value.
    /// </summary>
    public override void Clear()
    {
        m_AmountText.text = "";
    }
}

That will allow you to specify the Inventory you want to use if the component can't find the Inventory by itself.
Simply tick the UseInventoryID option and make sure the ID matches your Inventory Identifier ID.


If I understand correctly in problem 2 you would like to display the Icon the items already in the hotbar correct?
I'm afraid that's not possible right now with the current Assign Hotbar Item Action.

I'm planning to implement a solution for that in the next major update. I can bump up the priority for it and send you a solution once it is implemented.

In the meantime you can show the item name instead of the index number by using this option:
1621850884897.png
 
For problem 1, the issue is that the Item Info set to that Item View does not come from an inventory. The item views are directly set from the Recipe. Usually I set the Inventory directly but it seems that that's not the case for Recipes.

Until I find a better solution you can replace the InventoryAmountItemView by this:
C#:
/// <summary>
/// An Item View component that compares the item amount with an amount from an inventory.
/// </summary>
public class InventoryAmountItemView : ItemViewModule, IInventoryDependent
{
    [Tooltip("The amount text.")]
    [SerializeField] protected Text m_AmountText;
    [Tooltip("The ID of the Inventory to get the amount from.")]
    [SerializeField] protected uint m_InventoryID = 1;
    [Tooltip("Use the Inventory ID to get the Inventory or get it from the Item Info.")]
    [SerializeField] protected bool m_UseInventoryID = false;
    public Inventory Inventory { get; set; }
    /// <summary>
    /// Set the value.
    /// </summary>
    /// <param name="info">The item info.</param>
    public override void SetValue(ItemInfo info)
    {
        if (Inventory == null) {
            if (m_UseInventoryID) {
                Inventory = InventorySystemManager.GetInventoryIdentifier(m_InventoryID)?.Inventory;
            } else {
                Inventory = info.Inventory as Inventory;
            }
           
        }
        if (Inventory == null) {
            Debug.LogWarning("Inventory is missing from component.", gameObject);
            Clear();
            return;
        }
        var inventoryAmount = Inventory.GetItemAmount(info.Item.ItemDefinition, false, false);
        m_AmountText.text = $"{inventoryAmount}";
    }
    /// <summary>
    /// Clear the value.
    /// </summary>
    public override void Clear()
    {
        m_AmountText.text = "";
    }
}

That will allow you to specify the Inventory you want to use if the component can't find the Inventory by itself.
Simply tick the UseInventoryID option and make sure the ID matches your Inventory Identifier ID.


If I understand correctly in problem 2 you would like to display the Icon the items already in the hotbar correct?
I'm afraid that's not possible right now with the current Assign Hotbar Item Action.

I'm planning to implement a solution for that in the next major update. I can bump up the priority for it and send you a solution once it is implemented.

In the meantime you can show the item name instead of the index number by using this option:
View attachment 5931
really thanks for your reply, now the number is working.

I have a further question, I do not need too much informations for the recipe ingredients. how to I get rid of the item description for recipe ingredients. I try to delete it but there's a script called recipe panel looks like prevent me to do that. Please teach me how to do this, I take a few images and explain what I mean for that , please see the below images for your reference.螢幕截圖 2021-05-24 下午10.19.29.png
螢幕截圖 2021-05-24 下午10.19.46.png
Thank you very much for your help!
 
I see, looking at the code it seems that I made it such that the descriptions are required.

When I first designed this crafting UI it was meant to be as an example in the demo scene. But a few people wanted to use it outside the demo scene so I made some changes and moved it out, but it is still quite rigid. I expected people to code their own crafting UI by using my code as a base or at least as an inspiration. But for people who do not code I see that this could be an issue.

I could add a null check each time before I try using the views and descriptions.
Please find the new Recipe Panel script with null checks attached, let me know if that works for you
 

Attachments

  • RecipePanel.cs
    11.6 KB · Views: 2
I see, looking at the code it seems that I made it such that the descriptions are required.

When I first designed this crafting UI it was meant to be as an example in the demo scene. But a few people wanted to use it outside the demo scene so I made some changes and moved it out, but it is still quite rigid. I expected people to code their own crafting UI by using my code as a base or at least as an inspiration. But for people who do not code I see that this could be an issue.

I could add a null check each time before I try using the views and descriptions.
Please find the new Recipe Panel script with null checks attached, let me know if that works for you
the scripts works for me, thank you very much for your help!
 
For problem 1, the issue is that the Item Info set to that Item View does not come from an inventory. The item views are directly set from the Recipe. Usually I set the Inventory directly but it seems that that's not the case for Recipes.

Until I find a better solution you can replace the InventoryAmountItemView by this:
C#:
/// <summary>
/// An Item View component that compares the item amount with an amount from an inventory.
/// </summary>
public class InventoryAmountItemView : ItemViewModule, IInventoryDependent
{
    [Tooltip("The amount text.")]
    [SerializeField] protected Text m_AmountText;
    [Tooltip("The ID of the Inventory to get the amount from.")]
    [SerializeField] protected uint m_InventoryID = 1;
    [Tooltip("Use the Inventory ID to get the Inventory or get it from the Item Info.")]
    [SerializeField] protected bool m_UseInventoryID = false;
    public Inventory Inventory { get; set; }
    /// <summary>
    /// Set the value.
    /// </summary>
    /// <param name="info">The item info.</param>
    public override void SetValue(ItemInfo info)
    {
        if (Inventory == null) {
            if (m_UseInventoryID) {
                Inventory = InventorySystemManager.GetInventoryIdentifier(m_InventoryID)?.Inventory;
            } else {
                Inventory = info.Inventory as Inventory;
            }
           
        }
        if (Inventory == null) {
            Debug.LogWarning("Inventory is missing from component.", gameObject);
            Clear();
            return;
        }
        var inventoryAmount = Inventory.GetItemAmount(info.Item.ItemDefinition, false, false);
        m_AmountText.text = $"{inventoryAmount}";
    }
    /// <summary>
    /// Clear the value.
    /// </summary>
    public override void Clear()
    {
        m_AmountText.text = "";
    }
}

That will allow you to specify the Inventory you want to use if the component can't find the Inventory by itself.
Simply tick the UseInventoryID option and make sure the ID matches your Inventory Identifier ID.


If I understand correctly in problem 2 you would like to display the Icon the items already in the hotbar correct?
I'm afraid that's not possible right now with the current Assign Hotbar Item Action.

I'm planning to implement a solution for that in the next major update. I can bump up the priority for it and send you a solution once it is implemented.

In the meantime you can show the item name instead of the index number by using this option:
View attachment 5931
I have one more small issue, the upper code works fine for the inventory amount when opening the menu, but it does not update the number immediately after craft an item, they update after refresh the menu. I did tried so hard to look into the code but still can not find which value represents the select item about which I can send the event function to update the inventory number. I have recorded a short video to show you what I mean by that.

Please watch the below video for your reference.

Thank you!
 
That makes sense, since I never thought the recipes needed to be drawn again.

In the CraftingMenu script replace the CraftSelectedQuantity function:

Code:
/// <summary>
/// Wait for the player to select a quantity.
/// </summary>
/// <returns>The task.</returns>
private void CraftSelectedQuantity()
{
    var quantity = m_QuantityPickerPanel.QuantityPicker.Quantity;
    if (quantity >= 1) {
        m_Crafter.Processor.Craft(m_SelectedRecipe, m_Inventory, quantity);
    }
    
    DrawRecipes();
    m_RecipePanel.SetQuantity(1);
    m_RecipePanel.Refresh();
}

I added Draw Recipes, so now the number should update as soon as you craft something.
Let me know if it works, I'm keeping all those changes, they will be part of the next major update
 
That makes sense, since I never thought the recipes needed to be drawn again.

In the CraftingMenu script replace the CraftSelectedQuantity function:

Code:
/// <summary>
/// Wait for the player to select a quantity.
/// </summary>
/// <returns>The task.</returns>
private void CraftSelectedQuantity()
{
    var quantity = m_QuantityPickerPanel.QuantityPicker.Quantity;
    if (quantity >= 1) {
        m_Crafter.Processor.Craft(m_SelectedRecipe, m_Inventory, quantity);
    }
   
    DrawRecipes();
    m_RecipePanel.SetQuantity(1);
    m_RecipePanel.Refresh();
}

I added Draw Recipes, so now the number should update as soon as you craft something.
Let me know if it works, I'm keeping all those changes, they will be part of the next major update
Really thanks for your help, that function works!

why did I just keep going very deep into the scripts, even go into the CraftingOutput one, but still do not know this useful function is just right on the first script haha....

Now my Crafting menu looks fine for me, I think I can close this threads now.

Really appreciate for your help! You are so awesome!
 
Top