- Thread Author
- #1
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:
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:
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>);