Skip to content

Commit 83db478

Browse files
committed
feat(TRSFriends): implement friends tab functionality
1 parent e6e8336 commit 83db478

File tree

1 file changed

+329
-2
lines changed

1 file changed

+329
-2
lines changed

osrs/interfaces/gametabs/friends.simba

Lines changed: 329 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,342 @@
22
{$INCLUDE_ONCE WaspLib/osrs.simba}
33

44
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+
536
TRSFriends = record
637
Scroll: TRSScrollBar;
7-
Toggle, Add, Del: TBox;
38+
Buttons: array [ERSFriendsButton] of TRSButton;
839
end;
940

1041
procedure TRSFriends.SetupGameTab();
1142
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+
Self.Buttons[ERSFriendsButton.DEL].Click(EMouseButton.LEFT);
253+
Result := Chat.AnswerQuery('Enter name of friend to delete from list', name, 2000, 250);
254+
end;
255+
256+
(*
257+
## Friends.SendMessage
258+
```pascal
259+
function TRSFriends.SendMessage(name, message: String): Boolean;
260+
```
261+
262+
Attempts to send a message to a friend.
263+
264+
Example:
265+
```pascal
266+
WriteLn Friends.SendMessage('SomePlayer', 'Hello there!');
267+
```
268+
*)
269+
function TRSFriends.SendMessage(name, message: String): Boolean;
270+
var
271+
friend: TRSFriend;
272+
begin
273+
if not Self.Open() then Exit;
274+
275+
friend := Self.Find(name);
276+
if friend = Default(TRSFriend) then Exit;
277+
if friend.World = -1 then Exit;
278+
279+
Mouse.Click(friend.Bounds, EMouseButton.LEFT);
280+
Result := Chat.AnswerQuery('Enter message to send to ' + name, message, 2000, 250);
281+
end;
282+
283+
(*
284+
## Friends.AddIgnore
285+
```pascal
286+
function TRSFriends.AddIgnore(name: String): Boolean;
287+
```
288+
289+
Attempts to add a player to the ignore list.
290+
291+
Example:
292+
```pascal
293+
WriteLn Friends.AddIgnore('SomePlayer');
294+
```
295+
*)
296+
function TRSFriends.AddIgnore(name: String): Boolean;
297+
begin
298+
if not Self.Open() then Exit;
299+
if not Self.Buttons[ERSFriendsButton.IGNORE].Enable() then Exit;
300+
301+
Self.Buttons[ERSFriendsButton.ADD].Click(EMouseButton.LEFT);
302+
Result := Chat.AnswerQuery('Enter name of player to add to list', name, 2000, 250);
303+
end;
304+
305+
(*
306+
## Friends.DeleteIgnore
307+
```pascal
308+
function TRSFriends.DeleteIgnore(name: String): Boolean;
309+
```
310+
311+
Attempts to delete a player from the ignore list.
312+
313+
Example:
314+
```pascal
315+
WriteLn Friends.DeleteIgnore('SomePlayer');
316+
```
317+
*)
318+
function TRSFriends.DeleteIgnore(name: String): Boolean;
319+
var
320+
friend: TRSFriend;
321+
begin
322+
if not Self.Open() then Exit;
323+
if not Self.Buttons[ERSFriendsButton.IGNORE].Enable() then Exit;
324+
325+
if Biometrics.RandomBoolean() then
326+
begin
327+
friend := Self.Find(name);
328+
if friend = Default(TRSFriend) then Exit;
329+
330+
Mouse.Click(friend.Bounds, EMouseButton.Right);
331+
if not ChooseOption.WaitOpen(2000, 250) then Exit;
332+
333+
Result := ChooseOption.Select('Delete ' + friend.Name);
334+
end
335+
else
336+
Self.Buttons[ERSFriendsButton.DEL].Click(EMouseButton.LEFT);
337+
Result := Chat.AnswerQuery('Enter name of player to delete from list', name, 2000, 250);
13338
end;
14339

15340
var
16341
Friends: TRSFriends;
342+
343+

0 commit comments

Comments
 (0)