Code was done by Sam or Poohman or whatever gender he is now.
1. Create a new class; your default position value will vary depending on the width; feel free to add it into the constructor.
Code:
public class Slider {
private int position = 86;
private double value;
private int x, y;
private final double minValue, maxValue, length;
private final Sprite[] images = new Sprite[2];
public Slider(Sprite icon, Sprite background, double minimumValue, double maximumValue) {
this.images[0] = icon;
this.images[1] = background;
this.minValue = this.value = minimumValue;
this.maxValue = maximumValue;
this.length = this.images[1].myWidth;
}
public void draw(int x, int y) {
this.x = x;
this.y = y;
images[1].drawSprite(x, y);
images[0].drawSprite(x + position - (int) (position / length * images[0].myWidth), y - images[0].myHeight / 2 + images[1].myHeight / 2);
}
public void handleClick(int mouseX, int mouseY, int offsetX, int offsetY, int contentType) {
if (RSApplet.mouseX - offsetX >= x && RSApplet.mouseX - offsetX <= x + length
&& RSApplet.mouseY - offsetY >= y + images[1].myHeight / 2 - images[0].myHeight / 2
&& RSApplet.mouseY - offsetY <= y + images[1].myHeight / 2 + images[0].myHeight / 2)
{
position = mouseX - x - offsetX;
if (position >= length) {
position = (int) length;
}
if (position <= 0) {
position = 0;
}
value = minValue + ((mouseX - x - offsetX) / length) * (maxValue - minValue);
if (value < minValue) {
value = minValue;
}
if (value > maxValue) {
value = maxValue;
}
switch(contentType) {
case 1:
Texture.method372(minValue + maxValue - value);
break;
}
}
}
public double getPercentage() {
return ((position / length) * 100);
}
}
2. Client.java, create a new interface type; pick any number.
Code:
else if (class9_1.type == 123) {
Slider slider = class9_1.slider;
if (slider != null) {
slider.draw(k2, l2);
}
3. Add these in Interface.java
Code:
public Slider slider;
public static void addSlider(int interfaceId, double min, double max, String iconSprite, String backgroundSprite, int contentType) {
Interface widget = interfaceCache[interfaceId] = new RSInterface();
Sprite icon = imageLoader(Integer.parseInt(iconSprite.split(" ")[1]), iconSprite.split(" ")[0]);
Sprite background = imageLoader(Integer.parseInt(backgroundSprite.split(" ")[1]), backgroundSprite.split(" ")[0]);
widget.slider = new Slider(icon, background, min, max);
widget.type = 123;
widget.contentType = contentType;
}
MouseDragged, MousePressed
Code:
if (interfaceId != -1) {
RSInterface widget = RSInterface.interfaceCache[interfaceId];
for (int childId : widget.children) {
RSInterface child = RSInterface.interfaceCache[childId];
if (child == null || child.slider == null)
continue;
child.slider.handleClick(i, j, Client.isFullScreen ? 0 : 519, Client.isFullScreen ? 0 : 168, child.contentType);
}
Client.tabAreaAltered = true;
Client.needDrawTabArea = true;
}
interfaceId = Client.openInterfaceID;
if (interfaceId != -1) {
RSInterface widget = RSInterface.interfaceCache[interfaceId];
for (int childId : widget.children) {
RSInterface child = RSInterface.interfaceCache[childId];
if (child == null || child.slider == null)
continue;
child.slider.handleClick(i, j, 4, 4, child.contentType);
}
}
Usage:
Code:
addSlider(child, 0.6, 1.5, "icon_sprite.png", "background_sprite.png", 1);
4. Images, these are mine for brightness.
5. This is what you're adding.
Do Enjoy.ee