Skip to content

Commit 69f1287

Browse files
committed
fix(TRSInterface): interface bounds builder
Now has better math. I didn't look how the client does it but comparing to actual results from the client in fixed and resizable and multiple window sizes multiple interfaces have a perfect match now Fixed multiple bugs in the debugging file which is not normally compiled
1 parent 66ac097 commit 69f1287

5 files changed

Lines changed: 210 additions & 163 deletions

File tree

osrs/interfaces/debugging.simba

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ end;
198198

199199
procedure TRSChat.Draw(img: TImage);
200200
var
201-
tab: TRSChatTab;
201+
tab: TRSButton;
202202
begin
203-
if not Self.IsOpen() then Exit;
203+
if not Self.IsOpen() then
204+
Exit;
204205

205206
img.DrawColor := $00FFFF;
206207
img.DrawBox(Self.Bounds);
@@ -213,7 +214,7 @@ begin
213214

214215
Self.Scroll.Draw(img);
215216
for tab in Self.Tabs.Tabs do
216-
tab.Button.Draw(img);
217+
tab.Draw(img);
217218
end;
218219

219220
procedure TRSMake.Draw(img: TImage);
@@ -236,14 +237,29 @@ procedure TRSBank.Draw(img: TImage);
236237
var
237238
i: Integer;
238239
begin
239-
if not Self.IsOpen() then Exit;
240+
if not Self.IsOpen() then
241+
Exit;
240242

241-
for i := 0 to 1 do
242-
begin
243+
img.DrawColor := $FFFFFF;
244+
img.DrawBox(Self.Bounds);
245+
246+
for i := 0 to High(Self.Buttons) do
243247
Self.Buttons[i].Draw(img);
244-
Self.ArrangementButtons[i].Draw(img);
245-
Self.WithdrawModeButtons[i].Draw(img);
246-
end;
248+
249+
for i := 0 to High(Self.SidebarButtons) do
250+
Self.SidebarButtons[i].Draw(img);
251+
252+
for i := 0 to High(Self.ModeButtons) do
253+
Self.ModeButtons[i].Draw(img);
254+
255+
for i := 0 to High(Self.QuantityButtons) do
256+
Self.QuantityButtons[i].Draw(img);
257+
258+
for i := 0 to High(Self.MiscButtons) do
259+
Self.MiscButtons[i].Draw(img);
260+
261+
for i := 0 to High(Self.DepositButtons) do
262+
Self.DepositButtons[i].Draw(img);
247263

248264
img.DrawColor := $FFFFFF;
249265
for i := 0 to Self.CountTabs() do
@@ -252,12 +268,6 @@ begin
252268
img.DrawColor := $FFFF00;
253269
img.DrawBoxArray(Self.FindItemBoundaries(), False);
254270
Self.Scroll.Draw(img);
255-
256-
for i := 0 to 4 do
257-
Self.QuantityButtons[i].Draw(img);
258-
259-
for i := 0 to 3 do
260-
Self.DynamicButtons[i].Draw(img);
261271
end;
262272

263273
procedure TRSBankPin.Draw(img: TImage);
@@ -357,23 +367,43 @@ begin
357367
end;
358368

359369
procedure TRSGoldScreen.Draw(img: TImage);
370+
var
371+
i: Integer;
360372
begin
361373
img.DrawBox(Self.Bounds);
362374
img.DrawBoxArray(Self.ItemBoxes, False);
363-
Self.GetButtons().Draw(img);
375+
for i := 0 to High(Self.Buttons) do
376+
Self.Buttons[i].Draw(img);
364377
end;
365378

366379
procedure TRSSilverScreen.Draw(img: TImage);
380+
var
381+
i: Integer;
367382
begin
368383
img.DrawBox(Self.Bounds);
369384
img.DrawBoxArray(Self.SlotBoxes, False);
370385
img.DrawBoxArray(Self.ClickBoxes, False);
371-
Self.GetButtons().Draw(img);
386+
for i := 0 to High(Self.Buttons) do
387+
Self.Buttons[i].Draw(img);
372388
end;
373389

