any_one
2011-05-02 21:55:07
I was rather surprised to find that there was no function that took an array of strings and chose an option that contains ALL of those on the same line. I suggest adding such a function:
This would be useful for eg. picking up items, which have both Examine and Take options. You could use ChooseOptionSameLine(['ake', itemname]). The function I wrote is just a quick hack based on ChooseOptionMultiEx, but unfortunately there were no option functions that actually returned the position of the option, so it was the only way to do it. If I've missed/duplicated something that is already in the include then please advise me + close thread :)
{*******************************************************************************
function ChooseOptionSameLine(Text : TStringArray) : Boolean;
By: any_one, makers of ChooseOptionMultiEx
Description: Finds and clicks option that contains all strings in Text on the same line.
*******************************************************************************}
function ChooseOptionSameLine(Text : TStringArray) : Boolean;
var
B : TBox;
TPA1, TPA2, TPA : TPointArray;
ATPA, TextTPA : T2DPointArray;
Colors, height : TIntegerArray;
i, j, c : Integer;
begin
Result := False;
GetClientDimensions(B.X2, B.Y2);
B.X1 := 0;
B.Y1 := 0;
Dec(B.X2);
Dec(B.Y2);
FindColorsTolerance(TPA1, 4343893, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(TPA2, 3950929, B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := CombineTPA(TPA1, TPA2);
If Length(TPA) < 10 Then
Exit;
B.X2 := 0;
B.Y2 := 0;
aTPA := SplitTPAEx(TPA, 20, 20);
SortATPASize(aTPA, True);
B := GetTPABounds(aTPA[0]);
Colors := [13034990, 4231423, 2070783, 65535, 16776960, 9812166, 16777215];
SetArrayLength(aTPA, Length(colors));
for i := 0 to high(colors) do
FindColorsTolerance(aTPA[i], Colors[i], B.X1, B.Y1, B.X2, B.Y2, 3);
TPA := MergeATPA(aTPA);
aTPA := SplitTPAEx(TPA, 15, 1);
SortATPAFromFirstPoint(ATPA, Point(B.X1, B.y1));
SetArrayLength(TextTPA, Length(Text));
SetArrayLength(height, Length(Text));
for i := 0 to High(Text) do
TextTPA[i] := LoadTextTPA(Text[i], UpChars, height[i]);
for i := 0 to High(aTPA) do
begin
c := 0;
for j := 0 to High(Text) do
begin
if FindTextTPAInTPA(height[j], TextTPA[j], aTPA[i], TPA) then
begin
Inc(c);
if (c > High(Text)) then
begin
Result := True;
MouseBoxEx(B.x1 + 5, TPA[0].Y, B.x2 - 5, TPA[0].Y + 5,5, 1);
Exit;
end;
end;
end;
end;
MMouse(B.X1 - 50, B.Y1 - 50, 40, B.Y2 - B.Y1);
Wait(200 + Random(100));
//Mostly copied from chooseoptionMultiEx - this function could be much shorter if
//chooseoptionmultiEx returned x, y coordinates of options
end;This would be useful for eg. picking up items, which have both Examine and Take options. You could use ChooseOptionSameLine(['ake', itemname]). The function I wrote is just a quick hack based on ChooseOptionMultiEx, but unfortunately there were no option functions that actually returned the position of the option, so it was the only way to do it. If I've missed/duplicated something that is already in the include then please advise me + close thread :)