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();
  }
 @Override
 public void forward() {
   if (client.isClientActive()) {
     if (secondPanel instanceof ForwardBackwardListener) {
       ((ForwardBackwardListener) secondPanel).forward();
     }
     client.getControlPanel().getActionPanel().forward();
   }
 }
  public GridPanel(Client client, Snapshot snapshot) {
    setDoubleBuffered(true);
    setOpaque(false);
    setLayout(null);

    this.client = client;
    this.controlPanel = client.getControlPanel();

    squareSize = INITIAL_SQUARE_SIZE;
    left = 0 - STARTING_GRID_SIZE / 2;
    right = 0 + STARTING_GRID_SIZE / 2;
    top = 0 - STARTING_GRID_SIZE / 2;
    bottom = 0 + STARTING_GRID_SIZE / 2;

    if (snapshot != null) {
      NodeList nl = snapshot.getTileElements();
      for (int i = 0; i < nl.getLength(); i++) {
        Element el = (Element) nl.item(i);
        Position pos = XmlUtils.extractPosition(el);
        if (pos.x <= left) left = pos.x - 1;
        if (pos.x >= right) right = pos.x + 1;
        if (pos.y <= top) top = pos.y - 1;
        if (pos.y >= bottom) bottom = pos.y + 1;
      }
    }
    registerMouseListeners();
    controlPanel.registerSwingComponents(this);
  }
Beispiel #4
0
 @Override
 public void paint(Graphics g) {
     Graphics2D g2 = (Graphics2D) g;
     g2.setColor(client.getTheme().getTransparentPanelBg());
     if (messagesPane.isVisible()) {
         g2.fillRect(0, 0, getWidth(), getHeight());
     } else {
         g2.fillRect(0, getHeight() - 40, getWidth(), 40);
     }
     super.paint(g);
 }
Beispiel #5
0
    @Subscribe
    public void displayChatMessage(ChatEvent ev) {
        ReceivedChatMessage fm = createReceivedMessage(ev);
        formattedMessages.addLast(fm);

        if (client.getState() == JFrame.ICONIFIED) {
            messageReceivedWhileIconified = true;
        } else {
            setForceFocus();
        }

        DefaultStyledDocument doc = new DefaultStyledDocument();
        int offset = 0;
        try {
            for (ReceivedChatMessage msg : formattedMessages) {
                SimpleAttributeSet attrs = new SimpleAttributeSet();
                ColorConstants.setForeground(attrs, msg.color);
                String nick = msg.nickname;
                String text = msg.ev.getText();
                doc.insertString(offset, nick + ": ", attrs);
                offset += nick.length() + 2;

                Color textColor = client.getTheme().getTextColor();
                if (textColor == null) {
                    attrs = null;
                } else {
                    attrs = new SimpleAttributeSet();
                    ColorConstants.setForeground(attrs, client.getTheme().getTextColor());
                }
                doc.insertString(offset, text + "\n", attrs);
                offset += text.length() + 1;
            }
        } catch (BadLocationException e) {
            logger.error(e.getMessage(), e); //should never happen
        }
        messagesPane.setDocument(doc);
        repaint();
    }
Beispiel #6
0
    public void initHidingMode() {
        hidingMode = true;
        repaintTimer = new Timer(DISPLAY_MESSAGES_INTERVAL, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                forceFocus = false;
                repaintTimer.stop();
                updateMessaagesVisibility();
            }
        });
        this.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentHidden(ComponentEvent e) {
                repaintTimer.stop();
            }
        });
        if (forceFocus) {
            repaintTimer.start();
        }

        setBackground(new Color(0, 0, 0, 0));
        input.setBackground(client.getTheme().getInputBg());
        updateMessaagesVisibility();
    }
 /** Called when user select action in action panel */
 public void select() {
   gridLayer = createGridLayer();
   if (gridLayer != null) {
     client.getGridPanel().addLayer(gridLayer);
   }
 }
 public Image getImage(Player player, boolean active) {
   return getImage(active ? client.getPlayerColor(player) : Color.GRAY);
 }
 public PlayerPanelImageCache(Client client, Game game) {
   this.rm = client.getResourceManager();
   scaleImages(game);
 }
Beispiel #10
0
 public void backward() {
   client.getControlPanel().getActionPanel().rollAction(-1);
 }
Beispiel #11
0
 public AnimationService getAnimationService() {
   return client.getMainPanel().getAnimationService();
 }
Beispiel #12
0
 public Tile getTile(Position p) {
   return client.getGame().getBoard().get(p);
 }
Beispiel #13
0
    public ChatPanel(final Client client) {
        this.client = client;

        input = new JTextField();
        //prevent unintended focus (by window activate etc. - allow focus just on direct click)
        input.setFocusable(false);
        input.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                activateChat();
            }
        });
        input.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    clean();
                }
            }
        });
        input.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String msg = input.getText();
                if (!"".equals(msg)) {
                    forceFocus = true; //prevent panel flashing
                    client.getConnection().send(createPostChatMessage(msg));
                }
                clean();
            }
        });
        input.addFocusListener(new FocusListener() {
            @Override
            public void focusLost(FocusEvent e) {
                updateMessaagesVisibility();
            }

            @Override
            public void focusGained(FocusEvent e) {
                updateMessaagesVisibility();
            }
        });

        input.setOpaque(false);
        input.setBackground(client.getTheme().getTransparentInputBg());
        Color textColor = client.getTheme().getTextColor();
        if (textColor != null) {
            input.setForeground(client.getTheme().getTextColor());
            input.setCaretColor(client.getTheme().getTextColor());
        }
        TextPrompt tp = new TextPrompt(_("Type to chat"), input);
        tp.setShow(Show.FOCUS_LOST);
        tp.changeStyle(Font.ITALIC);
        tp.changeAlpha(0.4f);

        messagesPane = new JTextPane();
        messagesPane.setEditorKit(new WrapEditorKit());
        messagesPane.setFocusable(false);
        messagesPane.setOpaque(false);

        setBackground(client.getTheme().getTransparentPanelBg());
        setLayout(new MigLayout(""));
        add(messagesPane, "pos 10 n (100%-10) (100%-35)");
        add(input, "pos 10 (100%-35) (100%-10) (100%-10)");
    }
Beispiel #14
0
 private void clean() {
     input.setText("");
     input.setFocusable(false);
     client.requestFocusInWindow();
     client.getContentPane().repaint(); //need to repain whote grid pane
 }
Beispiel #15
0
 /** Called when user deselect action in action panel */
 public void deselect() {
   if (gridLayer != null) {
     client.getGridPanel().clearActionDecorations();
     gridLayer = null;
   }
 }
Beispiel #16
0
 /** Called after right mouse click */
 public void forward() {
   client.getControlPanel().getActionPanel().rollAction(1);
 }
Beispiel #17
0
 public void showRecentHistory() {
   Collection<Tile> tiles = client.getGame().getBoard().getAllTiles();
   addLayer(new PlacementHistory(this, tiles));
 }
Beispiel #18
0
 protected Image getImage(Color color) {
   return client.getFigureTheme().getActionImage(this, color);
 }
Beispiel #19
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);

        }
    }