390+
procedure TRSAnvil.Draw(img: TImage);
391+
begin
392+
img.DrawColor := $FFFFFF;
393+
img.DrawBox(Self.Bounds);
374394

395+
img.DrawColor := $00FFFF;
396+
img.DrawBox(Self.SlotsArea);
397+
398+
img.DrawColor := $00FF00;
399+
img.DrawBoxArray(Self.GetSlotBoxes(), False);
400+
img.DrawColor := $00FFFF;
375401

376-
procedure ShowOnTarget(button: TRSButton); overload;
402+
Self.QuantityButtons.Draw(img);
403+
end;
404+
405+
406+
procedure ShowOnTarget(constref button: TRSButton); overload;
377407
var
378408
img: TImage;
379409
begin
@@ -382,7 +412,7 @@ begin
382412
img.Show();
383413
end;
384414

385-
procedure ShowOnTarget(buttons: TRSButtonArray); overload;
415+
procedure ShowOnTarget(constref buttons: TRSButtonArray); overload;
386416
var
387417
img: TImage;
388418
begin
@@ -391,7 +421,7 @@ begin
391421
img.Show();
392422
end;
393423

394-
procedure ShowOnTarget(scroll: TRSScrollBar); overload;
424+
procedure ShowOnTarget(constref scroll: TRSScrollBar); overload;
395425
var
396426
img: TImage;
397427
begin
@@ -400,7 +430,7 @@ begin
400430
img.Show();
401431
end;
402432

403-
procedure ShowOnTarget(dropdown: TRSDropDown); overload;
433+
procedure ShowOnTarget(constref dropdown: TRSDropDown); overload;
404434
var
405435
img: TImage;
406436
begin
@@ -409,7 +439,7 @@ begin
409439
img.Show();
410440
end;
411441

412-
procedure ShowOnTarget(chat: TRSChat); overload;
442+
procedure ShowOnTarget(constref chat: TRSChat); overload;
413443
var
414444
img: TImage;
415445
begin
@@ -418,7 +448,7 @@ begin
418448
img.Show();
419449
end;
420450

421-
procedure ShowOnTarget(bank: TRSBank); overload;
451+
procedure ShowOnTarget(constref bank: TRSBank); overload;
422452
var
423453
img: TImage;
424454
begin
@@ -427,7 +457,7 @@ begin
427457
img.Show();
428458
end;
429459

430-
procedure ShowOnTarget(collectionBox: TRSCollectionBox); overload;
460+
procedure ShowOnTarget(constref collectionBox: TRSCollectionBox); overload;
431461
var
432462
img: TImage;
433463
begin
@@ -436,7 +466,7 @@ begin
436466
img.Show();
437467
end;
438468

439-
procedure ShowOnTarget(depositBox: TRSDepositBox); overload;
469+
procedure ShowOnTarget(constref depositBox: TRSDepositBox); overload;
440470
var
441471
img: TImage;
442472
begin
@@ -445,7 +475,7 @@ begin
445475
img.Show();
446476
end;
447477

448-
procedure ShowOnTarget(shop: TRSShop); overload;
478+
procedure ShowOnTarget(constref shop: TRSShop); overload;
449479
var
450480
img: TImage;
451481
begin
@@ -454,7 +484,7 @@ begin
454484
img.Show();
455485
end;
456486

457-
procedure ShowOnTarget(bankPin: TRSBankPin); overload;
487+
procedure ShowOnTarget(constref bankPin: TRSBankPin); overload;
458488
var
459489
img: TImage;
460490
begin
@@ -463,7 +493,7 @@ begin
463493
img.Show();
464494
end;
465495

466-
procedure ShowOnTarget(goldscreen: TRSGoldScreen); overload;
496+
procedure ShowOnTarget(constref goldscreen: TRSGoldScreen); overload;
467497
var
468498
img: TImage;
469499
begin
@@ -472,7 +502,7 @@ begin
472502
img.Show();
473503
end;
474504

