diff --git a/DivaBot/config.txt b/DivaBot/config.txt index c404a95..87d001f 100644 --- a/DivaBot/config.txt +++ b/DivaBot/config.txt @@ -1,3 +1,10 @@ -WIDTH 546 -HEIGHT 384 -BACKGROUND -10092442 +LAST_HEIGHT 48 +WIDTH 1071 +HEIGHT 765 +BACKGROUND -6697729 +LAST_TEXT -6723841 +LAST_FONT Serif.italic +LAST_FONTSIZE 32 +LAST_BACKGROUND -16776961 +LAST_WIDTH 200 +LAST_DELAY 10000 diff --git a/DivaBot/src/sig/Display.java b/DivaBot/src/sig/Display.java new file mode 100644 index 0000000..895d5cf --- /dev/null +++ b/DivaBot/src/sig/Display.java @@ -0,0 +1,186 @@ +package sig; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics; +import java.util.HashMap; + +public class Display { + Color backgroundCol=Color.BLUE; + Color textCol=Color.WHITE; + Font font=new Font("Batang",Font.PLAIN,32); + int fontSize=32; + int x; + int y; + int width=200; + int height=48; + int delay=10000; + String[] labels; + String currentText; + int cycle=0; + boolean deleted=false; + Display() { + HashMap config = MyRobot.p.configData; + if (config.containsKey("LAST_BACKGROUND")) { + try { + backgroundCol=new Color(Integer.parseInt(config.get("LAST_BACKGROUND"))); + } catch (NumberFormatException e) { + backgroundCol=Color.BLUE; + } + } + if (config.containsKey("LAST_TEXT")) { + try { + textCol=new Color(Integer.parseInt(config.get("LAST_TEXT"))); + } catch (NumberFormatException e) { + textCol=Color.WHITE; + } + } + if (config.containsKey("LAST_WIDTH")) { + try { + width=Integer.parseInt(config.get("LAST_WIDTH")); + } catch (NumberFormatException e) { + width=200; + } + } + if (config.containsKey("LAST_HEIGHT")) { + try { + height=Integer.parseInt(config.get("LAST_HEIGHT")); + } catch (NumberFormatException e) { + height=48; + } + } + x=0; + y=0; + if (config.containsKey("LAST_DELAY")) { + try { + delay=Integer.parseInt(config.get("LAST_DELAY")); + } catch (NumberFormatException e) { + delay=10000; + } + } + cycle=0; + if (config.containsKey("LAST_FONTSIZE")) { + try { + fontSize=Integer.parseInt(config.get("LAST_FONTSIZE")); + } catch (NumberFormatException e) { + fontSize=32; + } + } + if (config.containsKey("LAST_FONT")) { + try { + font = new Font(config.get("LAST_FONT"),Font.PLAIN,fontSize); + } catch (NumberFormatException e) { + font = new Font("Batang",Font.PLAIN,fontSize); + } + } + labels = new String[]{"Add a label!"}; + currentText=interpretLabel(labels[cycle]); + Thread t = new Thread() { + public void run() { + try { + while (!deleted) { + AdvanceCycle(); + MyRobot.p.repaint(); + Thread.sleep(delay); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private void AdvanceCycle() { + cycle=(cycle+1)%labels.length; + currentText=interpretLabel(labels[cycle]); + } + }; + t.start(); + } + + public void draw(Graphics g) { + g.setColor(backgroundCol); + g.fill3DRect(x, y, width, height, true); + g.setColor(textCol); + g.setFont(font); + g.drawString(currentText,x,y+fontSize); + } + + private String interpretLabel(String string){ + DrawCanvas data = MyRobot.p; + try { + switch (string) { + case "Best Play":{ + if (data.bestPlayTime>System.currentTimeMillis()-10000) { + return "New Record!"; + } else { + return ((data.bestPlay!=null)?data.bestPlay.display():""); + } + } + case "Overall Rating":{ + if (data.ratingTime>System.currentTimeMillis()-10000) { + return "Rating up! "+data.lastRating+" -> "+data.overallrating; + } else { + return Integer.toString(data.overallrating); + } + } + case "Song Difficulty":{ + return data.difficultyRating + " - " + fullNameDifficulty(data.difficulty); + } + case "Song Title (Japanese)":{ + return data.songname + " by "+data.artist; + } + case "Song Title (Romanized)":{ + return ((data.romanizedname.length()>0)?data.romanizedname:data.englishname) + " by "+data.artist; + } + case "Song Title (Japanese+Romanized)":{ + return (data.songname + " - " + ((data.romanizedname.length()>0)?data.romanizedname:data.englishname)) + " by "+data.artist; + } + case "Song Title (English)":{ + return data.englishname + " by "+data.artist; + } + case "Song Title (Japanese+Romanized+ENG)":{ + return (data.songname + " - " + ((data.romanizedname.length()>0)?(data.romanizedname.equalsIgnoreCase(data.englishname))?data.romanizedname:data.romanizedname+" ("+data.englishname+")":data.englishname)) + " by "+data.artist; + } + case "Play Count":{ + return Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":""); + } + case "Pass/Play Count":{ + return Integer.toString(data.passes) + "/" + Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":""); + } + case "Pass/Play Count (+%)":{ + return (data.passes)+"/"+(data.plays)+" play"+((data.plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)data.passes)/data.plays*100)))+"% pass rate)"; + } + case "FC Count":{ + return data.fcCount +" FC"+(data.fcCount==1?"":"s"); + } + case "FC Count (+%)":{ + return data.fcCount +" FC"+(data.fcCount==1?"":"s")+" "+((int)(Math.floor(((float)data.fcCount)/data.plays*100)))+"% FC rate"; + } + default:{ + return string; + } + } + } catch(NullPointerException e) { + return string; + } + } + private String fullNameDifficulty(String difficulty) { + switch (difficulty) { + case "E":{ + return "Easy"; + } + case "N":{ + return "Normal"; + } + case "H":{ + return "Hard"; + } + case "EX":{ + return "Extreme"; + } + case "EXEX":{ + return "Extra Extreme"; + } + } + return ""; + } +} diff --git a/DivaBot/src/sig/DisplayManager.java b/DivaBot/src/sig/DisplayManager.java index dad0918..99d94c1 100644 --- a/DivaBot/src/sig/DisplayManager.java +++ b/DivaBot/src/sig/DisplayManager.java @@ -9,6 +9,8 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.io.File; @@ -30,36 +32,42 @@ import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.ListCellRenderer; import javax.swing.ListSelectionModel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import javax.swing.text.BadLocationException; -public class DisplayManager extends JPanel implements MouseListener,ListSelectionListener{ - JFrame f = new JFrame(); - GridBagConstraints g = new GridBagConstraints(); - Font[] fontList = null; - ColorButton colorButton; - ColorButton colorButton2; - JTextField fontSizeInput; - JTextField widthInput; - JTextField heightInput; - JTextField delayInput; - DefaultListModel model = new DefaultListModel(); - DefaultListModel model2 = new DefaultListModel(); +public class DisplayManager extends JPanel implements MouseListener,ListSelectionListener,ItemListener{ + public static JFrame f = new JFrame(); + static GridBagConstraints g = new GridBagConstraints(); + static Font[] fontList = null; + static ColorButton colorButton; + static ColorButton colorButton2; + static JTextField fontSizeInput; + static JTextField widthInput; + static JTextField heightInput; + static JTextField delayInput; + static DefaultListModel model = new DefaultListModel(); + static DefaultListModel model2 = new DefaultListModel(); + static JComboBox fonts; JList labels = new JList(model); JList displayedLabels = new JList(model2); - String[] AVAILABLELABELS = new String[] { + public static Display selectedDisplay; + static String[] AVAILABLELABELS = new String[] { "Best Play", "Overall Rating", "Song Difficulty", "Song Title (Japanese)", "Song Title (Romanized)", + "Song Title (Japanese+Romanized)", "Song Title (English)", - "Play", - "Play/Pass Count (+%)", - "Play/Pass Count (+%)", + "Song Title (Japanese+Romanized+ENG)", + "Play Count", + "Pass/Play Count", + "Pass/Play Count (+%)", "FC Count", - "FC/Play Count", - "FC/Play Count (+%)" + "FC Count (+%)" }; DisplayManager() throws IOException { @@ -70,8 +78,9 @@ public class DisplayManager extends JPanel implements MouseListener,ListSelectio List tempFontList = new ArrayList(Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts())); for (int i=0;i configData = new HashMap(); + List displays = new ArrayList(); + public static Display selectedDisplay = null; + public static Display draggedDisplay = null; DrawCanvas() throws FontFormatException, IOException { loadConfig(); addConfigButton = ImageIO.read(new File("addDisplay.png")); @@ -209,41 +216,9 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener, g2.drawImage(addConfigButton,getWidth()-addConfigButton.getWidth()+1,0,this); g2.drawImage(backgroundColorButton,getWidth()-backgroundColorButton.getWidth()+1,backgroundColorButton.getHeight()+1,this); - -// String songDisplay = ((romanizedname.length()>0)?romanizedname:englishname) + " - " + artist; -// Rectangle2D bounds = TextUtils.calculateStringBoundsFont(songDisplay, programFont); -// if (bounds.getWidth()>675) { -// DrawUtils.drawOutlineText(g2, programFontSmall, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay); -// } else { -// DrawUtils.drawOutlineText(g2, programFont, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay); -// } -// -// if ((bestPlayTime>System.currentTimeMillis()-10000)) { -// DrawUtils.drawOutlineText(g2, programFont, 8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-bestPlayTime))/5,255)), new Color(0,0,0,64),"New Record!"); -// } else { -// 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, programFontSmall, 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()); -// } -// } + for (int i=0;i=getWidth()-addConfigButton.getWidth()&& + Point cursor = GetCursorPosition(e); + switch (e.getButton()) { + case MouseEvent.BUTTON3:{ + selectedDisplay=null; + for (int i=0;i=d.x&& + cursor.x<=d.x+d.width&& + cursor.y>=d.y&& + cursor.y<=d.y+d.height) { + selectedDisplay=d; + break; + } + } + DeleteDisplay(); + }break; + case MouseEvent.BUTTON1:{ + //System.out.println(cursor+"/"+addConfigButton.getHeight()); + if (cursor.x>=getWidth()-addConfigButton.getWidth()&& + cursor.x<=getWidth()&& + cursor.y>=0&& + cursor.y<=addConfigButton.getHeight()) { + Display d = new Display(); + displays.add(d); + selectedDisplay=d; + DisplayManager.setupSettings(selectedDisplay); + return; + } else + if (cursor.x>=getWidth()-addConfigButton.getWidth()&& cursor.x<=getWidth()&& - cursor.y>=0&& - cursor.y<=addConfigButton.getHeight()) { - MyRobot.FRAME.setCursor(new Cursor(Cursor.HAND_CURSOR)); - } else - if (cursor.x>=getWidth()-addConfigButton.getWidth()&& - cursor.x<=getWidth()&& - cursor.y>=addConfigButton.getHeight()+1&& - cursor.y<=addConfigButton.getHeight()+1+addConfigButton.getHeight()) { - Color c = MyRobot.CP.getBackgroundColor(); - if (c!=null) { - configData.put("BACKGROUND",Integer.toString(c.getRGB())); - applyConfig(); - } - } else - { - MyRobot.FRAME.setCursor(Cursor.getDefaultCursor()); + cursor.y>=addConfigButton.getHeight()+1&& + cursor.y<=addConfigButton.getHeight()+1+addConfigButton.getHeight()) { + Color c = MyRobot.CP.getBackgroundColor(); + if (c!=null) { + configData.put("BACKGROUND",Integer.toString(c.getRGB())); + applyConfig(); + } + return; + } + + Display previousDisplay = selectedDisplay; + selectedDisplay=null; + for (int i=0;i=d.x&& + cursor.x<=d.x+d.width&& + cursor.y>=d.y&& + cursor.y<=d.y+d.height) { + selectedDisplay=d; + break; + } + } + + if (selectedDisplay==null) { + MyRobot.FRAME.setCursor(Cursor.getDefaultCursor()); + DisplayManager.f.setVisible(false); + } else { + MyRobot.FRAME.setCursor(new Cursor(Cursor.MOVE_CURSOR)); + draggedDisplay=selectedDisplay; + if (selectedDisplay.equals(previousDisplay)) { + //System.out.println("Double click"); + DisplayManager.setupSettings(selectedDisplay); + } + } + }break; } } + private Point GetCursorPosition(MouseEvent e) { + Point cursor = e.getPoint(); + cursor.translate(-MyRobot.FRAME.getInsets().left,-MyRobot.FRAME.getInsets().top); + return cursor; + } + @Override public void mouseReleased(MouseEvent e) { - // TODO Auto-generated method stub - + draggedDisplay=null; } @Override @@ -395,4 +433,20 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener, // TODO Auto-generated method stub } + + @Override + public void mouseDragged(MouseEvent e) { + if (draggedDisplay!=null) { + Point cursor = GetCursorPosition(e); + draggedDisplay.x=(int)(Math.floor((cursor.x-draggedDisplay.width/2)/8)*8); + draggedDisplay.y=(int)(Math.floor((cursor.y-draggedDisplay.height/2)/8)*8); + MyRobot.p.repaint(); + } + } + + @Override + public void mouseMoved(MouseEvent e) { + // TODO Auto-generated method stub + + } } diff --git a/DivaBot/src/sig/ListTransferHandler.java b/DivaBot/src/sig/ListTransferHandler.java index fb70d2a..a3b46bd 100644 --- a/DivaBot/src/sig/ListTransferHandler.java +++ b/DivaBot/src/sig/ListTransferHandler.java @@ -104,7 +104,13 @@ public class ListTransferHandler extends TransferHandler { } } } - System.out.println("Selected indexes: "+Arrays.toString(indices)); + String[] labels = new String[listModel.getSize()]; + for (int i=0;i