@Andreim44, us working on turfbattles decided to make our own Inventory code. We have set values for how many rows and columns. A bigger piece of equipment may take up 5x3 whilst there are some that only take up 2x2 and 1x1. For this the code becomes alot more complex, since you are supposed to sort your items to get more, also you can chose to sort using our algorithm.
at the creation of our inventory & inventory slots we initialize it's graphical view. A slot is never anything but data until we link it with a screen rectangle. We create our grids Memb by doing this
Code:
for(int row = 0; row < MAX_INV_ROW; ++row)
for(int col = 0; col < MAX_INV_COL; ++col){
*window+=InvGrid.New().create(Rect_RU(pos.x+Width(scale.x,col),pos.y-Height(scale.y,row),scale.x,scale.y));
}
Those loops creates 13x9 elements for us. And at the same time we link them to a graphical rectangle (GuiImage).
right now we have 117 elements inside our Memb. When adding a new item & to make sure it fits the slot you have chosen you can simply do something like this
Code:
--slot; //Keep it membable, I.e start at 0
InventorySlots *invg = &InvGrid[slot];
for(int row = 0; row < (-1 + item.ItemSize.y); ++row)
for(int col = 0; col < (-1 + item.ItemSize.x); ++col){
if(!InvGrid[slot + (row * 9) + col].valid()){
return false;
}
}
/*Reach this and you have selected a slot with all free x*Y*/
invg->tbitems =& item;
invg->PartUsed= item.ItemSize;
invg->rectangle=Rect_RU(invg->screenPos().x+invg->screenRect().w() * invg->tbitems->ItemSize.x,invg->screenPos().y,invg->screenRect().w() * (invg->tbitems->ItemSize.x), invg->screenRect().h() * (invg->tbitems->ItemSize.y ));
Now, i selected the first row and the second column, with an item of 5x3, then this easy bool above will check if it fits in both directions x and y.
if it does then you are ok to add. When it comes to equipped items, you can keep a set array, since my guess your slots are always going to be available. And then just keep definitions (MyArrayEquip[0] == Head)
Code:
struct Equipment_slots
{
Item * myitem;
Rect visiblilitycloak;
}MyArray[6];/*MyArray[0] = Head, MyArray[1] = feet, MyArray[2] = body*/
to know if it is valid or not you keep the pointer to you item. This way it can be NULL and it can also point to somewhere.
I hope i answered some questions for you, and i'd be glad to give you some more examples.