Boreas
2009-07-21 22:33:48
These work with only the clickable areas of inventory slots. No more miss clicks with InvBox. And if you somehow get bad coords from another method, CoordsToItem will predict whether it will be a miss click. Also, since InvBox is accurate, if you want to do something like BlackLists, you can use the x1,y1 as a reference point (sort of like the parent point of a DTM).
{*******************************************************************************
Function InvBox(i :Integer): TBox;
By: Boreas. Coords by Ogre July 15th 2009.
Description: Returns TBox of surrounding Inventory SlotBox
1-2-3-4
5-6-7-8
etc.
*******************************************************************************}
function InvBox(i :Integer): TBox;
var Slot1, Slot6: TBox;
begin
if not InRange(I, 1, 28) then
begin
srl_Warn('InvBox', 'Incorrect index: ' + IntToStr(i), warn_AllVersions);
exit;
end;
Slot1 := IntToBox(563,213,594,244); //update these
Slot6 := IntToBox(605,249,31415,92653); //except pi :p
Result.x1 :=Slot1.X1+((((i+(4-1))mod 4))*(Slot6.X1-Slot1.X1)); //4 for number
Result.y1 :=Slot1.Y1+((((i-1)/4))*(Slot6.Y1-Slot1.Y1)); //of columns
Result.x2 := Result.x1+(Slot1.X2-Slot1.X1);
Result.y2 := Result.y1+(Slot1.Y2-Slot1.Y1);
end;
procedure MMouseItem(i: Integer);
var
TB: TBox;
begin
GameTab(tab_inv);
TB:=InvBox(I);
MouseBox(TB.X1, TB.Y1, TB.X2, TB.Y2,3);
end;
{*******************************************************************************
function CoordsToItem (ThePoint: TPoint): integer;
By: Boreas
Description: Returns which Inventory slot a ThePoint is in. If point is between
slots (or not in the inventory area at all) it will return 0.
*******************************************************************************}
function CoordsToItem (ThePoint: TPoint): integer;
var tmpBox: TBox;
begin
if not PointInBox(ThePoint, IntToBox(MIX1, MIY1, MIX2, MIY2)) then
exit;
for Result:=1 to 4 do
begin
tmpBox := InvBox(result);
if InRange(ThePoint.x, tmpBox.x1, tmpBox.x2) then
break;
end;
while not InRange(ThePoint.y, tmpBox.y1, tmpBox.y2) do
begin
IncEx(result,4);
if result>28 then
break;
tmpBox := InvBox(result);
end;
if not PointInBox(ThePoint, tmpBox) then
Result := 0;
end;