PauseMenu.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package view.ui.menu;
  2. import util.GAMESTATE;
  3. import util.Translator;
  4. import view.GamePanel;
  5. import view.components.Button;
  6. import java.awt.*;
  7. public class PauseMenu extends AbstractMenu{
  8. public PauseMenu(GamePanel gamePanel){
  9. super(gamePanel);
  10. }
  11. public void draw(Graphics2D g2){
  12. this.g2 = g2;
  13. String message = Translator.translate("menu.pause");
  14. // Background overlay
  15. g2.setColor(new Color(0, 0, 0, 150));
  16. g2.fillRect(0, 0, gp.screenWidth, gp.screenHeight);
  17. // Dialog box
  18. int boxWidth = gp.screenWidth / 2;
  19. int boxHeight = gp.screenHeight / 2;
  20. int boxX = gp.screenWidth / 2 - boxWidth / 2;
  21. int boxY = gp.screenHeight / 4;
  22. g2.setColor(Color.WHITE);
  23. g2.fillRoundRect(boxX, boxY, boxWidth, boxHeight, 25, 25);
  24. // Message text
  25. g2.setColor(Color.BLACK);
  26. g2.setFont(new Font("Arial", Font.BOLD, 28));
  27. FontMetrics fm = g2.getFontMetrics();
  28. int msgWidth = fm.stringWidth(message);
  29. g2.drawString(message, gp.screenWidth / 2 - msgWidth / 2, boxY + 50);
  30. // Buttons
  31. int buttonWidth = 260;
  32. int buttonHeight = 40;
  33. int buttonX = gp.screenWidth / 2 - buttonWidth / 2;
  34. int resumeY = boxY + 100;
  35. int saveY = getYForNewButton(resumeY);
  36. int exitY = getYForNewButton(saveY);
  37. int menuY = getYForNewButton(exitY);
  38. int settingsY = getYForNewButton(menuY);
  39. view.components.Button resumeButton = new view.components.Button(buttonWidth, buttonHeight, Translator.translate("menu.resume"), () -> {
  40. gp.gameState = GAMESTATE.PLAY;
  41. });
  42. drawAndRegisterButton(resumeButton, buttonX, resumeY);
  43. view.components.Button exitButton = new view.components.Button(buttonWidth, buttonHeight, Translator.translate("menu.quit"), () -> {
  44. gp.gameState = GAMESTATE.QUIT;
  45. });
  46. drawAndRegisterButton(exitButton, buttonX, exitY);
  47. view.components.Button saveButton = new view.components.Button(buttonWidth, buttonHeight, Translator.translate("menu.save"), () -> {
  48. gp.gameState = GAMESTATE.SAVE;
  49. });
  50. drawAndRegisterButton(saveButton, buttonX, saveY);
  51. view.components.Button menuButton = new Button(buttonWidth, buttonHeight, Translator.translate("menu.main_menu"), () -> {
  52. gp.gameState = GAMESTATE.MAIN_MENU;
  53. });
  54. drawAndRegisterButton(menuButton, buttonX, menuY);
  55. view.components.Button settingsButton = new Button(buttonWidth, buttonHeight, Translator.translate("menu.settings"), () -> {
  56. gp.gameState = GAMESTATE.SETTINGS;
  57. });
  58. drawAndRegisterButton(settingsButton, buttonX, settingsY);
  59. }
  60. private int getYForNewButton(int oldY){
  61. int buttonHeight = 40;
  62. int spacing = 20;
  63. return oldY + buttonHeight + spacing;
  64. }
  65. }