📄 physicaldisplay.java
字号:
/* * MegaMek - Copyright (C) 2000,2001,2002,2003,2004 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.Building;import megamek.common.BuildingTarget;import megamek.common.Compute;import megamek.common.Coords;import megamek.common.Entity;import megamek.common.IGame;import megamek.common.GameTurn;import megamek.common.Mech;import megamek.common.Mounted;import megamek.common.QuadMech;import megamek.common.Targetable;import megamek.common.ToHitData;import megamek.common.actions.BreakGrappleAttackAction;import megamek.common.actions.BrushOffAttackAction;import megamek.common.actions.ClubAttackAction;import megamek.common.actions.DodgeAction;import megamek.common.actions.JumpJetAttackAction;import megamek.common.actions.GrappleAttackAction;import megamek.common.actions.KickAttackAction;import megamek.common.actions.LayExplosivesAttackAction;import megamek.common.actions.ProtomechPhysicalAttackAction;import megamek.common.actions.PunchAttackAction;import megamek.common.actions.PushAttackAction;import megamek.common.actions.SearchlightAttackAction;import megamek.common.actions.ThrashAttackAction;import megamek.common.actions.TripAttackAction;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.Enumeration;import java.util.Iterator;import java.util.Vector;public class PhysicalDisplay extends StatusBarPhaseDisplay implements GameListener, ActionListener, DoneButtoned, KeyListener, BoardViewListener, Distractable { // Distraction implementation. private DistractableAdapter distracted = new DistractableAdapter(); public static final String PHYSICAL_PUNCH = "punch"; //$NON-NLS-1$ public static final String PHYSICAL_KICK = "kick"; //$NON-NLS-1$ public static final String PHYSICAL_CLUB = "club"; //$NON-NLS-1$ public static final String PHYSICAL_BRUSH_OFF = "brushOff"; //$NON-NLS-1$ public static final String PHYSICAL_THRASH = "thrash"; //$NON-NLS-1$ public static final String PHYSICAL_DODGE = "dodge"; //$NON-NLS-1$ public static final String PHYSICAL_PUSH = "push"; //$NON-NLS-1$ public static final String PHYSICAL_TRIP = "trip"; //$NON-NLS-1$ public static final String PHYSICAL_GRAPPLE = "grapple"; //$NON-NLS-1$ public static final String PHYSICAL_JUMPJET = "jumpjet"; //$NON-NLS-1$ public static final String PHYSICAL_NEXT = "next"; //$NON-NLS-1$ public static final String PHYSICAL_PROTO = "protoPhysical"; //$NON-NLS-1$ public static final String PHYSICAL_SEARCHLIGHT = "fireSearchlight"; //$NON-NLS-1$ public static final String PHYSICAL_EXPLOSIVES = "explosives"; //$NON-NLS-1$ private static final int NUM_BUTTON_LAYOUTS = 2; // parent game private ClientGUI clientgui; private Client client; // buttons private JComponent panButtons; private JButton butPunch; private JButton butKick; private JButton butPush; private JButton butTrip; private JButton butGrapple; private JButton butJumpJet; private JButton butClub; private JButton butBrush; private JButton butThrash; private JButton butDodge; private JButton butProto; private JButton butExplosives; private JButton butNext; private JButton butDone; private JButton butMore; private JButton butSpace; private JButton butSpace2; private JButton butSearchlight; 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 // stuff we want to do private Vector attacks; /** * Creates and lays out a new movement phase display * for the specified client. */ public PhysicalDisplay(ClientGUI clientgui) { this.clientgui = clientgui; this.client = clientgui.getClient(); client.game.addGameListener(this); clientgui.getBoardView().addBoardViewListener(this); attacks = new Vector(); setupStatusBar(Messages.getString("PhysicalDisplay.waitingForPhysicalAttackPhase")); //$NON-NLS-1$ butSpace = new JButton("."); //$NON-NLS-1$ butSpace.setEnabled(false); butSpace2 = new JButton("."); //$NON-NLS-1$ butSpace2.setEnabled(false); butPunch = new JButton(Messages.getString("PhysicalDisplay.Punch")); //$NON-NLS-1$ butPunch.addActionListener(this); butPunch.setEnabled(false); butPunch.setActionCommand(PHYSICAL_PUNCH); butKick = new JButton(Messages.getString("PhysicalDisplay.Kick")); //$NON-NLS-1$ butKick.addActionListener(this); butKick.setEnabled(false); butKick.setActionCommand(PHYSICAL_KICK); butPush = new JButton(Messages.getString("PhysicalDisplay.Push")); //$NON-NLS-1$ butPush.addActionListener(this); butPush.setEnabled(false); butPush.setActionCommand(PHYSICAL_PUSH); butTrip = new JButton(Messages.getString("PhysicalDisplay.Trip")); //$NON-NLS-1$ butTrip.addActionListener(this); butTrip.setEnabled(false); butTrip.setActionCommand(PHYSICAL_TRIP); butGrapple = new JButton(Messages.getString("PhysicalDisplay.Grapple")); //$NON-NLS-1$ butGrapple.addActionListener(this); butGrapple.setEnabled(false); butGrapple.setActionCommand(PHYSICAL_GRAPPLE); butJumpJet = new JButton(Messages.getString("PhysicalDisplay.JumpJet")); //$NON-NLS-1$ butJumpJet.addActionListener(this); butJumpJet.setEnabled(false); butJumpJet.setActionCommand(PHYSICAL_JUMPJET); butClub = new JButton(Messages.getString("PhysicalDisplay.Club")); //$NON-NLS-1$ butClub.addActionListener(this); butClub.setEnabled(false); butClub.setActionCommand(PHYSICAL_CLUB); butBrush = new JButton(Messages.getString("PhysicalDisplay.BrushOff")); //$NON-NLS-1$ butBrush.addActionListener(this); butBrush.setEnabled(false); butBrush.setActionCommand(PHYSICAL_BRUSH_OFF); butThrash = new JButton(Messages.getString("PhysicalDisplay.Trash")); //$NON-NLS-1$ butThrash.addActionListener(this); butThrash.setEnabled(false); butThrash.setActionCommand(PHYSICAL_THRASH); butDodge = new JButton(Messages.getString("PhysicalDisplay.Dodge")); //$NON-NLS-1$ butDodge.addActionListener(this); butDodge.setEnabled(false); butDodge.setActionCommand(PHYSICAL_DODGE); butProto = new JButton(Messages.getString("PhysicalDisplay.ProtoPhysical")); //$NON-NLS-1$ butProto.addActionListener(this); butProto.setEnabled(false); butProto.setActionCommand(PHYSICAL_PROTO); butExplosives = new JButton(Messages.getString("PhysicalDisplay.Explosives")); //$NON-NLS-1$ butExplosives.addActionListener(this); butExplosives.setEnabled(false); butExplosives.setActionCommand(PHYSICAL_EXPLOSIVES); butDone = new JButton(Messages.getString("PhysicalDisplay.Done")); //$NON-NLS-1$ butDone.addActionListener(this); butDone.setEnabled(false); butNext = new JButton(Messages.getString("PhysicalDisplay.NextUnit")); //$NON-NLS-1$ butNext.addActionListener(this); butNext.setEnabled(false); butNext.setActionCommand(PHYSICAL_NEXT); butMore = new JButton(Messages.getString("PhysicalDisplay.More")); //$NON-NLS-1$ butMore.addActionListener(this); butMore.setEnabled(false); butSearchlight = new JButton(Messages.getString("FiringDisplay.Searchlight")); //$NON-NLS-1$ butSearchlight.addActionListener(this); butSearchlight.addKeyListener(this); butSearchlight.setActionCommand(PHYSICAL_SEARCHLIGHT); butSearchlight.setEnabled(false); // layout button grid panButtons = new JPanel(); 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); } private void addBag(JComponent 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(butPunch); panButtons.add(butKick); panButtons.add(butPush); panButtons.add(butClub); panButtons.add(butTrip); panButtons.add(butGrapple); panButtons.add(butMore);// panButtons.add(butDone); break; case 1: panButtons.add(butBrush); panButtons.add(butThrash); panButtons.add(butDodge); panButtons.add(butProto); panButtons.add(butSearchlight); panButtons.add(butExplosives); panButtons.add(butJumpJet); panButtons.add(butMore);// panButtons.add(butDone); break; } validate(); } /** * Selects an entity, by number, for movement. */ public void selectEntity(int en) { if (client.game.getEntity(en) == null) { System.err.println("PhysicalDisplay: tried to select non-existant entity: " + en); //$NON-NLS-1$ return; } this.cen = en; clientgui.setSelectedEntityNum(en); Entity entity = ce(); target(null); if(entity instanceof Mech) { int grapple = ((Mech)entity).getGrappled(); if(grapple != Entity.NONE) { Entity t = client.game.getEntity(grapple); if(t != null) target(t); } } clientgui.getBoardView().highlight(ce().getPosition()); clientgui.getBoardView().select(null); clientgui.getBoardView().cursor(null); clientgui.mechD.displayEntity(entity); clientgui.mechD.showPanel("movement"); //$NON-NLS-1$ clientgui.bv.centerOnHex(entity.getPosition()); // Update the menu bar. clientgui.getMenuBar().setEntity(ce()); // does it have a club? String clubLabel = null; for (Iterator<Mounted> clubs = entity.getClubs().iterator(); clubs.hasNext();) { Mounted club = clubs.next(); String thisLab; if (club.getName().endsWith("Club")) { //$NON-NLS-1$ thisLab = Messages.getString("PhysicalDisplay.Club"); //$NON-NLS-1$ } else { thisLab = club.getName(); } if (clubLabel == null) clubLabel = thisLab; else clubLabel = clubLabel + "/" + thisLab; } if (clubLabel == null) clubLabel = Messages.getString("PhysicalDisplay.Club"); //$NON-NLS-1$ butClub.setText(clubLabel); if ((entity instanceof Mech) && !entity.isProne() && entity.getCrew().getOptions().booleanOption("dodge_maneuver")) { //$NON-NLS-1$ setDodgeEnabled(true); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -