Ejemplo n.º 1
0
  public void tilePlaced(Tile tile, TileLayer tileLayer) {
    Position p = tile.getPosition();

    removeLayer(AbstractTilePlacementLayer.class);
    removeLayer(PlacementHistory.class);

    if (p.x == left) --left;
    if (p.x == right) ++right;
    if (p.y == top) --top;
    if (p.y == bottom) ++bottom;

    tileLayer.tilePlaced(tile);

    if (client.getSettings().isShowHistory()) {
      showRecentHistory();
    }
    boolean initialPlacement =
        client.getActivePlayer() == null; // if active player is null we are placing initial tiles
    if ((!initialPlacement && !client.isClientActive())
        || (initialPlacement && tile.equals(client.getGame().getCurrentTile()))) {
      getAnimationService()
          .registerAnimation(tile.getPosition(), new RecentPlacement(tile.getPosition()));
    }
    repaint();
  }
Ejemplo n.º 2
0
    public MenuBar(Client client2) {
        this.client = client2;

        boolean isMac = Bootstrap.isMac();

        JMenu menu;
        JMenuItem menuItem;

        //menu.getAccessibleContext().setAccessibleDescription(
        //"The only menu in this program that has menu items");

        menu = new JMenu(_("Game"));
        menu.setMnemonic(KeyEvent.VK_G);
        create = new JMenuItem(_("New game"));
        create.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        create.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.createGame();
            }
        });
        menu.add(create);

        connect = new JMenuItem(_("Connect"));
        connect.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        connect.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.showConnectGamePanel();
            }
        });
        menu.add(connect);

        close = new JMenuItem(_("Close game"));
        close.setEnabled(false);
        close.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.closeGame();
            }
        });
        menu.add(close);


        menu.addSeparator();

        save = new JMenuItem(_("Save"));
        save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        save.setEnabled(false);
        save.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.handleSave();
            }
        });
        menu.add(save);

        load = new JMenuItem(_("Load"));
        load.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        load.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.handleLoad();
            }
        });
        menu.add(load);

        if (! isMac) {
            menu.addSeparator();

            menuItem = new JMenuItem(_("Quit"));
            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
            menuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    client.handleQuit();
                }
            });
            menu.add(menuItem);
        }

        this.add(menu);


        menu = new JMenu(_("Window"));
        zoomIn = new JMenuItem(_("Zoom in"));
        zoomIn.setAccelerator(KeyStroke.getKeyStroke('+')); //only show key code, handled by KeyController
        zoomIn.setEnabled(false);
        zoomIn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.getGridPanel().zoom(2.0);
            }
        });
        menu.add(zoomIn);
        zoomOut = new JMenuItem(_("Zoom out"));
        zoomOut.setAccelerator(KeyStroke.getKeyStroke('-')); //only show key code, handled by KeyController
        zoomOut.setEnabled(false);
        zoomOut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.getGridPanel().zoom(-2.0);
            }
        });
        menu.add(zoomOut);

//		menuItem = new JMenuItem(_("FullScreen"));
//		menuItem.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				//fullScreen();
//				throw new UnsupportedOperationException();
//			}
//		});
//		/*if (! GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().isFullScreenSupported()) {
//			menuItem.setEnabled(false);
//		}*/
//		menuItem.setEnabled(false);
//		menu.add(menuItem);

        menu.addSeparator();
        history = new JCheckBoxMenuItem(_("Show last placements"));
        history.setAccelerator(KeyStroke.getKeyStroke('x'));
        history.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JCheckBoxMenuItem ch = (JCheckBoxMenuItem) e.getSource();
                client.getSettings().setShowHistory(ch.isSelected());
                if (ch.isSelected()) {
                    client.getGridPanel().showRecentHistory();
                } else {
                    client.getGridPanel().removeLayer(PlacementHistory.class);
                }
            }
        });
        menu.add(history);


        showDiscard = new JMenuItem(_("Show discarded tiles"));
        showDiscard.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        showDiscard.setEnabled(false);
        showDiscard.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                client.getDiscardedTilesDialog().setVisible(true);
            }
        });
        menu.add(showDiscard);


        this.add(menu);

        menu = new JMenu(_("Settings"));
        menuItem = new JCheckBoxMenuItem(_("Beep alert at player turn"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
                client.getSettings().setPlayBeep(state);
            }
        });
        ((JCheckBoxMenuItem)menuItem).setSelected(client.getSettings().isPlayBeep());
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JCheckBoxMenuItem(_("Confirm placement on a farm"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
                client.getSettings().setConfirmFarmPlacement(state);
            }
        });
        ((JCheckBoxMenuItem)menuItem).setSelected(client.getSettings().isConfirmFarmPlacement());
        menu.add(menuItem);
        menuItem = new JCheckBoxMenuItem(_("Confirm placement on a tower"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
                client.getSettings().setConfirmTowerPlacement(state);
            }
        });
        ((JCheckBoxMenuItem)menuItem).setSelected(client.getSettings().isConfirmTowerPlacement());
        menu.add(menuItem);
        menuItem = new JCheckBoxMenuItem(_("Confirm ransom payment"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
                client.getSettings().setConfirmRansomPayment(state);
            }
        });
        ((JCheckBoxMenuItem)menuItem).setSelected(client.getSettings().isConfirmTowerPlacement());
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JCheckBoxMenuItem(_("Confirm game close"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                boolean state = ((JCheckBoxMenuItem) e.getSource()).getState();
                client.getSettings().setConfirmGameClose(state);
            }
        });
        ((JCheckBoxMenuItem)menuItem).setSelected(client.getSettings().isConfirmGameClose());
        menu.add(menuItem);

        this.add(menu);

        if (! isMac) {

            menu = new JMenu(_("Help"));

            menuItem = new JMenuItem(_("About"));
            menuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    client.handleAbout();
                }
            });
            menu.add(menuItem);

            menuItem = new JMenuItem(_("Controls"));
            menuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new HelpDialog();
                }
            });
            menu.add(menuItem);

            this.add(menu);

        }
    }