| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package view.ui;
- import controller.InteractiveController;
- import controller.entity.EntityController;
- import controller.tiles.interactive.InteractiveTileController;
- import util.Translator;
- import view.GamePanel;
- import view.components.Button;
- import view.popUpMenu.PopupMenu;
- import view.tile.ONCLICKTYPE;
- import view.ui.menu.PauseMenu;
- import java.awt.*;
- import java.util.ArrayList;
- public class UI {
- private GamePanel gp;
- private Graphics2D g2;
- private Font arial_40;
- private static ArrayList<Button> activeButtons = new ArrayList<>();
- public UI(GamePanel gp){
- this.gp = gp;
- arial_40 = new Font("Arial", Font.PLAIN, 80);
- }
- public void draw(Graphics2D g2){
- this.g2 = g2;
- g2.setFont(arial_40);
- g2.setColor(Color.white);
- }
- public void handleMenuClick(int screenX, int screenY) {
- for (Button button : activeButtons) {
- if (button.wasClicked(screenX, screenY)) {
- button.click();
- break;
- }
- }
- }
- public void handleClick(int screenX, int screenY){
- for (InteractiveTileController tile : gp.gameController.interactiveTileControllers) {
- handleClickForController(tile, screenX, screenY);
- }
- for (EntityController controller : gp.gameController.entityControllers) {
- handleClickForController(controller, screenX, screenY);
- }
- }
- private void handleClickForController(InteractiveController interactiveController, int screenX, int screenY){
- if(interactiveController.getClicked() && interactiveController.getOnClickType() == ONCLICKTYPE.POPUP){
- PopupMenu popupMenu = interactiveController.getPopupMenu();
- Button clickedButton = popupMenu.getClickedButton(screenX,screenY);
- if(clickedButton != null){
- clickedButton.click();
- interactiveController.unClick();
- return;
- }
- }
- if (interactiveController.isClicked(screenX, screenY, gp.camera) && !interactiveController.getClicked()) {
- interactiveController.click(screenX, screenY);
- }else if(interactiveController.getClicked()){
- interactiveController.unClick();
- }
- }
- public static void drawAndRegisterButton(Graphics2D g2, Button button, int buttonX, int buttonY){
- button.setScreenCoordinates(buttonX, buttonY);
- button.draw(g2);
- activeButtons.add(button);
- }
- public int getXForCenteredText(String text){
- int length = (int)g2.getFontMetrics().getStringBounds(text, g2).getWidth();
- return gp.screenWidth/2 - length/2;
- }
- public void closeMenus() {
- for (InteractiveTileController tile : gp.gameController.interactiveTileControllers) {
- tile.unClick();
- }
- for(EntityController e : gp.gameController.entityControllers){
- e.unClick();
- }
- }
- }
|