diff --git a/DivaBot/src/sig/DrawPanel.java b/DivaBot/src/sig/DrawCanvas.java similarity index 73% rename from DivaBot/src/sig/DrawPanel.java rename to DivaBot/src/sig/DrawCanvas.java index aef1cdc..6fc2400 100644 --- a/DivaBot/src/sig/DrawPanel.java +++ b/DivaBot/src/sig/DrawCanvas.java @@ -1,9 +1,11 @@ package sig; +import java.awt.Canvas; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; +import java.awt.Toolkit; import java.awt.font.TextAttribute; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; @@ -24,9 +26,10 @@ import org.json.JSONObject; import sig.utils.DrawUtils; import sig.utils.FileUtils; +import sig.utils.ImageUtils; import sig.utils.TextUtils; -public class DrawPanel extends JPanel{ +public class DrawCanvas extends JPanel{ String difficulty; String panelText; Font programFont = new Font("Open Sans Condensed", Font.PLAIN, 32); @@ -51,26 +54,35 @@ public class DrawPanel extends JPanel{ int scrollX = 0; int scrollSpd = 2; Timer scrollTimer = new Timer(); + BufferedImage doubleBuffer=null,firstBuffer=null; + boolean targetBuffer=false; - DrawPanel() { + DrawCanvas() { + try { - bar = ImageIO.read(new File("divabar.png")); - overallbar = ImageIO.read(new File("overlaybar.png")); - exextreme = ImageIO.read(new File("exex.png")); - extreme = ImageIO.read(new File("ex.png")); - hard = ImageIO.read(new File("hd.png")); + bar = ImageUtils.toCompatibleImage(ImageIO.read(new File("divabar.png"))); + overallbar = ImageUtils.toCompatibleImage(ImageIO.read(new File("overlaybar.png"))); + exextreme = ImageUtils.toCompatibleImage(ImageIO.read(new File("exex.png"))); + extreme = ImageUtils.toCompatibleImage(ImageIO.read(new File("ex.png"))); + hard = ImageUtils.toCompatibleImage(ImageIO.read(new File("hd.png"))); - Timer t = new Timer(); - t.scheduleAtFixedRate(new TimerTask() { - @Override + Thread t = new Thread() { public void run() { - if (MyRobot.p.scrolling) { - MyRobot.p.scrollX-=MyRobot.p.scrollSpd; - MyRobot.p.repaint(); + while (true) { + if (MyRobot.p.scrolling) { + MyRobot.p.scrollX-=MyRobot.p.scrollSpd; + } + MyRobot.p.repaint(0, 0, 1400, 100); + try { + Thread.sleep(20); + } catch (InterruptedException e) { + e.printStackTrace(); + } } } - },0,20); + }; + t.start(); } catch (IOException e) { e.printStackTrace(); } @@ -86,7 +98,7 @@ public class DrawPanel extends JPanel{ passes=0; fcCount=0; artist=""; - this.repaint(); + this.repaint(0,0,1400,100); if (t!=null && t.isAlive()) { t.stop(); } @@ -112,8 +124,9 @@ public class DrawPanel extends JPanel{ /*obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2"); lastRating = overallrating; overallrating = (int)obj.getDouble("rating"); - if (lastRating0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():""+" Overall Rating: "+overallrating); + if (lastRating0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():"")+" Overall Rating: "+overallrating; Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont); if (bounds.getWidth()>1345) { scrolling=true; @@ -121,7 +134,7 @@ public class DrawPanel extends JPanel{ scrolling=false; } scrollX = 0; - MyRobot.p.repaint(); + MyRobot.p.repaint(0,0,1400,100); } catch (JSONException | IOException e) { e.printStackTrace(); } @@ -130,41 +143,44 @@ public class DrawPanel extends JPanel{ t.start(); } - protected void paintComponent(Graphics g) { + public void paintComponent(Graphics g) { super.paintComponent(g); - ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + Graphics2D g2 = (Graphics2D)g; + long startTime = System.currentTimeMillis(); + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, + g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - g.setColor(new Color(0,255,0)); - g.fillRect(0, 0, 1400, 100); - if (!MyRobot.isOnSongSelect()) { - g.setFont(programFont); - g.drawImage(bar, 0, 0, this); + g2.setColor(new Color(0,255,0)); + g2.fillRect(0, 0, 1400, 100); + //if (!MyRobot.isOnSongSelect()) { + //g2.setFont(programFont); + g2.drawImage(bar, 0, 0,null); if (ratingTime>System.currentTimeMillis()-10000) { DrawUtils.drawOutlineText(g, programFont, 32, 36, 3, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64), "Rating up! "+lastRating+" -> "+overallrating); } else { - String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():""+" Overall Rating: "+overallrating); + String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():"")+" Overall Rating: "+overallrating; Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont); if (scrollX<-bounds.getWidth()-100) { scrollX=(int)bounds.getWidth()+100; } - DrawUtils.drawOutlineText(g, programFont, 32+scrollX, 36, 3, Color.WHITE, new Color(0,0,0,64) , text); + DrawUtils.drawOutlineText(g2, programFont, 32+scrollX, 36, 3, Color.WHITE, new Color(0,0,0,64), text); } switch (difficulty) { case "H":{ - g.drawImage(hard,0,0,20,51,this); + g2.drawImage(hard,0,0,20,51,null); }break; case "EX":{ - g.drawImage(extreme,0,0,20,51,this); + g2.drawImage(extreme,0,0,20,51,null); }break; case "EXEX":{ - g.drawImage(exextreme,0,0,20,51,this); + g2.drawImage(exextreme,0,0,20,51,null); }break; } - } + //} //as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); - //g.drawString(songname, 24, 32); - g.drawImage(overallbar, 1349, 0, this); + //g2.drawString(songname, 24, 32); + g2.drawImage(overallbar, 1349, 0,null); + //System.out.println(System.currentTimeMillis()-startTime+"ms"); } } diff --git a/DivaBot/src/sig/MyRobot.java b/DivaBot/src/sig/MyRobot.java index 0a9f24f..507629c 100644 --- a/DivaBot/src/sig/MyRobot.java +++ b/DivaBot/src/sig/MyRobot.java @@ -94,7 +94,7 @@ public class MyRobot{ static JTextField title; final int WIDTH = 200; final int HEIGHT = 5; - public static DrawPanel p; + public static DrawCanvas p; static int currentSong = 0; static SongData selectedSong = null; static String difficulty = "H"; //H=Hard EX=Extreme EXEX=Extra Extreme @@ -102,6 +102,7 @@ public class MyRobot{ int lastcool,lastfine,lastsafe,lastsad,lastworst; float lastpercent; + boolean lastfail; long lastSongSelectTime = System.currentTimeMillis(); static TypeFace typeface1,typeface2; @@ -113,6 +114,8 @@ public class MyRobot{ boolean recordingResults=false; long lastReportedEyeTrackingTime = System.currentTimeMillis(); + boolean overlayHidden=false; + static boolean onSongSelect=false; public static void main(String[] args) { @@ -122,13 +125,20 @@ public class MyRobot{ boolean EyeTrackingIsOn() { //1888,760 if (System.currentTimeMillis()-5000>lastReportedEyeTrackingTime) { - BufferedImage img = MYROBOT.createScreenCapture(new Rectangle(1871,760,1,1)); + BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(1866,759,1,1))); Color pixel = new Color(img.getRGB(0, 0)); lastReportedEyeTrackingTime=System.currentTimeMillis(); eyeTrackingSceneOn=pixel.getRed()<60 && pixel.getGreen()<60 && pixel.getBlue()<60; } return eyeTrackingSceneOn; } + + boolean textFailPixel(BufferedImage img) { + Color failPixel = new Color(img.getRGB(0, 0)); + //System.out.println(failPixel); + //r=128,g=5,b=232 + return failPixel.getRed()>=50 && failPixel.getRed()<=150 && failPixel.getGreen()>=50 && failPixel.getGreen()<=150 && failPixel.getBlue()>=50 && failPixel.getBlue()<=150; + } void BotMain() { try { @@ -145,8 +155,11 @@ public class MyRobot{ t.scheduleAtFixedRate(new TimerTask() { @Override public void run() { - - if (isOnSongSelect()) { + if (checkSongSelect()) { + if (!overlayHidden) { + overlayHidden=true; + p.repaint(0, 0, 1400, 100); + } GetCurrentSong(); GetCurrentDifficulty(); recordedResults=false; @@ -160,6 +173,10 @@ public class MyRobot{ } lastSongSelectTime = System.currentTimeMillis(); } else { + if (overlayHidden) { + overlayHidden=false; + p.repaint(0, 0, 1400, 100); + } /*selectedSong=new SongData("test",new Color[] {}); difficulty="EXEX";*/ if ((selectedSong!=null && difficulty!=null) /*|| true*/) { @@ -172,6 +189,7 @@ public class MyRobot{ lastSongSelectTime=System.currentTimeMillis(); if (EyeTrackingIsOn()) { eyeTrackingSceneOn=false; + lastReportedEyeTrackingTime=System.currentTimeMillis(); gotoxy(800,64); click(); gotoxy(1870,761); @@ -195,6 +213,8 @@ public class MyRobot{ int safe = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,518,115,26)),new File(tmp,"safe")); int sad = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,553,115,26)),new File(tmp,"sad")); int worst = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),new File(tmp,"worst")); + + boolean fail = textFailPixel(MYROBOT.createScreenCapture(new Rectangle(952,385,1,1))); /*try { ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),"png",new File("worst.png")); } catch (IOException e) { @@ -204,7 +224,7 @@ public class MyRobot{ if (cool==-1 || fine==-1 || safe==-1 || sad==-1 || worst==-1 || percent==-0.01f) { System.out.println("Waiting for results to populate..."); } else - if (cool!=lastcool || lastfine!=fine || lastsafe!=safe || lastsad!=sad || lastworst!=worst /*|| lastpercent!=percent*/){ + if (fail!=lastfail || cool!=lastcool || lastfine!=fine || lastsafe!=safe || lastsad!=sad || lastworst!=worst /*|| lastpercent!=percent*/){ System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+cool+"/"+fine+"/"+safe+"/"+sad+"/"+worst+" "+percent+"%"); File songFolder = new File(selectedSong.title+"/"+difficulty); if (!songFolder.exists()) { @@ -233,10 +253,13 @@ public class MyRobot{ lastsad=sad; lastworst=worst; lastpercent=percent; - results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent)); + lastfail=fail; + + results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail)); SoundUtils.playSound("collect_item.wav"); if (!EyeTrackingIsOn()) { eyeTrackingSceneOn=true; + lastReportedEyeTrackingTime=System.currentTimeMillis(); gotoxy(800,64); click(); gotoxy(1870,761); @@ -263,6 +286,7 @@ public class MyRobot{ params.add(new BasicNameValuePair("sad", Integer.toString(r.sad))); params.add(new BasicNameValuePair("worst", Integer.toString(r.worst))); params.add(new BasicNameValuePair("percent", Float.toString(r.percent))); + params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail))); try { httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); } catch (UnsupportedEncodingException e) { @@ -296,9 +320,8 @@ public class MyRobot{ p.lastRating = p.overallrating; p.overallrating = (int)obj.getDouble("rating"); if (p.lastRating=254 && c1.getGreen()>=254 && c1.getBlue()>=254 && c2.getRed()==16 && c2.getGreen()==222 && c2.getBlue()==202 && c3.getRed()>=220 && c3.getRed()<=255 && c3.getGreen()>=220 && c3.getGreen()<=255 && c3.getBlue()>=160 && c3.getBlue()<=220; @@ -395,7 +418,7 @@ public class MyRobot{ } } private void GetCurrentSong() { - BufferedImage img = MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)); + BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT))); Color[] col = new Color[WIDTH*HEIGHT]; for (int i=0;i