[Help] Inventory Grid Cell

Join Discord

Wummy

Majestic Mir 2
Dedicated Member
Aug 24, 2015
608
82
70
Majestic Town
So im in middle of changing the UI's, i come across being stuck on inventory, i cant seem to get the equation in right place, any advise

would appreciate it

1663092876429.png
This was old one

Code:
            Grid = new MirItemCell[8 * 10];

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 12; y++)
                {
                    int idx = 8 * y + x;
                    Grid[idx] = new MirItemCell
                    {
                        ItemSlot = 7 + idx,
                        GridType = MirGridType.Inventory,
                        Library = Libraries.Items,
                        Parent = this,
                        Location = new Point(x * 36 + 9 + x, y % 5 * 32 + 37 + y % 5),
                    };

                    if (idx >= 40)
                        Grid[idx].Visible = false;
                }
            }
 

Far

tsniffer
Developer
May 19, 2003
19,716
23
2,146
400
Quite a few things wrong that i can see.

Your inventory is 10 x 5

why are you making an 8 x 10 grid?
why is your X looping 8
why is your Y looping 12

location doesn't need the % since you've got 2 loops for X and Y

xOffset + (x * 36), yOffset + (y * 32)

36 and 32 being your cells width and height
xOffset yOffset being the x and y distance from top corner of your inventory to the first cell corner.
 
Upvote 0

Wummy

Majestic Mir 2
Dedicated Member
Aug 24, 2015
608
82
70
Majestic Town
Quite a few things wrong that i can see.

Your inventory is 10 x 5

why are you making an 8 x 10 grid?
why is your X looping 8
why is your Y looping 12

location doesn't need the % since you've got 2 loops for X and Y

xOffset + (x * 36), yOffset + (y * 32)

36 and 32 being your cells width and height
xOffset yOffset being the x and y distance from top corner of your inventory to the first cell corner.
the code was from old UI (EE), posted it to get abit of advise on what does what

so Grid should be 10 x 5
so where it was looping X and Y = top left first box correct?

Location = new Point(x * 36 + 9 + x, y % 5 * 32 + 37 + y % 5),
abit confused on this bit here with text in red
 
Upvote 0

IceMan

Leg end
Untrusted Member
Apr 17, 2003
8,514
2
346
300
Michigan,Usa
Quite a few things wrong that i can see.

Your inventory is 10 x 5

why are you making an 8 x 10 grid?
why is your X looping 8
why is your Y looping 12

location doesn't need the % since you've got 2 loops for X and Y

xOffset + (x * 36), yOffset + (y * 32)

36 and 32 being your cells width and height
xOffset yOffset being the x and y distance from top corner of your inventory to the first cell corner.
Its like that on default files.
 
  • Like
Reactions: andykid131
Upvote 0

Far

tsniffer
Developer
May 19, 2003
19,716
23
2,146
400
Its like that on default files.
Default is 8 x 10 - and 8 x 10 on the loop too (not 8 x 12)

Ah ok, yeah its 8 x 10 because its 10 x 4 on 2 tabs.

So in that case even easier, just change it to 10 x 10, and loop X over 10 too - the rest of it should stay the same.


The location numbers are just maths to work on the position of each cell. Don't over think it, its just a basic formula (replace X with the X value in the loop, same for Y).

% is just a modulus symbol - again no more complicated than a simple formula once you fill in X/Y with the current number.

btw, i often find it easier to see what its doing by turning on borders - then you can see all the cells its drawing.

Border = true,
Border = Color.Lime

add that to the MirItemCell
 
Last edited:
Upvote 1
Solution

andykid131

Golden Oldie
Golden Oldie
Mar 16, 2006
616
3
49
135
Default is 8 x 10 - and 8 x 10 on the loop too (not 8 x 12)

Ah ok, yeah its 8 x 10 because its 10 x 4 on 2 tabs.

So in that case even easier, just change it to 10 x 10, and loop X over 10 too - the rest of it should stay the same.


The location numbers are just maths to work on the position of each cell. Don't over think it, its just a basic formula (replace X with the X value in the loop, same for Y).

% is just a modulus symbol - again no more complicated than a simple formula once you fill in X/Y with the current number.

btw, i often find it easier to see what its doing by turning on borders - then you can see all the cells its drawing.

Border = true,
Border = Color.Lime

add that to the MirItemCell
Would just like to say.. Last time I tried messing with the Inventory Item Cells I had issues figuring out what I was looking at, so this Info is very much appreciated @Far :D ( Couldn't figure out how the code accounted for x2 "inventory tabs" ) Math was never my strongest subject lol.
 
  • Haha
Reactions: Wummy
Upvote 0