package de.miaurizius.jgame2d.core; import de.miaurizius.jgame2d.core.enums.GameState; import de.miaurizius.jgame2d.entity.Entity; import de.miaurizius.jgame2d.entity.item.HeartObj; import java.awt.*; import java.awt.image.BufferedImage; public class UI { GamePanel panel; Graphics2D graphics2d; Font arial_40, arial_80B; //TODO: Custom font loader: https://www.youtube.com/watch?v=g-wrebFVP3E BufferedImage heart_full, heart_half, heart_blank; public String currentDialogue; public int commandNum; public UI(GamePanel panel) { this.panel = panel; arial_40 = new Font("Arial", Font.PLAIN, 40); arial_80B = new Font("Arial", Font.BOLD, 80); // CREATE HUD OBJECT Entity heart = new HeartObj(panel); heart_full = heart.image; heart_half = heart.image2; heart_blank = heart.image3; } public void draw(Graphics2D graphics2d) { this.graphics2d = graphics2d; graphics2d.setFont(arial_40); graphics2d.setColor(Color.white); if(panel.gameState == null) return; switch (panel.gameState) { case GameState.PLAY: drawPlayerLife(); break; case GameState.PAUSE: drawPlayerLife(); drawPauseScreen(); break; case GameState.DIALOGUE: drawPlayerLife(); drawDialogueScreen(); break; case TITLE: drawTitleScreen(); break; } } // HUD public void drawPlayerLife() { int x = panel.tileSize / 2; int y = panel.tileSize / 2; int i = 0; // DRAW MAX HEART while(i", x-panel.tileSize, y); text = "LOAD GAME"; x = getCenteredX(text); y += panel.tileSize; graphics2d.drawString(text, x, y); if(commandNum == 1) graphics2d.drawString(">", x-panel.tileSize, y); text = "QUIT"; x = getCenteredX(text); y += panel.tileSize; graphics2d.drawString(text, x, y); if(commandNum == 2) graphics2d.drawString(">", x-panel.tileSize, y); } // UTILITY public void drawSubWindow(int x, int y, int width, int height) { graphics2d.setColor(new Color(0,0,0,210)); graphics2d.fillRoundRect(x, y, width, height, 35, 35); graphics2d.setColor(new Color(255,255,255)); graphics2d.setStroke(new BasicStroke(5)); graphics2d.drawRoundRect(x+5, y+5, width-10, height-10, 25, 25); } public int getCenteredX(String text) { return panel.screenWidth / 2 - (int) graphics2d.getFontMetrics().getStringBounds(text, graphics2d).getWidth() / 2; } }