📄 movementdisplay.java
字号:
/* * 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.swing;import megamek.client.Client;import megamek.client.event.BoardViewEvent;import megamek.client.event.BoardViewListener;import megamek.common.BipedMech;import megamek.common.Building;import megamek.common.BuildingTarget;import megamek.common.Compute;import megamek.common.Coords;import megamek.common.Entity;import megamek.common.EntitySelector;import megamek.common.GameTurn;import megamek.common.IEntityMovementMode;import megamek.common.IEntityMovementType;import megamek.common.IGame;import megamek.common.IHex;import megamek.common.Infantry;import megamek.common.Mech;import megamek.common.Minefield;import megamek.common.MiscType;import megamek.common.Mounted;import megamek.common.MovePath;import megamek.common.MoveStep;import megamek.common.PilotingRollData;import megamek.common.Protomech;import megamek.common.Tank;import megamek.common.TargetRoll;import megamek.common.Targetable;import megamek.common.Terrains;import megamek.common.ToHitData;import megamek.common.VTOL;import megamek.common.actions.ChargeAttackAction;import megamek.common.actions.DfaAttackAction;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.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.ArrayList;import java.util.Enumeration;import java.util.Vector;public class MovementDisplay extends StatusBarPhaseDisplay implements ActionListener, DoneButtoned, KeyListener, GameListener, BoardViewListener, Distractable { // Distraction implementation. private DistractableAdapter distracted = new DistractableAdapter(); private static final int NUM_BUTTON_LAYOUTS = 4; public static final String MOVE_WALK = "moveWalk"; //$NON-NLS-1$ public static final String MOVE_NEXT = "moveNext"; //$NON-NLS-1$ public static final String MOVE_JUMP = "moveJump"; //$NON-NLS-1$ public static final String MOVE_BACK_UP = "moveBackUp"; //$NON-NLS-1$ public static final String MOVE_TURN = "moveTurn"; //$NON-NLS-1$ public static final String MOVE_GET_UP = "moveGetUp"; //$NON-NLS-1$ public static final String MOVE_CHARGE = "moveCharge"; //$NON-NLS-1$ public static final String MOVE_DFA = "moveDFA"; //$NON-NLS-1$ public static final String MOVE_GO_PRONE = "moveGoProne"; //$NON-NLS-1$ public static final String MOVE_FLEE = "moveFlee"; //$NON-NLS-1$ public static final String MOVE_EJECT = "moveEject"; //$NON-NLS-1$ public static final String MOVE_LOAD = "moveLoad"; //$NON-NLS-1$ public static final String MOVE_UNLOAD = "moveUnload"; //$NON-NLS-1$ public static final String MOVE_UNJAM = "moveUnjam"; //$NON-NLS-1$ public static final String MOVE_CLEAR = "moveClear"; //$NON-NLS-1$ public static final String MOVE_CANCEL = "moveCancel"; //$NON-NLS-1$ public static final String MOVE_RAISE_ELEVATION = "moveRaiseElevation"; //$NON-NLS-1$ public static final String MOVE_LOWER_ELEVATION = "moveLowerElevation"; //$NON-NLS-1$ public static final String MOVE_SEARCHLIGHT = "moveSearchlight"; //$NON-NLS-1$ public static final String MOVE_LAY_MINE = "moveLayMine"; //$NON-NLS-1$ public static final String MOVE_HULL_DOWN = "moveHullDown"; //$NON-NLS-1$ public static final String MOVE_CLIMB_MODE = "moveClimbMode"; //$NON-NLS-1$ public static final String MOVE_SWIM = "moveSwim"; //$NON-NLS-1$ public static final String MOVE_DIG_IN = "moveDigIn"; //$NON-NLS-1$ public static final String MOVE_FORTIFY = "moveFortify"; //$NON-NLS-1$ // parent game public Client client; private ClientGUI clientgui; // buttons private JPanel panButtons; private JButton butWalk; private JButton butJump; private JButton butBackup; private JButton butTurn; private JButton butSwim; private JButton butUp; private JButton butDown; private JButton butCharge; private JButton butDfa; private JButton butRAC; private JButton butFlee; private JButton butEject; private JButton butLoad; private JButton butUnload; private JButton butSpace; private JButton butClear; private JButton butNext; private JButton butDone; private JButton butMore; private JButton butRaise; private JButton butLower; private JButton butSearchlight; private JButton butLayMine; private JButton butHullDown; private JButton butClimbMode; private JButton butDigIn; private JButton butFortify; private int buttonLayout; //order of buttons for various entity types private ArrayList<JButton> buttonsMech; private ArrayList<JButton> buttonsTank; private ArrayList<JButton> buttonsVtol; private ArrayList<JButton> buttonsInf; // let's keep track of what we're moving, too private int cen = Entity.NONE; // current entity number private MovePath cmd; // considering movement data // what "gear" is our mech in? private int gear; // is the shift key held? private boolean shiftheld; /** * A local copy of the current entity's loaded units. */ private Vector loadedUnits = null; public static final int GEAR_LAND = 0; public static final int GEAR_BACKUP = 1; public static final int GEAR_JUMP = 2; public static final int GEAR_CHARGE = 3; public static final int GEAR_DFA = 4; public static final int GEAR_TURN = 5; public static final int GEAR_SWIM = 6; /** * Creates and lays out a new movement phase display * for the specified client. */ public MovementDisplay(ClientGUI clientgui) { this.clientgui = clientgui; client = clientgui.getClient(); client.game.addGameListener(this); gear = MovementDisplay.GEAR_LAND; shiftheld = false; clientgui.getBoardView().addBoardViewListener(this); setupStatusBar(Messages.getString("MovementDisplay.waitingForMovementPhase")); //$NON-NLS-1$ butClear = new JButton(Messages.getString("MovementDisplay.butClear")); //$NON-NLS-1$ butClear.addActionListener(this); butClear.setEnabled(false); butClear.setActionCommand(MOVE_CLEAR); butClear.addKeyListener(this); butWalk = new JButton(Messages.getString("MovementDisplay.butWalk")); //$NON-NLS-1$ butWalk.addActionListener(this); butWalk.setEnabled(false); butWalk.setActionCommand(MOVE_WALK); butWalk.addKeyListener(this); butJump = new JButton(Messages.getString("MovementDisplay.butJump")); //$NON-NLS-1$ butJump.addActionListener(this); butJump.setEnabled(false); butJump.setActionCommand(MOVE_JUMP); butJump.addKeyListener(this); butSwim = new JButton(Messages.getString("MovementDisplay.butSwim")); //$NON-NLS-1$ butSwim.addActionListener(this); butSwim.setEnabled(false); butSwim.setActionCommand(MOVE_SWIM); butSwim.addKeyListener(this); butBackup = new JButton(Messages.getString("MovementDisplay.butBackup")); //$NON-NLS-1$ butBackup.addActionListener(this); butBackup.setEnabled(false); butBackup.setActionCommand(MOVE_BACK_UP); butBackup.addKeyListener(this); butTurn = new JButton(Messages.getString("MovementDisplay.butTurn")); //$NON-NLS-1$ butTurn.addActionListener(this); butTurn.setEnabled(false); butTurn.setActionCommand(MOVE_TURN); butTurn.addKeyListener(this); butUp = new JButton(Messages.getString("MovementDisplay.butUp")); //$NON-NLS-1$ butUp.addActionListener(this); butUp.setEnabled(false); butUp.setActionCommand(MOVE_GET_UP); butUp.addKeyListener(this); butDown = new JButton(Messages.getString("MovementDisplay.butDown")); //$NON-NLS-1$ butDown.addActionListener(this); butDown.setEnabled(false); butDown.setActionCommand(MOVE_GO_PRONE); butDown.addKeyListener(this); butCharge = new JButton(Messages.getString("MovementDisplay.butCharge")); //$NON-NLS-1$ butCharge.addActionListener(this); butCharge.setEnabled(false); butCharge.setActionCommand(MOVE_CHARGE); butCharge.addKeyListener(this); butDfa = new JButton(Messages.getString("MovementDisplay.butDfa")); //$NON-NLS-1$ butDfa.addActionListener(this); butDfa.setEnabled(false); butDfa.setActionCommand(MOVE_DFA); butDfa.addKeyListener(this); butFlee = new JButton(Messages.getString("MovementDisplay.butFlee")); //$NON-NLS-1$ butFlee.addActionListener(this); butFlee.setEnabled(false); butFlee.setActionCommand(MOVE_FLEE); butFlee.addKeyListener(this); butEject = new JButton(Messages.getString("MovementDisplay.butEject")); //$NON-NLS-1$ butEject.addActionListener(this); butEject.setEnabled(false); butEject.setActionCommand(MOVE_EJECT); butEject.addKeyListener(this); butRAC = new JButton(Messages.getString("MovementDisplay.butRAC")); //$NON-NLS-1$ butRAC.addActionListener(this); butRAC.setEnabled(false); butRAC.setActionCommand(MOVE_UNJAM); butRAC.addKeyListener(this); butSearchlight = new JButton(Messages.getString("MovementDisplay.butSearchlightOn")); //$NON-NLS-1$ butSearchlight.addActionListener(this); butSearchlight.setEnabled(false); butSearchlight.setActionCommand(MOVE_SEARCHLIGHT); butSearchlight.addKeyListener(this); butMore = new JButton(Messages.getString("MovementDisplay.butMore")); //$NON-NLS-1$ butMore.addActionListener(this); butMore.setEnabled(false); butMore.addKeyListener(this); butNext = new JButton(Messages.getString("MovementDisplay.butNext")); //$NON-NLS-1$ butNext.addActionListener(this); butNext.setEnabled(false); butNext.setActionCommand(MOVE_NEXT); butNext.addKeyListener(this); butDone = new JButton(Messages.getString("MovementDisplay.butDone")); //$NON-NLS-1$ butDone.addActionListener(this); butDone.setEnabled(false); butDone.addKeyListener(this); butLoad = new JButton(Messages.getString("MovementDisplay.butLoad")); //$NON-NLS-1$ butLoad.addActionListener(this); butLoad.setEnabled(false); butLoad.setActionCommand(MOVE_LOAD); butLoad.addKeyListener(this); butUnload = new JButton(Messages.getString("MovementDisplay.butUnload")); //$NON-NLS-1$ butUnload.addActionListener(this); butUnload.setEnabled(false); butUnload.setActionCommand(MOVE_UNLOAD); butUnload.addKeyListener(this); butRaise = new JButton(Messages.getString("MovementDisplay.butRaise")); //$NON-NLS-1$ butRaise.addActionListener(this); butRaise.setEnabled(false); butRaise.setActionCommand(MOVE_RAISE_ELEVATION); butRaise.addKeyListener(this); butLower = new JButton(Messages.getString("MovementDisplay.butLower")); //$NON-NLS-1$ butLower.addActionListener(this); butLower.setEnabled(false); butLower.setActionCommand(MOVE_LOWER_ELEVATION); butLower.addKeyListener(this); butLayMine = new JButton(Messages.getString("MovementDisplay.butLayMine")); //$NON-NLS-1$ butLayMine.addActionListener(this); butLayMine.setEnabled(false); butLayMine.setActionCommand(MOVE_LAY_MINE); butLayMine.addKeyListener(this); butHullDown = new JButton(Messages.getString("MovementDisplay.butHullDown")); //$NON-NLS-1$ butHullDown.addActionListener(this); butHullDown.setEnabled(false); butHullDown.setActionCommand(MOVE_HULL_DOWN); butHullDown.addKeyListener(this); butClimbMode = new JButton(Messages.getString("MovementDisplay.butClimbMode")); //$NON-NLS-1$ butClimbMode.addActionListener(this); butClimbMode.setEnabled(false); butClimbMode.setActionCommand(MOVE_CLIMB_MODE); butClimbMode.addKeyListener(this); butDigIn = new JButton(Messages.getString("MovementDisplay.butDigIn")); //$NON-NLS-1$ butDigIn.addActionListener(this); butDigIn.setEnabled(false); butDigIn.setActionCommand(MOVE_DIG_IN); butDigIn.addKeyListener(this); butFortify = new JButton(Messages.getString("MovementDisplay.butFortify")); //$NON-NLS-1$ butFortify.addActionListener(this); butFortify.setEnabled(false); butFortify.setActionCommand(MOVE_FORTIFY); butFortify.addKeyListener(this); butSpace = new JButton("."); butSpace.setEnabled(false); butSpace.addKeyListener(this); //add buttons to the lists, except space, more & next buttonsMech = new ArrayList<JButton>(22); buttonsMech.add(butWalk); buttonsMech.add(butJump); buttonsMech.add(butBackup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -