|
2 | 2 | {$INCLUDE_ONCE WaspLib/osrs.simba} |
3 | 3 |
|
4 | 4 | type |
| 5 | +(* |
| 6 | +## Friends Button Enum |
| 7 | +```pascal |
| 8 | +ERSFriendsButton = enum (ADD, DEL, FRIENDS, IGNORE); |
| 9 | +``` |
| 10 | + |
| 11 | +Represents the buttons in the friends tab. |
| 12 | +*) |
| 13 | + ERSFriendsButton = enum (ADD, DEL, FRIENDS, IGNORE); |
| 14 | + |
| 15 | +(* |
| 16 | +## Friend Record |
| 17 | +```pascal |
| 18 | +type |
| 19 | + TRSFriend = record |
| 20 | + Name: String; |
| 21 | + World: Integer; |
| 22 | + Bounds: TBox; |
| 23 | + end; |
| 24 | +``` |
| 25 | + |
| 26 | +Represents a friend/ignore in the friends tab. |
| 27 | +*) |
| 28 | + TRSFriend = record |
| 29 | + Name: String; |
| 30 | + World: Integer; |
| 31 | + Bounds: TBox; |
| 32 | + end; |
| 33 | + |
| 34 | + TRSFriendArray = array of TRSFriend; |
| 35 | + |
5 | 36 | TRSFriends = record |
6 | 37 | Scroll: TRSScrollBar; |
7 | | - Toggle, Add, Del: TBox; |
| 38 | + Buttons: array [ERSFriendsButton] of TRSButton; |
8 | 39 | end; |
9 | 40 |
|
10 | 41 | procedure TRSFriends.SetupGameTab(); |
11 | 42 | begin |
12 | | - //TODO... |
| 43 | + with GameTab.Bounds do |
| 44 | + begin |
| 45 | + Self.Scroll.Area.X1 := X1 + 5; |
| 46 | + Self.Scroll.Area.Y1 := Y1 + 38; |
| 47 | + Self.Scroll.Area.X2 := X2 - 21; |
| 48 | + Self.Scroll.Area.Y2 := Y2 - 42; |
| 49 | + |
| 50 | + Self.Buttons[ERSFriendsButton.ADD].Bounds.X1 := X1 + 19; |
| 51 | + Self.Buttons[ERSFriendsButton.ADD].Bounds.Y1 := Y1 + 230; |
| 52 | + Self.Buttons[ERSFriendsButton.ADD].Bounds.X2 := X1 + 82; |
| 53 | + Self.Buttons[ERSFriendsButton.ADD].Bounds.Y2 := Y1 + 257; |
| 54 | + |
| 55 | + Self.Buttons[ERSFriendsButton.DEL].Bounds.X1 := X1 + 101; |
| 56 | + Self.Buttons[ERSFriendsButton.DEL].Bounds.Y1 := Y1 + 230; |
| 57 | + Self.Buttons[ERSFriendsButton.DEL].Bounds.X2 := X1 + 164; |
| 58 | + Self.Buttons[ERSFriendsButton.DEL].Bounds.Y2 := Y1 + 257; |
| 59 | + |
| 60 | + Self.Buttons[ERSFriendsButton.FRIENDS].Bounds.X1 := X1 + 170; |
| 61 | + Self.Buttons[ERSFriendsButton.FRIENDS].Bounds.Y1 := Y1 + 5; |
| 62 | + Self.Buttons[ERSFriendsButton.FRIENDS].Bounds.X2 := X1 + 181; |
| 63 | + Self.Buttons[ERSFriendsButton.FRIENDS].Bounds.Y2 := Y1 + 16; |
| 64 | + Self.Buttons[ERSFriendsButton.FRIENDS].EnabledColors := [[$233EFB, 0], [$2C41B3, 0]]; |
| 65 | + |
| 66 | + Self.Buttons[ERSFriendsButton.IGNORE].Bounds.X1 := X1 + 170; |
| 67 | + Self.Buttons[ERSFriendsButton.IGNORE].Bounds.Y1 := Y1 + 5; |
| 68 | + Self.Buttons[ERSFriendsButton.IGNORE].Bounds.X2 := X1 + 181; |
| 69 | + Self.Buttons[ERSFriendsButton.IGNORE].Bounds.Y2 := Y1 + 16; |
| 70 | + Self.Buttons[ERSFriendsButton.IGNORE].EnabledColors := [[$3AC8FF, 0], [$3791B6, 0]]; |
| 71 | + end; |
| 72 | + |
| 73 | + Self.Scroll.Setup(); |
| 74 | +end; |
| 75 | + |
| 76 | +(* |
| 77 | +## Friends.IsOpen |
| 78 | +```pascal |
| 79 | +function TRSFriends.IsOpen(): Boolean; |
| 80 | +``` |
| 81 | +Returns true if the friends tab is open. |
| 82 | + |
| 83 | +Example: |
| 84 | +```pascal |
| 85 | +WriteLn Friends.IsOpen(); |
| 86 | +``` |
| 87 | +*) |
| 88 | +function TRSFriends.IsOpen(): Boolean; |
| 89 | +begin |
| 90 | + Result := GameTabs.IsOpen(ERSGameTab.FRIENDS); |
| 91 | +end; |
| 92 | + |
| 93 | +(* |
| 94 | +## Friends.Open |
| 95 | +```pascal |
| 96 | +function TRSFriends.Open(): Boolean; |
| 97 | +``` |
| 98 | + |
| 99 | +Attempts to open the friends gametab. |
| 100 | + |
| 101 | +Example: |
| 102 | +```pascal |
| 103 | +WriteLn Friends.Open(); |
| 104 | +``` |
| 105 | +*) |
| 106 | +function TRSFriends.Open(): Boolean; |
| 107 | +begin |
| 108 | + Result := GameTabs.Open(ERSGameTab.FRIENDS); |
| 109 | +end; |
| 110 | + |
| 111 | +(* |
| 112 | +## Friends.GetFriends |
| 113 | +```pascal |
| 114 | +function TRSFriends.GetFriends(): TRSFriendArray; |
| 115 | +``` |
| 116 | +Returns an array of all friends/ignores currently visible in the friends tab. |
| 117 | + |
| 118 | +Example: |
| 119 | +```pascal |
| 120 | +var |
| 121 | + friend: TRSFriend; |
| 122 | + friends: TRSFriendArray; |
| 123 | +begin |
| 124 | + friends := Friends.GetFriends(); |
| 125 | + for friend in friends do |
| 126 | + WriteLn('Friend: ' + friend.Name + ' World: ' + IntToStr(friend.World)); |
| 127 | +end; |
| 128 | +*) |
| 129 | +function TRSFriends.GetFriends(): TRSFriendArray; |
| 130 | +var |
| 131 | + tpa : TPointArray; |
| 132 | + atpa : T2DPointArray; |
| 133 | + friend: TRSFriend; |
| 134 | +begin |
| 135 | + if not Self.Open() then Exit; |
| 136 | + |
| 137 | + tpa := Target.FindColor($FFFFFF, 0, Self.Scroll.Area); |
| 138 | + atpa := tpa.Cluster(20, 1.5); |
| 139 | + for tpa in atpa do |
| 140 | + with tpa.Bounds() do |
| 141 | + begin |
| 142 | + friend.Name := OCR.Recognize([X1, Y1, X2, Y2], RSFonts.PLAIN_12, [$FFFFFF], 0); |
| 143 | + friend.World := OCR.RecognizeNumber([X2, Y1, Self.Scroll.Area.X2, Y2], RSFonts.PLAIN_12, [$0DC10D, $00FFFF], 0); |
| 144 | + friend.Bounds := tpa.Bounds(); |
| 145 | + |
| 146 | + if friend.Name <> '' then |
| 147 | + Result += friend; |
| 148 | + end; |
| 149 | +end; |
| 150 | + |
| 151 | +(* |
| 152 | +## Friends.Find |
| 153 | +```pascal |
| 154 | +function TRSFriends.Find(name: String): TRSFriend; |
| 155 | +``` |
| 156 | + |
| 157 | +Searches for a friend/ignore by name in the friends tab. |
| 158 | + |
| 159 | +Example: |
| 160 | +```pascal |
| 161 | +var |
| 162 | + friend: TRSFriend; |
| 163 | +begin |
| 164 | + friend := Friends.Find('SomePlayer'); |
| 165 | + if friend <> Default(TRSFriend) then |
| 166 | + WriteLn('Found friend: ' + friend.Name + ' World: ' + IntToStr(friend.World)) |
| 167 | + else |
| 168 | + WriteLn('Friend not found.'); |
| 169 | +end; |
| 170 | +*) |
| 171 | +function TRSFriends.Find(name: String): TRSFriend; |
| 172 | +var |
| 173 | + timeout: TCountDown; |
| 174 | + friend: TRSFriend; |
| 175 | + friends: TRSFriendArray; |
| 176 | +begin |
| 177 | + Result := Default(TRSFriend); |
| 178 | + if not Self.Open() then Exit; |
| 179 | + |
| 180 | + timeout.Start(10 * ONE_SECOND); |
| 181 | + |
| 182 | + Self.Scroll.SetLevel(0); |
| 183 | + |
| 184 | + repeat |
| 185 | + friends := Self.GetFriends(); |
| 186 | + if friends = [] then |
| 187 | + Exit; |
| 188 | + |
| 189 | + for friend in friends do |
| 190 | + begin |
| 191 | + if friend.Name.Equals(name, False) then |
| 192 | + Exit(friend); |
| 193 | + end; |
| 194 | + |
| 195 | + Self.Scroll.Scroll(1, True); |
| 196 | + until timeout.IsFinished; |
| 197 | +end; |
| 198 | + |
| 199 | +(* |
| 200 | +## Friends.AddFriend |
| 201 | +```pascal |
| 202 | +function TRSFriends.AddFriend(name: String): Boolean; |
| 203 | +``` |
| 204 | + |
| 205 | +Attempts to add a friend to the friends list. |
| 206 | + |
| 207 | +Example: |
| 208 | +```pascal |
| 209 | +WriteLn Friends.AddFriend('SomePlayer'); |
| 210 | +``` |
| 211 | +*) |
| 212 | +function TRSFriends.AddFriend(name: String): Boolean; |
| 213 | +begin |
| 214 | + if not Self.Open() then Exit; |
| 215 | + if not Self.Buttons[ERSFriendsButton.FRIENDS].Enable() then Exit; |
| 216 | + |
| 217 | + Self.Buttons[ERSFriendsButton.ADD].Click(EMouseButton.LEFT); |
| 218 | + Result := Chat.AnswerQuery('Enter name of friend to add to list', name, 2000, 250); |
| 219 | +end; |
| 220 | + |
| 221 | +(* |
| 222 | +## Friends.DeleteFriend |
| 223 | +```pascal |
| 224 | +function TRSFriends.DeleteFriend(name: String): Boolean; |
| 225 | +``` |
| 226 | + |
| 227 | +Attempts to delete a friend from the friends list. |
| 228 | + |
| 229 | +Example: |
| 230 | +```pascal |
| 231 | +WriteLn Friends.DeleteFriend('SomePlayer'); |
| 232 | +``` |
| 233 | +*) |
| 234 | +function TRSFriends.DeleteFriend(name: String): Boolean; |
| 235 | +var |
| 236 | + friend: TRSFriend; |
| 237 | +begin |
| 238 | + if not Self.Open() then Exit; |
| 239 | + if not Self.Buttons[ERSFriendsButton.FRIENDS].Enable() then Exit; |
| 240 | + |
| 241 | + if Biometrics.RandomBoolean() then |
| 242 | + begin |
| 243 | + friend := Self.Find(name); |
| 244 | + if friend = Default(TRSFriend) then Exit; |
| 245 | + |
| 246 | + Mouse.Click(friend.Bounds, EMouseButton.Right); |
| 247 | + if not ChooseOption.WaitOpen(2000, 250) then Exit; |
| 248 | + |
| 249 | + Result := ChooseOption.Select('Delete ' + friend.Name); |
| 250 | + end |
| 251 | + else |
| 252 | + begin |
| 253 | + Self.Buttons[ERSFriendsButton.DEL].Click(EMouseButton.LEFT); |
| 254 | + Result := Chat.AnswerQuery('Enter name of friend to delete from list', name, 2000, 250); |
| 255 | + end; |
| 256 | +end; |
| 257 | + |
| 258 | +(* |
| 259 | +## Friends.SendMessage |
| 260 | +```pascal |
| 261 | +function TRSFriends.SendMessage(name, message: String): Boolean; |
| 262 | +``` |
| 263 | + |
| 264 | +Attempts to send a message to a friend. |
| 265 | + |
| 266 | +Example: |
| 267 | +```pascal |
| 268 | +WriteLn Friends.SendMessage('SomePlayer', 'Hello there!'); |
| 269 | +``` |
| 270 | +*) |
| 271 | +function TRSFriends.SendMessage(name, message: String): Boolean; |
| 272 | +var |
| 273 | + friend: TRSFriend; |
| 274 | +begin |
| 275 | + if not Self.Open() then Exit; |
| 276 | + |
| 277 | + friend := Self.Find(name); |
| 278 | + if friend = Default(TRSFriend) then Exit; |
| 279 | + if friend.World = -1 then Exit; |
| 280 | + |
| 281 | + Mouse.Click(friend.Bounds, EMouseButton.LEFT); |
| 282 | + Result := Chat.AnswerQuery('Enter message to send to ' + name, message, 2000, 250); |
| 283 | +end; |
| 284 | + |
| 285 | +(* |
| 286 | +## Friends.AddIgnore |
| 287 | +```pascal |
| 288 | +function TRSFriends.AddIgnore(name: String): Boolean; |
| 289 | +``` |
| 290 | + |
| 291 | +Attempts to add a player to the ignore list. |
| 292 | + |
| 293 | +Example: |
| 294 | +```pascal |
| 295 | +WriteLn Friends.AddIgnore('SomePlayer'); |
| 296 | +``` |
| 297 | +*) |
| 298 | +function TRSFriends.AddIgnore(name: String): Boolean; |
| 299 | +begin |
| 300 | + if not Self.Open() then Exit; |
| 301 | + if not Self.Buttons[ERSFriendsButton.IGNORE].Enable() then Exit; |
| 302 | + |
| 303 | + Self.Buttons[ERSFriendsButton.ADD].Click(EMouseButton.LEFT); |
| 304 | + Result := Chat.AnswerQuery('Enter name of player to add to list', name, 2000, 250); |
| 305 | +end; |
| 306 | + |
| 307 | +(* |
| 308 | +## Friends.DeleteIgnore |
| 309 | +```pascal |
| 310 | +function TRSFriends.DeleteIgnore(name: String): Boolean; |
| 311 | +``` |
| 312 | + |
| 313 | +Attempts to delete a player from the ignore list. |
| 314 | + |
| 315 | +Example: |
| 316 | +```pascal |
| 317 | +WriteLn Friends.DeleteIgnore('SomePlayer'); |
| 318 | +``` |
| 319 | +*) |
| 320 | +function TRSFriends.DeleteIgnore(name: String): Boolean; |
| 321 | +var |
| 322 | + friend: TRSFriend; |
| 323 | +begin |
| 324 | + if not Self.Open() then Exit; |
| 325 | + if not Self.Buttons[ERSFriendsButton.IGNORE].Enable() then Exit; |
| 326 | + |
| 327 | + if Biometrics.RandomBoolean() then |
| 328 | + begin |
| 329 | + friend := Self.Find(name); |
| 330 | + if friend = Default(TRSFriend) then Exit; |
| 331 | + |
| 332 | + Mouse.Click(friend.Bounds, EMouseButton.Right); |
| 333 | + if not ChooseOption.WaitOpen(2000, 250) then Exit; |
| 334 | + |
| 335 | + Result := ChooseOption.Select('Delete ' + friend.Name); |
| 336 | + end |
| 337 | + else |
| 338 | + begin |
| 339 | + Self.Buttons[ERSFriendsButton.DEL].Click(EMouseButton.LEFT); |
| 340 | + Result := Chat.AnswerQuery('Enter name of player to delete from list', name, 2000, 250); |
| 341 | + end; |
13 | 342 | end; |
14 | 343 |
|
15 | 344 | var |
16 | 345 | Friends: TRSFriends; |
| 346 | + |
| 347 | + |
0 commit comments