Skip to content
This repository has been archived by the owner on Dec 22, 2019. It is now read-only.

Commit

Permalink
#13 added hex colors to options, and tolltip to table
Browse files Browse the repository at this point in the history
remove robot.setAutoDelay()
  • Loading branch information
Evgeny Frolov committed Jan 7, 2016
1 parent 8d35541 commit 068d30d
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 30 deletions.
6 changes: 3 additions & 3 deletions bot.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fishing.fishKey = =
fishing.failTryings = 5
fishing.firstColors = #6B240E,#4D160E,#C62F12,#94260B,#49150A,#341209
fishing.secondColors = #353C59,#2F3756,#4D5363,#626574,#1E2D4A,#17263D
fishing.thirdColors = #6A5344,#756051,#4D4030,#624D38,#504D3E,#42453A
fishing.firstColors = #6B240E,#4D160E,#C62F12,#94260B,#49150A,#341209,#DF453B,#A52927,#7B461C,#211009,#7B3615,#6A3219
fishing.secondColors = #353C59,#2F3756,#4D5363,#626574,#1E2D4A,#17263D,#6970C8,#5D5DB5,#5E6872
fishing.thirdColors = #6A5344,#756051,#4D4030,#624D38,#504D3E,#754E51,#6C4C4F,#657D70,#E99F72,#A36D49,#25333E,#FFDEBF
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void setAzimuthByKey(Double value) throws InterruptedException {
getController().azimuthByKey(value);
}