475-
procedure ShowOnTarget(silverscreen: TRSSilverScreen); overload;
505+
procedure ShowOnTarget(constref silverscreen: TRSSilverScreen); overload;
476506
var
477507
img: TImage;
478508
begin
@@ -481,7 +511,7 @@ begin
481511
img.Show();
482512
end;
483513

484-
procedure ShowOnTarget(make: TRSMake); overload;
514+
procedure ShowOnTarget(constref make: TRSMake); overload;
485515
var
486516
img: TImage;
487517
begin
@@ -490,4 +520,13 @@ begin
490520
img.Show();
491521
end;
492522

523+
procedure ShowOnTarget(constref anvil: TRSAnvil); overload;
524+
var
525+
img: TImage;
526+
begin
527+
img := Target.GetImage();
528+
anvil.Draw(img);
529+
img.Show();
530+
end;
531+
493532
{$ENDIF}

osrs/interfaces/interfacearea.simba

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ begin
2525
ERSMode.RESIZABLE:
2626
begin
2727
Self.Bounds.X2 := GameTabs.Bounds.X1 - 10;
28-
Self.Bounds.Y2 := Chat.Bounds.Y1;
28+
Self.Bounds.Y2 := Chat.Bounds.Y1-1;
2929
end;
3030

3131
ERSMode.MODERN_COMPACT, ERSMode.MODERN_WIDE:
3232
begin
3333
Self.Bounds.X2 := GameTab.Bounds.X1 - 22;
34-
Self.Bounds.Y2 := Chat.Bounds.Y1;
34+
Self.Bounds.Y2 := Chat.Bounds.Y1-1;
3535
end;
3636
end;
3737

@@ -149,7 +149,7 @@ end;
149149

150150
function TRSInterfaceArea.CreateBounds(offset: TBox; width, height: Integer = 0): TBox;
151151
var
152-
center, half, halfMax: Integer;
152+
center, half, halfSize: Double;
153153
begin
154154
offset.X1 += Self.Bounds.X1;
155155
offset.Y1 += Self.Bounds.Y1;
@@ -158,12 +158,12 @@ begin
158158

159159
if width > 0 then
160160
begin
161-
half := (offset.X2 - offset.X1) div 2;
161+
half := (offset.X2 - offset.X1) / 2;
162162
center := offset.X1 + half;
163-
halfMax := (width - 1) div 2;
163+
halfSize := (width - 1) / 2;
164164

165-
Result.X1 := Max(center - half, center - halfMax);
166-
Result.X2 := Min(center + half, center + halfMax);
165+
Result.X1 := Floor(Max(center - half, center - halfSize));
166+
Result.X2 := Floor(Min(center + half, center + halfSize));
167167
end
168168
else
169169
begin
@@ -173,12 +173,12 @@ begin
173173

174174
if height > 0 then
175175
begin
176-
half := (offset.Y2 - offset.Y1) div 2;
176+
half := (offset.Y2 - offset.Y1) / 2;
177177
center := offset.Y1 + half;
178-
halfMax := (height - 1) div 2;
178+
halfSize := (height - 1) / 2;
179179

180-
Result.Y1 := Max(center - half, center - halfMax);
181-
Result.Y2 := Min(center + half, center + halfMax);
180+
Result.Y1 := Floor(Max(center - half, center - halfSize));
181+
Result.Y2 := Floor(Min(center + half, center + halfSize));
182182
end
183183
else
184184
begin

osrs/interfaces/mainscreen/anvil.simba

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,49 @@ Main record to interact with the {ref}`Anvil` interface.
2424
Anvils: TRSObjectArray;
2525
end;
2626

