InfoPanel.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package model.objects;
  2. import image.Images;
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.GradientPaint;
  6. import java.awt.Graphics2D;
  7. import java.awt.RenderingHints;
  8. import java.awt.Transparency;
  9. import java.awt.geom.Ellipse2D;
  10. import java.awt.image.VolatileImage;
  11. import control.button.ButtonHandler;
  12. import main.Window;
  13. import model.SongHandler;
  14. import model.gameState.PlayState;
  15. public class InfoPanel {
  16. private static String totalHighscore = "000000";
  17. private int x, y;
  18. private VolatileImage infoPanel;
  19. private SongHandler sh;
  20. private String time;
  21. private int highscore = 0;
  22. public InfoPanel(int x, int y, SongHandler sh){
  23. this.x = x;
  24. this.y = y;
  25. this.sh = sh;
  26. updateIPanel();
  27. generateInfoPanel();
  28. }
  29. public void init(int highscore)
  30. {
  31. this.highscore = highscore;
  32. updateIPanel();
  33. generateInfoPanel();
  34. }
  35. public void updateIPanel() {
  36. totalHighscore = "" + PlayState.currentScore;
  37. long progress = (sh.getProgress() / 1000);
  38. String millis = (((progress) % 1000) + "").length() > 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
  39. String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
  40. String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
  41. time = minute + ":" + second + ":" + millis;
  42. generateInfoPanel();
  43. }
  44. private void generateInfoPanel(){
  45. infoPanel = Images.initVolatileImage(256, 1024, Transparency.OPAQUE);
  46. Graphics2D g2 = infoPanel.createGraphics();
  47. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  48. g2.setRenderingHints(rh);
  49. GradientPaint gp = new GradientPaint(0, 0, new Color(245,245,245), 256, 1024, Color.WHITE);
  50. g2.setPaint(gp);
  51. g2.setColor(Color.GREEN);
  52. g2.fillRect(25, 900, (int)(2 * PlayState.lifePoints), 30);
  53. g2.setColor(Color.YELLOW);
  54. g2.fillRect(25, 950, (int)(2 * PlayState.comboScore), 30);
  55. g2.setColor(Color.BLACK);
  56. g2.drawRect(25, 900, 200, 30);
  57. g2.drawRect(25, 950, 200, 30);
  58. Font scoreFont = new Font("OCR A Extended", Font.BOLD, 35);
  59. g2.setFont(scoreFont);
  60. g2.drawString("Score: ", 25, 75);
  61. g2.drawString(sh.getCurrentSong().getTitle(), 25, 215);
  62. g2.drawString(time, 25, 295);
  63. g2.drawString("" + highscore, 25, 375);
  64. Font scoreFont2 = new Font("OCR A Extended", Font.BOLD, 25);
  65. g2.setFont(scoreFont2);
  66. g2.drawString("Title: ", 25, 185);
  67. g2.drawString("Time: ", 25, 265);
  68. g2.drawString("Best: ", 25, 345);
  69. Font scoreFont3 = new Font("OCR A Extended", Font.BOLD, 45);
  70. g2.setFont(scoreFont3);
  71. g2.drawString("" + totalHighscore, 25, 115);
  72. Ellipse2D oval1 = new Ellipse2D.Double(25, 700, 50, 50);
  73. g2.setColor(ButtonHandler.getButton(1).getColor());
  74. g2.fill(oval1);
  75. Ellipse2D oval2 = new Ellipse2D.Double(85, 700, 50, 50);
  76. g2.setColor(ButtonHandler.getButton(2).getColor());
  77. g2.fill(oval2);
  78. Ellipse2D oval3 = new Ellipse2D.Double(145, 700, 50, 50);
  79. g2.setColor(ButtonHandler.getButton(3).getColor());
  80. g2.fill(oval3);
  81. Ellipse2D oval4 = new Ellipse2D.Double(50, 760, 50, 50);
  82. g2.setColor(ButtonHandler.getButton(4).getColor());
  83. g2.fill(oval4);
  84. Ellipse2D oval5 = new Ellipse2D.Double(110, 760, 50, 50);
  85. g2.setColor(ButtonHandler.getButton(5).getColor());
  86. g2.fill(oval5);
  87. Ellipse2D oval6 = new Ellipse2D.Double(170, 760, 50, 50);
  88. g2.setColor(ButtonHandler.getButton(6).getColor());
  89. g2.fill(oval6);
  90. // g2.setColor(Color.BLACK);
  91. // width = g2.getFontMetrics().stringWidth(""+i);
  92. // g2.drawString(""+i, (int)oval.getCenterX()-width/2,(int)oval.getMaxY()+height);
  93. g2.dispose();
  94. infoPanel.createGraphics();
  95. }
  96. public void draw(Graphics2D g2){
  97. g2.drawImage(infoPanel, 0, 0, 256,1024,null);
  98. }
  99. public static String getTotalHighscore()
  100. {
  101. return totalHighscore;
  102. }
  103. }