Sign in to follow this  
Nom

[OSRS] Fidget Widget (Widget explorer)

Recommended Posts

Nom   

Since the other widget explorer isn't working, I made a new one.

Source down below in case this gets outdated.

 

How to use:

Click to update point to search. You don't need input allowed as it uses the MouseListener.

 

Sorts from smallest to largest widget

 

gzJEbRB.png

 

 

 


package nomivore.SimpleScripts;

import CustomAPI.ClientContext;
import CustomAPI.PollingScript;
import org.powerbot.script.PaintListener;
import org.powerbot.script.Script;
import org.powerbot.script.rt4.Component;
import org.powerbot.script.rt4.Widget;
import org.powerbot.script.rt4.Widgets;

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.*;
import java.util.List;

@Script.Manifest(name = "FidgetWidget", properties = "author=nomivore; topic=1342073; client=4;", description = "Helps you find widgets (Developer Tool)")
public class WidgetExplorer extends PollingScript<ClientContext> implements PaintListener, MouseListener {
    private Font font = new Font("Trebuchet MS", Font.PLAIN, 20);
    private List<Component> compList = new ArrayList<>();
    private List subList = new ArrayList<>();
    private Point clickPoint = ctx.input.getLocation();
    private ArrayList<Color> colors = new ArrayList<Color>() {{
        add(Color.RED); add(Color.BLUE); add(Color.CYAN); add(Color.MAGENTA);
        add(Color.GREEN); add(Color.YELLOW);
    }};
    private Widgets widgets = ctx.widgets;

    @Override
    public synchronized void repaint(Graphics g) {
        g.setFont(font);
        int x = (clickPoint.getX() < ctx.game.dimensions().getWidth()/2) ? (int)ctx.game.dimensions().getWidth()-250 : 15;
        int y = 0;
        int i = 0;

        subList = compList.subList(0,Math.min(5,compList.size()));
        for (Object aSubList : subList) {
            Component c = (Component) aSubList;
            g.setColor(colors.get(i % colors.size()));
            i++;
            y += font.getSize();
            Component temp = c;
            StringBuilder s = new StringBuilder(String.valueOf(temp.index()) + ",");
            for (int depth = 0; depth < 3; depth++) {
                if (temp.parent().valid()) {
                    s.append(String.valueOf(temp.parent().index())).append(",");
                } else {
                    s.append(temp.widget().id());
                    break;
                }
                temp = temp.parent();
            }
//            Utils.drawStringOutline(g, x, y, "Widget: " + c.widget().id() + " Component: " + c.index());
            Utils.drawStringOutline(g, x, y, s.toString());
            g.drawRect((int) c.boundingRect().getX(), (int) c.boundingRect().getY(), (int) c.boundingRect().getWidth(), (int) c.boundingRect().getHeight());
        }
    }

    @Override
    public synchronized void mouseClicked(MouseEvent e) {
        clickPoint = e.getPoint();
        compList.clear();
        for (Widget w : widgets) {
            if (!w.valid()) continue;
            for (Component c : w.components()) {
                if (!c.valid() || !c.visible()) continue;
                if (c.components().length > 0) {
                    for (Component cc : c.components()) {
                        if (!cc.valid() || !cc.visible()) continue;
                        if (cc.boundingRect().contains(clickPoint)) {
                            compList.add(cc);
                        }
                    }
                } else {
                    if (c.boundingRect().contains(clickPoint)) {
                        compList.add(c);
                    }
                }
            }
        }
        compList.sort(new CustomComparator());
    }

    public class CustomComparator implements Comparator<Component> {
        @Override
        public int compare(Component c1, Component c2) {
            return (int) (c1.boundingRect().getWidth() * c1.boundingRect().getWidth() -
                    c2.boundingRect().getWidth() * c2.boundingRect().getWidth());
        }
    }

    @Override
    public void poll() {
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}

 

Edited by Nomivore

Share this post


Link to post


Nom   
2 hours ago, iDzn said:

Already come in handy, thanks for this!

 

6 minutes ago, Spearless said:

Thanks for this !

Glad to help!

Atm I feel it's really slow, but perhaps it's inevitable since it's going down 3 levels. If you have some suggestions I'd be happy to take them.

Share this post


Link to post
leche13   

I  have a question, when a widget has 3 values, for example 0, 6, 6 for silver symbol. How do i call this widget? For widgets with two values i'd make a component object(like the code line below), which only allows for two int inputs. What i thought of doing was creating two components, that pointed to the widget but i can't seem to figure it out. 

Component gui= ctx.widgets.component(,);
Edited by leche13

Share this post


Link to post
18 minutes ago, leche13 said:

I  have a question, when a widget has 3 values, for example 0, 6, 6 for silver symbol. How do i call this widget? For widgets with two values i'd make a component object(like the code line below), which only allows for two int inputs. What i thought of doing was creating two components, that pointed to the widget but i can't seem to figure it out. 


Component gui= ctx.widgets.component(,);

 

whatever = ctx.widgets.widgets(int).component(int).component(int)

Share this post


Link to post
leche13   
1 minute ago, ShowtimeScripts said:

 

whatever = ctx.widgets.widgets(int).component(int).component(int)

 

wow! thank you! i was pulling my hair this morning trying to figure it out. so simple -.-.
thank you for the fast reply!!!! 

Share this post


Link to post
1 minute ago, leche13 said:

 

wow! thank you! i was pulling my hair this morning trying to figure it out. so simple -.-.
thank you for the fast reply!!!! 

I'd recommend joining the discord, makes it a lot easier to glean info!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

Loading...
Sign in to follow this