| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- package view.ui.menu;
- import util.GAMESTATE;
- import util.Translator;
- import view.GamePanel;
- import view.components.Button;
- import java.awt.*;
- public class PauseMenu extends AbstractMenu{
- public PauseMenu(GamePanel gamePanel){
- super(gamePanel);
- }
- public void draw(Graphics2D g2){
- this.g2 = g2;
- String message = Translator.translate("menu.pause");
- // Background overlay
- g2.setColor(new Color(0, 0, 0, 150));
- g2.fillRect(0, 0, gp.screenWidth, gp.screenHeight);
- // Dialog box
- int boxWidth = gp.screenWidth / 2;
- int boxHeight = gp.screenHeight / 2;
- int boxX = gp.screenWidth / 2 - boxWidth / 2;
- int boxY = gp.screenHeight / 4;
- g2.setColor(Color.WHITE);
- g2.fillRoundRect(boxX, boxY, boxWidth, boxHeight, 25, 25);
- // Message text
- g2.setColor(Color.BLACK);
- g2.setFont(new Font("Arial", Font.BOLD, 28));
- FontMetrics fm = g2.getFontMetrics();
- int msgWidth = fm.stringWidth(message);
- g2.drawString(message, gp.screenWidth / 2 - msgWidth / 2, boxY + 50);
- // Buttons
- int buttonWidth = 260;
- int buttonHeight = 40;
- int buttonX = gp.screenWidth / 2 - buttonWidth / 2;
- int resumeY = boxY + 100;
- int saveY = getYForNewButton(resumeY);
- int exitY = getYForNewButton(saveY);
- int menuY = getYForNewButton(exitY);
- int settingsY = getYForNewButton(menuY);
- view.components.Button resumeButton = new view.components.Button(buttonWidth, buttonHeight, Translator.translate("menu.resume"), () -> {
- gp.gameState = GAMESTATE.PLAY;
- });
- drawAndRegisterButton(resumeButton, buttonX, resumeY);
- view.components.Button exitButton = new view.components.Button(buttonWidth, buttonHeight, Translator.translate("menu.quit"), () -> {
- gp.gameState = GAMESTATE.QUIT;
- });
- drawAndRegisterButton(exitButton, buttonX, exitY);
- view.components.Button saveButton = new view.components.Button(buttonWidth, buttonHeight, Translator.translate("menu.save"), () -> {
- gp.gameState = GAMESTATE.SAVE;
- });
- drawAndRegisterButton(saveButton, buttonX, saveY);
- view.components.Button menuButton = new Button(buttonWidth, buttonHeight, Translator.translate("menu.main_menu"), () -> {
- gp.gameState = GAMESTATE.MAIN_MENU;
- });
- drawAndRegisterButton(menuButton, buttonX, menuY);
- view.components.Button settingsButton = new Button(buttonWidth, buttonHeight, Translator.translate("menu.settings"), () -> {
- gp.gameState = GAMESTATE.SETTINGS;
- });
- drawAndRegisterButton(settingsButton, buttonX, settingsY);
- }
- private int getYForNewButton(int oldY){
- int buttonHeight = 40;
- int spacing = 20;
- return oldY + buttonHeight + spacing;
- }
- }
|