⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientgui.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        // Did the player select a file?        String unitPath = dlgLoadList.getDirectory();        String unitFile = dlgLoadList.getFile();        if (null != unitFile) {            try {                // Read the units from the file.                Vector loadedUnits = EntityListFile.loadFrom(new File(unitPath, unitFile));                // Add the units from the file.                for (Enumeration iter = loadedUnits.elements(); iter.hasMoreElements();) {                    final Entity entity = (Entity) iter.nextElement();                    entity.setOwner(client.getLocalPlayer());                    client.sendAddEntity(entity);                }            } catch (IOException excep) {                excep.printStackTrace(System.err);                doAlertDialog(Messages.getString("ClientGUI.errorLoadingFile"), excep.getMessage()); //$NON-NLS-1$            }        }    }    /**     * Allow the player to save a list of entities to a MegaMek Unit List     * file.  A "Save As" dialog will be displayed that allows the user to     * select the file's name and directory. The player can later load this     * file to quickly select the units for a new game.  The file will record     * damage sustained, non-standard munitions selected, and ammunition     * expended during the course of the current engagement.     *     * @param unitList - the <code>Vector</code> of <code>Entity</code>s     *                 to be saved to a file.  If this value is <code>null</code>     *                 or empty, the "Save As" dialog will not be displayed.     */    protected void saveListFile(Vector unitList) {        // Handle empty lists.        if (null == unitList || unitList.isEmpty()) {            return;        }        // Build the "save unit" dialog, if necessary.        if (null == dlgSaveList) {            dlgSaveList = new FileDialog(frame, Messages.getString("ClientGUI.saveUnitListFileDialog.title"), FileDialog.SAVE); //$NON-NLS-1$            // Add a filter for MUL files            dlgSaveList.setFilenameFilter(new FilenameFilter() {                public boolean accept(File dir, String name) {                    return (null != name && name.endsWith(".mul")); //$NON-NLS-1$                }            });            // use base directory by default            dlgSaveList.setDirectory("."); //$NON-NLS-1$            // Default to the player's name.            dlgSaveList.setFile(client.getLocalPlayer().getName() + ".mul"); //$NON-NLS-1$        }        // Display the "save unit" dialog.        dlgSaveList.setVisible(true);        // Did the player select a file?        String unitPath = dlgSaveList.getDirectory();        String unitFile = dlgSaveList.getFile();        if (null != unitFile) {            if (!(unitFile.toLowerCase().endsWith(".mul") //$NON-NLS-1$                    || unitFile.toLowerCase().endsWith(".xml"))) { //$NON-NLS-1$                unitFile += ".mul"; //$NON-NLS-1$            }            try {                // Save the player's entities to the file.                EntityListFile.saveTo(new File(unitPath, unitFile), unitList);            } catch (IOException excep) {                excep.printStackTrace(System.err);                doAlertDialog(Messages.getString("ClientGUI.errorSavingFile"), excep.getMessage()); //$NON-NLS-1$            }        }    }    //    // WindowListener    //    public void windowActivated(java.awt.event.WindowEvent windowEvent) {    }    public void windowClosed(java.awt.event.WindowEvent windowEvent) {    }    public void windowClosing(java.awt.event.WindowEvent windowEvent) {        if (windowEvent.getWindow() == minimapW) {            setMapVisible(false);        } else if (windowEvent.getWindow() == mechW) {            setDisplayVisible(false);        }    }    public void windowDeactivated(java.awt.event.WindowEvent windowEvent) {    }    public void windowDeiconified(java.awt.event.WindowEvent windowEvent) {    }    public void windowIconified(java.awt.event.WindowEvent windowEvent) {    }    public void windowOpened(java.awt.event.WindowEvent windowEvent) {    }    /**     * A menu item that lives to view an entity.     */    private class ViewMenuItem extends MenuItem implements ActionListener {        Entity entity;        public ViewMenuItem(Entity entity) {            super(Messages.getString("ClientGUI.viewMenuItem")                    + entity.getDisplayName()                    + (entity.isDone() ? " (" + Messages.getString("ClientGUI.doneMenuItem").trim() + ")" : "")); //$NON-NLS-1$            this.entity = entity;            addActionListener(this);        }        public void actionPerformed(java.awt.event.ActionEvent actionEvent) {            setDisplayVisible(true);            mechD.displayEntity(entity);        }    }    /**     * A menu item that would really like to select an entity.  You can use     * this during movement, firing & physical phases.  (Deployment would     * just be silly.)     */    private class SelectMenuItem extends MenuItem implements ActionListener {        Entity entity;        public SelectMenuItem(Entity entity) {            super(Messages.getString("ClientGUI.selectMenuItem") + entity.getDisplayName()); //$NON-NLS-1$            this.entity = entity;            addActionListener(this);        }        public void actionPerformed(java.awt.event.ActionEvent actionEvent) {            if (curPanel instanceof MovementDisplay) {                ((MovementDisplay) curPanel).selectEntity(entity.getId());            } else if (curPanel instanceof FiringDisplay) {                ((FiringDisplay) curPanel).selectEntity(entity.getId());            } else if (curPanel instanceof PhysicalDisplay) {                ((PhysicalDisplay) curPanel).selectEntity(entity.getId());            }        }    }    /**     * A menu item that will target an entity, provided that it's sensible to     * do so     */    private class TargetMenuItem extends MenuItem implements ActionListener {        Targetable target;        public TargetMenuItem(Targetable t) {            super(Messages.getString("ClientGUI.targetMenuItem") + t.getDisplayName()); //$NON-NLS-1$            target = t;            addActionListener(this);        }        public void actionPerformed(java.awt.event.ActionEvent actionEvent) {            if (curPanel instanceof FiringDisplay) {                ((FiringDisplay) curPanel).target(target);            } else if (curPanel instanceof PhysicalDisplay) {                ((PhysicalDisplay) curPanel).target(target);            } else if (curPanel instanceof TargetingPhaseDisplay) {                ((TargetingPhaseDisplay) curPanel).target(target);            }        }    }    /**     * @return the frame this client is displayed in     */    public Frame getFrame() {        return frame;    }    // Shows a dialg where the player can select the entity types    // used in the LOS tool.    public void showLOSSettingDialog() {        GUIPreferences gp = GUIPreferences.getInstance();        LOSDialog ld = new LOSDialog(frame, gp.getMechInFirst(), gp.getMechInSecond());        ld.setVisible(true);        gp.setMechInFirst(ld.getMechInFirst());        gp.setMechInSecond(ld.getMechInSecond());    }    // Loads a preview image of the unit into the BufferedPanel.    public void loadPreviewImage(BufferedPanel bp, Entity entity) {        Player player = client.game.getPlayer(entity.getOwnerId());        loadPreviewImage(bp, entity, player);    }    public void loadPreviewImage(BufferedPanel bp, Entity entity, Player player) {        Image camo = bv.getTilesetManager().getPlayerCamo(player);        int tint = PlayerColors.getColorRGB(player.getColorIndex());        bv.getTilesetManager().loadPreviewImage(entity, camo, tint, bp);    }    /**     * Make a "bing" sound.     */    public void bing() {        if (!GUIPreferences.getInstance().getSoundMute()                && null != bingClip) {            bingClip.play();        }    }    protected GameListener gameListener = new GameListenerAdapter() {        public void gamePlayerDisconnected(GamePlayerDisconnectedEvent e) {            AlertDialog alert = new AlertDialog(frame, Messages.getString("ClientGUI.Disconnected.title"), Messages.getString("ClientGUI.Disconnected.message")); //$NON-NLS-1$ //$NON-NLS-2$            alert.setVisible(true);            frame.setVisible(false);            die();        }        public void gamePlayerChat(GamePlayerChatEvent e) {            bing();        }        public void gamePhaseChange(GamePhaseChangeEvent e) {            boolean showRerollButton = false;                        //This is a really lame place for this, but I couldn't find a            //better one without making massive changes (which didn't seem            //worth it for one little feature).            if (bv.getLocalPlayer() == null) {                bv.setLocalPlayer(client.getLocalPlayer());            }                        // Swap to this phase's panel.            switchPanel(client.game.getPhase());                        // Hide tooltip (thanks Thrud Cowslayer, C.O.R.E, and others for helping test this! :)            bv.hideTooltip();                        // Handle phase-specific items.            switch (e.getNewPhase()) {                case IGame.PHASE_LOUNGE:                    //this will get rid of old report tabs                    ReportDisplay rD = (ReportDisplay) phaseComponents.get(String.valueOf(IGame.PHASE_INITIATIVE_REPORT));                    if (rD != null)                        rD.resetTabs();                    break;                case IGame.PHASE_DEPLOY_MINEFIELDS:                case IGame.PHASE_DEPLOYMENT:                case IGame.PHASE_TARGETING:                case IGame.PHASE_MOVEMENT:                case IGame.PHASE_OFFBOARD:                case IGame.PHASE_FIRING:                case IGame.PHASE_PHYSICAL:                    if (GUIPreferences.getInstance().getMinimapEnabled() && !minimapW.isVisible()) {                        setMapVisible(true);                    }                    break;                case IGame.PHASE_INITIATIVE_REPORT:                    showRerollButton = client.game.hasTacticalGenius(client.getLocalPlayer());                case IGame.PHASE_MOVEMENT_REPORT:                case IGame.PHASE_OFFBOARD_REPORT:                case IGame.PHASE_FIRING_REPORT:                case IGame.PHASE_END:                case IGame.PHASE_VICTORY:                    setMapVisible(false);                    // nemchenk, 2004-01-01 -- hide MechDisplay at the end                    mechW.setVisible(false);                    break;            }            menuBar.setPhase(client.game.getPhase());            cb.getComponent().setVisible(true);            validate();            doLayout();            cb.moveToEnd();        }        public void gameReport(GameReportEvent e) {            // Normally the Report Display is updated when the panel is            //  switched during a phase change.            // This update is for reports that get sent at odd times,            //  currently Tactical Genius reroll requests and when            //  a player wishes to continue moving after a fall.            if (e.getReport() == null && curPanel instanceof ReportDisplay) {                //Tactical Genius                ((ReportDisplay) curPanel).appendReportTab(client.phaseReport);                ((ReportDisplay) curPanel).resetReadyButton();                // Check if the player deserves an active reroll button                // (possible, if he gets one which he didn't use, and his                // opponent got and used one) and if so activates it.                if (client.game.hasTacticalGenius(client.getLocalPlayer())) {                    if (!((ReportDisplay) curPanel).hasRerolled()) {                        ((ReportDisplay) curPanel).resetRerollButton();                    }                }            } else {                //Continued movement after getting up                if (!(client instanceof megamek.client.bot.TestBot))                    doAlertDialog("Movement Report", e.getReport());            }        }        public void gameEnd(GameEndEvent e) {            bv.clearMovementData();            for (Iterator i = getBots().values().iterator(); i.hasNext();) {                ((Client) i.next()).die();            }            getBots().clear();                        // Make a list of the player's living units.            Vector living = client.game.getPlayerEntities(client.getLocalPlayer());                        // Be sure to include all units that have retreated.            for (Enumeration iter = client.game.getRetreatedEntities(); iter.hasMoreElements();) {                living.addElement(iter.nextElement());            }                        // Allow players to save their living units to a file.            // Don't bother asking if none survived.            if (!living.isEmpty()                    && doYesNoDialog(Messages.getString("ClientGUI.SaveUnitsDialog.title"), //$NON-NLS-1$                            Messages.getString("ClientGUI.SaveUnitsDialog.message"))) { //$NON-NLS-1$                                // Allow the player to save the units to a file.                saveListFile(living);            } // End user-wants-a-MUL        }        public void gameSettingsChange(GameSettingsChangeEvent e) {            if (boardSelectionDialog != null && boardSelectionDialog.isVisible()) {                boardSelectionDialog.update(client.getMapSettings(), true);            }            if (gameOptionsDialog != null && gameOptionsDialog.isVisible()) {                gameOptionsDialog.update(client.game.getOptions());            }            if (curPanel instanceof ChatLounge) {                ChatLounge cl = (ChatLounge) curPanel;                boolean useMinefields = client.game.getOptions().booleanOption("minefields"); //$NON-NLS-1$                cl.enableMinefields(useMinefields);                if (!useMinefields) {                    client.getLocalPlayer().setNbrMFConventional(0);                    client.getLocalPlayer().setNbrMFCommand(0);                    client.getLocalPlayer().setNbrMFVibra(0);                    client.sendPlayerInfo();                }            }        }        public void gameMapQuery(GameMapQueryEvent e) {            if (boardSelectionDialog != null && boardSelectionDialog.isVisible()) {                boardSelectionDialog.update(e.getSettings(), false);            }        }    };    public Client getClient() {        return client;    }    public Map getBots() {        return bots;    }    /**     * @return Returns the selectedEntityNum.     */    public int getSelectedEntityNum() {        return selectedEntityNum;    }    /**     * @param selectedEntityNum The selectedEntityNum to set.     */    public void setSelectedEntityNum(int selectedEntityNum) {        this.selectedEntityNum = selectedEntityNum;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -