📄 movementdisplay.java
字号:
setLowerEnabled(ce.canGoDown(cmd.getFinalElevation(), cmd.getFinalCoords())); } private synchronized void updateLoadButtons() { final Entity ce = ce(); if(null==ce) return; boolean legalGear = ((gear == MovementDisplay.GEAR_LAND) || (gear == MovementDisplay.GEAR_TURN) || (gear == MovementDisplay.GEAR_BACKUP)); int unloadEl = cmd.getFinalElevation(); IHex hex = ce.getGame().getBoard().getHex(cmd.getFinalCoords()); boolean canUnloadHere = false; for (Enumeration e = loadedUnits.elements(); e.hasMoreElements();) { Entity en = (Entity) e.nextElement(); if (en.isElevationValid(unloadEl, hex)) { canUnloadHere = true; break; } } // Disable the "Unload" button if we're in the wrong // gear or if the entity is not transporting units. if (!legalGear || loadedUnits.size() == 0 || cen == Entity.NONE || (!canUnloadHere)) { setUnloadEnabled(false); } else { setUnloadEnabled(true); } // If the current entity has moved, disable "Load" button. if (cmd.length() > 0 || cen == Entity.NONE) { setLoadEnabled(false); } else { // Check the other entities in the current hex for friendly units. Entity other = null; Enumeration entities = client.game.getEntities(ce.getPosition()); boolean isGood = false; while (entities.hasMoreElements()) { // Is the other unit friendly and not the current entity? other = (Entity) entities.nextElement(); if (ce.getOwner().equals(other.getOwner()) && !ce.equals(other)) { // Yup. If the current entity has at least 1 MP, if it can // transport the other unit, and if the other hasn't moved // then enable the "Load" button. if (ce.getWalkMP() > 0 && ce.canLoad(other) && other.isLoadableThisTurn()) { setLoadEnabled(true); isGood = true; } // We can stop looking. break; } // Nope. Discard it. other = null; } // Check the next entity in this position. if (!isGood) { setLoadEnabled(false); } } // End ce-hasn't-moved } // private void updateLoadButtons /** * Get the unit that the player wants to unload. This method will * remove the unit from our local copy of loaded units. * * @return The <code>Entity</code> that the player wants to unload. * This value will not be <code>null</code>. */ private Entity getUnloadedUnit() { Entity ce = ce(); Entity choice = null; // Handle error condition. if (loadedUnits.size() == 0) { System.err.println("MovementDisplay#getUnloadedUnit() called without loaded units."); //$NON-NLS-1$ } // If we have multiple choices, display a selection dialog. else if (loadedUnits.size() > 1) { String[] names = new String[loadedUnits.size()]; String question = Messages.getString("MovementDisplay.UnloadUnitDialog.message", new Object[]{//$NON-NLS-1$ ce.getShortName(), ce.getUnusedString()}); for (int loop = 0; loop < names.length; loop++) { names[loop] = ((Entity) loadedUnits.elementAt(loop)).getShortName(); } SingleChoiceDialog choiceDialog = new SingleChoiceDialog(clientgui.frame, Messages.getString("MovementDisplay.UnloadUnitDialog.title"), //$NON-NLS-1$ question, names); choiceDialog.setVisible(true); if (choiceDialog.getAnswer()) { choice = (Entity) loadedUnits.elementAt(choiceDialog.getChoice()); } } // End have-choices // Only one choice. else { choice = (Entity) loadedUnits.elementAt(0); loadedUnits.removeElementAt(0); } // Return the chosen unit. return choice; } /** * Have the player select a target from the entities at the given coords. * * @param pos - the <code>Coords</code> containing targets. */ private Targetable chooseTarget(Coords pos) { final Entity ce = ce(); // Assume that we have *no* choice. Targetable choice = null; // Get the available choices. Enumeration choices = client.game.getEntities(pos); // Convert the choices into a List of targets. ArrayList<Targetable> targets = new ArrayList<Targetable>(); while (choices.hasMoreElements()) { choice = (Targetable) choices.nextElement(); if (!ce.equals(choice)) { targets.add(choice); } } // Is there a building in the hex? Building bldg = client.game.getBoard().getBuildingAt(pos); if (bldg != null) { targets.add(new BuildingTarget(pos, client.game.getBoard(), false)); } // Do we have a single choice? if (targets.size() == 1) { // Return that choice. choice = targets.get(0); } // If we have multiple choices, display a selection dialog. else if (targets.size() > 1) { String[] names = new String[targets.size()]; String question = Messages.getString("MovementDisplay.ChooseTargetDialog.message", new Object[]{//$NON-NLS-1$ pos.getBoardNum()}); for (int loop = 0; loop < names.length; loop++) { names[loop] = targets.get(loop).getDisplayName(); } SingleChoiceDialog choiceDialog = new SingleChoiceDialog(clientgui.frame, Messages.getString("MovementDisplay.ChooseTargetDialog.title"), //$NON-NLS-1$ question, names); choiceDialog.setVisible(true); if (choiceDialog.getAnswer()) { choice = targets.get(choiceDialog.getChoice()); } } // End have-choices // Return the chosen unit. return choice; } // End private Targetable chooseTarget( Coords ) private int chooseMineToLay() { MineLayingDialog mld = new MineLayingDialog(clientgui.frame, ce()); mld.setVisible(true); if (mld.getAnswer()) { return mld.getMine(); } return -1; } // // GameListener // public void gameTurnChange(GameTurnChangeEvent e) { // Are we ignoring events? if (isIgnoringEvents()) { return; } if (client.game.getPhase() != IGame.PHASE_MOVEMENT) { // ignore return; } // else, change turn endMyTurn(); if (client.isMyTurn()) { // Can the player unload entities stranded on immobile transports? if (client.canUnloadStranded()) { unloadStranded(); } else { beginMyTurn(); } } else { if (e.getPlayer() == null && client.game.getTurn() instanceof GameTurn.UnloadStrandedTurn) { setStatusBarText(Messages.getString("MovementDisplay.waitForAnother")); //$NON-NLS-1$ } else { setStatusBarText(Messages.getString("MovementDisplay.its_others_turn", new Object[]{e.getPlayer().getName()})); //$NON-NLS-1$ } } } public void gamePhaseChange(GamePhaseChangeEvent e) { // Are we ignoring events? if (isIgnoringEvents()) { return; } if (client.isMyTurn() && client.game.getPhase() != IGame.PHASE_MOVEMENT) { endMyTurn(); } if (client.game.getPhase() == IGame.PHASE_MOVEMENT) { setStatusBarText(Messages.getString("MovementDisplay.waitingForMovementPhase")); //$NON-NLS-1$ } } // // ActionListener // public synchronized void actionPerformed(ActionEvent ev) { final Entity ce = ce(); // Are we ignoring events? if (isIgnoringEvents()) { return; } if (statusBarActionPerformed(ev, client)) return; if (!client.isMyTurn()) { // odd... return; } if (ev.getSource().equals(butDone)) { moveTo(cmd); } else if (ev.getActionCommand().equals(MOVE_NEXT)) { selectEntity(client.getNextEntityNum(cen)); } else if (ev.getActionCommand().equals(MOVE_CANCEL)) { clearAllMoves(); } else if (ev.getSource().equals(butMore)) { buttonLayout++; buttonLayout %= NUM_BUTTON_LAYOUTS; setupButtonPanel(); } else if (ev.getActionCommand().equals(MOVE_UNJAM)) { if (gear == MovementDisplay.GEAR_JUMP || gear == MovementDisplay.GEAR_CHARGE || gear == MovementDisplay.GEAR_DFA || cmd.getMpUsed() > ce.getWalkMP() || gear == MovementDisplay.GEAR_SWIM) { // in the wrong gear //clearAllMoves(); //gear = Compute.GEAR_LAND; setUnjamEnabled(false); } else { cmd.addStep(MovePath.STEP_UNJAM_RAC); moveTo(cmd); } } else if (ev.getActionCommand().equals(MOVE_SEARCHLIGHT)) { cmd.addStep(MovePath.STEP_SEARCHLIGHT); } else if (ev.getActionCommand().equals(MOVE_WALK)) { if (gear == MovementDisplay.GEAR_JUMP || gear == MovementDisplay.GEAR_SWIM) { clearAllMoves(); } gear = MovementDisplay.GEAR_LAND; } else if (ev.getActionCommand().equals(MOVE_JUMP)) { if (gear != MovementDisplay.GEAR_JUMP) { clearAllMoves(); } if (!cmd.isJumping()) { cmd.addStep(MovePath.STEP_START_JUMP); } gear = MovementDisplay.GEAR_JUMP; } else if (ev.getActionCommand().equals(MOVE_SWIM)) { if (gear != MovementDisplay.GEAR_SWIM) { clearAllMoves(); } //dcmd.addStep(MovePath.STEP_SWIM); gear = MovementDisplay.GEAR_SWIM; ce.setMovementMode((ce instanceof BipedMech) ? IEntityMovementMode.BIPED_SWIM : IEntityMovementMode.QUAD_SWIM); } else if (ev.getActionCommand().equals(MOVE_TURN)) { gear = MovementDisplay.GEAR_TURN; } else if (ev.getActionCommand().equals(MOVE_BACK_UP)) { if (gear == MovementDisplay.GEAR_JUMP) { clearAllMoves(); } gear = MovementDisplay.GEAR_BACKUP; } else if (ev.getActionCommand().equals(MOVE_CLEAR)) { clearAllMoves(); if (!client.game.containsMinefield(ce.getPosition())) { clientgui.doAlertDialog(Messages.getString("MovementDisplay.CantClearMinefield"), //$NON-NLS-1$ Messages.getString("MovementDisplay.NoMinefield")); //$NON-NLS-1$ return; } // Does the entity has a minesweeper? int clear = Minefield.CLEAR_NUMBER_INFANTRY; int boom = Minefield.CLEAR_NUMBER_INFANTRY_ACCIDENT; for (Mounted mounted : ce.getMisc()) { if (mounted.getType().hasFlag(MiscType.F_TOOLS) && mounted.getType().hasSubType(MiscType.S_MINESWEEPER)) { int sweeperType = mounted.getType().getToHitModifier(); clear = Minefield.CLEAR_NUMBER_SWEEPER[sweeperType]; boom = Minefield.CLEAR_NUMBER_SWEEPER_ACCIDENT[sweeperType]; break; } } if (clien
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -