@@ -427,27 +427,38 @@ are visible which you can do easily through the next methods.
427427*)
428428
429429(*
430- ### Make.IndexOfQuantity
430+ ### Make.FindQuantityButton
431431```pascal
432- function TRSMake.IndexOfQuantity (amount: Integer): Integer ;
432+ function TRSMake.FindQuantityButton (amount: Integer): TRSMakeQuantityButton ;
433433```
434- Finds the index of a quantity button by the specified `amount`.
435- If the `amount` we are looking for, the custom quantity button is returned,
436- otherwise the result is `-1`.
434+ Finds and returns the TRSMakeQuantityButton matching the specified `amount`.
435+
436+ For standard quantities (1, 5, 10, All), returns the corresponding button directly.
437+ For custom amounts, prioritizes a button already set to that value, otherwise
438+ returns the "Other" (X) button which will prompt for manual entry.
439+
440+ Returns an empty record if no matching button is found or the Make interface is not open.
441+
442+ Note: Automatically closes any tooltip that may be covering the quantity buttons.
437443
438444Example:
439445```pascal
440- WriteLn Make.IndexOfQuantity(Make.QUANTITY_ALL);
446+ var
447+ btn: TRSMakeQuantityButton;
448+ begin
449+ btn := Make.FindQuantityButton(5);
450+ if btn <> [] then
451+ WriteLn('Found button: ', btn);
452+ end;
441453```
442454*)
443- function TRSMake.IndexOfQuantity (amount: Integer): Integer ;
455+ function TRSMake.FindQuantityButton (amount: Integer): TRSMakeQuantityButton ;
444456var
445457 hintPt: TPoint;
446- i: Integer;
458+ i, idx : Integer;
447459 quantity: ERSItemQuantity;
460+ quantitybtns: array of TRSMakeQuantityButton;
448461begin
449- if amount <= 0 then Exit(0);
450-
451462 if Self.HasHint() then
452463 begin
453464 hintPt := Self.GetHintBox().TopRight;
@@ -457,19 +468,25 @@ begin
457468 raise GetDebugLn('Make', 'Failed to close the tooltip which is covering the quanitty buttons');
458469 end;
459470
471+ quantitybtns := Self.FindQuantityButtons();
460472 quantity := ERSItemQuantity.Integer2Quantity(amount);
461473
462- if quantity = ERSItemQuantity.CUSTOM then
474+ for idx := 0 to High(quantitybtns) do
463475 begin
464- if amount = OCR.RecognizeNumber(Self.QuantityButtonBoxes[2], RSFonts.PLAIN_11, [Self.TEXT_COLOR, RSFonts.WHITE], 0) then
465- Exit(2);
466- Exit(1);
476+ if quantitybtns[idx].Quantity = quantity then
477+ begin
478+ if quantity = ERSItemQuantity.CUSTOM then
479+ begin
480+ if quantitybtns[idx].UpText = IntToStr(amount) then
481+ Exit(quantitybtns[idx]);
482+ if quantitybtns[idx].UpText = 'Other' then
483+ Exit(quantitybtns[idx]);
484+ end
485+ else
486+ Exit(quantitybtns[idx]);
487+ end;
467488 end;
468-
469- for i := 1 to High(Self.QuantityButtonBoxes) do
470- if amount = OCR.RecognizeNumber(Self.QuantityButtonBoxes[i], RSFonts.PLAIN_11, [Self.TEXT_COLOR, RSFonts.WHITE], 0) then
471- Exit(i);
472- Result := -1;
489+ Result := [];
473490end;
474491
475492(*
@@ -503,18 +520,19 @@ WriteLn Make.SetQuantity(Make.QUANTITY_ALL);
503520*)
504521function TRSMake.SetQuantity(amount: Integer): Boolean;
505522var
506- idx: Integer ;
523+ quantityButton: TRSMakeQuantityButton ;
507524 done: Boolean;
508525begin
509- idx := Self.IndexOfQuantity (amount);
510- if idx < 0 then
526+ quantityButton := Self.FindQuantityButton (amount);
527+ if quantityButton = [] then
511528 raise GetDebugLn('Make', 'Quantity button for "' + ToStr(amount) + '" is not available.');
512529
513- if Self.IsQuantitySelected(idx) then Exit(True);
530+ if quantityButton.Button.Enabled() then Exit(True);
531+
532+ quantityButton.Button.Click(EMouseButton.LEFT);
514533
515- Mouse.Click(Self.QuantityButtonBoxes[idx], EMouseButton.LEFT);
516534 Result := SleepUntil(
517- (done := Self.IsQuantitySelected(idx )) or
535+ (done := quantityButton.Button.Enabled( )) or
518536 Chat.FindQuery('Enter amount', True), RandomMode(100, 50, 1500), 600
519537 );
520538 if done then Exit;
0 commit comments