Skip to content

Commit bd42084

Browse files
committed
feat: TRSScrollBar unfinished
1 parent 7f0758f commit bd42084

File tree

3 files changed

+114
-12
lines changed

3 files changed

+114
-12
lines changed

osrs/interfaces/interfacecontrols.simba

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ begin
2626
Exit(True);
2727
end;
2828

29-
function TRSButton.WaitEnabled(time: Integer; interval: Integer = 50): Boolean;
29+
function TRSButton.WaitEnabled(const time: Integer; interval: Integer = -1): Boolean;
3030
begin
31+
if interval < 0 then interval := RandomMode(100, 50, 1500);
3132
Result := SleepUntil(Self.Enabled(), interval, time);
3233
end;
3334

34-
procedure TRSButton.Click(button: EMouseButton = EMouseButton.LEFT);
35+
procedure TRSButton.Click(const button: EMouseButton = EMouseButton.LEFT);
3536
begin
3637
Mouse.Click(Self.Bounds, button);
3738
end;
@@ -136,7 +137,7 @@ begin
136137
Result := (tpa.Mean().X - Self.Bounds.X1) * 100 div Self.Width;
137138
end;
138139

139-
function TRSSlider.SetLevel(level: Integer): Boolean;
140+
function TRSSlider.SetLevel(const level: Integer): Boolean;
140141
var
141142
current: Integer;
142143
p: TPoint;
@@ -159,3 +160,104 @@ begin
159160
Mouse.Click(p, EMouseButton.LEFT);
160161
Result := SleepUntil(Abs(Self.GetLevel()-level) < 2, RandomMode(100, 50, 1500), 600);
161162
end;
163+
164+
165+
type
166+
TRSScrollBar = record
167+
ScrollArea, Up, Down: TBox;
168+
Bounds: TBox;
169+
Width, Height: Integer;
170+
end;
171+
172+
procedure TRSScrollBar.Setup();
173+
begin
174+
if Self.ScrollArea = Default(TBox) then
175+
raise GetDebugLn('ScrollBar', 'You need to set a ScrollArea to use the TRSScrollBar.Setup() method.');
176+
177+
Self.Bounds.X1 := Self.ScrollArea.X2 + 1;
178+
Self.Bounds.Y1 := Self.ScrollArea.Y1 + 16;
179+
Self.Bounds.X2 := Self.Bounds.X1 + 15;
180+
Self.Bounds.Y2 := Self.ScrollArea.Y2 - 16;
181+
182+
Self.Width := Self.Bounds.Width;
183+
Self.Height := Self.Bounds.Height;
184+
185+
Self.Up.X1 := Self.Bounds.X1;
186+
Self.Up.Y1 := Self.ScrollArea.Y1;
187+
Self.Up.X2 := Self.Bounds.X2;
188+
Self.Up.Y2 := Self.Bounds.Y1 - 1;
189+
190+
Self.Down.X1 := Self.Bounds.X1;
191+
Self.Down.Y1 := Self.Bounds.Y2 + 1;
192+
Self.Down.X2 := Self.Bounds.X2;
193+
Self.Down.Y2 := Self.ScrollArea.Y2;
194+
end;
195+
196+
function TRSScrollBar.IsVisible(): Boolean;
197+
begin
198+
Result := Target.HasColor(ColorTolerance($16091C, 16.971, EColorSpace.HSV, [0.277, 0.671, 2.054]), 1, Self.Up)
199+
and
200+
Target.HasColor(ColorTolerance($16091C, 16.971, EColorSpace.HSV, [0.277, 0.671, 2.054]), 1, Self.Down);
201+
end;
202+
203+
function TRSScrollBar.GetSlider(): TBox;
204+
var
205+
p: TPoint;
206+
tpa: TPointArray;
207+
begin
208+
p.X := Self.Bounds.X1 + Self.Width div 2;
209+
tpa := Target.FindColor(RSColors.INTERFACE_BORDER, 0, [p.X, Self.Bounds.Y1, p.X + 1, Self.Bounds.Y2]);
210+
if tpa = [] then Exit;
211+
Result.X1 := Self.Bounds.X1+1;
212+
Result.Y1 := tpa.First.Y;
213+
Result.X2 := Self.Bounds.X2-1;
214+
Result.Y2 := tpa.Last.Y;
215+
end;
216+
217+
function TRSScrollBar.CanScroll(): Boolean;
218+
begin
219+
Result := Self.IsVisible() and (Self.GetSlider() <> Self.Bounds);
220+
end;
221+
222+
223+
function TRSScrollBar.GetLevel(): Integer;
224+
begin
225+
with Self.GetSlider() do
226+
Result := Round((Y1 - Self.Bounds.Y1) * 100 / (Self.Height - Height));
227+
end;
228+
229+
function TRSScrollBar.SetLevel(value: Integer): Integer;
230+
begin
231+
if not Self.CanScroll() then Exit;
232+
value := EnsureRange(value, 0, 100);
233+
end;
234+
235+
236+
237+
procedure ShowOnClient(scroll: TRSScrollBar); overload;
238+
var
239+
img: TImage;
240+
bounds: TBox;
241+
begin
242+
img := TImage.CreateFromTarget();
243+
244+
img.DrawColor := $FFFF00;
245+
img.DrawBox(scroll.Bounds);
246+
247+
img.DrawColor := $FFFFFF;
248+
bounds := scroll.GetSlider();
249+
img.DrawBox(bounds);
250+
251+
img.DrawColor := $FF;
252+
img.FontSize := 12;
253+
bounds.X2 := bounds.X1 - 2;
254+
bounds.X1 -= 30;
255+
img.DrawText(ToStr(scroll.GetLevel()), bounds, [EImageTextAlign.CENTER]);
256+
257+
img.DrawColor := $00FFFF;
258+
img.DrawBoxArray([scroll.Up, scroll.Down], False);
259+
260+
img.Show();
261+
img.Free();
262+
end;
263+

