InfoPanel.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.SongHandler;
  12. import control.button.ButtonHandler;
  13. import main.Window;
  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(sh.getCurrentSongInstance().getDifficulty(), 25, 295);
  63. g2.drawString(time, 25, 375);
  64. g2.drawString("" + highscore, 25, 455);
  65. Font scoreFont2 = new Font("OCR A Extended", Font.BOLD, 25);
  66. g2.setFont(scoreFont2);
  67. g2.drawString("Title: ", 25, 185);
  68. g2.drawString("Difficulty: ", 25, 265);
  69. g2.drawString("Time: ", 25, 345);
  70. g2.drawString("Best: ", 25, 425);
  71. Font scoreFont3 = new Font("OCR A Extended", Font.BOLD, 45);
  72. g2.setFont(scoreFont3);
  73. g2.drawString("" + totalHighscore, 25, 115);
  74. Ellipse2D oval1 = new Ellipse2D.Double(25, 700, 50, 50);
  75. g2.setColor(ButtonHandler.getButton(1).getColor());
  76. g2.fill(oval1);
  77. Ellipse2D oval2 = new Ellipse2D.Double(85, 700, 50, 50);
  78. g2.setColor(ButtonHandler.getButton(2).getColor());
  79. g2.fill(oval2);
  80. Ellipse2D oval3 = new Ellipse2D.Double(145, 700, 50, 50);
  81. g2.setColor(ButtonHandler.getButton(3).getColor());
  82. g2.fill(oval3);
  83. Ellipse2D oval4 = new Ellipse2D.Double(50, 760, 50, 50);
  84. g2.setColor(ButtonHandler.getButton(4).getColor());
  85. g2.fill(oval4);
  86. Ellipse2D oval5 = new Ellipse2D.Double(110, 760, 50, 50);
  87. g2.setColor(ButtonHandler.getButton(5).getColor());
  88. g2.fill(oval5);
  89. Ellipse2D oval6 = new Ellipse2D.Double(170, 760, 50, 50);
  90. g2.setColor(ButtonHandler.getButton(6).getColor());
  91. g2.fill(oval6);
  92. // g2.setColor(Color.BLACK);
  93. // width = g2.getFontMetrics().stringWidth(""+i);
  94. // g2.drawString(""+i, (int)oval.getCenterX()-width/2,(int)oval.getMaxY()+height);
  95. g2.dispose();
  96. infoPanel.createGraphics();
  97. }
  98. public void draw(Graphics2D g2){
  99. g2.drawImage(infoPanel, 0, 0, 256,1024,null);
  100. }
  101. public static String getTotalHighscore()
  102. {
  103. return totalHighscore;
  104. }
  105. }