# MainScreen Methods to interact with the game mainscreen. - - - ## TRSObjectFinder TRSObjectFinder is the record used in **MainScreen.FindObject**. * **TRSObjectFinder.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. ``` * **TRSObjectFinder.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. ``` * **TRSObjectFinder.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". ``` * **TRSObjectFinder.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. ``` * **TRSObjectFinder.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. ``` * **TRSObjectFinder.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 ``` * **TRSObjectFinder.MinLongSide, TRSObjectFinder.MaxLongSide, TRSObjectFinder.MinShortSide, TRSObjectFinder.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 TRSMainScreen.Setup(ClientMode: ERSClientMode); ``` Setups the mainscreen. ```{note} This is automatically called on the **MainScreen** variable. ``` - - - ## MainScreen.GetUpText ```pascal function TRSMainScreen.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 TRSMainScreen.IsUpText(Text: TStringArray; Timeout: Int32 = -1): Boolean; function TRSMainScreen.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 TRSMainScreen.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 TRSMainScreen.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 TRSMainScreen.GetPlayerBox(): TBox; ``` Returns a box surrounding our player. Works at any zoom level. Implemented in MM2MS: {ref}`MainScreen.GetPlayerBox() override` - - - ## MainScreen.FacePoint ```pascal function TRSMainScreen.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 TRSMainScreen.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 TRSMainScreen.FindObject(Finder: TRSObjectFinder; area: TBox): T2DPointArray; function TRSMainScreen.FindObject(Finder: TRSObjectFinder): T2DPointArray; overload; ``` Returns all matches of an TRSObjectFinder 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 TRSObjectFinder record. Example: ```pascal var MyFinder: TRSObjectFinder; 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 TRSMainScreen.IsVisible(p: TPoint): Boolean; function TRSMainScreen.IsVisible(tpa: TPointArray; useCenter: Boolean = True): Boolean; override; function TRSMainScreen.IsVisible(b: TBox; useCenter: Boolean = True): Boolean; overload; function TRSMainScreen.IsVisible(rect: TRectangle; useCenter: Boolean = True): Boolean; overload; function TRSMainScreen.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 TRSMainScreen.Filter(arr: TPointArray): TPointArray; function TRSMainScreen.Filter(arr: TBoxArray): TBoxArray; overload; function TRSMainScreen.Filter(arr: TRectArray): TRectArray; overload; function TRSMainScreen.Filter(arr: TPolyArray): TPolyArray; overload; ``` Filters the given TPointArray, TBoxArray, TRectArray or TCuboidArray and returns only those that are visible in the MainScreen. - - - (TRSHitsplat)= ## type TRSHitsplat ```pascal TRSHitsplat = record Position: TPoint; // Middle of the found hitsplat Hit: Int32; // Hit amount Red: Boolean; // True if red, false if blue. end; TRSHitsplatArray = array of TRSHitsplat; ``` - - - ## Mainscreen.FindHitsplats ```pascal function TRSMainScreen.FindHitsplats(area: TBox): TRSHitsplatArray; function TRSMainScreen.FindHitsplats(): TRSHitsplatArray; overload; ``` Finds hitsplats in the desired `area` if specified or the entire mainscreen. Returns an array of TRSHitsplat. Example: ```pascal var splat: TRSHitsplat; begin for splat in MainScreen.FindHitsplats() do begin Debug(splat); WriteLn(splat.Hit); Wait(2000); end; end; ``` - - - (TRSHPBar)= ## type TRSHPBar ```pascal TRSHPBar = record Bounds: TBox; // Bounds of the bar Percent: Double; // Green percent of the bar. end; ``` - - - ## Mainscreen.FindHPBars() ```pascal function TRSMainScreen.FindHPBars(area: TBox): TRSHPBarArray; function TRSMainScreen.FindHPBars(): TRSHPBarArray; overload; ``` Finds hitpoints bars in the desired area. Returns an array of TRSHPBar. If no `area` is specified the whole mainscreen is used. Example: ```pascal var Bars: TRSHPBarArray; 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 TRSMainScreen.FindClick(Area: TBox): ERSClickType; ``` Finds a click type in the desired area. Will return either: - RS_CLICK_NONE - RS_CLICK_RED - RS_CLICK_YELLOW Example: ```pascal if MainScreen.FindClick([50,50,100,100]) = RS_CLICK_RED then WriteLn('Found a red click in 50,50,100,100'); ``` - - - ## Mainscreen.DidRedClick ```pascal function TRSMainScreen.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!'); ```