I just wanted to tell you, that I tried it out and it works. Thanks again. I don't know if anybody else is interested in that, but here is my solution:
toolBar is the name of my gui, InventoryWindow1 the name of my inventory window within this gui.
It certainly isn't the easiest way to do this, but it works. :-)
Feel free to use the code if you need it.
Code: ags [/code]
toolBar is the name of my gui, InventoryWindow1 the name of my inventory window within this gui.
It certainly isn't the easiest way to do this, but it works. :-)
Feel free to use the code if you need it.
function getIndex() {
int inventoryWindowPositionX = InventoryWindow1.X + toolBar.X;
int inventoryWindowPositionY = InventoryWindow1.Y + toolBar.Y;
if(mouse.x < inventoryWindowPositionX || mouse.y < inventoryWindowPositionY
|| mouse.x > (inventoryWindowPositionX+InventoryWindow1.Width)
|| mouse.y > (inventoryWindowPositionY+InventoryWindow1.Height)) {
player.Say("Error: Inventory index could not be determined. Please contact the game's author to resolve.");
/*player.Say("Debugging mouse-x: %d", mouse.x);
player.Say("Debugging mouse-y: %d", mouse.y);
player.Say("Debugging InventoryWindow1-X: %d", inventoryWindowPositionX);
player.Say("Debugging InventoryWindow1-Y: %d", inventoryWindowPositionY);*/
return 0;
}
int x = mouse.x-inventoryWindowPositionX;
int y = mouse.y-inventoryWindowPositionY;
x = FloatToInt(IntToFloat(x)/IntToFloat(InventoryWindow1.ItemWidth));
y = FloatToInt(IntToFloat(y)/IntToFloat(InventoryWindow1.ItemHeight));
//player.Say("Debugging X: %d", x);
//player.Say("Debugging Y: %d", y);
return (y*InventoryWindow1.ItemsPerRow)+x;
}
[code]
function getIndex() {
int inventoryWindowPositionX = InventoryWindow1.X + toolBar.X;
int inventoryWindowPositionY = InventoryWindow1.Y + toolBar.Y;
if(mouse.x < inventoryWindowPositionX || mouse.y < inventoryWindowPositionY
|| mouse.x > (inventoryWindowPositionX+InventoryWindow1.Width)
|| mouse.y > (inventoryWindowPositionY+InventoryWindow1.Height)) {
// The mouse cursor is not in the inventory area. That should never happen - but if it does, error handling goes here.
return 0;
}
int x = mouse.x-inventoryWindowPositionX;
int y = mouse.y-inventoryWindowPositionY;
x = FloatToInt(IntToFloat(x)/IntToFloat(InventoryWindow1.ItemWidth));
y = FloatToInt(IntToFloat(y)/IntToFloat(InventoryWindow1.ItemHeight));
return (y*InventoryWindow1.ItemsPerRow)+x;
}