# MainScreen Methods to interact with the game mainscreen. - - - ## TObjectFinder TObjectFinder is the record used in **MainScreen.FindObject**. * **TObjectFinder.Zoom** When designing a object finder you **must** be at **default zoom(50)** in the **fixed** client mode. This allows SRL to convert the finder to work at any zoom and client mode once made. ```{figure} ../../images/zoom.png A finder working at different zoom levels producing similar results. ``` * **TObjectFinder.Colors** An color array which will searched for. Use ACA to acquire color(s). ```pascal Finder.Colors += CTS2(2503237, 20, 0.10, 0.14); // brown Finder.Colors += CTS2(5526875, 15, 0.19, 0.06); // grey ``` ```{figure} ../../images/color_array.png The two colors above found and merged together. ``` * **TObjectFinder.ColorClusters** An array of "color clusters" which will be merged together. Use ACA to acquire color(s). A "color cluster" consists of a `primary` and `secondary` color and a `distance` value. When searched for only `primary` colors within `distance` of `secondary` colors are returned. ```pascal Finder.ColorClusters += [ CTS2(2503237, 20, 0.10, 0.14), // brown CTS2(5526875, 15, 0.19, 0.06), // grey 2 // distance ]; ``` ```{figure} ../../images/color_cluster.png The above color cluster found where "brown" is within 2 pixels of "grey". ``` * **TObjectFinder.Erode** The amount to erode before clustering. This is useful for removing small amounts of noise. ```pascal Finder.Erode := 2; ``` ```{figure} ../../images/erode.png Erode before and after. ``` * **TObjectFinder.Grow** The amount to grow **before** eroding. This is useful for filling gaps. ```pascal Finder.Grow := 2; ``` ```{figure} ../../images/grow.png Grow before and after. ``` Grow can also be paired with erode which is quite powerful. ```pascal Finder.Grow := 3; Finder.Erode := 4; ``` ```{figure} ../../images/grow_erode.png Grow paired with Erode. ``` * **TObjectFinder.ClusterDistance** The distance to pass to *ClusterTPA*, this is how multiple objects are grouped up. `Distance=5` would mean that points that are closer than or equal to 5 pixels away are considered close enough to merge into a singular group. ```pascal Finder.ClusterDistance := 5; ``` ```{figure} ../../images/cluster_5.png Cluster distance **5** produces four individual chairs ``` ```pascal Finder.ClusterDistance := 20; ``` ```{figure} ../../images/cluster_20.png Cluster distance **20** produces two sets of chairs ``` * **TObjectFinder.MinLongSide, TObjectFinder.MaxLongSide, TObjectFinder.MinShortSide, TObjectFinder.MaxShortSide** Any match that exceeds these values will be removed. The bounding rectangle is used which has a **long** and a **short** side measured in pixels. ```pascal // Removes matches where the short side isn't within 10 and 20 pixels Finder.MinShortSide := 10; Finder.MaxShortSide := 20; // Removes matches where the long side isn't within 20 and 40 pixels Finder.MinLongSide := 20; Finder.MaxLongSide := 40; ``` ```{figure} ../../images/bounding_rect.png Example bounding rectangle with a long and short side. ``` - - - ## MainScreen.Setup ```pascal procedure TMainScreen.Setup(ClientMode: EClientMode); ``` Setups the mainscreen. ```{note} This is automatically called on the **MainScreen** variable. ``` - - - ## MainScreen.GetUpText ```pascal function TMainScreen.GetUpText(): String; ``` Returns the current uptext. Uptext is the top left which appears when moving the mouse over a object. Example: ```pascal WriteLn(MainScreen.GetUpText()); ``` - - - ## MainScreen.IsUpText() ```pascal function TMainScreen.IsUpText(Text: TStringArray; Timeout: Int32 = -1): Boolean; function TMainScreen.IsUpText(Text: String; Timeout: Int32 = -1): Boolean; overload; ``` Returns true if the uptext is found **anywhere**. If a `TStringArray`is passed as `Text`, any match will result true. Example: ```pascal WriteLn(MainScreen.MainScreen.IsUpText(['Chicken', 'Wolf'])); ``` - - - ## MainScreen.SetHighestPitch ```pascal procedure TMainScreen.SetHighestPitch(); ``` Moves the camera to the highest pitch. There is no way to detect the camera pitch reliably using color, this is why SRL only provides this method. Example: ```pascal MainScreen.SetHighestPitch(); ``` - - - ## MainScreen.NormalizeDistance ```pascal function TMainScreen.NormalizeDistance(Dist: Int32; Accuracy: Single = 1.05): Int32; ``` Converts a distance acquired from the **fixed client* and **default zoom** to the current mainscreen. Example: ```pascal // 20 pixels on the fixed client and default zoom(50) is currently x pixels at the current zoom & client size. WriteLn(MainScreen.TranslateDistance(20)); ``` - - - ## MainScreen.GetPlayerBox() ```pascal function TMainScreen.GetPlayerBox(): TBox; ``` Returns a box surrounding our player. Works at any zoom level. Implemented in MM2MS: {ref}`MainScreen.GetPlayerBox() override` - - - ## MainScreen.FacePoint ```pascal function TMainScreen.FacePoint(P: TPoint; Randomness: Int32 = 0): Boolean; ``` Rotates the camera to face point `P`. Implemented in MM2MS: {ref}`MainScreen.FacePoint() override` - - - ## Mainscreen.PointToMM ```pascal function TMainScreen.PointToMM(MS: TPoint; Height: Int32 = 0; Accuracy:Double = 0.2): Vector3; ``` Takes a mainscreen point and converts it to a point on the minimap. Implemented in MM2MS: {ref}`MainScreen.PointToMM() override` - - - ## Mainscreen.FindObject() ```pascal function TMainScreen.FindObject(Finder: TObjectFinder; area: TBox): T2DPointArray; function TMainScreen.FindObject(Finder: TObjectFinder): T2DPointArray; overload; ``` Returns all matches of an TObjectFinder in the desired `area`. If no `area` is specified, the whole mainscreen is used. See the top of this page page for documentation about the TObjectFinder record. Example: ```pascal var MyFinder: TObjectFinder; begin // Some chairs in varrock west bank MyFinder.Colors += CTS2(1328725, 6, 0.06, 0.69); MyFinder.ClusterDistance := 5; MyFinder.Erode := 2; MyFinder.MinLongSide := 10; MyFinder.MaxLongSide := 15; Debug(MainScreen.FindObject(MyFinder, MainScreen.Bounds())); end; ``` - - - ## Mainscreen.IsVisible ```pascal function TMainScreen.IsVisible(p: TPoint): Boolean; function TMainScreen.IsVisible(tpa: TPointArray; useCenter: Boolean = True): Boolean; override; function TMainScreen.IsVisible(b: TBox; useCenter: Boolean = True): Boolean; overload; function TMainScreen.IsVisible(rect: TRectangle; useCenter: Boolean = True): Boolean; overload; function TMainScreen.IsVisible(cuboid: TCuboidEx; useCenter: Boolean = True): Boolean; overload; ``` Returns true if the TPoint, TPointArray, TBox, TRectangle or TCuboid is visible (not hidden by any other interfaces) on the mainscreen. This is only useful in resizable mode. The interfaces checked are Chatbox, Minimap and Gametabs. Example: ```pascal if MainScreen.IsVisible([100, 100]) then WriteLn('The point is not behind Chatbox, Minimap or Gametabs.'); ``` - - - ## MainScreen.Filter ```pascal function TMainScreen.Filter(arr: TPointArray): TPointArray; function TMainScreen.Filter(arr: TBoxArray): TBoxArray; overload; function TMainScreen.Filter(arr: TRectArray): TRectArray; overload; function TMainScreen.Filter(arr: TPolyArray): TPolyArray; overload; ``` Filters the given TPointArray, TBoxArray, TRectArray or TCuboidArray and returns only those that are visible in the MainScreen. - - - (THitsplat)= ## type THitsplat ```pascal THitsplat = record Position: TPoint; // Middle of the found hitsplat Hit: Int32; // Hit amount Red: Boolean; // True if red, false if blue. end; THitsplatArray = array of THitsplat; ``` - - - ## Mainscreen.FindHitsplats ```pascal function TMainScreen.FindHitsplats(area: TBox): THitsplatArray; function TMainScreen.FindHitsplats(): THitsplatArray; overload; ``` Finds hitsplats in the desired `area` if specified or the entire mainscreen. Returns an array of THitsplat. Example: ```pascal var splat: THitsplat; begin for splat in MainScreen.FindHitsplats() do begin Debug(splat); WriteLn(splat.Hit); Wait(2000); end; end; ``` - - - (THPBar)= ## type THPBar ```pascal THPBar = record Bounds: TBox; // Bounds of the bar Percent: Double; // Green percent of the bar. end; ``` - - - ## Mainscreen.FindHPBars() ```pascal function TMainScreen.FindHPBars(area: TBox): THPBarArray; function TMainScreen.FindHPBars(): THPBarArray; overload; ``` Finds hitpoints bars in the desired area. Returns an array of THPBar. If no `area` is specified the whole mainscreen is used. Example: ```pascal var Bars: THPBarArray; var I: Int32; begin Bars := MainScreen.FindHPBars(MainScreen.Bounds()); for I := 0 to High(Bars) do WriteLn(Bars[I].Percent, ' @ ', Bars[I].Bounds); end; ``` - - - ## Mainscreen.FindClick ```pascal function TMainScreen.FindClick(Area: TBox): EClickType; ``` Finds a click type in the desired area. Will return either: - CLICK_NONE - CLICK_RED - CLICK_YELLOW Example: ```pascal if MainScreen.FindClick([50,50,100,100]) = CLICK_RED then WriteLn('Found a red click in 50,50,100,100'); ``` - - - ## Mainscreen.DidRedClick ```pascal function TMainScreen.DidRedClick(time: UInt32 = 250): Boolean; ``` Returns true if a red click happened at the current mouse position. Example: ```pascal Mouse.Move(100, 100); Mouse.Click(MOUSE_LEFT); if MainScreen.DidRedClick() then WriteLn('Red click!'); ``` - - - ## Mainscreen.DidYellowClick ```pascal ``` Returns true if a yellow click happened at the current mouse position. Example: ```pascal Mouse.Move(100, 100); Mouse.Click(MOUSE_LEFT); if MainScreen.DidYellowClick() then WriteLn('Yellow click!'); ```