27+
function TRSAnvil.GetSlotBoxes(): TBoxArray; forward;
28+
29+
(*
30+
## Anvil.SetupInterface
31+
```pascal
32+
procedure TRSAnvil.SetupInterface;
33+
```
34+
Initializes {ref}`Anvil` variables.
35+
36+
```{note}
37+
This is automatically called for you on the {ref}`Anvil variable`.
38+
```
39+
*)
40+
procedure TRSAnvil.SetupInterface();
41+
var
42+
i: Integer;
43+
boxes: TBoxArray;
44+
begin
45+
case RSClient.Mode of
46+
ERSMode.FIXED: Self.Bounds := MSInterface.CreateBounds([0, 2, 0, -1], 500, 320);
47+
ERSMode.RESIZABLE, ERSMode.MODERN_COMPACT, ERSMode.MODERN_WIDE:
48+
Self.Bounds := MSInterface.CreateBounds([0, -1, 0, 1], 500, 320);
49+
end;
50+
51+
Self.Title.Setup(Self.Bounds);
52+
53+
Self.SlotsArea.X1 := Self.Bounds.X1 + 4;
54+
Self.SlotsArea.Y1 := Self.Bounds.Y1 + 30;
55+
Self.SlotsArea.X2 := Self.Bounds.X2 - 50;
56+
Self.SlotsArea.Y2 := Self.Bounds.Y2 - 4;
57+
58+
Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft + [6, 36], 6, 5, 75, 54, [1, 1]);
59+
for i in [5, 11, 17, 23, 29] do
60+
Self.SlotBoxes[i].X2 := Self.SlotBoxes[i].X1 + 67;
61+
62+
Self.Slots.Setup('Anvil.Slots', Self.SlotBoxes, @Self.GetSlotBoxes);
63+
Self.Items.Setup('Anvil.Items', @Self.Slots, [0, 0]);
64+
65+
with Self.Bounds do
66+
boxes := TBoxArray.Create([X2-43, Y1+36], 1, 6, 36, 36, [0,9]);
67+
Self.QuantityButtons := TRSButtonArray.Create(boxes, [[RSFonts.WHITE]]);
68+
end;
69+
2770
(*
2871
## Anvil.GetSlotBoxes
2972
```pascal
@@ -71,47 +114,6 @@ begin
71114
Result += Self.SlotBoxes[i];
72115
end;
73116

74-
(*
75-
## Anvil.SetupInterface
76-
```pascal
77-
procedure TRSAnvil.SetupInterface;
78-
```
79-
Initializes {ref}`Anvil` variables.
80-
81-
```{note}
82-
This is automatically called for you on the {ref}`Anvil variable`.
83-
```
84-
*)
85-
procedure TRSAnvil.SetupInterface();
86-
var
87-
i: Integer;
88-
boxes: TBoxArray;
89-
begin
90-
case RSClient.Mode of
91-
ERSMode.FIXED: Self.Bounds := MSInterface.CreateBounds([0, 2, 0, -1], 500, 320);
92-
ERSMode.RESIZABLE, ERSMode.MODERN_COMPACT, ERSMode.MODERN_WIDE:
93-
Self.Bounds := MSInterface.CreateBounds([0, -1, 0, 0], 500, 320);
94-
end;
95-
96-
Self.Title.Setup(Self.Bounds);
97-
98-
Self.SlotsArea.X1 := Self.Bounds.X1 + 4;
99-
Self.SlotsArea.Y1 := Self.Bounds.Y1 + 30;
100-
Self.SlotsArea.X2 := Self.Bounds.X2 - 50;
101-
Self.SlotsArea.Y2 := Self.Bounds.Y2 - 4;
102-
103-
Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft + [6, 36], 6, 5, 75, 54, [1, 1]);
104-
for i in [5, 11, 17, 23, 29] do
105-
Self.SlotBoxes[i].X2 := Self.SlotBoxes[i].X1 + 67;
106-
107-
Self.Slots.Setup('Anvil.Slots', Self.SlotBoxes, @Self.GetSlotBoxes);
108-
Self.Items.Setup('Anvil.Items', @Self.Slots, [0, 0]);
109-
110-
with Self.Bounds do
111-
boxes := TBoxArray.Create([X2-43, Y1+36], 1, 6, 36, 36, [0,9]);
112-
Self.QuantityButtons := TRSButtonArray.Create(boxes, [[RSFonts.WHITE]]);
113-
end;
114-
115117
(*
116118
## Anvil.IsOpen
117119
```pascal

0 commit comments

Comments
 (0)