From 4a18642f0c128cd3a2ae3f34e8376ba87ec72ac9 Mon Sep 17 00:00:00 2001 From: iryupnik Date: Fri, 10 Apr 2020 11:42:04 +0200 Subject: [PATCH] Fullscreen fix in FreeMove --- src/main/java/Game.java | 12 ++---------- .../gameOfProd/Windows/WindowOfFreeMove.java | 14 +++----------- .../game/gameOfProd/Windows/WindowOfMenu.java | 18 ++++++++++++++++++ src/main/resources/save/savedGame/person.txt | 4 ++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index e73eea6..1611396 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -27,6 +27,7 @@ public class Game extends JFrame { //tohle spustí na začátku menu add(menu); + menu.start(); //tohle spustí na začátku hru // add(freeMove); @@ -38,19 +39,10 @@ public class Game extends JFrame { setLocationRelativeTo(null); setResizable(false); setVisible(true); - setLayout(new BorderLayout()); getContentPane().setBackground(Color.BLACK); - setExtendedState(game().MAXIMIZED_BOTH); - centerContent(); + setExtendedState(MAXIMIZED_BOTH); } - - public Game game() {return this;} - - public void centerContent() { - getContentPane().getComponent(0).setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); - getContentPane().getComponent(0).setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); - } } diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java index 9a81a1b..ae908fe 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfFreeMove.java @@ -82,7 +82,6 @@ public class WindowOfFreeMove extends JLayeredPane { public Camera getCamera() { return camera; } public WindowOfFreeMove(JFrame game) { - this.game = game; isReadyToPaint = false; canPersonMove = true; @@ -145,7 +144,7 @@ public class WindowOfFreeMove extends JLayeredPane { } public void start(boolean newGame) { - + centerContent(); mapLinkedList = new LinkedList<>(); mapManager = new MapManager(mapLinkedList, canvas, this); @@ -164,10 +163,8 @@ public class WindowOfFreeMove extends JLayeredPane { int startX = 4; int startY = 2; - camera.moveCamera(); mapManager.createMap(); isReadyToPaint = true; - canvas.repaint(); Npc npc2 = new Npc(startX, startY, boss, mapManager); boss.setNpcs(npc2); @@ -175,11 +172,6 @@ public class WindowOfFreeMove extends JLayeredPane { musicManager = new MusicManager("Town1.wav"); // musicManager.playMusic(); - Timer center = new Timer(1, actionEvent -> { - centerContent(); - }); - center.start(); - Timer timer = new Timer(10, actionEvent -> { mapManager.getActualMap().getPerson().move(); camera.moveCamera(); @@ -241,7 +233,7 @@ public class WindowOfFreeMove extends JLayeredPane { } public void centerContent() { - game.getContentPane().getComponent(0).setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); - game.getContentPane().getComponent(0).setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); + game.getComponents()[0].setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); + game.getComponents()[0].setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); } } \ No newline at end of file diff --git a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java index ad1f619..d2877ac 100644 --- a/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java +++ b/src/main/java/ruscz/game/gameOfProd/Windows/WindowOfMenu.java @@ -4,6 +4,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; +import java.sql.Time; public class WindowOfMenu extends JLayeredPane { public static final int WINDOW_WIDTH = 13; @@ -53,6 +54,18 @@ public class WindowOfMenu extends JLayeredPane { add(startNewGame); add(loadSavedGame); add(exitGame); + setVisible(false); + } + + + public void start(){ + Timer timer = new Timer( 0, actionEvent -> { + setVisible(false); + centerContent(); + this.repaint(); + setVisible(true); + }); + timer.start(); } private void cleanUp() { @@ -71,4 +84,9 @@ public class WindowOfMenu extends JLayeredPane { } public WindowOfMenu menu() { return this; } + + public void centerContent() { + game.getComponents()[0].setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - (WINDOW_WIDTH * CELL_SIZE)) / 2, (Toolkit.getDefaultToolkit().getScreenSize().height - (WINDOW_HEIGHT * CELL_SIZE)) / 2); + game.getComponents()[0].setSize(WINDOW_WIDTH * CELL_SIZE, WINDOW_HEIGHT * CELL_SIZE); + } } diff --git a/src/main/resources/save/savedGame/person.txt b/src/main/resources/save/savedGame/person.txt index 77eed58..ee5b150 100644 --- a/src/main/resources/save/savedGame/person.txt +++ b/src/main/resources/save/savedGame/person.txt @@ -1,5 +1,5 @@ m1 - 8 - 4 + 1 + 7 \ No newline at end of file