Jump to content
Wanted

Correcting points based on scroll bar position

Recommended Posts

If you've read this http://forums.scar-divi.com/showthread.php?2189-OSI-2-Updates-e-g-Structure-Mouse-RS07-New-Bank-and-OCR-and-others under bank then you'll know I'm looking for a little help in writing OSI2 RS07's banking functions.

 

Basically in RS07's bank screen you have a scroll bar on the right.

 

When the scroll button as at the very top it shows row [0] when it's at the very bottom it shows row [49] there's also 8 columns [0..7] left to right but the X points are find it's the Y up-down axis where it get's tricky.

 

My plan is to have something like this

 

[sCAR]procedure OffsetPointBankScrollPos(var P: TPoint; Pos: Extended);

begin

//P := Point(P.X, Round(P.Y + ((1668.965517 * Pos) - 1520.896552))); dafuq did these come from I dont even

end;

 

procedure OffsetBoxBankScrollPos(var B: TBox);

var

CurrentPos: Extended;

P1, P2: TPoint;

begin

CurrentPos := GetBankScrollBarPos;

P1 := Point(B.X1, B.Y1);

P2 := Point(B.X2, B.Y2);

OffsetPointBankScrollPos(P1, CurrentPos);

OffsetPointBankScrollPos(P2, CurrentPos);

B := PointToBox(P1, P2);

end;[/sCAR]

 

^ obviously the functions above are just psedo code and are skeleton examples

 

so far I have completed

 

