Making Inventory Containers (Banks, NPC loots, Treasure Chests)

Mini Update. Having a third ‘ShowHideUI.cs’ script on the UI Canvas overwrites my bank when I click on the banker, so now he opens my crafting UI rather than my bank (although for both banker and equipment, they seemed to have no issues). Here’s what my UI Canvas inspector looks like so far (I can’t get the Bankers’ ShowHideUI in the image below, but it’s up there. It looks similar to that of the crafting one, but ‘other Inventory container’ is set to “Bank”:

UI Canvas ShowHideUI

You need a CraftingTable.cs script which would implement the IHandleRaycast interface, as well as manage the recipies and handle the actual crafting.

Cursor still won’t highlight it (for Resource gathering of the past week, this would be solved by now)… So far here’s my baby script:

using System.Collections;
using System.Collections.Generic;
using RPG.Control;
using UnityEngine;

public class CraftingTable : MonoBehaviour, IRaycastable
{

    public CursorType GetCursorType()
    {
        return CursorType.Crafting;
    }

    public bool HandleRaycast(PlayerController callingController)
    {

        return true;

    }

}

Edit: It’s been 2 hours of me trying to figure out why my CursorType won’t work, and I still have no idea why… I’m not even trying to open the Crafting UI yet, all I’m literally trying to do is to get the mouse icon of my crafting to display the way it should…

Edit 2: 4 hours later, I figure out it’s because I don’t have a Box Collider on my damn (apologies for the language, I was a bit furious) table…

Edit 3: I copied some of the script from last weeks’ Resource Gathering System to get my table to open when my player is close, and the table is clicked on, and to close the window if he walks away, into my “CraftingTable.cs”.

Now I’m just coding a solution to open both the Inventory and the Crafting UI simultaneously, which I also want to automatically shut it down if interrupted by a fight or the player walks away (I played with the Rect Transform code to achieve the ‘player walks away’ effect, now I just need the ‘player interrupted by battle’ effect (I’m thinking booleans…)). If you see this comment, please help, because even my Crafting UI buttons are not working for some reason (and apparently all of them, according to the debugger, are the exact same button). Hovering over them returns a Null Reference Exception error, as you can see below:

NullReferenceException: Object reference not set to an instance of an object
GameDevTV.UI.Inventories.InventorySlotUI.GetItem () (at Assets/GameDev.tv Assets/Scripts/UI/Inventories/InventorySlotUI.cs:44)
GameDevTV.UI.Inventories.ItemTooltipSpawner.CanCreateTooltip () (at Assets/GameDev.tv Assets/Scripts/UI/Inventories/ItemTooltipSpawner.cs:16)
GameDevTV.Core.UI.Tooltips.TooltipSpawner.UnityEngine.EventSystems.IPointerEnterHandler.OnPointerEnter (UnityEngine.EventSystems.PointerEventData eventData) (at Assets/GameDev.tv Assets/Scripts/Utils/UI/Tooltips/TooltipSpawner.cs:57)

This is what my finalized Crafting UI Design looks like (I’m seeking ideas on how to make this look fancier, NGL. But let’s keep that until the end, let’s get it to work properly first).

The whole idea here is to scan through all the inventory slots (i.e: Redraw the inventory slots that are not null, similar to the banking system) and search through the list of recipes we will give the computer. If the items in the slots match the requirements for a specific recipe, then bring up the output crafting product (and the crafting button) in a bit of a transparent light (indicating it’s available for crafting), and then check for if it can be crafted or not. If it can, then the craft button can be activated (like what you can see in the image below). If not (maybe a level constraint or something), the crafting button remains transparent (I’ll try coding this on my own first, but I desperately need help to get the inventory open when the CraftingUI opens up first, and for an inventory transfer system to function properly to even consider that crafting system):

And the Inventory is supposed to be on its right hand side, similar to the Banking system (still trying to figure out which function to use for that)

Should I open a new topic system for this already…?

It’s really off topic for tis thread…

Have you considered freezing time while the windows are open? If you’re dragging items to the crafting table and get interrupted, you’re risking data loss… In any event, you need to get the UI to open and the crafting working FIRST, then then start worrying about adding in interruptions. Some of the issues you’ve encountered in the past are trying to do too many things at the same time, which has lead to unintended consequences.

As we’re adding multiple setups

  • Inventory + Equipment
  • Inventory + OtherInventory
  • Inventory + Crafting

It might make sense to create three different HidingPanels, one with each configuration…

But for now… we’ll handle things this way…
Add the following to ShowHideUI in the Fields:

        [SerializeField] private GameObject craftingTable = null;
        //[SerializeField] CraftingTableUI craftingTableUI; //Whatever your UI is for the crafting table

        public bool HasCraftingTable => craftingTable != null;
        public void ShowCraftingTable(GameObject go)
        {
            uiContainer.SetActive(true);
            craftingTable.SetActive(true);
            //call setup on crafting table ui
        }

Now your CraftingTable will want to find the ShowHideUI whose HasCraftingTable == true (much like in the Bank) and call ShowCraftingTable.

I’m trying to take it slow, for now just trying to get the UI to properly open up

Well, it’s an idea… but I want the player to risk getting attacked as well. It just makes things a bit more… fun :sweat_smile:

I have a function called ‘OpenCraftingUI()’ in ‘CraftingTable.cs’ that I tried coding last night. It’s responsible for the UI, do I call it there?

I’ll open a new thread for this, since it’s clearly going off topic (done, check your notifications)

And one last thing… the parameters here are pointless :stuck_out_tongue_winking_eye: (the compiler complains, and the system works perfectly fine without them)

Are you saying the GameObject go is pointless or the SetActive(true); pointer is pointless???

You use the go parameter to pass to the setup on the CraftingTableUI so it knows so it can communicate with the crafting table.

the gameObject go (at least for now :sweat_smile:)

OK I know my questions are a little bit rapid nowadays, and this is a function I’ve been putting aside for now, but it’s really bugging me. I have a severe issue where extracting/banking stackable items in large quantities takes a lot of time, and I want to get rid of it. My thought is that if the player clicks on something stackable, instead of withdrawing it one-by-one, display to him a UI that requests for a number of items to extract from the bank, and that number can be anything the player wants, as long as it’s a numeric value (so it can’t accept alphabetical values)

If it’s larger than the quantity the bank has, just extract the entire stack for him (the value shall not exceed the stack number). If it’s lower, extract the quantity he needs. This is my request, and in the meanwhile I’ll go ahead and give it a go (or at least try develop the UI for it) :slight_smile: - I’ll update my comment as I go (for the UI, I’ll use what the ‘New Game Menu’ text UI used)

Dragging it takes the full stack, no? If you’re using the click to move stuff, do this:

  • Click moves 1
  • Ctrl+Click moves all - you know how many items are in the stack
  • Shift+Click opens a UI with a slider. Again, you know how many items are in the stack for the max of the slider

It’s an idea, but… it sounds a little too complex for the players. I don’t want them to press countless buttons to achieve a specific objective, I want to keep this as simple and hassle-free as possible as well, especially with extremely simple functions that players are expecting, like this one, because again… it’s a simple point-and-click game system, so I think we can try mine for the moment (no offence meant btw, just personal preference) :slight_smile:

I wanted to do something at first that involves a right-click UI to make everyones’ life easier, but since Brian mentioned that it’s a little too complex, I think for now I’ll just settle for something a little simpler. If you try withdraw a stackable item, just show up a UI that asks you for a number, and then we can withdraw the number given by the player of that item (again, if the number exceeds the max stack for that item, then only withdraw the max number)

The simpler the system is for the player, the better

You underestimate players. This is how most games’ inventories do it - or some variation on it - and players that have played games with inventories before will pretty much automatically assume that’s how it will work. But you can do a UI if you want. It’s your game

That makes it even better, so now I have a selling point… my game is simpler and hassle-free :stuck_out_tongue_winking_eye: (I just hope we can actually get it to the stage of extraction, xD)

How can i populate the slots of the containers ?

You mean like for a treasure chest?
On the same GameObject as the otherInventory Container, add a script that adds the items to the Inventory. Something like this:

public class InventoryLoader : MonoBehaviour
{
    [System.Serializable]
    struct LoaderRecord
    {
          public InventoryItem item;
          public int number;
     }
     
     [SerializeField] private LoaderRecord[] itemsToLoad;
    
      void Awake()
      {
            Inventory inventory = GetComponent<Inventory>();
            foreach(LoaderRecord record in itemsToLoad)
            {
                   inventory.AddToFirstEmptySlot(record.item, record.number);
            }
      }
}
1 Like

thank you

Hey Brian. Just curious, can we also please get instructions on how to blend the bank into your Third Person migration gitbook? :slight_smile:. I revised the bank system, and it seems a bit… too complex tbh.

When I’m home, I’ll give that a go myself and keep you updated. Just thought to bring this idea up, xD

The only problem with putting it in the tutorial is that the bank itself isn’t in the version of the project that I’m using, and there’s no guarantee that it will work for everybody.

Eventually, it could be a side tutorial. Here’s the thing, though… the process to get from PlayerFreeLookState to opening the bank window pretty much the same as the process to open a shop. Once that happens, the rest sort of handles itself… Since the InventoryUI is already a WindowController, all that you need to do is to have a

  • BankFinder
  • A PlayerBankingState that can take in the bank
  • An InputAction/Event to open the bank (or rely on the “One Click”… the more things get added, the more the One Click makes perfect sense.

So this is your challenge. :stuck_out_tongue:

Not sure what I missed out on, but I did not make my ‘InventoryUI.cs’ a WindowController inheritant… (and I’m not sure how doing so now will mess this project up)

Anyway, will give the rest a go for now :slight_smile:

Privacy & Terms