InfoPanel.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.image.VolatileImage;
  10. import model.SongHandler;
  11. import model.gameState.PlayState;
  12. public class InfoPanel {
  13. private static String totalHighscore = "000000";
  14. private int x, y;
  15. private VolatileImage infoPanel;
  16. private SongHandler sh;
  17. private String time;
  18. public InfoPanel(int x, int y, SongHandler sh){
  19. this.x = x;
  20. this.y = y;
  21. this.sh = sh;
  22. updateIPanel();
  23. generateInfoPanel();
  24. }
  25. public void updateIPanel() {
  26. totalHighscore = "" + PlayState.currentScore;
  27. // time = "";
  28. // long progress = (sh.getProgress() / 1000);
  29. // time = progress%1000 + time;
  30. // progress /= 1000;
  31. // time = progress%1000 + ":" + time;
  32. // progress /= 1000;
  33. // time = progress + ":" + time;
  34. long progress = (sh.getProgress() / 1000);
  35. String millis = (((progress) % 1000) + "").length() > 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
  36. String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
  37. String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
  38. time = minute + ":" + second + ":" + millis;
  39. generateInfoPanel();
  40. }
  41. private void generateInfoPanel(){
  42. infoPanel = Images.initVolatileImage(256, 1024, Transparency.OPAQUE);
  43. Graphics2D g2 = infoPanel.createGraphics();
  44. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  45. g2.setRenderingHints(rh);
  46. // g2.setColor(Color.GRAY);
  47. GradientPaint gp = new GradientPaint(0, 0, new Color(245,245,245), 256, 1024, Color.WHITE);
  48. g2.setPaint(gp);
  49. g2.fillRect(x, y, 256, 1024);
  50. g2.setColor(Color.BLACK);
  51. g2.drawRect(x, y, 255, 1023);
  52. Font scoreFont = new Font("OCR A Extended", Font.BOLD, 30);
  53. g2.setFont(scoreFont);
  54. g2.setColor(Color.GREEN);
  55. g2.fillRect(25, 100, (int)(2 * PlayState.lifePoints), 30);
  56. g2.setColor(Color.BLACK);
  57. g2.drawString("Score: " + totalHighscore, 25, 75);
  58. g2.drawRect(25, 100, 200, 30);
  59. g2.drawRect(25, 300, 200, 700);
  60. g2.drawString(sh.getCurrentSong().getTitle(), 25, 200);
  61. g2.drawString(sh.getCurrentSongInstance().getDifficulty(), 25, 230);
  62. g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
  63. g2.drawString(time, 25, 290);
  64. // GradientPaint gp = new GradientPaint(300, 0, new Color(200,200,255), 256, 1024, Color.WHITE);
  65. // g2.setPaint(gp);
  66. // g2.fillRect(x, y, 256, 1024);
  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. }