[sCAR]{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function GetBankScrollBarPosition: Extended;

Contributors: Wanted

Description: Returns the percentage of scroll bar height relative to max top.

Date Created: March 16th, 2013. By Wanted. RS07 Build ???.

Last Modified: March 16th, 2013. By Wanted. RS07 Build ???.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

 

function GetBankScrollBarPos: Extended;

var

TPA: TPointArray;

begin

Result := 1.0;

if (GetColor(474, 75) = 5531254) then

Exit;

if (GetColor(474, 271) = 2436403) then

begin

Result := 0;

Exit;

end;

FindColorEx(TPA, 1777699, 468, 75, 468, 271);

InvertTPA(TPA);

SortTPAEx(TPA, Point(468, 75));

Result := (249 - TPA[0].Y) / 175;

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function ScrollToBankToRow(Row: Integer): Boolean;

Contributors: Wanted

Description: Scrolls bank to which ever row you specify, true if adjusted.

Date Created: March 16th, 2013. By Wanted. RS07 Build ???.

Last Modified: March 16th, 2013. By Wanted. RS07 Build ???.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

 

function ScrollToBankToRow(Row: Integer): Boolean;

var

Y, DY, CurrentPos: Extended;

B, DB: TBox;

begin

Result := False;

DY := (Row * 3.5) + 75;

CurrentPos := GetBankScrollBarPos;

Y := 249 - (174 * CurrentPos);

B := Box(470, Round(Y) + 2, 481, Round(Y) + 20);

if (InRange(Row, 0, 5)) then

begin

if (CurrentPos = 1.0) then

Exit;

DragMouseBox(B.X1, B.Y1, B.X2, B.Y2, 470, 67, 481, 72, True);

Result := True;

Exit;

end;

if (InRange(Row, 45, 49)) then

begin

if (CurrentPos = 0.0) then

Exit;

DragMouseBox(B.X1, B.Y1, B.X2, B.Y2, 470, 273, 481, 277, True);

Result := True;

Exit;

end;

if (CurrentPos = ((249 - DY) / 175)) then

Exit;

DB := Box(470, Round(DY + 12), 481, Round(DY + 12));

DragMouseBoxB(B, DB, True);

Result := True;

end;[/sCAR]

 

You'll notice some key information like

 

Max high position of the scroll bar is 75 and max low position is 249. That the Height itself is 175 and each row is 3.5 on the scroll bar relatively (it has some weird quadratic offset though but it shouldn't be a problem, everything is still visible that you need to be when using ScrollBankToRow... ok wow I need to fix that name in OSI -_-)

 

function GetBankScrollBarPosition: Extended; returns a number between 0 and 1 (like a percentage) 0 being at the maxed bottom, 1 being at maxed top, 0.5 being half way you get the idea

 

question is how do I utilize that to determine the points on the bank screen?

 

So far I have

 

[sCAR]{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function GetBankSlotsBounds(Slots: TIntegerArray): TBoxArray;

Contributors: Wanted

Description: Returns the bounds of items in the inventory.

Last Modified: March 9th, 2013. By Wanted. RS07 Build ???.

Last Modified: March 9th, 2013. By Wanted. RS07 Build ???.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

 

function GetBankSlotsBounds(Slots: TIntegerArray): TBoxArray;

var

I, H: Integer;

begin

SetLength(Result, Length(Slots));

H := High(Slots);

for I := 0 to H do

begin

Result := BoxFromGrid(Point(79, 62), Slots, 31, 31, 50, 8, 38, 47);

ConstrainBox(Result, MBB);

end;

end;[/sCAR]

 

But it only works at the very top of the bank screen obviously... once you scroll everything is off.

 

I tried plotting some points in my graphing calculator

 

1
(412, 146)

0.977142857142857
(412, 114)

0.954285714285714
(412, 70)

0.948571428571429
(412, 62)

 

0.811428571428571
(80, 61)

0.822857142857143
(80, 81)

0.845714285714286
(80, 121)

0.862857142857143
(80, 149)

0.891428571428571
80, 197

0.925714285714286
(80, 249)

0.942857142857143
(80, 285)

 

though I couldn't make sense of any of the results.

 

The answer might be super obvious but I just can't seem to think of it

 

Cheers to helping OSI.

Link to comment
Share on other sites

[sCAR]procedure OffsetPointBankScrollPos(var P: TPoint; Pos: Extended);

var

IPos: Extended;

begin

IPos := 1.0 - Pos;

P := Point(P.X, P.Y - Round(IPos * 1676));

end;[/sCAR]

 

That's as close as I can get honestly and it's still off because the scroll bar can move apparently without actually moving.. so looks like I'm going to use extended bounds with object outlines =/

Link to comment
Share on other sites

Why not just when an openBank function is called, when the bankscreen is open: Just scroll the mouse wheel up for a lil so it will ALWAYS be to the most-top item row in the bank.

That would be probably the easy way of doing it:P Haha

 

That's the way bank openers have always worked but we are trying to add new capability

Link to comment
Share on other sites

Well, something stinks Wanted, hard to make sens of your "1676".

 

List of ponts from 0.8 -> 1.0

List := [0.80, 0.822757, 0.845814, 0.862857, 0.885714, 0.908571, 0.931429, 0.954286, 0.977143, 1.00]...

The average increcement rate is 0.02222, this adds to 1.000 if there are 45 scrollable rows in the bank (+ the last 5 rows that cant be scrolled to).

let's dubble check it..: 1/45 = 0.02222

 

6 rows is = 230px.

per that definition, one slot height is:

230/6 = 38.33px (seems correct after some dubble checks, this is the height of each slot in the bank)

 

But WHAT is actually the number you posted, Wanted???

1676*0.02222 = 37.24px?? //Seems a little off.

 

If one where to calculate it like this, the most accurate number would be: 1724px (45*38.33).

 

NOTE:

"some wierd quadratic offset", as you mentioned is the reason for the scrollbar moving without the bank really changing (vice versa).

To partially eliminate that problem use the click-"up"-key, and click-"down"-key in the scrollbar instead of actully dragging the scrollbar. The buttons do NOT have some wierd scale shit. With "mouseXdown" untill the correct position is reached?

 

I might be taking a shit in the dark here, I just woke up :P

Edited by slacky
Link to comment
Share on other sites

Why not just when an openBank function is called, when the bankscreen is open: Just scroll the mouse wheel up for a lil so it will ALWAYS be to the most-top item row in the bank.

That would be probably the easy way of doing it:P Haha

Please no!!!

 

Often my scripts will rely on the bank positioning staying the same. I can see giving the option to do that, but leaving it optional.

Link to comment
Share on other sites

Well, something stinks Wanted, hard to make sens of your "1676".

 

List of ponts from 0.8 -> 1.0

List := [0.80, 0.822757, 0.845814, 0.862857, 0.885714, 0.908571, 0.931429, 0.954286, 0.977143, 1.00]...

The average increcement rate is 0.02222, this adds to 1.000 if there are 45 scrollable rows in the bank (+ the last 5 rows that cant be scrolled to).

let's dubble check it..: 1/45 = 0.02222

 

6 rows is = 230px.

per that definition, one slot height is:

230/6 = 38.33px (seems correct after some dubble checks, this is the height of each slot in the bank)

 

But WHAT is actually the number you posted, Wanted???

1676*0.02222 = 37.24px?? //Seems a little off.

 

If one where to calculate it like this, the most accurate number would be: 1724px (45*38.33).

 

NOTE:

"some wierd quadratic offset", as you mentioned is the reason for the scrollbar moving without the bank really changing (vice versa).

To partially eliminate that problem use the click-"up"-key, and click-"down"-key in the scrollbar instead of actully dragging the scrollbar. The buttons do NOT have some wierd scale shit. With "mouseXdown" untill the correct position is reached?

 

I might be taking a shit in the dark here, I just woke up :P

 

Those are just random points I took at random scroll heights.

 

I've pretty much got it figured out but it turns out there is positions between scroll points making a perfectly accurate system impossible. What I'm ending up doing is creating overlapping search areas and using the object outlines with TPA sorting etc. I should have this done by tonight.

Link to comment
Share on other sites

Those are just random points I took at random scroll heights.

 

I've pretty much got it figured out but it turns out there is positions between scroll points making a perfectly accurate system impossible. What I'm ending up doing is creating overlapping search areas and using the object outlines with TPA sorting etc. I should have this done by tonight.

 

If you are refering to my list: [0.80, 0.822757, 0.845814, 0.862857, 0.885714, 0.908571, 0.931429, 0.954286, 0.977143, 1.00]..., as the points you took at random scroll heights, you're wrong. I gathered this ponts my self. Each point above refers to "one item height".

 

it's the number: 1676 that makes no sense (as it's a little off from my calculations).

 

"there is positions between scroll points".

- I believe you are wrong.

 

It is only correct if you are:

1. dragging the scollbar. The stepsize would be inaccurate.

2. using the actuall mouse scroll. Same result as above.

 

-> Use the pointers/arrows, under the the bar, and above the bar. Hold the up/down-arrow down untill you're at the correct possition.

Link to comment
Share on other sites

I am using the scroll bar with mouse.

 

1676 is taking into account the 5 rows you can't scroll to I guess. That's just the only number that could accurately offset everything all the way from slot 0 to slot 399.

 

Sadly there is no seamless algorithm that can 100% safely and accurately determine bank slot bounds at different scroll positions so I am currently writing something that uses overlappping search bound with findcolors etc.

 

I appreciate your help and sorry I couldn't take time to show you more about this because it's very involved.

 

I'll say if you want to see my reasoning play with creating the box surrounding the click bounds of different items at different angles

 

This is what I've been playing with:

 

[sCAR]{$DEFINE RS07}

//{$DEFINE SMART}

{$DEFINE OSI_RS07_Color_Anti_Randoms}

 

{$I OSI\OSI.scar}

{$I OSI\Divi\Misc\Debug.scar}

 

procedure ScriptTerminate;

begin

FreeOSI;

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function FixBank2(FixUp: Boolean): Boolean;

Contributors: Wanted, Freddy

Description: Scrolls bank all the way to top or bottom, true if not needed to do so.

Date Created: October 30th, 2011. By Wanted. RS2 Build 671.

Last Modified: March 16th, 2013. By Wanted. RS07 Build ???.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

 

function FixBank2(FixUp: Boolean): Boolean;

var

TPA: TPointArray;

B: TBox;

begin

Result := False;

if (FixUp) then

if (GetColor(474, 75) = 5531254) then

Exit;

if (not (FixUp)) then

if (GetColor(474, 271) = 2436403) then

Exit;

Result := True;

FindColorEx(TPA, 1777699, 468, 75, 483, 271);

InvertTPA(TPA);

if (Length(TPA) < 20) then

begin

if (FixUp) then

B := Box(470, 252, 481, 269)

else

B := Box(470, 77, 480, 93);

end

else

B := TPABounds(TPA);

B := Box(B.X1 + 2, B.Y1 + 2, B.X2 - 2, B.Y2 - 2);

if (FixUp) then

DragMouseBox(B.X1, B.Y1, B.X2, B.Y2, 469, 55, 483, 71, True)

else

DragMouseBox(B.X1, B.Y1, B.X2, B.Y2, 470, 277, 484, 295, True);

end;

 

procedure OffsetPointBankScrollPos(var P: TPoint; Pos: Extended);

var

IPos: Extended;

begin

IPos := 1.0 - Pos;

P := Point(P.X, P.Y - Round(IPos * 1676));

end;

 

procedure OffsetBoxBankScrollPos(var B: TBox; Pos: Extended);

var

P1, P2: TPoint;

begin

P1 := Point(B.X1, B.Y1);

P2 := Point(B.X2, B.Y2);

OffsetPointBankScrollPos(P1, Pos);

OffsetPointBankScrollPos(P2, Pos);

B := PointToBox(P1, P2);

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function GetBankSlotsSearchBounds(Slots: TIntegerArray): TBoxArray;

Contributors: Wanted

Description: Returns the bounds of items in the inventory.

Last Modified: March 9th, 2013. By Wanted. RS07 Build ???.

Last Modified: March 9th, 2013. By Wanted. RS07 Build ???.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

 

function GetBankSlotsSearchBounds(Slots: TIntegerArray): TBoxArray;

var

I, H: Integer;

begin

SetLength(Result, Length(Slots));

H := High(Slots);

for I := 0 to H do

begin

//Result := BoxFromGrid(Point(79, 62), Slots, 31, 31, 50, 8, 38, 47);

//Result := BoxFromGrid(Point(71, 61), Slots, 47, 38, 50, 8, 38, 47);

//Result := BoxFromGrid(Point(67, 58), Slots, 55, 42, 50, 8, 38, 47);

Result := BoxFromGrid(Point(79, 52), Slots, 31, 50, 50, 8, 38, 47);

OffsetBoxBankScrollPos(Result, GetBankScrollBarPos);

ConstrainBox(Result, MBB);

end;

end;

 

function GetBankSlotSearchBounds(Slot: Integer): TBox;

var

TBA: TBoxArray;

begin

TBA := GetBankSlotsSearchBounds([slot]);

Result := TBA[0];

end;

 

{function GetBankSlotsBounds(Slots: TIntegerArray): TBoxArray;

begin

FindColorsEx(TPA, [clObjectOutline, clYellow, clWhite, 8453888],

end; }

 

//var

//CurrentPos, Y: Extended;

 

var

I : Integer;

TIA: TIntegerArray;

 

begin

SetUpOSI;

{DebugATPABounds(FindMMDotsEx([cldWhiteDot, cldYellowDot]));

SmartDebugATPABounds(FindMMDotsEx([cldWhiteDot, cldYellowDot]));}

//WriteLn(BankScreen);

//WriteLn(DepositItemsEx([0, 2, 27], True, True));

//WriteLn(ToggleUseNotes(False));

//WriteLn(ToggleSwapMode(True));

//WriteLn(FixBank(False));

//WriteLn(GetBankScrollBarPos);

//for I := 0 to 49 do

//begin

//WriteLn(ScrollToBankToRow(44));

//Wait(1000);

//end;

{DebugTBA(GetBankSlotsBounds([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,

13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,

24, 25, 26, 27, 28, 29, 30, 31, 32, 51, 70, 80, 90, 140, 180, 200, 250, 300, 390, 397, 398])); }

//DebugTBA(GetBankSlotsbounds([0, 2, 4, 6, 8, 10, 12, 14, 16, 366, 374, 382, 390]));

//WriteLn(GetBankScrollBarPos);

SetLength(TIA, 400);

for I := 0 to 399 do

TIA := I;

DebugTBA(GetBankSlotsSearchBounds(TIA));

end.

[/sCAR]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...