Redo display panel to incorporate new overlay.

secondmonitor
sigonasr2 4 years ago
parent 76aa65c49e
commit 8ba38cba4f
  1. 118
      DivaBot/src/sig/DrawCanvas.java
  2. 26
      DivaBot/src/sig/MyRobot.java

@ -2,8 +2,10 @@ package sig;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
@ -16,6 +18,7 @@ import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.AttributedString;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
@ -34,7 +37,9 @@ import sig.utils.TextUtils;
public class DrawCanvas extends JPanel implements KeyListener{
String difficulty;
String panelText;
Font programFont = new Font("Open Sans Condensed", Font.PLAIN, 32);
//Font programFont = new Font("Alata Regular", Font.PLAIN, 32);
Font programFont;
Font programFontSmall;
String songname = "";
String romanizedname = "";
String englishname = "";
@ -42,6 +47,7 @@ public class DrawCanvas extends JPanel implements KeyListener{
int fcCount = 0;
int passes = 0;
int plays = 0;
double difficultyRating = 0;
Result bestPlay=null;
int overallrating = 0;
BufferedImage bar;
@ -49,6 +55,7 @@ public class DrawCanvas extends JPanel implements KeyListener{
BufferedImage extreme;
BufferedImage exextreme;
BufferedImage overallbar;
BufferedImage panel,paneloverlay,songpanel,songpaneloverlay;
long ratingTime = System.currentTimeMillis()-10000;
int lastRating = -1;
Thread t = null;
@ -56,27 +63,32 @@ public class DrawCanvas extends JPanel implements KeyListener{
int scrollX = 0;
int scrollSpd = 2;
Timer scrollTimer = new Timer();
int displayTimer = 0;
BufferedImage doubleBuffer=null,firstBuffer=null;
boolean targetBuffer=false;
DrawCanvas() {
DrawCanvas() throws FontFormatException, IOException {
Font originalProgramFont = Font.createFont(Font.TRUETYPE_FONT,new File("Alata-Regular.ttf"));
programFont = originalProgramFont.deriveFont(36f);
programFontSmall = originalProgramFont.deriveFont(24f);
try {
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")));
panel = ImageUtils.toCompatibleImage(ImageIO.read(new File("panel.png")));
songpanel = ImageUtils.toCompatibleImage(ImageIO.read(new File("songpanel.png")));
paneloverlay = ImageUtils.toCompatibleImage(ImageIO.read(new File("paneloverlay.png")));
songpaneloverlay = ImageUtils.toCompatibleImage(ImageIO.read(new File("songpanel_overlay.png")));
Thread t = new Thread() {
public void run() {
while (true) {
if (MyRobot.p.scrolling) {
MyRobot.p.scrollX-=MyRobot.p.scrollSpd;
}
MyRobot.p.repaint(0, 0, 1400, 100);
displayTimer++;
MyRobot.p.repaint(0, 0, 1400, 1000);
try {
Thread.sleep(20);
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
@ -106,11 +118,18 @@ public class DrawCanvas extends JPanel implements KeyListener{
t = new Thread() {
public void run() {
try {
JSONObject obj = FileUtils.readJsonArrayFromUrl("http://45.33.13.215:4501/song/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")).getJSONObject(0);
/*JSONObject obj = FileUtils.readJsonArrayFromUrl("http://45.33.13.215:4501/song/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")).getJSONObject(0);
romanizedname = obj.getString("romanized_name");
englishname = obj.getString("english_name");
artist = obj.getString("artist");
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
artist = obj.getString("artist");*/
SongInfo currentSong = SongInfo.getByTitle(MyRobot.p.songname);
if (currentSong.rating.has(difficulty)) {
difficultyRating = currentSong.rating.getDouble(difficulty);
}
romanizedname = currentSong.romanized_name;
englishname = currentSong.english_name;
artist = currentSong.artist;
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
if (obj.has("cool")) {
bestPlay = new Result(MyRobot.p.songname,difficulty,obj.getInt("cool"),obj.getInt("fine"),obj.getInt("safe"),obj.getInt("sad"),obj.getInt("worst"),(float)obj.getDouble("percent"));
} else {
@ -135,7 +154,7 @@ public class DrawCanvas extends JPanel implements KeyListener{
scrolling=false;
}
scrollX = 0;
MyRobot.p.repaint(0,0,1400,100);
MyRobot.p.repaint(0,0,1400,1000);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
@ -153,26 +172,58 @@ public class DrawCanvas extends JPanel implements KeyListener{
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g2.setColor(new Color(0,255,0));
g2.fillRect(0, 0, 1400, 100);
g2.fillRect(0, 0, 1362, 1000);
//if (!MyRobot.isOnSongSelect()) {
//g2.setFont(programFont);
g2.drawImage(bar, 0, 0,null);
//g2.drawImage(bar, 0, 0,null);
g2.drawImage(songpanel, 0,0,null);
g2.drawImage(panel, 0,935,null);
g2.drawImage(panel, 484,935,null);
g2.drawImage(panel, 968,935,null);
DrawUtils.drawOutlineText(g2, programFont, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), ((romanizedname.length()>0)?romanizedname:englishname));
DrawUtils.drawOutlineText(g2, programFontSmall, 8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),((bestPlay!=null)?bestPlay.display():""));
if ((ratingTime>System.currentTimeMillis()-10000)) {
DrawUtils.drawOutlineText(g2, programFont, 484+8, 935+42, 1, 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(g2, programFont, 484+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),Integer.toString(overallrating));
}
if (displayTimer%3==0) {
DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),difficultyRating + " - " + fullNameDifficulty());
} else
if (displayTimer%3==1) {
if (plays>0) {
DrawUtils.drawOutlineText(g2, programFontSmall, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),""+(passes)+"/"+(plays)+" play"+((plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate)");
} else {
DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),"No plays");
}
} else {
if (fcCount>0) {
DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),fcCount +" FC"+(fcCount==1?"":"s")+" "+((int)(Math.floor(((float)fcCount)/plays*100)))+"% FC rate");
} else {
DrawUtils.drawOutlineText(g2, programFont, 968+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),difficultyRating + " - " + fullNameDifficulty());
}
}
/*
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);
DrawUtils.drawOutlineText(g, programFont, 32, 36, 1, 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"+((fcCount>0)?" - "+fcCount+" FC"+(fcCount==1?"":"s")+" "+((int)(Math.floor(((float)fcCount)/plays*100)))+"% FC rate":"")+")":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():"")+" Overall Rating: "+overallrating;
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont);
if (scrollX<-bounds.getWidth()-100) {
scrollX=0;
}
DrawUtils.drawOutlineText(g2, programFont, 32+scrollX, 36, 3, Color.WHITE, new Color(0,0,0,64), text);
DrawUtils.drawOutlineText(g2, programFont, 32+scrollX, 36, 1, Color.WHITE, new Color(0,0,0,64), text);
if (scrolling) {
DrawUtils.drawOutlineText(g2, programFont, 32+scrollX+(int)bounds.getWidth()+100, 36, 3, Color.WHITE, new Color(0,0,0,64), text);
DrawUtils.drawOutlineText(g2, programFont, 32+scrollX+(int)bounds.getWidth()+100, 36, 1, Color.WHITE, new Color(0,0,0,64), text);
}
}
}*/
switch (difficulty) {
/*switch (difficulty) {
case "H":{
g2.drawImage(hard,0,0,20,51,null);
}break;
@ -182,14 +233,39 @@ public class DrawCanvas extends JPanel implements KeyListener{
case "EXEX":{
g2.drawImage(exextreme,0,0,20,51,null);
}break;
}
}*/
//}
//as.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
//g2.drawString(songname, 24, 32);
g2.drawImage(overallbar, 1349, 0,null);
//g2.drawImage(overallbar, 1349, 0,null);
g2.drawImage(songpaneloverlay, 0,0,null);
g2.drawImage(paneloverlay, 0,935,null);
g2.drawImage(paneloverlay, 484,935,null);
g2.drawImage(paneloverlay, 968,935,null);
//System.out.println(System.currentTimeMillis()-startTime+"ms");
}
private String fullNameDifficulty() {
switch (difficulty) {
case "E":{
return "Easy";
}
case "N":{
return "Normal";
}
case "H":{
return "Hard";
}
case "EX":{
return "Extreme";
}
case "EXEX":{
return "Extra Extreme";
}
}
return "";
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub

@ -1,6 +1,7 @@
package sig;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
@ -76,7 +77,8 @@ public class MyRobot{
static CustomRobot 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","みくみくにしてあげる♪","メルト","モノクロ∞ブルースカイ","ゆめゆめ","16 -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","砂の惑星","テオ","初音ミクの消失 -DEAD END-","秘密警察","妄想スケッチ","リンちゃんなう!","ローリンガール","ロキ","ロミオとシンデレラ","エンヴィキャットウォーク","骸骨楽団とリリア","サイハテ","ジグソーパズル","千本桜","ピアノ×フォルテ×スキャンダル","Blackjack","ぽっぴっぽー","裏表ラバーズ","Sadistic.Music∞Factory","デンパラダイム","二次元ドリームフィーバー","ネガポジ*コンティニューズ","初音ミクの激唱","ワールズエンド・ダンスホール","ココロ","システマティック・ラヴ","Knife","二息歩行","PIANOGIRL","夢喰い白黒バク","ブレス・ユア・ブレス","恋は戦争","あなたの歌姫","Starduster","StargazeR","リンリンシグナル","Rosary Pale","多重未来のカルテット~QUARTET THEME~","LIKE THE WIND","AFTER BURNER"};
//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","みくみくにしてあげる♪","メルト","モノクロ∞ブルースカイ","ゆめゆめ","16 -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","砂の惑星","テオ","初音ミクの消失 -DEAD END-","秘密警察","妄想スケッチ","リンちゃんなう!","ローリンガール","ロキ","ロミオとシンデレラ","エンヴィキャットウォーク","骸骨楽団とリリア","サイハテ","ジグソーパズル","千本桜","ピアノ×フォルテ×スキャンダル","Blackjack","ぽっぴっぽー","裏表ラバーズ","Sadistic.Music∞Factory","デンパラダイム","二次元ドリームフィーバー","ネガポジ*コンティニューズ","初音ミクの激唱","ワールズエンド・ダンスホール","ココロ","システマティック・ラヴ","Knife","二息歩行","PIANOGIRL","夢喰い白黒バク","ブレス・ユア・ブレス","恋は戦争","あなたの歌姫","Starduster","StargazeR","リンリンシグナル","Rosary Pale","多重未来のカルテット~QUARTET THEME~","LIKE THE WIND","AFTER BURNER"};
static SongInfo SONGNAMES[] = new SongInfo[] {};
static String NEWSONGS[] = new String[] {};
int SCREEN_X;
int SCREEN_Y;
@ -126,7 +128,12 @@ public class MyRobot{
static boolean onSongSelect=false;
public static void main(String[] args) {
public static void main(String[] args) throws JSONException, IOException, FontFormatException {
JSONObject obj = FileUtils.readJsonFromUrl("http://www.projectdivar.com/songs");
SONGNAMES = new SongInfo[JSONObject.getNames(obj).length];
for (String key : JSONObject.getNames(obj)) {
SONGNAMES[Integer.parseInt(key)-1] = new SongInfo(obj.getJSONObject(key));
}
new MyRobot().go();
}
@ -154,6 +161,7 @@ public class MyRobot{
p.lastRating = p.overallrating;
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
@ -167,7 +175,7 @@ public class MyRobot{
if (checkSongSelect()) {
if (!overlayHidden) {
overlayHidden=true;
p.repaint(0, 0, 1400, 100);
p.repaint(0, 0, 1400, 1000);
}
GetCurrentSong();
GetCurrentDifficulty();
@ -190,7 +198,7 @@ public class MyRobot{
} else {
if (overlayHidden) {
overlayHidden=false;
p.repaint(0, 0, 1400, 100);
p.repaint(0, 0, 1400, 1000);
}
/*selectedSong=new SongData("test",new Color[] {});
difficulty="EXEX";*/
@ -462,7 +470,7 @@ public class MyRobot{
50);
}
void go() {
void go() throws FontFormatException, IOException {
initialize();
//gotoxy(100, 100);
SCREEN = new Color[SCREEN_X][SCREEN_Y];
@ -573,13 +581,13 @@ public class MyRobot{
}
});*/
f.setVisible(true);
f.setSize(1416, 51+48);
f.setSize(1362, 1036);
f.add(p);
f.setTitle("DivaBot");
title = new JTextField();
title.setSize(200,100);
title.setText((currentSong>=SONGNAMES.length)?"DONE!":SONGNAMES[currentSong]);
SongData s = SongData.getByTitle(SONGNAMES[currentSong]);
title.setText((currentSong>=SONGNAMES.length)?"DONE!":SONGNAMES[currentSong].name);
SongData s = SongData.getByTitle(SONGNAMES[currentSong].name);
/*BufferedImage bufferedImage = new BufferedImage(TypeFace.WIDTH, TypeFace.HEIGHT,
BufferedImage.TYPE_INT_RGB);
for (int i=0;i<TypeFace.WIDTH;i++) {
@ -681,7 +689,7 @@ public class MyRobot{
public static boolean checkSongSelect() throws IOException {
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(1255,824,20,20)).getRGB(10, 10));
onSongSelect = c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
System.out.println(onSongSelect+"/"+c);
//System.out.println(onSongSelect+"/"+c);
return onSongSelect;
}

Loading…
Cancel
Save