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

📄 chatlounge.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        if (editable && cmd.isOkay()) {            // send changes            c.sendUpdateEntity(entity);            // Do we need to update the members of our C3 network?            if ((c3master != null && !c3master.equals(entity.getC3Master()))                || (c3master == null && entity.getC3Master() != null)) {                playerUnits = c3members.elements();                while (playerUnits.hasMoreElements()) {                    Entity unit = (Entity) playerUnits.nextElement();                    c.sendUpdateEntity(unit);                }            }        }    }    /**     * Pop up the view mech dialog     */    public void mechReadout() {        if (lisEntities.getSelectedIndex() == -1) {            return;        }        Entity entity = client.game.getEntity(entityCorrespondance[lisEntities.getSelectedIndex()]);        MechView mechView = new MechView(entity);        TextArea ta = new TextArea();        ta.setEditable(false);        ta.setFont(new Font("Monospaced", Font.PLAIN, 12)); //$NON-NLS-1$        ta.setText(mechView.getMechReadout());        final Dialog dialog = new Dialog(clientgui.frame, Messages.getString("ChatLounge.quickView"), false); //$NON-NLS-1$        Button btn = new Button(Messages.getString("Okay")); //$NON-NLS-1$        dialog.add("South", btn); //$NON-NLS-1$        btn.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(ActionEvent e) {                dialog.setVisible(false);            }        });        dialog.addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(WindowEvent e) {                dialog.setVisible(false);            }        });        dialog.add("Center", ta); //$NON-NLS-1$        // Preview image of the Mech...        BufferedPanel panPreview = new BufferedPanel();        panPreview.setPreferredSize(84, 72);        clientgui.loadPreviewImage(panPreview, entity);        dialog.add("North", panPreview); //$NON-NLS-1$        dialog.setLocation(            clientgui.frame.getLocation().x + clientgui.frame.getSize().width / 2 - dialog.getSize().width / 2,            clientgui.frame.getLocation().y + clientgui.frame.getSize().height / 5 - dialog.getSize().height / 2);        dialog.setSize(300, 450);        dialog.validate();        dialog.setVisible(true);    }    /**     * Pop up the dialog to load a mech     */    public void loadMech() {        clientgui.getMechSelectorDialog().setVisible(true);    }    public void loadCustomBA() {        clientgui.getCustomBADialog().setVisible(true);    }    public void viewGroup() {        new MechGroupView(clientgui.getFrame(), client, entityCorrespondance).setVisible(true);    }    //    // GameListener    //    public void gamePlayerChange(GamePlayerChangeEvent e) {        // Are we ignoring events?        if (this.isIgnoringEvents()) {            return;        }        refreshDoneButton();        refreshBVs();        refreshPlayerInfo();        refreshStarts();        refreshCamos();        refreshMinefield();    }    public void gamePhaseChange(GamePhaseChangeEvent e) {        // Are we ignoring events?        if (this.isIgnoringEvents()) {            return;        }        if (client.game.getPhase() == IGame.PHASE_LOUNGE) {            refreshDoneButton();            refreshGameSettings();            refreshPlayerInfo();            refreshTeams();            refreshCamos();            refreshMinefield();            refreshEntities();            refreshBVs();            refreshStarts();            refreshBoardSettings();        }    }    public void gameEntityNew(GameEntityNewEvent e) {        // Are we ignoring events?        if (this.isIgnoringEvents()) {            return;        }        refreshEntities();        refreshBVs();    }    public void gameEntityRemove(GameEntityRemoveEvent e) {        // Are we ignoring events?        if (this.isIgnoringEvents()) {            return;        }        refreshEntities();        refreshBVs();    }    public void gameSettingsChange(GameSettingsChangeEvent e) {        // Are we ignoring events?        if (this.isIgnoringEvents()) {            return;        }        refreshGameSettings();        refreshBoardSettings();        refreshEntities();    }    /*     * NOTE: On linux, this gets called even when programatically updating the     * list box selected item.  Do not let this go into an infinite loop.  Do not     * update the selected item (even indirectly, by sending player info) if      * it is already selected.     */    public void itemStateChanged(ItemEvent ev) {        // Are we ignoring events?        if (this.isIgnoringEvents()) {            return;        }        if (ev.getSource() == choTeam) {            changeTeam(choTeam.getSelectedIndex());        } else if (ev.getSource() == chkBV || ev.getSource() == chkTons || ev.getSource() == chkCost) {            refreshBVs();            if (ev.getSource() == chkBV) {                labBVs.setText(Messages.getString("ChatLounge.labBVs.BV"));            } else if (ev.getSource() == chkTons) {                labBVs.setText(Messages.getString("ChatLounge.labBVs.Tons"));            } else {                labBVs.setText(Messages.getString("ChatLounge.labBVs.Cost"));            }        } else if (ev.getSource() == lisEntities) {            boolean selected = lisEntities.getSelectedIndex() != -1;            butCustom.setEnabled(selected);            // Handle "Blind drop" option.            if (selected && client.game.getOptions().booleanOption("blind_drop")) { //$NON-NLS-1$                Entity entity = client.game.getEntity(entityCorrespondance[lisEntities.getSelectedIndex()]);                butMechReadout.setEnabled(entity.getOwner().equals(client.getLocalPlayer()));                butCustom.setEnabled(entity.getOwner().equals(client.getLocalPlayer()));            } else {                butMechReadout.setEnabled(selected);            }            butDelete.setEnabled(selected);        }    }    //    // ActionListener    //    public void actionPerformed(ActionEvent ev) {        // Are we ignoring events?        if (this.isIgnoringEvents()) {            return;        }        if (ev.getSource() == butDone) {                        // enforce exclusive deployment zones in double blind            if (client.game.getOptions().booleanOption("double_blind") &&                client.game.getOptions().booleanOption("exclusive_db_deployment")) {                int i = client.getLocalPlayer().getStartingPos();                if (i == 0) {                    clientgui.doAlertDialog("Starting Position not allowed","In Double Blind play, you cannot choose 'Any' as starting position.");                    return;                }                for (Enumeration e = client.game.getPlayers();e.hasMoreElements();) {                    Player player = (Player)e.nextElement();                    if (player.getStartingPos() == 0) {                        continue;                    }                    // check for overlapping starting directions                    if ((player.getStartingPos() == i ||                        player.getStartingPos()+1 == i ||                        player.getStartingPos()-1 == i) &&                        player.getId() != client.getLocalPlayer().getId() ) {                       clientgui.doAlertDialog("Must choose exclusive deployment zone","When using double blind, each player needs to have an exclusive deployment zone.");                       return;                    }                }            }            boolean anyDelayed = false;            Enumeration iter = client.getEntities();            while (iter.hasMoreElements()) {                Entity en = (Entity) iter.nextElement();                if (en.getDeployRound() > 0) {                    anyDelayed = true;                    break;                }            }            boolean done = !client.getLocalPlayer().isDone();            client.sendDone(done);            refreshDoneButton(done);            for (Iterator i = clientgui.getBots().values().iterator(); i.hasNext();) {                ((Client)i.next()).sendDone(done);            }        } else if (ev.getSource() == butLoad) {            loadMech();        } else if (ev.getSource() == butLoadCustomBA) {            loadCustomBA();        } else if (ev.getSource() == butCustom || ev.getSource() == lisEntities) {            customizeMech();        } else if (ev.getSource() == butDelete) {            // delete mech            Entity e = client.getEntity(entityCorrespondance[lisEntities.getSelectedIndex()]);            Client c = (Client)clientgui.getBots().get(e.getOwner().getName());            if (c == null) {                c = client;            }            if (lisEntities.getSelectedIndex() != -1) {                c.sendDeleteEntity(entityCorrespondance[lisEntities.getSelectedIndex()]);            }        } else if (ev.getSource() == butDeleteAll) {            // Build a Vector of this player's entities.            Vector currentUnits = client.game.getPlayerEntities(client.getLocalPlayer());            // Walk through the vector, deleting the entities.            Enumeration entities = currentUnits.elements();            while (entities.hasMoreElements()) {                final Entity entity = (Entity) entities.nextElement();                client.sendDeleteEntity(entity.getId());            }        } else if (ev.getSource() == butChangeBoard || ev.getSource() == lisBoardsSelected) {            // board settings            clientgui.getBoardSelectionDialog().update(client.getMapSettings(), true);            clientgui.getBoardSelectionDialog().setVisible(true);        } else if (ev.getSource() == butOptions) {            // Make sure the game options dialog is editable.            if (!clientgui.getGameOptionsDialog().isEditable()) {                clientgui.getGameOptionsDialog().setEditable(true);            }            // Display the game options dialog.            clientgui.getGameOptionsDialog().update(client.game.getOptions());            clientgui.getGameOptionsDialog().setVisible(true);        } else if (ev.getSource() == butChangeStart || ev.getSource() == lisStarts) {            Client c = getPlayerListSelected(lisStarts);            if (c == null) {                clientgui.doAlertDialog(Messages.getString("ChatLounge.ImproperCommand"), Messages.getString("ChatLounge.SelectBotOrPlayer")); //$NON-NLS-1$ //$NON-NLS-2$                return;            }            clientgui.getStartingPositionDialog().setClient(c);            clientgui.getStartingPositionDialog().update();            clientgui.getStartingPositionDialog().setVisible(true);        } else if (ev.getSource() == butMechReadout) {            mechReadout();        } else if (ev.getSource() == butViewGroup) {            viewGroup();        } else if (ev.getSource() == butLoadList) {            // Allow the player to replace their current            // list of entities with a list from a file.            clientgui.loadListFile();        } else if (ev.getSource() == butSaveList) {            // Allow the player to save their current            // list of entities to a file.            clientgui.saveListFile(client.game.getPlayerEntities(client.getLocalPlayer()));        } else if (ev.getSource() == butMinefield) {            updateMinefield();        } else if (ev.getSource() == butCamo) {            camoDialog.setVisible(true);        } else if (ev.getSource() == butAddBot) {            String name = "Bot" + lisPlayerInfo.getItemCount(); //$NON-NLS-1$            Prompt p = new Prompt(clientgui.frame, Messages.getString("ChatLounge.ChooseBotName"), Messages.getString("ChatLounge.Name"), name, 15); //$NON-NLS-1$ //$NON-NLS-2$            if (!p.showDialog()){                return;            }            if (p.getText().trim().equals("")) { //$NON-NLS-1$                name = "Bot" + lisPlayerInfo.getItemCount(); //$NON-NLS-1$            } else {                name = p.getText();            }            BotClient c = new TestBot(name, client.getHost(), client.getPort());            c.game.addGameListener(new BotGUI(c));            try {                c.connect();            } catch (Exception e) {                clientgui.doAlertDialog(Messages.getString("ChatLounge.AlertBot.title"), Messages.getString("ChatLounge.AlertBot.message")); //$NON-NLS-1$ //$NON-NLS-2$            }            c.retrieveServerInfo();            clientgui.getBots().put(name, c);        } else if (ev.getSource() == butRemoveBot) {            Client c = getPlayerListSelected(lisPlayerInfo);            if (c == null || c == client) {                clientgui.doAlertDialog(Messages.getString("ChatLounge.ImproperCommand"), Messages.getString("ChatLounge.SelectBo")); //$NON-NLS-1$ //$NON-NLS-2$                return;            }             c.die();            clientgui.getBots().remove(c.getName());        }    }        private Client getPlayerListSelected(List l) {        if (l.getSelectedIndex() == -1) {            return client;        }        String name = l.getSelectedItem().substring(0, Math.max(0,l.getSelectedItem().indexOf(" :"))); //$NON-NLS-1$        BotClient c = (BotClient)clientgui.getBots().get(name);        if (c == null && client.getName().equals(name)) {            return client;        }        return c;    }        /**     * Determine if the listener is currently distracted.     *     * @return  <code>true</code> if the listener is ignoring events.     */    public boolean isIgnoringEvents() {        return this.distracted.isIgnoringEvents();    }    /**     * Specify if the listener should be distracted.     *     * @param   distract <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>java.awt.Button</code> that activates this     *          object's "Done" action.     */    public Button getDoneButton() {        return butDone;    }    /**     * Stop just ignoring events and actually stop listening to them.     */    public void removeAllListeners() {        client.game.removeGameListener(this);        clientgui.getBoardView().removeBoardViewListener(this);    }    /**     * Get the secondary display section of this phase.     *     * @return  the <code>Component</code> which is displayed in the     *          secondary section during this phase.     */    public Component getSecondaryDisplay() {        return labStatus;    }    //TODO Is there a better solution?    //This is required because the ChatLounge adds the listener to the    //MechSummaryCache that must be removed explicitly.                public void die() {        MechSummaryCache.getInstance().removeListener(mechSummaryCacheListener);    }}

⌨️ 快捷键说明

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