Inventory Grid Widgets with Items that span more than one space


I am trying to do an inventory grid system that allows me to represent items within more than one grid square, i.e. it could occupy multiple grid squares.
At the moment I have a simple system with one widget that represents each inventory slot (it has a variable for a texture) and then a widget for the inventory as a whole that basically creates a load of the slot widgets and then uses the players array of items (structs with parameters for name and the inventory texture etc).
However, this approach only lets me have each item as a single grid square, as the items texture is essentially set as the image in the grid square.

I am trying to setup a grid for the inventory (lets say 84) and then each item could be a different size (12 or 2*2) and then these are represented within the grid.

Obviously the grid itself needs to be a matrix of some kind, and I figured that in the struct for the item I would store int values for width and height and also an array of int’s to store which slots it occupies in the inventory grid.

However, I am a bit lost in terms of how to represent the inventory within the actual widgets, because the individual slots with an item texture wont work.

Any help/advice would be greatly appreciated.

I’d imagine you could have bigger items occupy more inventory slots, even in a single slot inventory.

For example, a 2x2 hat could occupy 4 single slots in your array inventory system. The default texture size for this 2x2 hat would then also be 2x2, taking 4 spaces but representing one item.

I am a bit lost as to how could I get the texture to spread over more than one inventory slot though, as that approach would presumably have the texture duplicated 4 times rather than being one texture over all 4 slots. At the moment each slot is simply a button and an image, the texture for that image is set by the item it is due to represent, so it simply takes the whole texture. I am not sure how I could get it to only take a proportion of it. I had presumed that i needed another layer of abstraction?

In that case, I think you need to change your method of representing your items. It sounds like a 1x1 item works fine for your current set up, but you want bigger items to also be available.

So if you want to start using, say, a 2x2 item you’re going to have to make it so that your inventory knows its working with a 2x2 item, and not a 1x1. In which case the inventory shouldn’t display a texture in each of the 1x1 spaces, but rather make sure, by a method you make, that its taking up 4 connected spaces. After that is checked, then you display the texture over all four of those spaces.

In essence, you need:

  1. A layer of variables that checks what kind of item you’re working
    with(Is it 1x1? Is it 2x2? ect).
  2. Then another layer to determine where you’ll be placing it in your
    inventory (Placing a 2x2 item in the
    top left of a 4x4).
  3. And a layer to render the item’s texture over of that ‘chunk’ of
    space(There is a 2x2 hat occupying
    the top left 4x4 inventory. Render a
    2x2 hat on that space)

I’m sure I missed a few things, but I’d imagine this is the right direction.

Thanks for the advice, I’ll give it a go :slight_smile: I know roughly what I need to do, but I think it might take me some time and a few goes to get my head straight.

Hello @johnparkes
Are you solved this situation?