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

📄 deploymentdisplay.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * MegaMek - Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Ben Mazur (bmazur@sev.org) *  *  This program is free software; you can redistribute it and/or modify it  *  under the terms of the GNU General Public License as published by the Free  *  Software Foundation; either version 2 of the License, or (at your option)  *  any later version. *  *  This program is distributed in the hope that it will be useful, but  *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License  *  for more details. */package megamek.client.ui.swing;import megamek.client.Client;import megamek.client.event.BoardViewEvent;import megamek.client.event.BoardViewListener;import megamek.common.Compute;import megamek.common.Coords;import megamek.common.Entity;import megamek.common.IGame;import megamek.common.Player;import megamek.common.event.GameListener;import megamek.common.event.GamePhaseChangeEvent;import megamek.common.event.GameTurnChangeEvent;import megamek.common.util.Distractable;import megamek.common.util.DistractableAdapter;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JOptionPane;import javax.swing.JPanel;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.util.Enumeration;import java.util.Vector;public class DeploymentDisplay        extends StatusBarPhaseDisplay        implements BoardViewListener, ActionListener, DoneButtoned,        KeyListener, GameListener, Distractable {    // Distraction implementation.    private DistractableAdapter distracted = new DistractableAdapter();    // Action command names    public static final String DEPLOY_TURN = "deployTurn"; //$NON-NLS-1$    public static final String DEPLOY_NEXT = "deployNext"; //$NON-NLS-1$    public static final String DEPLOY_LOAD = "deployLoad"; //$NON-NLS-1$    public static final String DEPLOY_UNLOAD = "deployUnload"; //$NON-NLS-1$    public static final String DEPLOY_REMOVE = "deployRemove"; //$NON-NLS-1$    public static final String DEPLOY_ASSAULTDROP = "assaultDrop"; //$NON-NLS-1$    // parent game    public Client client;    private ClientGUI clientgui;    // buttons    private JPanel panButtons;    private JButton butNext;    private JButton butTurn;//     private JButton            butSpace;//     private JButton            butSpace2;//     private JButton            butSpace3;    private JButton butLoad;    private JButton butUnload;    private JButton butRemove;    private JButton butAssaultDrop;    private JButton butDone;    private int cen = Entity.NONE;    // current entity number    // is the shift key held?    private boolean turnMode = false;    private boolean assaultDropPreference = false;    /**     * Creates and lays out a new deployment phase display     * for the specified client.     */    public DeploymentDisplay(ClientGUI clientgui) {        this.clientgui = clientgui;        client = clientgui.getClient();        client.game.addGameListener(this);        clientgui.getBoardView().addBoardViewListener(this);        setupStatusBar(Messages.getString("DeploymentDisplay.waitingForDeploymentPhase")); //$NON-NLS-1$        butTurn = new JButton(Messages.getString("DeploymentDisplay.Turn")); //$NON-NLS-1$        butTurn.addActionListener(this);        butTurn.setActionCommand(DEPLOY_TURN);        butTurn.setEnabled(false);                        //         butSpace = new JButton(".");//         butSpace.setEnabled(false);//         butSpace2 = new JButton(".");//         butSpace2.setEnabled(false);//         butSpace3 = new JButton(".");//         butSpace3.setEnabled(false);        butLoad = new JButton(Messages.getString("DeploymentDisplay.Load")); //$NON-NLS-1$        butLoad.addActionListener(this);        butLoad.setActionCommand(DEPLOY_LOAD);        butLoad.setEnabled(false);        butUnload = new JButton(Messages.getString("DeploymentDisplay.Unload")); //$NON-NLS-1$        butUnload.addActionListener(this);        butUnload.setActionCommand(DEPLOY_UNLOAD);        butUnload.setEnabled(false);        butNext = new JButton(Messages.getString("DeploymentDisplay.NextUnit")); //$NON-NLS-1$        butNext.addActionListener(this);        butNext.setActionCommand(DEPLOY_NEXT);        butNext.setEnabled(true);        butRemove = new JButton(Messages.getString("DeploymentDisplay.Remove")); //$NON-NLS-1$        butRemove.addActionListener(this);        butRemove.setActionCommand(DEPLOY_REMOVE);        setRemoveEnabled(true);        butAssaultDrop = new JButton(Messages.getString("DeploymentDisplay.AssaultDropOn")); //$NON-NLS-1$        butAssaultDrop.addActionListener(this);        butAssaultDrop.setActionCommand(DEPLOY_ASSAULTDROP);        butAssaultDrop.setEnabled(false);        butDone = new JButton(Messages.getString("DeploymentDisplay.Deploy")); //$NON-NLS-1$        butDone.addActionListener(this);        butDone.setEnabled(false);        // layout button grid        panButtons = new JPanel();        panButtons.setLayout(new GridLayout(0, 8));        panButtons.add(butNext);        panButtons.add(butTurn);        panButtons.add(butLoad);        panButtons.add(butUnload);        panButtons.add(butRemove);        panButtons.add(butAssaultDrop);//         panButtons.add(butSpace);//         panButtons.add(butSpace2);//         panButtons.add(butSpace3);//         panButtons.add(butDone);        // layout screen        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        setLayout(gridbag);        c.fill = GridBagConstraints.BOTH;        c.weightx = 1.0;        c.weighty = 1.0;        c.insets = new Insets(1, 1, 1, 1);//         c.gridwidth = GridBagConstraints.REMAINDER;//         addBag(clientgui.bv, gridbag, c);//         c.weightx = 1.0;    c.weighty = 0;//         c.gridwidth = 1;//         addBag(client.cb.getComponent(), gridbag, c);        c.gridwidth = GridBagConstraints.REMAINDER;        c.weightx = 0.0;        c.weighty = 0.0;        addBag(panButtons, gridbag, c);        c.weightx = 1.0;        c.weighty = 0.0;        c.gridwidth = GridBagConstraints.REMAINDER;        addBag(panStatus, gridbag, c);        clientgui.bv.addKeyListener(this);        addKeyListener(this);    }    private void addBag(JComponent comp, GridBagLayout gridbag, GridBagConstraints c) {        gridbag.setConstraints(comp, c);        add(comp);        comp.addKeyListener(this);    }    /**     * Selects an entity for deployment     */    public void selectEntity(int en) {        // hmm, sometimes this gets called when there's no ready entities?        if (client.game.getEntity(en) == null) {            System.err.println("DeploymentDisplay: tried to select non-existant entity: " + en); //$NON-NLS-1$            return;        }        // remove C3 sprites from earlier here, or we might crash when        // trying to draw a c3 sprite belonging to the previously selected,        // but not deployed entity        clientgui.bv.clearC3Networks();        cen = en;        clientgui.setSelectedEntityNum(en);        setTurnEnabled(true);        butDone.setEnabled(false);        setLoadEnabled(true);        setUnloadEnabled(true);        clientgui.getBoardView().select(null);        clientgui.getBoardView().cursor(null);        // RACE : if player clicks fast enough, ce() is null.        if (null != ce()) {            // set facing according to starting position            switch (client.getLocalPlayer().getStartingPos()) {                case 8:                    ce().setFacing(1);                    ce().setSecondaryFacing(1);                    break;                case 7:                    ce().setFacing(1);                    ce().setSecondaryFacing(1);                    break;                case 6:                    ce().setFacing(0);                    ce().setSecondaryFacing(0);                    break;                case 5:                    ce().setFacing(5);                    ce().setSecondaryFacing(5);                    break;                case 4:                    ce().setFacing(5);                    ce().setSecondaryFacing(5);                    break;                case 3:                    ce().setFacing(4);                    ce().setSecondaryFacing(4);                    break;                case 2:                    ce().setFacing(3);                    ce().setSecondaryFacing(3);                    break;                case 1:                    ce().setFacing(2);                    ce().setSecondaryFacing(2);                    break;                case 0:                    ce().setFacing(0);                    ce().setSecondaryFacing(0);                    break;            }            setAssaultDropEnabled(ce().canAssaultDrop()                    && ce().getGame().getOptions().booleanOption("assault_drop"));            clientgui.mechD.displayEntity(ce());            clientgui.mechD.showPanel("movement"); //$NON-NLS-1$                    // Update the menu bar.            clientgui.getMenuBar().setEntity(ce());        }    }    /**     * Enables relevant buttons and sets up for your turn.     */    private void beginMyTurn() {        clientgui.setDisplayVisible(true);        selectEntity(client.getFirstDeployableEntityNum());        setNextEnabled(true);        Player p = client.getLocalPlayer();        // mark deployment hexes        clientgui.bv.markDeploymentHexesFor(p);        clientgui.bv.repaint(100);    }    /**     * Clears out old deployment data and disables relevant buttons.     */    private void endMyTurn() {        // end my turn, then.        disableButtons();        Entity next = client.game.getNextEntity(client.game.getTurnIndex());        if (IGame.PHASE_DEPLOYMENT == client.game.getPhase()                && null != next                && null != ce()                && next.getOwnerId() != ce().getOwnerId()) {            clientgui.setDisplayVisible(false);        }        cen = Entity.NONE;        clientgui.getBoardView().select(null);        clientgui.getBoardView().highlight(null);        clientgui.getBoardView().cursor(null);        clientgui.bv.markDeploymentHexesFor(null);        clientgui.bv.repaint(100);    }    /**     * Disables all buttons in the interface     */    private void disableButtons() {        setTurnEnabled(false);        setNextEnabled(false);        butDone.setEnabled(false);        setLoadEnabled(false);        setUnloadEnabled(false);    }    /**     * Sends a deployment to the server     */    private void deploy() {        disableButtons();        Entity en = ce();        client.deploy(cen, en.getPosition(), en.getFacing(), en.getLoadedUnits(), assaultDropPreference);        en.setDeployed(true);    }    /**     * Sends an entity removal to the server     */    private void remove() {        disableButtons();        client.sendDeleteEntity(cen);        beginMyTurn();    }    /**     * Returns the current entity.     */    private Entity ce() {        return client.game.getEntity(cen);    }    public void die() {        if (client.isMyTurn()) {            endMyTurn();        }        clientgui.bv.markDeploymentHexesFor(null);

⌨️ 快捷键说明

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