From 07e207ebed1cc71b38c497b01969802d23c2812e Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 12 Jul 2020 19:16:54 +0900 Subject: [PATCH] Finish up overlay bar. Fix all bugs. --- .../org.eclipse.core.resources.prefs | 2 +- DivaBot/src/{ => sig}/DrawPanel.java | 70 ++++++++++++++----- DivaBot/src/{ => sig}/MyRobot.java | 7 +- DivaBot/src/{ => sig}/Result.java | 1 + DivaBot/src/{ => sig}/SongData.java | 1 + DivaBot/src/{ => sig}/TypeFace.java | 1 + DivaBot/src/sig/utils/TextUtils.java | 5 +- 7 files changed, 63 insertions(+), 24 deletions(-) rename DivaBot/src/{ => sig}/DrawPanel.java (64%) rename DivaBot/src/{ => sig}/MyRobot.java (99%) rename DivaBot/src/{ => sig}/Result.java (97%) rename DivaBot/src/{ => sig}/SongData.java (99%) rename DivaBot/src/{ => sig}/TypeFace.java (99%) diff --git a/DivaBot/.settings/org.eclipse.core.resources.prefs b/DivaBot/.settings/org.eclipse.core.resources.prefs index aea1f3f..c0f5aca 100644 --- a/DivaBot/.settings/org.eclipse.core.resources.prefs +++ b/DivaBot/.settings/org.eclipse.core.resources.prefs @@ -1,3 +1,3 @@ eclipse.preferences.version=1 -encoding//src/MyRobot.java=UTF-8 +encoding//src/sig/MyRobot.java=UTF-8 encoding/colorData=UTF-8 diff --git a/DivaBot/src/DrawPanel.java b/DivaBot/src/sig/DrawPanel.java similarity index 64% rename from DivaBot/src/DrawPanel.java rename to DivaBot/src/sig/DrawPanel.java index 21a8464..aef1cdc 100644 --- a/DivaBot/src/DrawPanel.java +++ b/DivaBot/src/sig/DrawPanel.java @@ -1,15 +1,19 @@ +package sig; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.font.TextAttribute; +import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.text.AttributedString; +import java.util.Timer; +import java.util.TimerTask; import javax.imageio.ImageIO; import javax.swing.JPanel; @@ -20,6 +24,7 @@ import org.json.JSONObject; import sig.utils.DrawUtils; import sig.utils.FileUtils; +import sig.utils.TextUtils; public class DrawPanel extends JPanel{ String difficulty; @@ -42,6 +47,10 @@ public class DrawPanel extends JPanel{ long ratingTime = System.currentTimeMillis()-10000; int lastRating = -1; Thread t = null; + boolean scrolling = false; + int scrollX = 0; + int scrollSpd = 2; + Timer scrollTimer = new Timer(); DrawPanel() { try { @@ -50,6 +59,18 @@ public class DrawPanel extends JPanel{ exextreme = ImageIO.read(new File("exex.png")); extreme = ImageIO.read(new File("ex.png")); hard = ImageIO.read(new File("hd.png")); + + + Timer t = new Timer(); + t.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + if (MyRobot.p.scrolling) { + MyRobot.p.scrollX-=MyRobot.p.scrollSpd; + MyRobot.p.repaint(); + } + } + },0,20); } catch (IOException e) { e.printStackTrace(); } @@ -92,6 +113,14 @@ public class DrawPanel extends JPanel{ 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); + Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont); + if (bounds.getWidth()>1345) { + scrolling=true; + } else { + scrolling=false; + } + scrollX = 0; MyRobot.p.repaint(); } catch (JSONException | IOException e) { e.printStackTrace(); @@ -109,23 +138,30 @@ public class DrawPanel extends JPanel{ RenderingHints.VALUE_FRACTIONALMETRICS_ON); g.setColor(new Color(0,255,0)); g.fillRect(0, 0, 1400, 100); - g.setFont(programFont); - g.drawImage(bar, 0, 0, this); - 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 { - DrawUtils.drawOutlineText(g, programFont, 32, 36, 3, Color.WHITE, new Color(0,0,0,64), 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)); - } - switch (difficulty) { - case "H":{ - g.drawImage(hard,0,0,20,51,this); - }break; - case "EX":{ - g.drawImage(extreme,0,0,20,51,this); - }break; - case "EXEX":{ - g.drawImage(exextreme,0,0,20,51,this); - }break; + if (!MyRobot.isOnSongSelect()) { + g.setFont(programFont); + g.drawImage(bar, 0, 0, this); + 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); + 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); + } + switch (difficulty) { + case "H":{ + g.drawImage(hard,0,0,20,51,this); + }break; + case "EX":{ + g.drawImage(extreme,0,0,20,51,this); + }break; + case "EXEX":{ + g.drawImage(exextreme,0,0,20,51,this); + }break; + } } //as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); //g.drawString(songname, 24, 32); diff --git a/DivaBot/src/MyRobot.java b/DivaBot/src/sig/MyRobot.java similarity index 99% rename from DivaBot/src/MyRobot.java rename to DivaBot/src/sig/MyRobot.java index 16ba9bb..0a9f24f 100644 --- a/DivaBot/src/MyRobot.java +++ b/DivaBot/src/sig/MyRobot.java @@ -1,3 +1,4 @@ +package sig; import java.awt.Color; import java.awt.Font; import java.awt.GraphicsDevice; @@ -65,7 +66,7 @@ import sig.utils.ImageUtils; import sig.utils.SoundUtils; public class MyRobot{ - Robot MYROBOT; + static Robot MYROBOT; Color SCREEN[][]; static SongData SONGS[]; static String SONGNAMES[] = new String[] {"Yellow","The secret garden","Tell Your World","愛言葉","Weekender Girl","歌に形はないけれど","えれくとりっく・えんじぇぅ","神曲","カンタレラ","巨大少女","クローバー♣クラブ","恋スルVOC@LOID","桜ノ雨","39","深海シティアンダーグラウンド","深海少女","積乱雲グラフィティ","千年の独奏歌","ダブルラリアット","ハジメテノオト","初めての恋が終わる時","packaged","Palette","FREELY TOMORROW","from Y to Y","みくみくにしてあげる♪","メルト","モノクロ∞ブルースカイ","ゆめゆめ","1/6 -out of the gravity-","ACUTE","インタビュア","LOL -lots of laugh-","Glory 3usi9","soundless voice","ジェミニ","白い雪のプリンセスは","スキキライ","タイムマシン","Dear","DECORATOR","トリコロール・エア・ライン","Nostalogic","Hand in Hand","Fire◎Flower","ブラック★ロックシューター","メテオ","ワールドイズマイン","アマツキツネ","erase or zero","エレクトロサチュレイタ","on the rocks","からくりピエロ","カラフル×メロディ","Catch the Wave","キャットフード","サマーアイドル","shake it!","Just Be Friends","スイートマジック","SPiCa -39's Giving Day Edition-","番凩","テレカクシ思春期","天樂","どういうことなの!?","東京テディベア","どりーみんチュチュ","トリノコシティ","ネトゲ廃人シュプレヒコール","No Logic","ハイハハイニ","はじめまして地球人さん","*ハロー、プラネット。 (I.M.PLSE-EDIT)","Hello, Worker","忘却心中","magnet","右肩の蝶","結ンデ開イテ羅刹ト骸","メランコリック","リモコン","ルカルカ★ナイトフィーバー","炉心融解","WORLD'S END UMBRELLA","アカツキアライヴァル","アゲアゲアゲイン","1925","え?あぁ、そう。","エイリアンエイリアン","ODDS&ENDS","君の体温","こっち向いて Baby","壊セ壊セ","39みゅーじっく!","サンドリヨン","SING&SMILE","スノーマン","DYE","なりすましゲンガー","ヒバナ","ヒビカセ","ブラックゴールド","ミラクルペイント","指切り","ありふれたせかいせいふく","アンハッピーリフレイン","大江戸ジュリアナイト","ゴーストルール","こちら、幸福安心委員会です。","孤独の果て -extend edition-","ジターバグ","Sweet Devil","砂の惑星","テオ","初音ミクの消失","秘密警察","妄想スケッチ","リンちゃんなう!","ローリンガール","ロキ","ロミオとシンデレラ","エンヴィキャットウォーク","骸骨楽団とリリア","サイハテ","ジグソーパズル","千本桜","ピアノ×フォルテ×スキャンダル","Blackjack","ぽっぴっぽー","裏表ラバーズ","Sadistic.Music∞Factory","デンパラダイム","二次元ドリームフィーバー","ネガポジ*コンティニューズ","初音ミクの激唱","ワールズエンド・ダンスホール","ココロ","システマティック・ラヴ","Knife","二息歩行","PIANOGIRL","夢喰い白黒バク"}; @@ -93,7 +94,7 @@ public class MyRobot{ static JTextField title; final int WIDTH = 200; final int HEIGHT = 5; - static DrawPanel p; + public static DrawPanel p; static int currentSong = 0; static SongData selectedSong = null; static String difficulty = "H"; //H=Hard EX=Extreme EXEX=Extra Extreme @@ -606,7 +607,7 @@ public class MyRobot{ System.out.println(" Passed ("+(System.currentTimeMillis()-startTime)+"ms)!"); } - boolean isOnSongSelect() { + public static boolean isOnSongSelect() { Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(1255,824,20,20)).getRGB(10, 10)); return c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213; } diff --git a/DivaBot/src/Result.java b/DivaBot/src/sig/Result.java similarity index 97% rename from DivaBot/src/Result.java rename to DivaBot/src/sig/Result.java index 5aed8c7..53b7e81 100644 --- a/DivaBot/src/Result.java +++ b/DivaBot/src/sig/Result.java @@ -1,3 +1,4 @@ +package sig; public class Result { String songName; diff --git a/DivaBot/src/SongData.java b/DivaBot/src/sig/SongData.java similarity index 99% rename from DivaBot/src/SongData.java rename to DivaBot/src/sig/SongData.java index 373265c..629573f 100644 --- a/DivaBot/src/SongData.java +++ b/DivaBot/src/sig/SongData.java @@ -1,3 +1,4 @@ +package sig; import java.awt.Color; import sig.utils.FileUtils; diff --git a/DivaBot/src/TypeFace.java b/DivaBot/src/sig/TypeFace.java similarity index 99% rename from DivaBot/src/TypeFace.java rename to DivaBot/src/sig/TypeFace.java index d00dfb2..c12b4df 100644 --- a/DivaBot/src/TypeFace.java +++ b/DivaBot/src/sig/TypeFace.java @@ -1,3 +1,4 @@ +package sig; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Image; diff --git a/DivaBot/src/sig/utils/TextUtils.java b/DivaBot/src/sig/utils/TextUtils.java index f34a346..693f45f 100644 --- a/DivaBot/src/sig/utils/TextUtils.java +++ b/DivaBot/src/sig/utils/TextUtils.java @@ -6,13 +6,12 @@ import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.List; - -import sig.sigIRC; +import sig.MyRobot; public class TextUtils { public static Rectangle2D calculateStringBoundsFont(String msg, Font font) { - FontRenderContext frc = sigIRC.panel.getFontMetrics(font).getFontRenderContext(); + FontRenderContext frc = MyRobot.p.getFontMetrics(font).getFontRenderContext(); return font.getStringBounds(msg, frc); }