1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resource Old School Scroll Bar Util

Discussion in 'Tutorials & Resources' started by sothatsit, Apr 8, 2015.

  1. sothatsit

    Joined:
    Mar 14, 2015
    Messages:
    24
    Likes Received:
    3
    Just a small resource i made to handle the scroll bars in old school. Currently it has the chatbox (not tested) and the emotes tab built in to use but it should be easy enough to implement other scroll bars and if you post them below ill add them.

    le code:
    Code (Text):
    1. package me.sothatsit.dancingformoney.util;
    2.  
    3. import com.runemate.game.api.hybrid.input.Mouse;
    4. import com.runemate.game.api.hybrid.local.hud.InteractableRectangle;
    5. import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
    6. import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
    7. import com.runemate.game.api.hybrid.util.Filter;
    8. import com.runemate.game.api.hybrid.util.calculations.Random;
    9.  
    10. import java.util.List;
    11.  
    12. public class ScrollBar {
    13.  
    14.     private InterfaceComponent scrollBox;
    15.     private InterfaceComponent scrollBar;
    16.     private InterfaceComponent contentBox;
    17.     private List<InterfaceComponent> content;
    18.  
    19.     public ScrollBar(InterfaceComponent scrollBox, InterfaceComponent scrollBar, InterfaceComponent contentBox, List<InterfaceComponent> content) {
    20.         this.scrollBox = scrollBox;
    21.         this.scrollBar = scrollBar;
    22.         this.contentBox = contentBox;
    23.         this.content = content;
    24.     }
    25.  
    26.     public InterfaceComponent getScrollBox() {
    27.         return scrollBox;
    28.     }
    29.  
    30.     public InterfaceComponent getScrollBar() {
    31.         return scrollBar;
    32.     }
    33.  
    34.     public InterfaceComponent getContentBox() {
    35.         return contentBox;
    36.     }
    37.  
    38.     public List<InterfaceComponent> getContent() {
    39.         return content;
    40.     }
    41.  
    42.     public float getScroll(InterfaceComponent component) {
    43.         int minY = content.stream().mapToInt(comp -> comp.getBounds().y).min().getAsInt();
    44.         int maxY = content.stream().mapToInt(comp -> comp.getBounds().y).max().getAsInt();
    45.  
    46.         return (component.getBounds().y - minY) / (maxY - minY);
    47.     }
    48.  
    49.     public float getCurrentScroll() {
    50.         return (float) (scrollBar.getBounds().y - scrollBox.getBounds().y) / (float) (scrollBox.getHeight() - scrollBar.getHeight());
    51.     }
    52.  
    53.     public boolean scrollTo(InterfaceComponent component) {
    54.         return isVisible(component) || (scrollTo(getScroll(component)) && isVisible(component));
    55.     }
    56.  
    57.     public boolean scrollTo(float scroll) {
    58.         int difY = (int) (scroll * (scrollBox.getHeight() - scrollBar.getHeight())) - (scrollBar.getBounds().y - scrollBox.getBounds().y) + Random.nextInt(-3, 3);
    59.  
    60.         Mouse.move(scrollBar);
    61.         Mouse.press(Mouse.Button.LEFT);
    62.         Mouse.move(new InteractableRectangle(Mouse.getPosition().x + Random.nextInt(-3, 3), Mouse.getPosition().y + difY, 7, 7));
    63.         Mouse.release(Mouse.Button.LEFT);
    64.  
    65.         return true;
    66.     }
    67.  
    68.     public boolean isVisible(InterfaceComponent component) {
    69.         return isVisible(component.getBounds());
    70.     }
    71.  
    72.     public boolean isVisible(InteractableRectangle bounds) {
    73.         return contentBox.getBounds().contains(bounds);
    74.     }
    75.  
    76.     public static ScrollBar getScrollBar(InterfaceComponent scrollBox, InterfaceComponent scrollBar, InterfaceComponent contentBox, List<InterfaceComponent> content) {
    77.         return new ScrollBar(scrollBox, scrollBar, contentBox, content);
    78.     }
    79.  
    80.     public static ScrollBar getEmotesScrollBar() {
    81.         InterfaceComponent scrollBox = Interfaces.getAt(216, 2, 0);
    82.         InterfaceComponent scrollBar = Interfaces.getAt(216, 2 , 1);
    83.         InterfaceComponent contentBox = Interfaces.getAt(216, 1);
    84.         List<InterfaceComponent> content = contentBox.getComponents();
    85.  
    86.         return getScrollBar(scrollBox, scrollBar, contentBox, content);
    87.     }
    88.  
    89.     public static ScrollBar getChatboxScrollBar() {
    90.         InterfaceComponent scrollBox = Interfaces.getAt(137, 3, 0);
    91.         InterfaceComponent scrollBar = Interfaces.getAt(137, 3 , 1);
    92.         InterfaceComponent contentBox = Interfaces.getAt(137, 2);
    93.  
    94.         List<InterfaceComponent> content = Interfaces.getLoadedAt(137, new Filter<InterfaceComponent>() {
    95.             @Override
    96.             public boolean accepts(InterfaceComponent component) {
    97.                 return component.getIndex() >= 4;
    98.             }
    99.         }).asList();
    100.  
    101.         return getScrollBar(scrollBox, scrollBar, contentBox, content);
    102.     }
    103.  
    104. }
    105.  
    Features:
    - get the current scroll of scroll bars
    - get the scroll required to make components visible
    - scroll to a component or float value
    - check if a component is visible in the content box

    To make a new scroll bar which hasn't been implemented you just need to get the scroll box, scroll bar, content box and a list of the components in the content box.

    scroll box = The box in which the bit you drag to scroll is located. This should not contain the arrows.
    scroll bar = The thing you click and drag to scroll up/down
    content box = The box where the content components are visible
    content = A list of all the components in the content box. (eg. the emote components for the emotes scroll bar)

    then you just use ScrollBar#getScrollBar(scrollBox, scrollBar, contentBox, content); to get the ScrollBar object for that scroll bar.

    Example usage:
    Code (Text):
    1. ScrollBar.getEmotesScrollBar().getCurrentScroll();
    2. ScrollBar.getEmotesScrollBar().scrollTo(<component>);
    3. ScrollBar.getEmotesScrollBar().isVisible(<component>);
     
  2. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,073
    Likes Received:
    1,894
    Thanks for the resource, might come in handy for me some time soon! I'd just like to tell you that Interfaces#getAt() will be deprecated some time soon.
     
  3. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    Just a note, Interfaces.getAt(137, 2) isn't recommended. Interfaces.getAt should generally not be used.
    --- Double Post Merged, Apr 8, 2015, Original Post Date: Apr 8, 2015 ---
    Beat me to it haha
     
    Defeat3d likes this.
  4. sothatsit

    Joined:
    Mar 14, 2015
    Messages:
    24
    Likes Received:
    3
    What should be used instead? I dont really see any other way to do it except for using bounding box size or texture id which seems even more hacky to me.
     
  5. Cloud

    Cloud Engineer

    Joined:
    Jul 28, 2013
    Messages:
    2,777
    Likes Received:
    1,124
    You can use either of those, it's not about it being "hacky" it's about it being dynamic enough that Jagex couldn't break the recognition without changing something that an actual user would notice too.
     
  6. sothatsit

    Joined:
    Mar 14, 2015
    Messages:
    24
    Likes Received:
    3
    Fair enough, ill change it to use queries in a bit.
     

Share This Page

Loading...