public void setPitch(Double value) {
public void setPitch(Double value) throws InterruptedException {
StaticFunc.upWindow(ConfigKeys.WINDOW_CLASS, ConfigKeys.WINDOW_NAME);
getController().pitch(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ public void azimuthByKey(double rad) throws InterruptedException {
*
* @param rad new pitch in radians
*/
public void pitch(double rad) {
public void pitch(double rad) throws InterruptedException {
double currentPitch = getReceiver().getPitch();
while (Math.abs(currentPitch - rad) > ConfigKeys.PITCH_TOLERANCE) {
Thread.sleep(20);
double changeRad = currentPitch - rad;
driver.mousePitch(changeRad);

Expand Down
31 changes: 23 additions & 8 deletions src/main/java/org/freekode/wowbot/beans/service/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class Driver {
private static final Logger logger = LogManager.getLogger(Driver.class);
private static final int AUTO_DELAY_MS = 40;
private static Driver INSTANCE;
/**
* operated rectangle of window
Expand All @@ -27,7 +28,7 @@ private Driver(Rectangle window) {

try {
robot = new Robot();
robot.setAutoDelay(50);
// robot.setAutoDelay(50);
} catch (AWTException e) {
logger.error("exception during creating of robot", e);
}
Expand All @@ -41,13 +42,13 @@ public static Driver getInstance(Rectangle window) {
return INSTANCE;
}

public void centerMouse() {
public void centerMouse() throws InterruptedException {
int centerX = (int) (window.getX() + window.getWidth() / 2);
int centerY = (int) (window.getY() + window.getHeight() / 2) - 11;
mouse(centerX, centerY);
}

public void mouseForGather(int stepNum, Integer steps) {
public void mouseForGather(int stepNum, Integer steps) throws InterruptedException {
if (steps == null) {
steps = 5;
}
Expand Down Expand Up @@ -81,8 +82,9 @@ public void gather() throws InterruptedException {
Thread.sleep(500);
}

public void mouse(int x, int y) {
public void mouse(int x, int y) throws InterruptedException {
robot.mouseMove(x, y);
Thread.sleep(AUTO_DELAY_MS);
}

public void run(double distance) throws InterruptedException {
Expand Down Expand Up @@ -113,47 +115,58 @@ public void keyRotateLeft(double rad) throws InterruptedException {
*
* @param rad difference of angle
*/
public void mouseYaw(double rad) {
public void mouseYaw(double rad) throws InterruptedException {
int interval = ((int) (rad / 0.005)) * ConfigKeys.MOUSE_YAW_DOUBLE_O_ONE;

centerMouse();
Point mousePoint = MouseInfo.getPointerInfo().getLocation();

robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
Thread.sleep(AUTO_DELAY_MS);
robot.mouseMove(mousePoint.x + interval, mousePoint.y);
Thread.sleep(AUTO_DELAY_MS);
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
Thread.sleep(AUTO_DELAY_MS);
}

public void pitchInit() {
public void pitchInit() throws InterruptedException {
mousePitch(-0.01);
mousePitch(0.01);
}

public void mousePitch(double rad) {
public void mousePitch(double rad) throws InterruptedException {
int interval = ((int) (rad / 0.01)) * ConfigKeys.MOUSE_PITCH_DOUBLE_O_TWO;

centerMouse();
Point mousePoint = MouseInfo.getPointerInfo().getLocation();

robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
Thread.sleep(AUTO_DELAY_MS);
robot.mouseMove(mousePoint.x, mousePoint.y + interval);
Thread.sleep(AUTO_DELAY_MS);
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
Thread.sleep(AUTO_DELAY_MS);
}

public void fpv() throws InterruptedException {
robot.keyPress(KeyEvent.VK_END);
Thread.sleep(AUTO_DELAY_MS);
robot.keyRelease(KeyEvent.VK_END);

robot.keyPress(KeyEvent.VK_HOME);
Thread.sleep(AUTO_DELAY_MS);
robot.keyRelease(KeyEvent.VK_HOME);

robot.keyPress(KeyEvent.VK_HOME);
Thread.sleep(AUTO_DELAY_MS);
robot.keyRelease(KeyEvent.VK_HOME);

robot.keyPress(KeyEvent.VK_HOME);
Thread.sleep(AUTO_DELAY_MS);
robot.keyRelease(KeyEvent.VK_HOME);

robot.keyPress(KeyEvent.VK_HOME);
Thread.sleep(AUTO_DELAY_MS);
robot.keyRelease(KeyEvent.VK_HOME);

Thread.sleep(3500);
Expand Down Expand Up @@ -186,9 +199,11 @@ public void thirdByMouse() throws InterruptedException {
}
}

public void pressKey(int keyCode) {
public void pressKey(int keyCode) throws InterruptedException {
robot.keyPress(keyCode);
Thread.sleep(AUTO_DELAY_MS);
robot.keyRelease(keyCode);
Thread.sleep(AUTO_DELAY_MS);
}

public Robot getRobot() {
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/org/freekode/wowbot/modules/TestMovingModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,10 @@ public void setAzimuth() {

try {
ai.setAzimuth(newAzimuth);
logger.info("current azimuth = " + ai.getController().getReceiver().getAzimuth());
} catch (InterruptedException e) {
logger.info("azimuth test exception", e);
}

logger.info("current azimuth = " + ai.getController().getReceiver().getAzimuth());
}

public void setAzimuthByKey() {
Expand All @@ -173,20 +172,22 @@ public void setAzimuthByKey() {

try {
ai.setAzimuthByKey(newAzimuth);
logger.info("current azimuth = " + ai.getController().getReceiver().getAzimuth());
} catch (InterruptedException e) {
logger.info("azimuth test exception", e);
}

logger.info("current azimuth = " + ai.getController().getReceiver().getAzimuth());
}

public void setPitch() {
Double newPitch = new Double(pitchField.getText());
logger.info("new pitch = " + newPitch);

ai.setPitch(newPitch);

logger.info("current pitch = " + ai.getController().getReceiver().getPitch());
try {
ai.setPitch(newPitch);
logger.info("current pitch = " + ai.getController().getReceiver().getPitch());
} catch (InterruptedException e) {
logger.info("pitch test exception", e);
}
}

public void run() {
Expand All @@ -196,12 +197,12 @@ public void run() {

try {
ai.run(distance);

Vector3D newLocation = ai.getController().getCoordinates();
logger.info("real distance = " + Vector3D.distance(currentLocation, newLocation));
} catch (InterruptedException e) {
logger.info("run test exception", e);
}

Vector3D newLocation = ai.getController().getCoordinates();
logger.info("real distance = " + Vector3D.distance(currentLocation, newLocation));
}

public void gatherHerb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.freekode.wowbot.beans.ai.FishingAI;
import org.freekode.wowbot.beans.ai.Intelligence;
import org.freekode.wowbot.modules.Module;
import org.freekode.wowbot.tools.ColorRenderer;
import org.freekode.wowbot.tools.ColorCellRenderer;
import org.freekode.wowbot.tools.DateRenderer;
import org.freekode.wowbot.tools.StaticFunc;

Expand Down Expand Up @@ -90,7 +90,7 @@ public Component buildInterface() {
// row 3
recordsTable = new JTable(new FishingTableModel());
recordsTable.setDefaultRenderer(Date.class, new DateRenderer("yyyy-MM-dd HH:mm:ss"));
recordsTable.setDefaultRenderer(Color.class, new ColorRenderer());
recordsTable.setDefaultRenderer(Color.class, new ColorCellRenderer());
JScrollPane scrollPane = new JScrollPane(recordsTable);
c.insets = new Insets(0, 0, 0, 0);
c.gridx = 0;
Expand Down Expand Up @@ -132,7 +132,8 @@ public void property(PropertyChangeEvent e) {
}

FishingTableModel model = (FishingTableModel) recordsTable.getModel();
model.updateOrAdd(record);
Integer index = model.updateOrAdd(record);
recordsTable.scrollRectToVisible(recordsTable.getCellRect(index, 0, true));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class ColorRenderer extends JLabel implements TableCellRenderer {
public ColorRenderer() {
public class ColorCellRenderer extends JLabel implements TableCellRenderer {
public ColorCellRenderer() {
setOpaque(true);
}

Expand All @@ -14,6 +14,11 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
Color color = (Color) value;
setBackground(color);

if (color != null) {
String colorText = String.format("#%06X", (0xFFFFFF & color.getRGB()));
setToolTipText(colorText);
}

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.*;

public class ColorListRenderer extends JLabel implements ListCellRenderer<Color> {
Expand All @@ -12,9 +13,10 @@ public ColorListRenderer() {
@Override
public Component getListCellRendererComponent(JList<? extends Color> list, Color value, int index, boolean isSelected, boolean cellHasFocus) {
setBackground(value);
// setText(String.format("#%06X", (0xFFFFFF & value.getRGB())));
setText(String.format("#%06X", (0xFFFFFF & value.getRGB())));
setForeground(new Color((0xFFFFFF - value.getRGB())));

setPreferredSize(new Dimension(20, 20));
// setPreferredSize(new Dimension(20, 20));

if (isSelected) {
Border selectedBorder = BorderFactory.createMatteBorder(2, 2, 2, 2, list.getSelectionBackground());
Expand Down

0 comments on commit 068d30d

Please sign in to comment.