diff --git a/DivaBot/DivaBot.jar b/DivaBot/DivaBot.jar index 0673004..21aae69 100644 Binary files a/DivaBot/DivaBot.jar and b/DivaBot/DivaBot.jar differ diff --git a/DivaBot/calibration_data.txt b/DivaBot/calibration_data.txt index 55c8a62..f7e71d9 100644 --- a/DivaBot/calibration_data.txt +++ b/DivaBot/calibration_data.txt @@ -1,4 +1,4 @@ -438 +437 288 1330 793 diff --git a/DivaBot/capture_1.png b/DivaBot/capture_1.png index fe95252..494bc18 100644 Binary files a/DivaBot/capture_1.png and b/DivaBot/capture_1.png differ diff --git a/DivaBot/capture_2.png b/DivaBot/capture_2.png index f5f787a..b682fde 100644 Binary files a/DivaBot/capture_2.png and b/DivaBot/capture_2.png differ diff --git a/DivaBot/capture_3.png b/DivaBot/capture_3.png index 0604272..cd6486c 100644 Binary files a/DivaBot/capture_3.png and b/DivaBot/capture_3.png differ diff --git a/DivaBot/screenConfig.txt b/DivaBot/screenConfig.txt new file mode 100644 index 0000000..573541a --- /dev/null +++ b/DivaBot/screenConfig.txt @@ -0,0 +1 @@ +0 diff --git a/DivaBot/src/sig/Calibrator2.java b/DivaBot/src/sig/Calibrator2.java index a0753c3..021ac54 100644 --- a/DivaBot/src/sig/Calibrator2.java +++ b/DivaBot/src/sig/Calibrator2.java @@ -2,6 +2,8 @@ package sig; import java.awt.Color; import java.awt.Cursor; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.io.File; @@ -34,8 +36,9 @@ public class Calibrator2 { int yoffset1=0; int xoffset2=0; int yoffset2=0; - - img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,MyRobot.STARTDRAG.y+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); ImageIO.write(img,"png",new File("capture_1.png")); boolean found=false; for (int x=0;x=0;y--) { - BufferedImage newimg = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); + BufferedImage newimg = MyRobot.MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,MyRobot.STARTDRAG.y+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y)); Color col = new Color(newimg.getRGB(0, 0)); if (col.getRed()+col.getGreen()+col.getBlue()<5) { break; @@ -84,7 +87,7 @@ public class Calibrator2 { MyRobot.STARTDRAG.y-=1; } for (int y=yoffset2;y0) { try { - currentScreen = super.createScreenCapture(new Rectangle(calibration_data[0],calibration_data[1],calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1])); + currentScreen = super.createScreenCapture(new Rectangle(calibration_data[0]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,calibration_data[1]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1])); } catch (IllegalArgumentException e) { calibration_data=new int[4]; File f = new File("calibration_data.txt"); f.delete(); } } else { - currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83)); + currentScreen = super.createScreenCapture(new Rectangle(418+18+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,204+83+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,912-18,586-83)); } } private void ReloadCalibrationData() throws IOException { @@ -69,9 +80,9 @@ public class CustomRobot extends Robot{ ReloadCalibrationData(); } if (calibration_data.length>0) { - scoreCurrentScreen = super.createScreenCapture(new Rectangle(calibration_data[0],calibration_data[1],calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1])); + scoreCurrentScreen = super.createScreenCapture(new Rectangle(calibration_data[0]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,calibration_data[1]+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1])); } else { - scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23,204+85,912-18,586-83)); + scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23+gs[MyRobot.screen].getDefaultConfiguration().getBounds().x,204+85+gs[MyRobot.screen].getDefaultConfiguration().getBounds().y,912-18,586-83)); } } diff --git a/DivaBot/src/sig/MyRobot.java b/DivaBot/src/sig/MyRobot.java index cd96ef6..c0ebe9f 100644 --- a/DivaBot/src/sig/MyRobot.java +++ b/DivaBot/src/sig/MyRobot.java @@ -172,17 +172,22 @@ public class MyRobot{ public static void main(String[] args) throws JSONException, IOException, FontFormatException { + File f = new File("screenConfig.txt"); + if (f.exists()) { + String[] data= FileUtils.readFromFile("screenConfig.txt"); + try { + screen=Integer.parseInt(data[0]); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + if (gs.length<=screen) { + screen=0; + } + } catch (Exception e) { + System.err.println("Could not read from screenConfig.txt. It's invalid data, consider deleting the file and run the program again."); + } + } if (args.length>0) { if (args[0].equalsIgnoreCase("calibrate")) { - File f = new File("screenConfig.txt"); - if (f.exists()) { - String[] data= FileUtils.readFromFile("screenConfig.txt"); - try { - screen=Integer.parseInt(data[0]); - } catch (Exception e) { - System.err.println("Could not read from screenConfig.txt. It's invalid data, consider deleting the file and run the program again."); - } - } CALIBRATION_MODE=true; } if (args[0].equalsIgnoreCase("debug")) { @@ -625,7 +630,9 @@ public class MyRobot{ SongData.loadSongsFromFile(); System.setProperty("awt.useSystemAAFontSettings","on"); - FRAME = new JFrame(); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + FRAME = new JFrame(gs[screen].getDefaultConfiguration()); FRAME.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); p.difficulty="EXEX"; p.songname = "Dear"; @@ -979,11 +986,12 @@ public class MyRobot{ void initialize() { System.setProperty("sun.java2d.opengl", "True"); grEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); - grDevice = grEnv.getDefaultScreenDevice(); + GraphicsDevice[] gs = grEnv.getScreenDevices(); + grDevice = gs[screen]; updateScreenInfo(); setKeyMap(); try { - MYROBOT = new CustomRobot(); + MYROBOT = new CustomRobot(gs[screen]); MYROBOT.refreshScreen(); } catch (Exception e) { e.printStackTrace(); @@ -992,7 +1000,7 @@ public class MyRobot{ } X = SCREEN_X / 2; Y = SCREEN_Y / 2; - //MYROBOT.mouseMove(X, Y); + //MYROBOT.mouseMove(X+grDevice.getDefaultConfiguration().getBounds().x, Y+grDevice.getDefaultConfiguration().getBounds().y); PIX_CLOSE_ACTIVE_OFF_MOUSE = new Color(184, 67, 44); PIX_CLOSE_ACTIVE_ON_MOUSE = new Color(210, 35, 2); } @@ -1002,6 +1010,7 @@ public class MyRobot{ SCREEN_Y = grDevice.getDisplayMode().getHeight(); WINDOW_X = grEnv.getMaximumWindowBounds().width; WINDOW_Y = grEnv.getMaximumWindowBounds().height; + //System.out.println(SCREEN_X+"/"+SCREEN_Y+","+WINDOW_X+"/"+WINDOW_Y); } void setKeyMap() { diff --git a/DivaBot/src/sig/Overlay.java b/DivaBot/src/sig/Overlay.java index c5cee6c..fc64b44 100644 --- a/DivaBot/src/sig/Overlay.java +++ b/DivaBot/src/sig/Overlay.java @@ -4,6 +4,8 @@ import java.awt.Color; import java.awt.Cursor; import java.awt.Font; import java.awt.Graphics; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -16,6 +18,7 @@ import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.JPanel; +import sig.utils.FileUtils; import sig.utils.MouseUtils; public class Overlay extends JPanel implements MouseMotionListener,MouseListener{ @@ -98,7 +101,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener } else { g.drawImage(setupWindowButton,MyRobot.screenSize.width-setupWindowButton.getWidth()+1,0,this); - //g.drawImage(changeMonitorButton,MyRobot.screenSize.width-changeMonitorButton.getWidth()+1,setupWindowButton.getHeight(),this); + g.drawImage(changeMonitorButton,MyRobot.screenSize.width-changeMonitorButton.getWidth()+1,setupWindowButton.getHeight(),this); } } @@ -110,7 +113,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener public void mousePressed(MouseEvent e) { Point cursor = MouseUtils.GetCursorPosition(MyRobot.FRAME, e); if (started) { - MyRobot.STARTDRAG=e.getLocationOnScreen(); + MyRobot.STARTDRAG=e.getPoint(); } else if (MyRobot.CALIBRATIONSTATUS.length()>0) { if (cursor.x>=MyRobot.screenSize.width-finishButton.getWidth()+1&& @@ -126,6 +129,21 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener cursor.y>=0&& cursor.y<=setupWindowButton.getHeight()) { started=true; + } else + if (cursor.x>=MyRobot.screenSize.width-setupWindowButton.getWidth()+1&& + cursor.x<=MyRobot.screenSize.width&& + cursor.y>setupWindowButton.getHeight()&& + cursor.y<=setupWindowButton.getHeight()*2) { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] gs = ge.getScreenDevices(); + MyRobot.screen=(MyRobot.screen+1)%gs.length; + FileUtils.writetoFile(new String[] {Integer.toString(MyRobot.screen)}, "screenConfig.txt", false); + try { + Runtime.getRuntime().exec("java -ea -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -jar DivaBot.jar calibrate"); + } catch (IOException e1) { + e1.printStackTrace(); + } + System.exit(0); } } } @@ -134,7 +152,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener public void mouseReleased(MouseEvent e) { if (started) { if (MyRobot.STARTDRAG!=null) { - MyRobot.ENDDRAG=e.getLocationOnScreen(); + MyRobot.ENDDRAG=e.getPoint(); if (MyRobot.STARTDRAG.x>MyRobot.ENDDRAG.x) { int xTemp = MyRobot.STARTDRAG.x; MyRobot.STARTDRAG.x=MyRobot.ENDDRAG.x;