📄 clientgui.java
字号:
component = new Label(Messages.getString("ClientGUI.TransmittingData")); //$NON-NLS-1$ main = "Label-Exchange"; //$NON-NLS-1$ secondary = main; panMain.add(main, component); panSecondary.add(secondary, new Label("")); //$NON-NLS-1$ break; case IGame.PHASE_SET_ARTYAUTOHITHEXES: component = new SelectArtyAutoHitHexDisplay(this); main = "BoardView"; //$NON-NLS-1$ secondary = "SelectArtyAutoHitHexDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_DEPLOY_MINEFIELDS: component = new DeployMinefieldDisplay(this); main = "BoardView"; //$NON-NLS-1$ secondary = "DeployMinefieldDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_DEPLOYMENT: component = new DeploymentDisplay(this); main = "BoardView"; //$NON-NLS-1$ secondary = "DeploymentDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_TARGETING: component = new TargetingPhaseDisplay(this, false); ((TargetingPhaseDisplay) component).initializeListeners(); main = "BoardView"; //$NON-NLS-1$ secondary = "TargetingPhaseDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_MOVEMENT: component = new MovementDisplay(this); main = "BoardView"; //$NON-NLS-1$ secondary = "MovementDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_OFFBOARD: component = new TargetingPhaseDisplay(this, true); ((TargetingPhaseDisplay) component).initializeListeners(); main = "BoardView"; //$NON-NLS-1$ secondary = "OffboardDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_FIRING: component = new FiringDisplay(this); main = "BoardView"; //$NON-NLS-1$ secondary = "FiringDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_PHYSICAL: component = new PhysicalDisplay(this); main = "BoardView"; //$NON-NLS-1$ secondary = "PhysicalDisplay"; //$NON-NLS-1$ if (!mainNames.contains(main)) { panMain.add(main, this.scroller); } panSecondary.add(secondary, component); break; case IGame.PHASE_INITIATIVE_REPORT: component = new ReportDisplay(client); main = "ReportDisplay"; //$NON-NLS-1$ secondary = main; panMain.add(main, component); panSecondary.add(secondary, ((ReportDisplay) component).getSecondaryDisplay()); break; case IGame.PHASE_MOVEMENT_REPORT: case IGame.PHASE_OFFBOARD_REPORT: case IGame.PHASE_FIRING_REPORT: case IGame.PHASE_PHYSICAL_REPORT: case IGame.PHASE_END_REPORT: case IGame.PHASE_VICTORY: // Try to reuse the ReportDisplay for other phases... component = (Component) phaseComponents.get(String.valueOf(IGame.PHASE_INITIATIVE_REPORT)); if (null == component) { // no ReportDisplay to reuse -- get a new one component = initializePanel(IGame.PHASE_INITIATIVE_REPORT); } main = "ReportDisplay"; //$NON-NLS-1$ secondary = main; break; default : component = new Label(Messages.getString("ClientGUI.waitingOnTheServer")); //$NON-NLS-1$ main = "Label-Default"; //$NON-NLS-1$ secondary = main; panMain.add(main, component); panSecondary.add(secondary, new Label("")); //$NON-NLS-1$ } phaseComponents.put(name, component); mainNames.put(name, main); secondaryNames.put(name, secondary); return component; } protected void addBag(Component comp, GridBagLayout gridbag, GridBagConstraints c) { gridbag.setConstraints(comp, c); add(comp); } protected void showBoardPopup(Point point) { if (!bv.mayDrawPopup()) return; fillPopup(bv.getCoordsAt(point)); if (popup.getItemCount() > 0) { popup.show(bv, point.x, point.y); } } private boolean canTargetEntities() { return client.isMyTurn() && (curPanel instanceof FiringDisplay || curPanel instanceof PhysicalDisplay || curPanel instanceof TargetingPhaseDisplay); } private boolean canSelectEntities() { return client.isMyTurn() && (curPanel instanceof FiringDisplay || curPanel instanceof PhysicalDisplay || curPanel instanceof MovementDisplay || curPanel instanceof TargetingPhaseDisplay); } /** * Toggles the entity display window */ public void toggleDisplay() { mechW.setVisible(!mechW.isVisible()); if (mechW.isVisible()) { frame.requestFocus(); } } /** * Sets the visibility of the entity display window */ public void setDisplayVisible(boolean visible) { mechW.setVisible(visible); if (visible) { frame.requestFocus(); } } public void toggleUnitOverview() { uo.setVisible(!uo.isVisible()); bv.repaint(); } /** * Toggles the minimap window * Also, toggles the minimap enabled setting */ public void toggleMap() { if (minimapW.isVisible()) { GUIPreferences.getInstance().setMinimapEnabled(false); } else { GUIPreferences.getInstance().setMinimapEnabled(true); } minimapW.setVisible(!minimapW.isVisible()); if (minimapW.isVisible()) { frame.requestFocus(); } } /** * Sets the visibility of the minimap window */ public void setMapVisible(boolean visible) { minimapW.setVisible(visible); if (visible) { frame.requestFocus(); } } protected void fillPopup(Coords coords) { popup.removeAll(); // add select options if (canSelectEntities()) { for (Enumeration i = client.game.getEntities(coords); i.hasMoreElements();) { final Entity entity = (Entity) i.nextElement(); if (client.game.getTurn().isValidEntity(entity, client.game)) { popup.add(new SelectMenuItem(entity)); } } } if (popup.getItemCount() > 0) { popup.addSeparator(); } // add view options for (Enumeration i = client.game.getEntities(coords); i.hasMoreElements();) { final Entity entity = (Entity) i.nextElement(); popup.add(new ViewMenuItem(entity)); } // add target options if (canTargetEntities()) { if (popup.getItemCount() > 0) { popup.addSeparator(); } for (Enumeration i = client.game.getEntities(coords); i.hasMoreElements();) { final Entity entity = (Entity) i.nextElement(); popup.add(new TargetMenuItem(entity)); } // Can target weapons at the hex if it contains woods or building. // Can target physical attacks at the hex if it contains building. if (curPanel instanceof FiringDisplay || curPanel instanceof PhysicalDisplay || curPanel instanceof TargetingPhaseDisplay) { IHex h = client.game.getBoard().getHex(coords); if (h != null && curPanel instanceof FiringDisplay) { popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_HEX_CLEAR))); if (client.game.getOptions().booleanOption("fire")) { //$NON-NLS-1$ popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_HEX_IGNITE))); } } else if (h != null && h.containsTerrain(Terrains.FUEL_TANK)) { popup.add(new TargetMenuItem(new BuildingTarget(coords, client.game.getBoard(), false))); if (client.game.getOptions().booleanOption("fire")) { //$NON-NLS-1$ popup.add(new TargetMenuItem(new BuildingTarget(coords, client.game.getBoard(), true))); } } else if (h != null && h.containsTerrain(Terrains.BUILDING)) { popup.add(new TargetMenuItem(new BuildingTarget(coords, client.game.getBoard(), false))); if (client.game.getOptions().booleanOption("fire")) { //$NON-NLS-1$ popup.add(new TargetMenuItem(new BuildingTarget(coords, client.game.getBoard(), true))); } } if (h != null && client.game.containsMinefield(coords) && curPanel instanceof FiringDisplay) { popup.add(new TargetMenuItem(new MinefieldTarget(coords, client.game.getBoard()))); } if (h != null && curPanel instanceof FiringDisplay) { popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_MINEFIELD_DELIVER))); popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_FLARE_DELIVER))); popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_HEX_BOMB))); popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_HEX_ARTILLERY))); if (client.game.getOptions().booleanOption("fire") && h.containsTerrain(Terrains.FIRE)) { popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_HEX_EXTINGUISH))); } } if (h != null && curPanel instanceof TargetingPhaseDisplay) { popup.add(new TargetMenuItem(new HexTarget(coords, client.game.getBoard(), Targetable.TYPE_HEX_ARTILLERY))); } } } } /** * Pops up a dialog box giving the player a series of choices that * are not mutually exclusive. * * @param title the <code>String</code> title of the dialog box. * @param question the <code>String</code> question that has a * "Yes" or "No" answer. The question will be split across * multiple line on the '\n' characters. * @param choices the array of <code>String</code> choices that * the player can select from. * @return The array of the <code>int</code> indexes of the from the * input array that match the selected choices. If no choices * were available, if the player did not select a choice, or * if the player canceled the choice, a <code>null</code> value * is returned. */ public int[] doChoiceDialog(String title, String question, String[] choices) { ChoiceDialog choice = new ChoiceDialog(frame, title, question, choices); choice.setVisible(true); return choice.getChoices(); } /** * Pops up a dialog box showing an alert */ public void doAlertDialog(String title, String message) { AlertDialog alert = new AlertDialog(frame, title, message); alert.setVisible(true); } /** * Pops up a dialog box asking a yes/no question * * @param title the <code>String</code> title of the dialog box. * @param question the <code>String</code> question that has a * "Yes" or "No" answer. The question will be split across * multiple line on the '\n' characters. * @return <code>true</code> if yes */ public boolean doYesNoDialog(String title, String question) { ConfirmDialog confirm = new ConfirmDialog(frame, title, question); confirm.setVisible(true); return confirm.getAnswer(); } /** * Pops up a dialog box asking a yes/no question * <p/> * The player will be given a chance to not show the dialog again. * * @param title the <code>String</code> title of the dialog box. * @param question the <code>String</code> question that has a * "Yes" or "No" answer. The question will be split across * multiple line on the '\n' characters. * @return the <code>ConfirmDialog</code> containing the player's * responses. The dialog will already have been shown to * the player, and is only being returned so the calling * function can see the answer to the question and the state * of the "Show again?" question. */ public ConfirmDialog doYesNoBotherDialog(String title, String question) { ConfirmDialog confirm = new ConfirmDialog(frame, title, question, true); confirm.setVisible(true); return confirm; } public void mouseClicked(java.awt.event.MouseEvent mouseEvent) { } public void mouseEntered(java.awt.event.MouseEvent mouseEvent) { } public void mouseExited(java.awt.event.MouseEvent mouseEvent) { } public void mousePressed(java.awt.event.MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { showBoardPopup(mouseEvent.getPoint()); } } public void mouseReleased(java.awt.event.MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { showBoardPopup(mouseEvent.getPoint()); } } /** * Allow the player to select a MegaMek Unit List file to load. The * <code>Entity</code>s in the file will replace any that the player * has already selected. As such, this method should only be called * in the chat lounge. The file can record damage sustained, non- * standard munitions selected, and ammunition expended in a prior * engagement. */ protected void loadListFile() { // Build the "load unit" dialog, if necessary. if (null == dlgLoadList) { dlgLoadList = new FileDialog(frame, Messages.getString("ClientGUI.openUnitListFileDialog.title"), FileDialog.LOAD); //$NON-NLS-1$ // Add a filter for MUL files dlgLoadList.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return (null != name && name.endsWith(".mul")); //$NON-NLS-1$ } }); // use base directory by default dlgLoadList.setDirectory("."); //$NON-NLS-1$ // Default to the player's name. //dlgLoadList.setFile( getLocalPlayer().getName() + ".mul" ); // Instead, use setFile as a windoze hack, see Server.java // (search for "setFile") for details. dlgLoadList.setFile("*.mul"); //$NON-NLS-1$ } // Display the "load unit" dialog. dlgLoadList.setVisible(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -