inlustra Posted March 23, 2016 Share Posted March 23, 2016 Hi guys, Pretty simple: I'm making a component system using the g2d (Have made). I have to ask, what's with the BotMouseListener, how does it work? (Docs are empty) where does it interact? and how does it differ from the regular MouseEvents and Listeners. My issue is with the blockInput(Point) method, why? Why not just use the regular Java consume()/isConsumed()? The blockInput(Point) method does not allow components to differentiate the click by any other method (Such as modifiers) Why not just use consume? Thanks, Tom Quote Link to comment Share on other sites More sharing options...
Vilius Posted March 23, 2016 Share Posted March 23, 2016 (edited) Make a class which would implement MouseListener, add all the default methods and use them to your liking. Then create a new object of your class and simply add it to your script like this: //your mouse object Mouse mouseObject = new Mouse(); public void onStart(){ getBot().addMouseListener(mouseObject); } Here are some snippets on how to hide your paint if you want: public class Mouse implements MouseListener { //create a boolean public boolean hidePaint; @Override public void mouseClicked(MouseEvent e) { //create our point variable Point p = e.getPoint(); //create our rectangle Rectangle rec = new Rectangle(x,y,width,height); //check if the rectangle contains point and change booleans state if(rec.contains(p)) hidePaint = !hidePaint; } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } } public class Main extends Script{ //pas our mouse object Mouse mouse = new Mouse(); public void onStart(){ //add our mouse object as a mouse listener getBot().addMouseListener(mouse); } public void onPaint(Graphics2D g){ //check if our boolean is false if(!mouse.hidePaint){ //draw our stuff } } public int onLoop(){ return 0; } } Edited March 23, 2016 by Vilius Quote Link to comment Share on other sites More sharing options...
inlustra Posted March 23, 2016 Author Share Posted March 23, 2016 (edited) Thanks for your input, but that's not really my question. I understand how to use the MouseListener interface, my question is about the logic behind blocking and input from the user. Currently, you can override BotMouseListener and return false on the blockInput(Point) method in order to stop a users input from reaching the canvas. Not only must this require extra logic behind the scenes (instanceof BotMouseListener?) but the MouseListeners also take no notice of the isConsumed() method in the MouseEvent classes. Either I'm missing something or the devs have implemented it differently. For example: @Override public void mouseClicked(MouseEvent e) { e.consume(); //This does nothing! :'( log.trace("Consumed click event."); } @Override public boolean blockInput(Point point) { return true; //This does! But I don't have access to the MouseEvent! :'( } The MouseEvent is still fired on the Frame/WrappedCanvas Edited March 23, 2016 by inlustra Quote Link to comment Share on other sites More sharing options...
Vilius Posted March 23, 2016 Share Posted March 23, 2016 Thanks for your input, but that's not really my question. I understand how to use the MouseListener interface, my question is about the logic behind blocking and input from the user. Currently, you can override BotMouseListener and return false on the blockInput(Point) method in order to stop a users input from reaching the canvas. Not only must this require extra logic behind the scenes (instanceof BotMouseListener?) but the MouseListeners also take no notice of the isConsumed() method in the MouseEvent classes. Either I'm missing something or the devs have implemented it differently. For example: @Override public void mouseClicked(MouseEvent e) { e.consume(); //This does nothing! :'( log.trace("Consumed click event."); } @Override public boolean blockInput(Point point) { return true; //This does! But I don't have access to the MouseEvent! :'( } The MouseEvent is still fired on the Frame/WrappedCanvas From what I understand you just want to block the input from the user? If so, then this is useless to you, you need to do it like this: getBot().disableHumanInput(true); And I think BotMouseListener is used for internal use only. Quote Link to comment Share on other sites More sharing options...
inlustra Posted March 23, 2016 Author Share Posted March 23, 2016 No, this is the thing, I want to block user input depending on where they click (Did they click in my rectangle?) My component system wraps the MouseEvent using a custom class that modifies the x and y relative to the component: if (this.mousePressed(new LightMouseEvent(e, this))) e.consume(); Which ultimately doesn't matter because e.consume() wasn't implemented :P I thought maybe someone knew if there is a specific implementation I can hook into using one of the many addMouseListener functions out there, such as getBot().getWrappedCanvas()! There's definitely a Frame with the same implementation. What's the difference! Quote Link to comment Share on other sites More sharing options...
FrostBug Posted March 24, 2016 Share Posted March 24, 2016 (edited) Before dispatching a mouse event to the RS client, the bot client checks if any registered BotMouseListener is blocking it. To achieve what you want, create a new MouseListener class by implementing the BotMouseListener interface. This interface will implement the method blockInput(Point point) Which will let you specify whether a mouse event at the specified point should be dispatched to the RS client or not. Much like consuming the event, except it will still trigger all the subsequent MouseListeners (Unless you consume all events as well) So if you have a button at Rectangle x, you will simply need to return true at blockInput if the given Point is within that rectangle. Edited March 24, 2016 by FrostBug Quote Link to comment Share on other sites More sharing options...
inlustra Posted March 24, 2016 Author Share Posted March 24, 2016 (edited) Before dispatching a mouse event to the RS client, the bot client checks if any registered BotMouseListener is blocking it. To achieve what you want, create a new MouseListener class by implementing the BotMouseListener interface. This interface will implement the method blockInput(Point point) Which will let you specify whether a mouse event at the specified point should be dispatched to the RS client or not. Much like consuming the event, except it will still trigger all the subsequent MouseListeners (Unless you consume all events as well) So if you have a button at Rectangle x, you will simply need to return true at blockInput if the given Point is within that rectangle. Thanks, Best explanation so far, but it actually confirms my suspicions that the mouse handling of the bot was written somewhat poorly where they've decided to implement a custom interface rather than use default Java. Again, by forcing the use of blockInput(Point point) (infact, I'd be totally fine with a method `blockInput(MouseEvent event)`), I don't have access to any of the InputEvent parameters from my inner-components, which means I'll need to create some kind of wrapper! *sigh* Do the devs accept any developer git-branching? Thanks again. Edited March 24, 2016 by inlustra Quote Link to comment Share on other sites More sharing options...
Lemons Posted March 27, 2016 Share Posted March 27, 2016 Thanks, Best explanation so far, but it actually confirms my suspicions that the mouse handling of the bot was written somewhat poorly where they've decided to implement a custom interface rather than use default Java. Again, by forcing the use of blockInput(Point point) (infact, I'd be totally fine with a method `blockInput(MouseEvent event)`), I don't have access to any of the InputEvent parameters from my inner-components, which means I'll need to create some kind of wrapper! *sigh* Do the devs accept any developer git-branching? Thanks again. Best you can do is leave a suggestion, they rarely take code from others for the client. Quote Link to comment Share on other sites More sharing options...