InfoPanel.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package model.objects;
  2. import image.Images;
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics2D;
  6. import java.awt.RenderingHints;
  7. import java.awt.Transparency;
  8. import java.awt.image.VolatileImage;
  9. import model.SongHandler;
  10. import model.gameState.PlayState;
  11. public class InfoPanel {
  12. private static String totalHighscore = "000000";
  13. private int x, y;
  14. private VolatileImage infoPanel;
  15. private SongHandler sh;
  16. private String time;
  17. public InfoPanel(int x, int y, SongHandler sh){
  18. this.x = x;
  19. this.y = y;
  20. this.sh = sh;
  21. updateIPanel();
  22. generateInfoPanel();
  23. }
  24. public void updateIPanel() {
  25. totalHighscore = "" + PlayState.currentScore;
  26. // time = "";
  27. // long progress = (sh.getProgress() / 1000);
  28. // time = progress%1000 + time;
  29. // progress /= 1000;
  30. // time = progress%1000 + ":" + time;
  31. // progress /= 1000;
  32. // time = progress + ":" + time;
  33. long progress = (sh.getProgress() / 1000);
  34. String millis = ((progress) % 1000) + "".length() > 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
  35. String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
  36. String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
  37. time = minute + ":" + second + ":" + millis;
  38. generateInfoPanel();
  39. }
  40. private void generateInfoPanel(){
  41. infoPanel = Images.initVolatileImage(256, 1024, Transparency.OPAQUE);
  42. Graphics2D g2 = infoPanel.createGraphics();
  43. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  44. g2.setRenderingHints(rh);
  45. g2.setColor(Color.BLACK);
  46. g2.fillRect(x, y, 256, 1024);
  47. Font scoreFont = new Font("OCR A Extended", Font.BOLD, 30);
  48. g2.setFont(scoreFont);
  49. g2.setColor(Color.GREEN);
  50. g2.fillRect(25, 100, (int)(2 * PlayState.lifePoints), 30);
  51. g2.setColor(Color.ORANGE);
  52. g2.drawString("Score: " + totalHighscore, 25, 75);
  53. g2.drawRect(25, 100, 200, 30);
  54. g2.drawRect(25, 300, 200, 700);
  55. g2.drawString(sh.getCurrentSong().getTitle(), 25, 200);
  56. if(sh.getCurrentSong().getSubtitle() != "")
  57. {
  58. g2.drawString(sh.getCurrentSong().getSubtitle(), 25, 230);
  59. g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
  60. g2.drawString(time, 25, 290);
  61. }
  62. else
  63. {
  64. g2.drawString(sh.getCurrentSong().getAuthor(), 25, 230);
  65. g2.drawString(time, 25, 260);
  66. }
  67. g2.setColor(Color.YELLOW);
  68. g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore);
  69. g2.dispose();
  70. infoPanel.createGraphics();
  71. }
  72. public void draw(Graphics2D g2){
  73. g2.drawImage(infoPanel, 0, 0, 256,1024,null);
  74. }
  75. public static String getTotalHighscore()
  76. {
  77. return totalHighscore;
  78. }
  79. }