roguehippo Posted September 10, 2016 Posted September 10, 2016 (edited) what is the best way to highlight a tile. im trying to iterate through a list of positions but when i try to use g.drawPolygon (as suggested by other threads on the forum) it just gives me a red underline and sys drawpolygon is undefined. did they change how tiles are highlighted? thanks! edit for visibility of the real problem i need help with still --------------------------------------------------- my gui class seems to not be able to use myPlayer().getlocation effectively because i always just get a null pointer when the code executes. this is the snippet of code JButton SetSpotButton = new JButton("Set Safe Spot"); SetSpotButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if(CustomSpotButton.isSelected()) { SafeSpot = m.myPlayer().getPosition(); } } }); if the button is pressed and a checkbox is checked to use the method then it tries to save the tile i am standing on. also my "m" is a global in my gui so i dont know why its not working MethodProvider m; public Gui(MethodProvider m){ this.m = m; } Edited September 15, 2016 by roguehippo
Sebastian Posted September 10, 2016 Posted September 10, 2016 Do you have to give it a name or something?
FrostBug Posted September 10, 2016 Posted September 10, 2016 (edited) graphics.draw(position.getPolygon(bot)) Edited September 10, 2016 by FrostBug 2
roguehippo Posted September 10, 2016 Author Posted September 10, 2016 i have no idea graphics.draw(position.getPolygon(bot)) hey frost, thanks for the help, but it still says that "graphics" cannot be resolved do i have to import a source into my script?
Saiyan Posted September 10, 2016 Posted September 10, 2016 i have no idea hey frost, thanks for the help, but it still says that "graphics" cannot be resolved do i have to import a source into my script? public class GodWarsDungeon extends Script { private Position position = new Position(0,0,0); // obviously have the correct co-ordinates //in your onPaint do this @[member='Override'] public void onPaint(Graphics2D g) { g.draw(position.getPolygon(bot)); } Do you have to give it a name or something? The reason why graphics did not resolve was because by default your onPaint(Graphics2D g) is set at g so you can change that to whatever you want :P (the g part)
roguehippo Posted September 10, 2016 Author Posted September 10, 2016 i forgot about onPaint... i havent coded in like all summer. my b public class GodWarsDungeon extends Script { private Position position = new Position(0,0,0); // obviously have the correct co-ordinates //in your onPaint do this @[member='Override'] public void onPaint(Graphics2D g) { g.draw(position.getPolygon(bot)); } The reason why graphics did not resolve was because by default your onPaint(Graphics2D g) is set at g so you can change that to whatever you want :P (the g part) this is a function i made to color the tiles of an area. im wondering if this is going to work, the only thing im worried about is it had me automatically set g2 = null. does it have to be something else? i havent tested it yet public void drawArea() { if(gui.ShowOverlay == true ) { Graphics2D g2 = null; g2.setColor(Color.WHITE); log("drawing tiles"); for(int i = 0;i < FightArea.getPositions().size(); i++ ) { Polygon poly = FightArea.getPositions().get(i).getPolygon(bot); g2.draw(poly); } } }
FrostBug Posted September 10, 2016 Posted September 10, 2016 i forgot about onPaint... i havent coded in like all summer. my b this is a function i made to color the tiles of an area. im wondering if this is going to work, the only thing im worried about is it had me automatically set g2 = null. does it have to be something else? i havent tested it yet public void drawArea() { if(gui.ShowOverlay == true ) { Graphics2D g2 = null; g2.setColor(Color.WHITE); log("drawing tiles"); for(int i = 0;i < FightArea.getPositions().size(); i++ ) { Polygon poly = FightArea.getPositions().get(i).getPolygon(bot); g2.draw(poly); } } } 1
jython Posted September 11, 2016 Posted September 11, 2016 (edited) I'm using this fellow's "Drawing Tiles" useful snippet: http://osbot.org/forum/topic/80826-useful-methods/?hl=fill and it works perfectly. My snippet iterating through Positions: for (Position p : fishingArea.getPositions() ) { drawTile(script, g, p, Color.pink, Color.white, ""); } With drawTile() slightly modified from the link's example, looking like this: /** * * @param script Most likely: client.getBot().getScriptExecutor().getCurrent() * @param g The Graphics2D object passed into the onPaint() method * @param position The Position for the tile you are wishing to draw on * @param tileColor The color that will be drawn around the border of the tile * @param textColor The color of the text for the "s" parameter * @param s The text you wish to display next to the tile, if any. */ public void drawTile(Script script, Graphics g, Position position, Color tileColor, Color textColor, String s) { Polygon polygon; if (position != null && (polygon = position.getPolygon(script.getBot(), position.getTileHeight(script.getBot()))) != null) { g.setColor(tileColor); for (int i = 0; i < polygon.npoints; i++) { g.setColor(new Color(0, 0, 0, 20)); g.fillPolygon(polygon); g.setColor(tileColor); g.drawPolygon(polygon); } g.setColor(textColor); g.drawString(s, (int) polygon.getBounds().getX(), (int) polygon.getBounds().getY()); } } Edited September 11, 2016 by jython 1
roguehippo Posted September 14, 2016 Author Posted September 14, 2016 (edited) my gui class seems to not be able to use myPlayer().getlocation effectively because i always just get a null pointer when the code executes. this is the snippet of code JButton SetSpotButton = new JButton("Set Safe Spot"); SetSpotButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if(CustomSpotButton.isSelected()) { SafeSpot = m.myPlayer().getPosition(); } } }); if the button is pressed and a checkbox is checked to use the method then it tries to save the tile i am standing on. also my "m" is a global in my gui so i dont know why its not working MethodProvider m; public Gui(MethodProvider m){ this.m = m; } Edited September 14, 2016 by roguehippo