Show text in Dialog Menu

This commit is contained in:
iryupnik 2020-03-01 19:11:39 +01:00
parent 87338c9484
commit 4621e60fc6

View File

@ -8,7 +8,7 @@ public class WindowOfFreeMove extends JFrame {
static final int CANVAS_WIDTH = 20; static final int CANVAS_WIDTH = 20;
static final int CANVAS_HEIGHT = 20; static final int CANVAS_HEIGHT = 20;
private static boolean isMoveablePerson; private static boolean canPersonMove;
static final int KEY_LEFT = 37; static final int KEY_LEFT = 37;
static final int KEY_UP = 38; static final int KEY_UP = 38;
@ -20,19 +20,32 @@ public class WindowOfFreeMove extends JFrame {
private JLayeredPane lp; private JLayeredPane lp;
private static Map map; private static Map map;
public static Map getMap() { return map; } public static Map getMap() {
public static JPanel getDialogBar() { return dialogBar; } return map;
public static void setIsMoveablePerson(boolean isMoveablePerson) {
WindowOfFreeMove.isMoveablePerson = isMoveablePerson;
} }
public static void setDialogBar(JPanel dialogBar) { WindowOfFreeMove.dialogBar = dialogBar; } public static JPanel getDialogBar() {
public static void setMap(Map map){ WindowOfFreeMove.map = map; } return dialogBar;
public static void paintMapOnWindow() {WindowOfFreeMove.map.createMap();} }
public static void setCanPersonMove(boolean canPersonMove) {
WindowOfFreeMove.canPersonMove = canPersonMove;
}
public static void setDialogBar(JPanel dialogBar) {
WindowOfFreeMove.dialogBar = dialogBar;
}
public static void setMap(Map map) {
WindowOfFreeMove.map = map;
}
public static void paintMapOnWindow() {
WindowOfFreeMove.map.createMap();
}
public WindowOfFreeMove() { public WindowOfFreeMove() {
isMoveablePerson = true; canPersonMove = true;
lp = getLayeredPane(); lp = getLayeredPane();
canvas = new Canvas(); canvas = new Canvas();
@ -40,7 +53,7 @@ public class WindowOfFreeMove extends JFrame {
canvas.setPreferredSize(new Dimension( canvas.setPreferredSize(new Dimension(
CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_WIDTH,
CELL_SIZE * CANVAS_HEIGHT)); CELL_SIZE * CANVAS_HEIGHT));
canvas.setBounds(0,0,CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH); canvas.setBounds(0, 0, CELL_SIZE * CANVAS_HEIGHT, CELL_SIZE * CANVAS_WIDTH);
dialogBar = new JPanel(); dialogBar = new JPanel();
dialogBar.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4); dialogBar.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4);
@ -50,17 +63,18 @@ public class WindowOfFreeMove extends JFrame {
addKeyListener(new KeyAdapter() { addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (isMoveablePerson) if (canPersonMove)
map.getPerson().setDirection(e.getKeyCode()); map.getPerson().setDirection(e.getKeyCode());
} }
}); });
lp.add(dialogBar, JLayeredPane.PALETTE_LAYER);
lp.add(canvas, JLayeredPane.PALETTE_LAYER); lp.add(canvas, JLayeredPane.PALETTE_LAYER);
lp.add(dialogBar, JLayeredPane.POPUP_LAYER);
setTitle("Ahoj"); setTitle("Ahoj");
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(0,0,CELL_SIZE*CANVAS_WIDTH + 15, CELL_SIZE*CANVAS_HEIGHT + 40); setBounds(0, 0, CELL_SIZE * CANVAS_WIDTH, CELL_SIZE * CANVAS_HEIGHT);
setLocationRelativeTo(null); setLocationRelativeTo(null);
setResizable(true); setResizable(true);
setVisible(true); setVisible(true);
@ -69,9 +83,9 @@ public class WindowOfFreeMove extends JFrame {
public void start() { public void start() {
Map m1 = new Map(CANVAS_HEIGHT,CANVAS_WIDTH, true); Map m1 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, true);
m1.setName("1"); m1.setName("1");
m1.setSpawnPoint(12,12); m1.setSpawnPoint(1, 1);
Map m2 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, false); Map m2 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, false);
m2.setName("2"); m2.setName("2");
Map m3 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, true); Map m3 = new Map(CANVAS_HEIGHT, CANVAS_WIDTH, true);
@ -80,21 +94,45 @@ public class WindowOfFreeMove extends JFrame {
m4.setName("4"); m4.setName("4");
m1.addMoveToEvent(new EventMoveToCell(1,1,18,18, m2)); m1.addMoveToEvent(new EventMoveToCell(1, 1, 18, 18, m2));
m1.addMoveToEvent(new EventMoveToCell(4, 3,18,1, m4)); m1.addMoveToEvent(new EventMoveToCell(4, 3, 18, 1, m4));
m2.addMoveToEvent(new EventMoveToCell(2,1, 18, 18, m3)); m2.addMoveToEvent(new EventMoveToCell(2, 1, 18, 18, m3));
m2.addMoveToEvent(new EventMoveToCell(1, 3,18, 1, m1)); m2.addMoveToEvent(new EventMoveToCell(1, 3, 18, 1, m1));
m3.addMoveToEvent(new EventMoveToCell(3, 1,18, 18, m4)); m3.addMoveToEvent(new EventMoveToCell(3, 1, 18, 18, m4));
m3.addMoveToEvent(new EventMoveToCell(2, 3,18, 1, m2)); m3.addMoveToEvent(new EventMoveToCell(2, 3, 18, 1, m2));
m4.addMoveToEvent(new EventMoveToCell(4, 1,18, 18, m1)); m4.addMoveToEvent(new EventMoveToCell(4, 1, 18, 18, m1));
m4.addMoveToEvent(new EventMoveToCell(3,3,18,1, m3)); m4.addMoveToEvent(new EventMoveToCell(3, 3, 18, 1, m3));
setMap(m1); setMap(m1);
map.createMap(); map.createMap();
lp.remove(dialogBar);
JPanel jf = new JPanel() {
Font f = new Font("Times New Roman", Font.ITALIC, 50);
@Override
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.green);
g.setFont(f);
g.drawString("> Test", 10, 50);
}
};
jf.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4);
jf.setBackground(Color.BLACK);
jf.setVisible(false);
setDialogBar(jf);
dialogBar.setVisible(true);
lp.add(jf, JLayeredPane.POPUP_LAYER);
while (true) { while (true) {
map.getPerson().move(); map.getPerson().move();
canvas.repaint(); canvas.repaint();