InfoPanel.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 model.gameState.PlayState;
  12. import control.SongHandler;
  13. import control.button.ButtonHandler;
  14. public class InfoPanel {
  15. private static String totalHighscore = "000000";
  16. private VolatileImage infoPanel;
  17. private SongHandler sh;
  18. private String time;
  19. private int highscore = 0;
  20. public InfoPanel(SongHandler sh){
  21. this.sh = sh;
  22. updateIPanel();
  23. generateInfoPanel();
  24. }
  25. public void init(int highscore)
  26. {
  27. this.highscore = highscore;
  28. updateIPanel();
  29. generateInfoPanel();
  30. }
  31. public void updateIPanel() {
  32. totalHighscore = "" + PlayState.currentScore;
  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. GradientPaint gp = new GradientPaint(0, 0, new Color(245,245,245), 256, 1024, Color.WHITE);
  46. g2.setPaint(gp);
  47. g2.setColor(Color.GREEN);
  48. g2.fillRect(25, 900, (int)(2 * PlayState.lifePoints), 30);
  49. g2.setColor(Color.YELLOW);
  50. g2.fillRect(25, 950, (int)(2 * PlayState.comboScore), 30);
  51. g2.setColor(Color.BLACK);
  52. g2.drawRect(25, 900, 200, 30);
  53. g2.drawRect(25, 950, 200, 30);
  54. Font scoreFont = new Font("OCR A Extended", Font.BOLD, 35);
  55. g2.setFont(scoreFont);
  56. g2.drawString("Score: ", 25, 75);
  57. g2.drawString(sh.getCurrentSong().getTitle(), 25, 215);
  58. g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 295);
  59. g2.drawString(time, 25, 375);
  60. g2.drawString("" + highscore, 25, 455);
  61. Font scoreFont2 = new Font("OCR A Extended", Font.BOLD, 25);
  62. g2.setFont(scoreFont2);
  63. g2.drawString("Title: ", 25, 185);
  64. g2.drawString("Difficulty: ", 25, 265);
  65. g2.drawString("Time: ", 25, 345);
  66. g2.drawString("Best: ", 25, 425);
  67. Font scoreFont3 = new Font("OCR A Extended", Font.BOLD, 45);
  68. g2.setFont(scoreFont3);
  69. g2.drawString("" + totalHighscore, 25, 115);
  70. Ellipse2D oval1 = new Ellipse2D.Double(25, 700, 50, 50);
  71. g2.setColor(ButtonHandler.getButton(1).getColor());
  72. g2.fill(oval1);
  73. Ellipse2D oval2 = new Ellipse2D.Double(85, 700, 50, 50);
  74. g2.setColor(ButtonHandler.getButton(2).getColor());
  75. g2.fill(oval2);
  76. Ellipse2D oval3 = new Ellipse2D.Double(145, 700, 50, 50);
  77. g2.setColor(ButtonHandler.getButton(3).getColor());
  78. g2.fill(oval3);
  79. Ellipse2D oval4 = new Ellipse2D.Double(50, 760, 50, 50);
  80. g2.setColor(ButtonHandler.getButton(4).getColor());
  81. g2.fill(oval4);
  82. Ellipse2D oval5 = new Ellipse2D.Double(110, 760, 50, 50);
  83. g2.setColor(ButtonHandler.getButton(5).getColor());
  84. g2.fill(oval5);
  85. Ellipse2D oval6 = new Ellipse2D.Double(170, 760, 50, 50);
  86. g2.setColor(ButtonHandler.getButton(6).getColor());
  87. g2.fill(oval6);
  88. g2.dispose();
  89. infoPanel.createGraphics();
  90. }
  91. public void draw(Graphics2D g2){
  92. g2.drawImage(infoPanel, 0, 0, 256,1024,null);
  93. }
  94. public static String getTotalHighscore()
  95. {
  96. return totalHighscore;
  97. }
  98. }