Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Resource Old School Scroll Bar Util

Joined
Mar 14, 2015
Messages
24
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:
package me.sothatsit.dancingformoney.util;

import com.runemate.game.api.hybrid.input.Mouse;
import com.runemate.game.api.hybrid.local.hud.InteractableRectangle;
import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
import com.runemate.game.api.hybrid.util.Filter;
import com.runemate.game.api.hybrid.util.calculations.Random;

import java.util.List;

public class ScrollBar {

    private InterfaceComponent scrollBox;
    private InterfaceComponent scrollBar;
    private InterfaceComponent contentBox;
    private List<InterfaceComponent> content;

    public ScrollBar(InterfaceComponent scrollBox, InterfaceComponent scrollBar, InterfaceComponent contentBox, List<InterfaceComponent> content) {
        this.scrollBox = scrollBox;
        this.scrollBar = scrollBar;
        this.contentBox = contentBox;
        this.content = content;
    }

    public InterfaceComponent getScrollBox() {
        return scrollBox;
    }

    public InterfaceComponent getScrollBar() {
        return scrollBar;
    }

    public InterfaceComponent getContentBox() {
        return contentBox;
    }

    public List<InterfaceComponent> getContent() {
        return content;
    }

    public float getScroll(InterfaceComponent component) {
        int minY = content.stream().mapToInt(comp -> comp.getBounds().y).min().getAsInt();
        int maxY = content.stream().mapToInt(comp -> comp.getBounds().y).max().getAsInt();

        return (component.getBounds().y - minY) / (maxY - minY);
    }

    public float getCurrentScroll() {
        return (float) (scrollBar.getBounds().y - scrollBox.getBounds().y) / (float) (scrollBox.getHeight() - scrollBar.getHeight());
    }

    public boolean scrollTo(InterfaceComponent component) {
        return isVisible(component) || (scrollTo(getScroll(component)) && isVisible(component));
    }

    public boolean scrollTo(float scroll) {
        int difY = (int) (scroll * (scrollBox.getHeight() - scrollBar.getHeight())) - (scrollBar.getBounds().y - scrollBox.getBounds().y) + Random.nextInt(-3, 3);

        Mouse.move(scrollBar);
        Mouse.press(Mouse.Button.LEFT);
        Mouse.move(new InteractableRectangle(Mouse.getPosition().x + Random.nextInt(-3, 3), Mouse.getPosition().y + difY, 7, 7));
        Mouse.release(Mouse.Button.LEFT);

        return true;
    }

    public boolean isVisible(InterfaceComponent component) {
        return isVisible(component.getBounds());
    }

    public boolean isVisible(InteractableRectangle bounds) {
        return contentBox.getBounds().contains(bounds);
    }

    public static ScrollBar getScrollBar(InterfaceComponent scrollBox, InterfaceComponent scrollBar, InterfaceComponent contentBox, List<InterfaceComponent> content) {
        return new ScrollBar(scrollBox, scrollBar, contentBox, content);
    }

    public static ScrollBar getEmotesScrollBar() {
        InterfaceComponent scrollBox = Interfaces.getAt(216, 2, 0);
        InterfaceComponent scrollBar = Interfaces.getAt(216, 2 , 1);
        InterfaceComponent contentBox = Interfaces.getAt(216, 1);
        List<InterfaceComponent> content = contentBox.getComponents();

        return getScrollBar(scrollBox, scrollBar, contentBox, content);
    }

    public static ScrollBar getChatboxScrollBar() {
        InterfaceComponent scrollBox = Interfaces.getAt(137, 3, 0);
        InterfaceComponent scrollBar = Interfaces.getAt(137, 3 , 1);
        InterfaceComponent contentBox = Interfaces.getAt(137, 2);

        List<InterfaceComponent> content = Interfaces.getLoadedAt(137, new Filter<InterfaceComponent>() {
            @Override
            public boolean accepts(InterfaceComponent component) {
                return component.getIndex() >= 4;
            }
        }).asList();

        return getScrollBar(scrollBox, scrollBar, contentBox, content);
    }

}

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:
ScrollBar.getEmotesScrollBar().getCurrentScroll();
ScrollBar.getEmotesScrollBar().scrollTo(<component>);
ScrollBar.getEmotesScrollBar().isVisible(<component>);
 
Conelander
Joined
Oct 30, 2014
Messages
3,610
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.
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
Just a note, Interfaces.getAt(137, 2) isn't recommended. Interfaces.getAt should generally not be used.
 
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.
Beat me to it haha
 
Joined
Mar 14, 2015
Messages
24
Just a note, Interfaces.getAt(137, 2) isn't recommended. Interfaces.getAt should generally not be used.
 

Beat me to it haha
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.
 
Engineer
Joined
Jul 28, 2013
Messages
2,776
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.
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.
 
Joined
Mar 14, 2015
Messages
24
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.
Fair enough, ill change it to use queries in a bit.
 
Top