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

📄 firingdisplay.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * MegaMek - * Copyright (C) 2000,2001,2002,2003,2004,2005 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.AWT;import java.awt.*;import java.awt.event.*;import java.util.*;import megamek.client.Client;import megamek.client.event.BoardViewEvent;import megamek.client.event.BoardViewListener;import megamek.client.ui.AWT.widget.IndexedCheckbox;import megamek.common.*;import megamek.common.actions.*;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 megamek.common.LosEffects;public class FiringDisplay     extends StatusBarPhaseDisplay    implements BoardViewListener, GameListener, ActionListener, DoneButtoned,               KeyListener, ItemListener, Distractable{    // Distraction implementation.    private DistractableAdapter distracted = new DistractableAdapter();    private static final int    NUM_BUTTON_LAYOUTS = 2;        // Action command names    public static final String FIRE_AIM        = "fireAim"; //$NON-NLS-1$    public static final String FIRE_FIND_CLUB  = "fireFindClub"; //$NON-NLS-1$    public static final String FIRE_FIRE       = "fireFire"; //$NON-NLS-1$    public static final String FIRE_MODE       = "fireMode"; //$NON-NLS-1$    public static final String FIRE_FLIP_ARMS  = "fireFlipArms"; //$NON-NLS-1$    public static final String FIRE_MORE       = "fireMore"; //$NON-NLS-1$    public static final String FIRE_NEXT       = "fireNext"; //$NON-NLS-1$    public static final String FIRE_NEXT_TARG  = "fireNextTarg"; //$NON-NLS-1$    public static final String FIRE_SKIP       = "fireSkip"; //$NON-NLS-1$    public static final String FIRE_SPOT       = "fireSpot"; //$NON-NLS-1$    public static final String FIRE_TWIST      = "fireTwist"; //$NON-NLS-1$    public static final String FIRE_CANCEL     = "fireCancel"; //$NON-NLS-1$    public static final String FIRE_SEARCHLIGHT= "fireSearchlight"; //$NON-NLS-1$    // parent game    public Client client;    private ClientGUI clientgui;    // buttons    private Container        panButtons;        private Button            butFire;    private Button            butTwist;    private Button            butSkip;        private Button            butFindClub;    private Button            butNextTarg;    private Button            butFlipArms;    private Button            butSpot;    private Button            butSearchlight;    //    private Button            butReport;    private Button            butSpace;    private Button            butFireMode; // Fire Mode - Add a Fire Mode Button - Rasia        private Button            butNext;    private Button            butDone;    private Button            butMore;        private int               buttonLayout;    // let's keep track of what we're shooting and at what, too    private int                cen = Entity.NONE;        // current entity number    private Targetable         target;        // target     // HACK : track when we wan to show the target choice dialog.    private boolean            showTargetChoice = true;      // shots we have so far.    private Vector attacks;        // is the shift key held?    private boolean            shiftheld;    private boolean            twisting;    private Entity[]            visibleTargets  = null;    private int                 lastTargetID    = -1;        private AimedShotHandler   ash;    /**     * Creates and lays out a new firing phase display      * for the specified client.     */    public FiringDisplay(ClientGUI clientgui) {        this.client = clientgui.getClient();        this.clientgui = clientgui;        client.game.addGameListener(this);                clientgui.getBoardView().addBoardViewListener(this);                shiftheld = false;            // fire        attacks = new Vector();        setupStatusBar(Messages.getString("FiringDisplay.waitingForFiringPhase")); //$NON-NLS-1$                butFire = new Button(Messages.getString("FiringDisplay.Fire")); //$NON-NLS-1$        butFire.addActionListener(this);        butFire.addKeyListener(this);        butFire.setActionCommand(FIRE_FIRE);        butFire.setEnabled(false);                butSkip = new Button(Messages.getString("FiringDisplay.Skip")); //$NON-NLS-1$        butSkip.addActionListener(this);        butSkip.addKeyListener(this);        butSkip.setActionCommand(FIRE_SKIP);        butSkip.setEnabled(false);                butTwist = new Button(Messages.getString("FiringDisplay.Twist")); //$NON-NLS-1$        butTwist.addActionListener(this);        butTwist.addKeyListener(this);        butTwist.setActionCommand(FIRE_TWIST);        butTwist.setEnabled(false);                butFindClub = new Button(Messages.getString("FiringDisplay.FindClub")); //$NON-NLS-1$        butFindClub.addActionListener(this);        butFindClub.addKeyListener(this);        butFindClub.setActionCommand(FIRE_FIND_CLUB);        butFindClub.setEnabled(false);                butNextTarg = new Button(Messages.getString("FiringDisplay.NextTarget")); //$NON-NLS-1$        butNextTarg.addActionListener(this);        butNextTarg.addKeyListener(this);        butNextTarg.setActionCommand(FIRE_NEXT_TARG);        butNextTarg.setEnabled(false);                butFlipArms = new Button(Messages.getString("FiringDisplay.FlipArms")); //$NON-NLS-1$        butFlipArms.addActionListener(this);        butFlipArms.addKeyListener(this);        butFlipArms.setActionCommand(FIRE_FLIP_ARMS);        butFlipArms.setEnabled(false);                butSpot = new Button(Messages.getString("FiringDisplay.Spot")); //$NON-NLS-1$        butSpot.addActionListener(this);        butSpot.addKeyListener(this);        butSpot.setActionCommand(FIRE_SPOT);        butSpot.setEnabled(false);                butSearchlight = new Button(Messages.getString("FiringDisplay.Searchlight")); //$NON-NLS-1$        butSearchlight.addActionListener(this);        butSearchlight.addKeyListener(this);        butSearchlight.setActionCommand(FIRE_SEARCHLIGHT);        butSearchlight.setEnabled(false);        butSpace = new Button("."); //$NON-NLS-1$        butSpace.setEnabled(false);        // Fire Mode - Adding a Fire Mode Button to the 2nd Menu - Rasia        butFireMode = new Button(Messages.getString("FiringDisplay.Mode")); //$NON-NLS-1$        butFireMode.addActionListener(this);        butFireMode.addKeyListener(this);        butFireMode.setActionCommand(FIRE_MODE);        butFireMode.setEnabled(false);        butDone = new Button(Messages.getString("FiringDisplay.Done")); //$NON-NLS-1$        butDone.addActionListener(this);        butDone.addKeyListener(this);        butDone.setEnabled(false);                butNext = new Button(Messages.getString("FiringDisplay.NextUnit")); //$NON-NLS-1$        butNext.addActionListener(this);        butNext.addKeyListener(this);        butNext.setActionCommand(FIRE_NEXT);        butNext.setEnabled(false);                butMore = new Button(Messages.getString("FiringDisplay.More")); //$NON-NLS-1$        butMore.addActionListener(this);        butMore.addKeyListener(this);        butMore.setActionCommand(FIRE_MORE);        butMore.setEnabled(false);                // layout button grid        panButtons = new Panel();        buttonLayout = 0;        setupButtonPanel();                // 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);                // mech display.        clientgui.mechD.wPan.weaponList.addItemListener(this);        clientgui.mechD.wPan.weaponList.addKeyListener(this);        ash = new AimedShotHandler();        }        private void addBag(Component comp, GridBagLayout gridbag, GridBagConstraints c) {        gridbag.setConstraints(comp, c);        add(comp);        comp.addKeyListener(this);    }    private void setupButtonPanel() {        panButtons.removeAll();        panButtons.setLayout(new GridLayout(0, 8));                switch (buttonLayout) {        case 0 :            panButtons.add(butNext);            panButtons.add(butFire);            panButtons.add(butSkip);            panButtons.add(butNextTarg);            panButtons.add(butTwist);            panButtons.add(butFireMode);            panButtons.add(butMore);//             panButtons.add(butDone);            break;        case 1 :            panButtons.add(butNext);            panButtons.add(butFire);            panButtons.add(butFlipArms);            panButtons.add(butFindClub);            panButtons.add(butSpot);            panButtons.add(butSearchlight);            panButtons.add(butMore);//             panButtons.add(butDone);            break;        }                validate();    }    /**     * Selects an entity, by number, for movement.     */    public void selectEntity(int en) {        // clear any previously considered attacks        if (en != cen) {            clearAttacks();            refreshAll();        }        if (client.game.getEntity(en) != null) {            this.cen = en;            clientgui.setSelectedEntityNum(en);            // If the selected entity is not on the board, use the next one.            // ASSUMPTION: there will always be *at least one* entity on map.            if ( null == ce().getPosition() ) {                // Walk through the list of entities for this player.                for ( int nextId = client.getNextEntityNum(en);                    nextId != en;                    nextId = client.getNextEntityNum(nextId) ) {                                if (null != client.game.getEntity(nextId).getPosition()) {                        this.cen = nextId;                        break;                    }                } // Check the player's next entity.                // We were *supposed* to have found an on-board entity.                if ( null == ce().getPosition() ) {                    System.err.println                        ("FiringDisplay: could not find an on-board entity: " + //$NON-NLS-1$                         en);                    return;                }            } // End ce()-not-on-board            int lastTarget = ce().getLastTarget();            if(ce() instanceof Mech) {                int grapple = ((Mech)ce()).getGrappled();                if(grapple != Entity.NONE) {                    lastTarget = grapple;                }                        }            Entity t = client.game.getEntity(lastTarget);            target(t);            clientgui.getBoardView().highlight(ce().getPosition());            clientgui.getBoardView().select(null);            clientgui.getBoardView().cursor(null);            refreshAll();            cacheVisibleTargets();            if (!clientgui.bv.isMovingUnits()) {                clientgui.bv.centerOnHex(ce().getPosition());            }            // Update the menu bar.            clientgui.getMenuBar().setEntity( ce() );                        // 2003-12-29, nemchenk -- only twist if crew conscious            setTwistEnabled(ce().canChangeSecondaryFacing() && ce().getCrew().isActive());            setFindClubEnabled(FindClubAction.canMechFindClub(client.game, en));            setSpotEnabled(ce().canSpot()              && client.game.getOptions().booleanOption("indirect_fire")); //$NON-NLS-1$            setFlipArmsEnabled(ce().canFlipArms());            updateSearchlight();        } else {            System.err.println("FiringDisplay: tried to select non-existant entity: " + en); //$NON-NLS-1$

⌨️ 快捷键说明

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