// then we need to offset the cursor so it shows over the center of the item
mousePos=GetSlotCoord(itemSlot);
itemSize=GetItemSizeOnSlot(itemSlot);
}
}
// At this point itemSize is either the size of the cell/item the hand cursor is over, or the size of the item we're currently holding.
// mousePos is the center of the top left cell of the item under the hand cursor, or the top left cell of the region that could fit the item we're holding.
// either way we need to offset the mouse position to account for items (we're holding or hovering over) with a dimension larger than a single cell.
// If we've picked up an item then use the same logic as the inventory so that the cursor is offset to the center of where the old item location was
// (in this case jumpSlot was the top left cell of where it used to be in the grid, and we need to update the cursor size since we're now holding the item)
// When trying to paste into the inventory we need to determine the top left cell of the nearest area that could fit the item, not the slot under the center/hot pixel.
if(itemSize.height<=1&&itemSize.width<=1){
// top left cell of a 1x1 item is the same cell as the hot pixel, no work to do
returnr;
}
// Otherwise work out how far the central cell is from the top-left cell
// For even dimension items we need to work out if the cursor is in the left/right (or top/bottom) half of the central cell and adjust the offset so the item lands in the area most covered by the cursor.
// hot pixel was in the top half of the cell, so we want to increase the offset to preference the row above
hotPixelCellOffset.deltaY++;
}
// Then work out the top left cell of the nearest area that could fit this item (as pasting on the edge of the inventory would otherwise put it out of bounds)
// FindTargetSlotUnderItemCursor returns the top left slot of the inventory region that fits the item, we can be confident this calculation is not going to read out of range.
assert(testCell<sizeof(player.InvGrid));
if(player.InvGrid[testCell]!=0){
int8_tiv=std::abs(player.InvGrid[testCell]);
if(it!=0){
if(it!=iv)
if(it!=iv){
// Found two different items that would be displaced by the held item, can't paste the item here.
return;
}
}else{
it=iv;
}
}
xx++;
}
yy+=INV_ROW_SLOT_SIZE;
}
}
}elseif(il==ILOC_BELT){
@ -526,13 +532,8 @@ void CheckInvPaste(Player &player, Point cursorPosition)
itemIndex=0;
}
}
intii=slot-SLOTXY_INV_FIRST;
// Calculate top-left position of item for InvGrid and then add item to InvGrid
@ -77,11 +78,30 @@ Point FindSlotUnderCursor(Point cursorPosition)
};
if(cell.contains(cursorPosition)){
// When trying to paste into the stash we need to determine the top left cell of the nearest area that could fit the item, not the slot under the center/hot pixel.
if(itemSize.height<=1&&itemSize.width<=1){
// top left cell of a 1x1 item is the same cell as the hot pixel, no work to do
returnpoint;
}
// Otherwise work out how far the central cell is from the top-left cell
// For even dimension items we need to work out if the cursor is in the left/right (or top/bottom) half of the central cell and adjust the offset so the item lands in the area most covered by the cursor.
// hot pixel was in the top half of the cell, so we want to increase the offset to preference the row above
hotPixelCellOffset.deltaY++;
}
// Then work out the top left cell of the nearest area that could fit this item (as pasting on the edge of the stash would otherwise put it out of bounds)