📄 deploymentdisplay.java
字号:
client.game.removeGameListener(this); clientgui.getBoardView().removeBoardViewListener(this); removeAll(); } public void gameTurnChange(GameTurnChangeEvent e) { // Are we ignoring events? if (isIgnoringEvents()) { return; } if (client.isMyTurn()) { beginMyTurn(); setStatusBarText(Messages.getString("DeploymentDisplay.its_your_turn")); //$NON-NLS-1$ } else { endMyTurn(); setStatusBarText(Messages.getString("DeploymentDisplay.its_others_turn", new Object[]{e.getPlayer().getName()})); //$NON-NLS-1$ } } public void gamePhaseChange(GamePhaseChangeEvent e) { DeploymentDisplay.this.clientgui.bv.markDeploymentHexesFor(null); // Are we ignoring events? if (isIgnoringEvents()) { return; } if (client.game.getPhase() == IGame.PHASE_DEPLOYMENT) { setStatusBarText(Messages.getString("DeploymentDisplay.waitingForDeploymentPhase")); //$NON-NLS-1$ } } // // BoardListener // public void hexMoused(BoardViewEvent b) { // Are we ignoring events? if (isIgnoringEvents()) { return; } if (b.getType() != BoardViewEvent.BOARD_HEX_DRAGGED) { return; } // ignore buttons other than 1 if (!client.isMyTurn() || ce() == null || (b.getModifiers() & MouseEvent.BUTTON1_MASK) == 0) { return; } // control pressed means a line of sight check. // added ALT_MASK by kenn if ((b.getModifiers() & InputEvent.CTRL_MASK) != 0 || (b.getModifiers() & InputEvent.ALT_MASK) != 0) { return; } // check for shifty goodness boolean shiftheld = (b.getModifiers() & MouseEvent.SHIFT_MASK) != 0; // check for a deployment Coords moveto = b.getCoords(); if (ce().getPosition() != null && (shiftheld || turnMode)) { // turn ce().setFacing(ce().getPosition().direction(moveto)); ce().setSecondaryFacing(ce().getFacing()); clientgui.bv.redrawEntity(ce()); turnMode = false; } else if (!(client.game.getBoard().isLegalDeployment(moveto, ce().getOwner()) || assaultDropPreference) || ce().isHexProhibited(client.game.getBoard().getHex(moveto))) { JOptionPane.showMessageDialog(clientgui.frame, Messages.getString("DeploymentDisplay.cantDeployInto", new Object[]{ce().getShortName(), moveto.getBoardNum()}), Messages.getString("DeploymentDisplay.alertDialog.title") //$NON-NLS-1$ , JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ return; } else if (Compute.stackingViolation(client.game, ce().getId(), moveto) != null) { // check if deployed unit violates stacking return; } else { ce().setPosition(moveto); clientgui.bv.redrawEntity(ce()); butDone.setEnabled(true); } clientgui.getBoardView().select(moveto); } // // ActionListener // public void actionPerformed(ActionEvent ev) { // Are we ignoring events? if (isIgnoringEvents()) { return; } if (statusBarActionPerformed(ev, client)) return; if (!client.isMyTurn()) { // odd... return; } if (ev.getSource().equals(butDone)) { deploy(); } else if (ev.getActionCommand().equals(DEPLOY_NEXT)) { ce().setPosition(null); clientgui.bv.redrawEntity(ce()); // Unload any loaded units. Enumeration iter = ce().getLoadedUnits().elements(); while (iter.hasMoreElements()) { Entity other = (Entity) iter.nextElement(); // Please note, the Server never got this unit's load orders. ce().unload(other); other.setTransportId(Entity.NONE); other.newRound(client.game.getRoundCount()); } selectEntity(client.getNextDeployableEntityNum(cen)); } else if (ev.getActionCommand().equals(DEPLOY_TURN)) { turnMode = true; } else if (ev.getActionCommand().equals(DEPLOY_LOAD)) { // What undeployed units can we load? Vector choices = new Vector(); Enumeration entities = client.game.getEntities(); Entity other; while (entities.hasMoreElements()) { other = (Entity) entities.nextElement(); if (other.isSelectableThisTurn() && ce().canLoad(other)) { choices.addElement(other); } } // Do we have anyone to load? if (choices.size() > 0) { String[] names = new String[choices.size()]; for (int loop = 0; loop < names.length; loop++) { names[loop] = ((Entity) choices.elementAt(loop)).getShortName(); } SingleChoiceDialog choiceDialog = new SingleChoiceDialog(clientgui.frame, Messages.getString("DeploymentDisplay.loadUnitDialog.title"), //$NON-NLS-1$ Messages.getString("DeploymentDisplay.loadUnitDialog.message", new Object[]{ce().getShortName(), ce().getUnusedString()}), //$NON-NLS-1$ names); choiceDialog.setVisible(true); if (choiceDialog.getAnswer()) { other = (Entity) choices.elementAt(choiceDialog.getChoice()); // Please note, the Server may never get this load order. ce().load(other); other.setTransportId(cen); clientgui.mechD.displayEntity(ce()); } } // End have-choices else { JOptionPane.showMessageDialog(clientgui.frame, Messages.getString("DeploymentDisplay.allertDialog1.message", new Object[]{ce().getShortName()}), Messages.getString("DeploymentDisplay.allertDialog1.title") //$NON-NLS-1$ , JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ } } // End load-unit else if (ev.getActionCommand().equals(DEPLOY_UNLOAD)) { // Do we have anyone to unload? Vector choices = ce().getLoadedUnits(); if (choices.size() > 0) { Entity other = null; String[] names = new String[choices.size()]; for (int loop = 0; loop < names.length; loop++) { names[loop] = ((Entity) choices.elementAt(loop)).getShortName(); } SingleChoiceDialog choiceDialog = new SingleChoiceDialog(clientgui.frame, Messages.getString("DeploymentDisplay.unloadUnitDialog.title"), //$NON-NLS-1$ Messages.getString("DeploymentDisplay.unloadUnitDialog.message", new Object[]{ce().getShortName(), ce().getUnusedString()}), //$NON-NLS-1$ names); choiceDialog.setVisible(true); if (choiceDialog.getAnswer()) { other = (Entity) choices.elementAt(choiceDialog.getChoice()); // Please note, the Server never got this load order. if (ce().unload(other)) { other.setTransportId(Entity.NONE); other.newRound(client.game.getRoundCount()); clientgui.mechD.displayEntity(ce()); } else { System.out.println("Could not unload " + //$NON-NLS-1$ other.getShortName() + " from " + ce().getShortName()); //$NON-NLS-1$ } } } // End have-choices else { JOptionPane.showMessageDialog(clientgui.frame, Messages.getString("DeploymentDisplay.allertDialog2.message", new Object[]{ce().getShortName()}), Messages.getString("DeploymentDisplay.allertDialog2.title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$ } } // End unload-unit else if (ev.getActionCommand().equals(DEPLOY_REMOVE)) { remove(); } else if (ev.getActionCommand().equals(DEPLOY_ASSAULTDROP)) { assaultDropPreference = !assaultDropPreference; if (assaultDropPreference) { butAssaultDrop.setText(Messages.getString("DeploymentDisplay.AssaultDropOff")); } else { butAssaultDrop.setText(Messages.getString("DeploymentDisplay.AssaultDropOn")); } } } // End public void actionPerformed(ActionEvent ev) // // KeyListener // public void keyPressed(KeyEvent ev) { } public void keyReleased(KeyEvent ev) { } public void keyTyped(KeyEvent ev) { } // // BoardViewListener // public void finishedMovingUnits(BoardViewEvent b) { } // Selected a unit in the unit overview. public void unitSelected(BoardViewEvent b) { // Are we ignoring events? if (isIgnoringEvents()) { return; } Entity e = client.game.getEntity(b.getEntityId()); if (null == e) { return; } if (client.isMyTurn()) { if (client.game.getTurn().isValidEntity(e, client.game)) { if (ce() != null) { ce().setPosition(null); clientgui.bv.redrawEntity(ce()); // Unload any loaded units. Enumeration iter = ce().getLoadedUnits().elements(); while (iter.hasMoreElements()) { Entity other = (Entity) iter.nextElement(); // Please note, the Server never got this unit's load orders. ce().unload(other); other.setTransportId(Entity.NONE); other.newRound(client.game.getRoundCount()); } } selectEntity(e.getId()); if (null != e.getPosition()) { clientgui.bv.centerOnHex(e.getPosition()); } } } else { clientgui.setDisplayVisible(true); clientgui.mechD.displayEntity(e); if (e.isDeployed()) { clientgui.bv.centerOnHex(e.getPosition()); } } } private void setNextEnabled(boolean enabled) { butNext.setEnabled(enabled); clientgui.getMenuBar().setDeployNextEnabled(enabled); } private void setTurnEnabled(boolean enabled) { butTurn.setEnabled(enabled); clientgui.getMenuBar().setDeployTurnEnabled(enabled); } private void setLoadEnabled(boolean enabled) { butLoad.setEnabled(enabled); clientgui.getMenuBar().setDeployLoadEnabled(enabled); } private void setUnloadEnabled(boolean enabled) { butUnload.setEnabled(enabled); clientgui.getMenuBar().setDeployUnloadEnabled(enabled); } private void setRemoveEnabled(boolean enabled) { butRemove.setEnabled(enabled); clientgui.getMenuBar().setDeployNextEnabled(enabled); } private void setAssaultDropEnabled(boolean enabled) { butAssaultDrop.setEnabled(enabled); clientgui.getMenuBar().setDeployAssaultDropEnabled(enabled); } /** * Determine if the listener is currently distracted. * * @return <code>true</code> if the listener is ignoring events. */ public boolean isIgnoringEvents() { return distracted.isIgnoringEvents(); } /** * Specify if the listener should be distracted. * * @param distracted <code>true</code> if the listener should ignore events * <code>false</code> if the listener should pay attention again. * Events that occured while the listener was distracted NOT * going to be processed. */ public void setIgnoringEvents(boolean distracted) { this.distracted.setIgnoringEvents(distracted); } /** * Retrieve the "Done" button of this object. * * @return the <code>javax.swing.JButton</code> that activates this * object's "Done" action. */ public JButton getDoneButton() { return butDone; } /** * Stop just ignoring events and actually stop listening to them. */ public void removeAllListeners() { die(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -