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

📄 clientgui.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        mechW.addWindowListener(this);        mechW.addKeyListener(this);        mechD = new MechDisplay(this);        mechD.addMechDisplayListener(bv);        mechW.add(mechD);        // added by kenn        Ruler.color1 = GUIPreferences.getInstance().getRulerColor1();        Ruler.color2 = GUIPreferences.getInstance().getRulerColor2();        ruler = new Ruler(frame, this.client, bv);        x = GUIPreferences.getInstance().getRulerPosX();        y = GUIPreferences.getInstance().getRulerPosY();        h = GUIPreferences.getInstance().getRulerSizeHeight();        w = GUIPreferences.getInstance().getRulerSizeWidth();        if (x + w > screenSize.width) {            x = 0;            w = Math.min(w, screenSize.width);        }        if (y + h > screenSize.height) {            y = 0;            h = Math.min(h, screenSize.height);        }        ruler.setLocation(x, y);        ruler.setSize(w, h);        // end kenn        // minimap        minimapW = new Dialog(frame, Messages.getString("ClientGUI.MiniMap"), false); //$NON-NLS-1$        x = GUIPreferences.getInstance().getMinimapPosX();        y = GUIPreferences.getInstance().getMinimapPosY();        try {            minimap = new MiniMap(minimapW, this, bv);        } catch (IOException e) {            doAlertDialog(Messages.getString("ClientGUI.FatalError.title"), Messages.getString("ClientGUI.FatalError.message1") + e); //$NON-NLS-1$ //$NON-NLS-2$            die();        }        minimap.addKeyListener(this);        h = minimap.getSize().height;        w = minimap.getSize().width;        if ((x + 10) >= screenSize.width || (x + w) < 10) {            x = screenSize.width - w;        }        if ((y +10 ) > screenSize.height || (y + h)  < 10 ) {            y = screenSize.height - h;        }        minimapW.setLocation(x, y);        minimapW.addWindowListener(this);        minimapW.addKeyListener(this);        minimapW.add(minimap);        cb = new ChatterBox(this);        this.add(cb.getComponent(), BorderLayout.SOUTH);        client.changePhase(IGame.PHASE_UNKNOWN);        mechSelectorDialog = new MechSelectorDialog(this, unitLoadingDialog);        customBADialog = new CustomBattleArmorDialog(this, unitLoadingDialog);        new Thread(mechSelectorDialog, "Mech Selector Dialog").start(); //$NON-NLS-1$        new Thread(customBADialog, "Custom Battle Armor Dialog").start();    }    /**     * Get the menu bar for this client.     *     * @return the <code>CommonMenuBar</code> of this client.     */    public CommonMenuBar getMenuBar() {        return this.menuBar;    }    /**     * Called when the user selects the "Help->About" menu item.     */    private void showAbout() {        // Do we need to create the "about" dialog?        if (this.about == null) {            this.about = new CommonAboutDialog(this.frame);        }        // Show the about dialog.        this.about.setVisible(true);    }    /**     * Change the default help file name for this client.     * <p/>     * This method should only be called by the constructor     * of subclasses.     *     * @param fileName the <code>String</code> name of the help file     *                 for this <code>Client</code> subclass.  This value should     *                 not be <code>null</code>.     */    protected void setHelpFileName(String fileName) {        if (null != fileName) {            this.helpFileName = fileName;        }    }    /**     * Called when the user selects the "Help->Contents" menu item.     * <p/>     * This method can be called by subclasses.     */    public void showHelp() {        // Do we need to create the "help" dialog?        if (this.help == null) {            this.help = new CommonHelpDialog(this.frame, new File(helpFileName));        }        // Show the help dialog.        this.help.setVisible(true);    }    /**     * Called when the user selects the "View->Client Settings" menu item.     */    private void showSettings() {        // Do we need to create the "settings" dialog?        if (this.setdlg == null) {            this.setdlg = new CommonSettingsDialog(this.frame);        }        // Show the settings dialog.        this.setdlg.setVisible(true);    }    /**     * Called when the user selects the "View->Game Options" menu item.     */    private void showOptions() {        if (client.game.getPhase() == IGame.PHASE_LOUNGE) {            getGameOptionsDialog().setEditable(true);        } else {            getGameOptionsDialog().setEditable(false);        }        // Display the game options dialog.        getGameOptionsDialog().update(client.game.getOptions());        getGameOptionsDialog().setVisible(true);    }    /**     * Called when the user selects the "View->Player List" menu item.     */    private void showPlayerList() {        if (playerListDialog == null) {            playerListDialog = new PlayerListDialog(frame, client);        }        playerListDialog.setVisible(true);    }    /**     * Called when the user selects the "View->Round Report" menu item.     */    private void showRoundReport() {        new MiniReportDisplay(frame, client.roundReport).setVisible(true);    }    /**     * Implement the <code>ActionListener</code> interface.     */    public void actionPerformed(ActionEvent event) {        if (event.getActionCommand().equalsIgnoreCase("fileGameSave")) { //$NON-NLS-1$            FileDialog fd = new FileDialog(frame, Messages.getString("ClientGUI.FileSaveDialog.title"), FileDialog.LOAD); //$NON-NLS-1$            fd.setDirectory("."); //$NON-NLS-1$            // limit file-list to savedgames only            fd.setFilenameFilter(new FilenameFilter() {                public boolean accept(File dir, String name) {                    return (null != name && name.endsWith(".sav")); //$NON-NLS-1$                }            });            //Using the FilenameFilter class would be the appropriate way to            // filter for certain extensions, but it's broken under windoze.  See            // http://developer.java.sun.com/developer/bugParade/bugs/4031440.html            // for details.  The hack below is better than nothing.            fd.setFile("*.sav"); //$NON-NLS-1$            fd.setVisible(true);            if (null != fd.getFile()) {                client.sendChat("/save " + fd.getFile()); //$NON-NLS-1$            }        }        if (event.getActionCommand().equalsIgnoreCase("helpAbout")) { //$NON-NLS-1$            showAbout();        }        if (event.getActionCommand().equalsIgnoreCase("helpContents")) { //$NON-NLS-1$            showHelp();        }        if (event.getActionCommand().equalsIgnoreCase("viewClientSettings")) { //$NON-NLS-1$            showSettings();        }        if (event.getActionCommand().equalsIgnoreCase("viewGameOptions")) { //$NON-NLS-1$            showOptions();        }        if (event.getActionCommand().equalsIgnoreCase("viewPlayerList")) { //$NON-NLS-1$            showPlayerList();        }        if (event.getActionCommand().equalsIgnoreCase("viewRoundReport")) { //$NON-NLS-1$            showRoundReport();        }        if (event.getActionCommand().equals(VIEW_MEK_DISPLAY)) {            toggleDisplay();        } else if (event.getActionCommand().equals(VIEW_MINI_MAP)) {            toggleMap();        } else if (event.getActionCommand().equals(VIEW_UNIT_OVERVIEW)) {            toggleUnitOverview();        } else if (event.getActionCommand().equals(VIEW_ZOOM_IN)) {            bv.zoomIn();        } else if (event.getActionCommand().equals(VIEW_ZOOM_OUT)) {            bv.zoomOut();        } else if (event.getActionCommand().equals(VIEW_LOS_SETTING)) {            showLOSSettingDialog();        }    }    /**     * Saves the current settings to the cfg file.     */    public void saveSettings() {        // save frame location        GUIPreferences.getInstance().setWindowPosX(frame.getLocation().x);        GUIPreferences.getInstance().setWindowPosY(frame.getLocation().y);        GUIPreferences.getInstance().setWindowSizeWidth(frame.getSize().width);        GUIPreferences.getInstance().setWindowSizeHeight(frame.getSize().height);        // also minimap        if (minimapW != null && (minimapW.getSize().width * minimapW.getSize().height) > 0) {            GUIPreferences.getInstance().setMinimapPosX(minimapW.getLocation().x);            GUIPreferences.getInstance().setMinimapPosY(minimapW.getLocation().y);            GUIPreferences.getInstance().setMinimapZoom(minimap.getZoom());        }        // also mech display        if (mechW != null && (mechW.getSize().width * mechW.getSize().height) > 0) {            GUIPreferences.getInstance().setDisplayPosX(mechW.getLocation().x);            GUIPreferences.getInstance().setDisplayPosY(mechW.getLocation().y);            GUIPreferences.getInstance().setDisplaySizeWidth(mechW.getSize().width);            GUIPreferences.getInstance().setDisplaySizeHeight(mechW.getSize().height);        }        // added by kenn        // also ruler display        if (ruler != null && ruler.getSize().width != 0 && ruler.getSize().height != 0) {            GUIPreferences.getInstance().setRulerPosX(ruler.getLocation().x);            GUIPreferences.getInstance().setRulerPosY(ruler.getLocation().y);            GUIPreferences.getInstance().setRulerSizeWidth(ruler.getSize().width);            GUIPreferences.getInstance().setRulerSizeHeight(ruler.getSize().height);        }        // end kenn    }    /**     * Shuts down threads and sockets     */    public void die() {        //Tell all the displays to remove themselves as listeners.        boolean reportHandled = false;        Enumeration names = phaseComponents.keys();        while (names.hasMoreElements()) {            Component component = (Component) phaseComponents.get(names.nextElement());            if (component instanceof ReportDisplay) {                if (reportHandled) {                    continue;                }                reportHandled = true;            }            if (component instanceof Distractable) {                ((Distractable) component).removeAllListeners();            }        } // Handle the next component        frame.removeAll();        frame.setVisible(false);        try {            frame.dispose();        } catch (Throwable error) {            error.printStackTrace();        }        client.die();                //TODO Is there a better solution?        //This is required because the BoardView creates the redraw thread         //that must be stopped explicitly         bv.die();                //TODO Is there a better solution?        //This is required because the ChatLounge adds the listener to the        //MechSummaryCache that must be removed explicitly.        if (chatlounge != null) {            chatlounge.die();        }    }    /**     * Returns the board selection dialog, creating it on the first call     */    public BoardSelectionDialog getBoardSelectionDialog() {        if (boardSelectionDialog == null) {            boardSelectionDialog = new BoardSelectionDialog(this);        }        return boardSelectionDialog;    }    public GameOptionsDialog getGameOptionsDialog() {        if (gameOptionsDialog == null) {            gameOptionsDialog = new GameOptionsDialog(this);        }        return gameOptionsDialog;    }    public MechSelectorDialog getMechSelectorDialog() {        return mechSelectorDialog;    }    public CustomBattleArmorDialog getCustomBADialog() {        return customBADialog;    }    public StartingPositionDialog getStartingPositionDialog() {        if (startingPositionDialog == null) {            startingPositionDialog = new StartingPositionDialog(this);        }        return startingPositionDialog;    }    private void switchPanel(int phase) {        // Clear the old panel's listeners.        if (curPanel instanceof BoardViewListener) {            bv.removeBoardViewListener((BoardViewListener) curPanel);        }        if (curPanel instanceof ActionListener) {            menuBar.removeActionListener((ActionListener) curPanel);        }        if (curPanel instanceof Distractable) {            ((Distractable) curPanel).setIgnoringEvents(true);        }        // Get the new panel.        String name = String.valueOf(phase);        curPanel = (Component) phaseComponents.get(name);        if (null == curPanel) {            curPanel = initializePanel(phase);        }        cardsMain.show(panMain, mainNames.get(name).toString());        cardsSecondary.show(panSecondary, secondaryNames.get(name).toString());        // Set the new panel's listeners        if (curPanel instanceof BoardViewListener) {            bv.addBoardViewListener((BoardViewListener) curPanel);        }        if (curPanel instanceof ActionListener) {            menuBar.addActionListener((ActionListener) curPanel);        }        if (curPanel instanceof Distractable) {            ((Distractable) curPanel).setIgnoringEvents(false);        }        if (curPanel instanceof DoneButtoned) {            Button done = ((DoneButtoned) curPanel).getDoneButton();            this.cb.setDoneButton(done);            done.setVisible(true);        }        // Make the new panel the focus, if the Client option says so        if (GUIPreferences.getInstance().getFocus() && !(client instanceof megamek.client.bot.TestBot)) curPanel.requestFocus();    }    private Component initializePanel(int phase) {        // Create the components for this phase.        String name = String.valueOf(phase);        Component component = null;        String secondary = null;        String main = null;        switch (phase) {            case IGame.PHASE_LOUNGE:                component = new ChatLounge(this);                chatlounge = (ChatLounge) component;                main = "ChatLounge"; //$NON-NLS-1$                secondary = main;                panMain.add(main, component);                panSecondary.add(secondary, ((ChatLounge) component).getSecondaryDisplay());                break;            case IGame.PHASE_STARTING_SCENARIO:                component = new Label(Messages.getString("ClientGUI.StartingScenario")); //$NON-NLS-1$                main = "Label-StartingScenario"; //$NON-NLS-1$                secondary = main;                panMain.add(main, component);                panSecondary.add(secondary, new Label("")); //$NON-NLS-1$                break;            case IGame.PHASE_EXCHANGE:

⌨️ 快捷键说明

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