osrs/interfaces/mainscreen/bank.simba

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type
3333
Bounds: TBox;
3434
Slots: TRSSlotInterface;
3535
Items: TRSItemInterface;
36+
Scroll: TRSScrollBar;
3637

3738
CachedQuantity: Int32;
3839

@@ -108,6 +109,13 @@ begin
108109
Self.Bounds.Y2 := Min(Floor(Center.Y+(Height-3)/2), Floor(Center.Y+799/2));
109110
end;
110111

112+
Self.Scroll.ScrollArea.X1 := Self.Bounds.X1 + 5;
113+
Self.Scroll.ScrollArea.Y1 := Self.Bounds.Y1 + 78;
114+
Self.Scroll.ScrollArea.X2 := Self.Bounds.X2 - 22;
115+
Self.Scroll.ScrollArea.Y2 := Self.Bounds.Y2 - 44;
116+
117+
Self.Scroll.Setup();
118+
111119
Self.Tabs := TBoxArray.Create(Self.Bounds.TopLeft.Offset(47, 42), 10, 1, 35, 28, [5, 0]);
112120
Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft.Offset(57, 77), 8, (Self.Bounds.Height - 135) div 35, 31, 31, [17, 5]);
113121

@@ -126,14 +134,6 @@ begin
126134
Self.PotionStorage.X2 := Self.Bounds.X1 + 51;
127135
Self.PotionStorage.Y2 := Self.Bounds.Y2 - 118;
128136

129-
(*
130-
Self.ScrollArea.X1 := Self.Bounds.X1 + 5;
131-
Self.ScrollArea.Y1 := Self.Bounds.Y1 + 77;
132-
Self.ScrollArea.X2 := Self.Bounds.X2 - 24;
133-
Self.ScrollArea.Y2 := Self.Bounds.Y2 - 44;
134-
*)
135-
136-
137137
Self.Slots.Setup('Bank.Slots', Self.SlotBoxes, @Self.FindItemBoundaries);
138138
Self.Items.Setup('Bank.Items', @Self.Slots, [0, 10, 3, 0]);
139139
end;
@@ -142,4 +142,3 @@ end;
142142

143143
var
144144
Bank: TRSBank;
145-

utils/misc.simba

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type
88
const ITEM_SHADOW: TColor = $202030;
99
const ITEM_SHADOW_GRAY: TColor = $333333;
1010
const ITEM_BORDER: TColor = $010000;
11+
const INTERFACE_BORDER: TColor = $010000;
1112
const ITEM_BORDER_WHITE: TColor = $FFFFFF;
1213

1314
const STACK_YELLOW: TColor = $00FFFF;

0 commit comments

Comments
 (0)