|
|
@@ -0,0 +1,82 @@
|
|
|
+package view;
|
|
|
+
|
|
|
+import util.GAMESTATE;
|
|
|
+
|
|
|
+import java.awt.*;
|
|
|
+
|
|
|
+public class UI {
|
|
|
+ private GamePanel gp;
|
|
|
+ private Graphics2D g2;
|
|
|
+ private Font arial_40;
|
|
|
+ private String message = "";
|
|
|
+ private boolean messageOn;
|
|
|
+
|
|
|
+ public UI(GamePanel gp){
|
|
|
+ this.gp = gp;
|
|
|
+ arial_40 = new Font("Arial", Font.PLAIN, 80);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void showMessage(String text){
|
|
|
+ message = text;
|
|
|
+ messageOn = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void draw(Graphics2D g2){
|
|
|
+ this.g2 = g2;
|
|
|
+ g2.setFont(arial_40);
|
|
|
+ g2.setColor(Color.white);
|
|
|
+
|
|
|
+ if(gp.gameState == GAMESTATE.PAUSED){
|
|
|
+ drawBlackScreenWithMessage(g2, "Spiel Pausiert");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void drawBlackScreenWithMessage(Graphics2D g2, String message) {
|
|
|
+ // 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 / 3;
|
|
|
+ int boxX = gp.screenWidth / 2 - boxWidth / 2;
|
|
|
+ int boxY = gp.screenHeight / 3;
|
|
|
+
|
|
|
+ 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 = 160;
|
|
|
+ int buttonHeight = 40;
|
|
|
+ int spacing = 20;
|
|
|
+
|
|
|
+ int buttonX = gp.screenWidth / 2 - buttonWidth / 2;
|
|
|
+ int resumeY = boxY + 100;
|
|
|
+ int exitY = resumeY + buttonHeight + spacing;
|
|
|
+
|
|
|
+ // Resume button
|
|
|
+ g2.setColor(new Color(200, 200, 200));
|
|
|
+ g2.fillRoundRect(buttonX, resumeY, buttonWidth, buttonHeight, 15, 15);
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
+ g2.drawString("Fortsetzen", buttonX + 11, resumeY + 30);
|
|
|
+
|
|
|
+ // Exit button
|
|
|
+ g2.setColor(new Color(200, 200, 200));
|
|
|
+ g2.fillRoundRect(buttonX, exitY, buttonWidth, buttonHeight, 15, 15);
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
+ g2.drawString("Beenden", buttonX + 22, exitY + 30);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public int getXForCenteredText(String text){
|
|
|
+ int length = (int)g2.getFontMetrics().getStringBounds(text, g2).getWidth();
|
|
|
+ return gp.screenWidth/2 - length/2;
|
|
|
+ }
|
|
|
+}
|