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

📄 custommechdialog.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * 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. *//* * CustomMechDialog.java * * Created on March 18, 2002, 2:56 PM */package megamek.client.ui.AWT;import megamek.client.Client;import megamek.common.AmmoType;import megamek.common.Entity;import megamek.common.EntitySelector;import megamek.common.EquipmentType;import megamek.common.IGame;import megamek.common.IOffBoardDirections;import megamek.common.Infantry;import megamek.common.Mech;import megamek.common.MiscType;import megamek.common.Mounted;import megamek.common.Pilot;import megamek.common.Player;import megamek.common.Protomech;import megamek.common.TechConstants;import megamek.common.WeaponType;import megamek.common.options.IOption;import megamek.common.options.IOptionGroup;import megamek.common.options.PilotOptions;import megamek.common.preference.PreferenceManager;import java.awt.Button;import java.awt.Checkbox;import java.awt.Choice;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.Label;import java.awt.Panel;import java.awt.ScrollPane;import java.awt.TextArea;import java.awt.TextField;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;/** * A dialog that a player can use to customize his mech before battle.   * Currently, changing pilots, setting up C3 networks, changing ammunition, * deploying artillery offboard, setting MGs to rapidfire, setting auto-eject * is supported. * * @author  Ben * @version  */public class CustomMechDialog extends ClientDialog implements ActionListener, DialogOptionListener {         private Label labName = new Label(Messages.getString("CustomMechDialog.labName"), Label.RIGHT); //$NON-NLS-1$    private TextField fldName = new TextField(20);    private Label labGunnery = new Label(Messages.getString("CustomMechDialog.labGunnery"), Label.RIGHT); //$NON-NLS-1$    private TextField fldGunnery = new TextField(3);    private Label labPiloting = new Label(Messages.getString("CustomMechDialog.labPiloting"), Label.RIGHT); //$NON-NLS-1$    private TextField fldPiloting = new TextField(3);    private Label labC3 = new Label(Messages.getString("CustomMechDialog.labC3"), Label.RIGHT); //$NON-NLS-1$    private Choice choC3 = new Choice();    private int[] entityCorrespondance;    private Label labCallsign = new Label(Messages.getString("CustomMechDialog.labCallsign"), Label.CENTER); //$NON-NLS-1$    private Label labUnitNum = new Label(Messages.getString("CustomMechDialog.labUnitNum"), Label.CENTER); //$NON-NLS-1$    private Choice choUnitNum = new Choice();    private Vector entityUnitNum = new Vector();    private Label labDeployment = new Label(Messages.getString("CustomMechDialog.labDeployment"), Label.RIGHT); //$NON-NLS-1$    private Choice choDeployment = new Choice();    private Label labAutoEject = new Label(Messages.getString("CustomMechDialog.labAutoEject"), Label.RIGHT); //$NON-NLS-1$    private Checkbox chAutoEject = new Checkbox();    private Label labSearchlight = new Label(Messages.getString("CustomMechDialog.labSearchlight"), Label.RIGHT); //$NON-NLS-1$    private Checkbox chSearchlight = new Checkbox();        private Label labOffBoard = new Label(Messages.getString("CustomMechDialog.labOffBoard"), Label.RIGHT); //$NON-NLS-1$    private Checkbox chOffBoard = new Checkbox();    private Label labOffBoardDirection = new Label(Messages.getString("CustomMechDialog.labOffBoardDirection"), Label.RIGHT); //$NON-NLS-1$    private Choice choOffBoardDirection = new Choice();    private Label labOffBoardDistance = new Label(Messages.getString("CustomMechDialog.labOffBoardDistance"), Label.RIGHT); //$NON-NLS-1$    private TextField fldOffBoardDistance = new TextField(4);    private Button butOffBoardDistance = new Button ("0");    private Label labTargSys = new Label(Messages.getString("CustomMechDialog.labTargSys"), Label.RIGHT);    private Choice choTargSys = new Choice();    private Panel panButtons = new Panel();    private Button butOkay = new Button(Messages.getString("Okay")); //$NON-NLS-1$    private Button butCancel = new Button(Messages.getString("Cancel")); //$NON-NLS-1$    private Button butNext = new Button(Messages.getString("Next"));    private Button butPrev = new Button(Messages.getString("Previous"));        private Vector m_vMunitions = new Vector();    private Panel panMunitions = new Panel();    private Vector m_vMGs = new Vector();    private Panel panRapidfireMGs = new Panel();    private Vector m_vMines = new Vector();    private Panel panMines = new Panel();            private Entity entity;    private boolean okay = false;    private ClientGUI clientgui;    private Client client;    private PilotOptions options;        private Vector optionComps = new Vector();        private Panel panOptions = new Panel();    private ScrollPane scrOptions = new ScrollPane();        private ScrollPane scrAll = new ScrollPane();    private TextArea texDesc = new TextArea(Messages.getString("CustomMechDialog.texDesc"), 3, 35, TextArea.SCROLLBARS_VERTICAL_ONLY); //$NON-NLS-1$    private boolean editable;        private int direction = -1;    private int distance = 17;        /** Creates new CustomMechDialog */    public CustomMechDialog(ClientGUI clientgui, Client client, Entity entity, boolean editable) {        super(clientgui.frame, Messages.getString("CustomMechDialog.title"), true); //$NON-NLS-1$                Panel tempPanel = new Panel();        this.entity = entity;        this.clientgui = clientgui;        this.client = client;        this.options = entity.getCrew().getOptions();        this.editable = editable;                texDesc.setEditable(false);                // layout        GridBagLayout gridbag = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        tempPanel.setLayout(gridbag);                    c.fill = GridBagConstraints.VERTICAL;        c.insets = new Insets(5, 5, 5, 5);                    c.weightx = 1.0;    c.weighty = 1.0;        c.gridwidth = 1;        c.anchor = GridBagConstraints.EAST;        gridbag.setConstraints(labName, c);        tempPanel.add(labName);                c.gridwidth = GridBagConstraints.REMAINDER;        c.anchor = GridBagConstraints.WEST;        gridbag.setConstraints(fldName, c);        tempPanel.add(fldName);                c.gridwidth = 1;        c.anchor = GridBagConstraints.EAST;        gridbag.setConstraints(labGunnery, c);        tempPanel.add(labGunnery);                c.gridwidth = GridBagConstraints.REMAINDER;        c.anchor = GridBagConstraints.WEST;        gridbag.setConstraints(fldGunnery, c);        tempPanel.add(fldGunnery);                c.gridwidth = 1;        c.anchor = GridBagConstraints.EAST;        gridbag.setConstraints(labPiloting, c);        tempPanel.add(labPiloting);                c.gridwidth = GridBagConstraints.REMAINDER;        c.anchor = GridBagConstraints.WEST;        gridbag.setConstraints(fldPiloting, c);        tempPanel.add(fldPiloting);                // Auto-eject checkbox.        if (entity instanceof Mech) {            Mech mech = (Mech)entity;            // Torso-mounted cockpits can't eject, so lets not bother showing this.            if (mech.getCockpitType() != Mech.COCKPIT_TORSO_MOUNTED) {                c.gridwidth = 1;                c.anchor = GridBagConstraints.EAST;                gridbag.setConstraints(labAutoEject, c);                tempPanel.add(labAutoEject);                            c.gridwidth = GridBagConstraints.REMAINDER;                c.anchor = GridBagConstraints.WEST;                gridbag.setConstraints(chAutoEject, c);                tempPanel.add(chAutoEject);                chAutoEject.setState(!mech.isAutoEject());            }        }                c.gridwidth = 1;        c.anchor = GridBagConstraints.EAST;        gridbag.setConstraints(labDeployment, c);        tempPanel.add(labDeployment);              c.gridwidth = GridBagConstraints.REMAINDER;        c.anchor = GridBagConstraints.WEST;        gridbag.setConstraints(choDeployment, c);        tempPanel.add(choDeployment);        refreshDeployment();        if ( clientgui.getClient().game.getOptions().booleanOption("pilot_advantages") ) { //$NON-NLS-1$            scrOptions.add(panOptions);            c.weightx = 1.0;    c.weighty = 1.0;            c.fill = GridBagConstraints.BOTH;            c.gridwidth = GridBagConstraints.REMAINDER;            gridbag.setConstraints(scrOptions, c);            tempPanel.add(scrOptions);            c.weightx = 1.0;    c.weighty = 0.0;            gridbag.setConstraints(texDesc, c);            tempPanel.add(texDesc);        }        if (entity.hasC3() || entity.hasC3i()) {                    c.gridwidth = 1;            c.anchor = GridBagConstraints.EAST;            gridbag.setConstraints(labC3, c);            tempPanel.add(labC3);            c.gridwidth = GridBagConstraints.REMAINDER;            c.anchor = GridBagConstraints.WEST;            gridbag.setConstraints(choC3, c);            tempPanel.add(choC3);            refreshC3();        }        boolean eligibleForOffBoard = false;        for (Mounted mounted : entity.getWeaponList()) {            WeaponType wtype = (WeaponType)mounted.getType();            if (wtype.hasFlag(WeaponType.F_ARTILLERY)) {                eligibleForOffBoard = true;            }        }        if (eligibleForOffBoard) {            c.gridwidth = 1;            c.anchor = GridBagConstraints.EAST;            gridbag.setConstraints(labOffBoard, c);            tempPanel.add(labOffBoard);                      c.gridwidth = GridBagConstraints.REMAINDER;            c.anchor = GridBagConstraints.WEST;            gridbag.setConstraints(chOffBoard, c);            tempPanel.add(chOffBoard);            chOffBoard.setState(entity.isOffBoard());                        c.gridwidth = 1;            c.anchor = GridBagConstraints.EAST;            gridbag.setConstraints(labOffBoardDirection, c);            tempPanel.add(labOffBoardDirection);                        c.gridwidth = GridBagConstraints.REMAINDER;            c.anchor = GridBagConstraints.WEST;            gridbag.setConstraints(choOffBoardDirection, c);            choOffBoardDirection.add(Messages.getString("CustomMechDialog.North")); //$NON-NLS-1$            choOffBoardDirection.add(Messages.getString("CustomMechDialog.South")); //$NON-NLS-1$            choOffBoardDirection.add(Messages.getString("CustomMechDialog.East")); //$NON-NLS-1$            choOffBoardDirection.add(Messages.getString("CustomMechDialog.West")); //$NON-NLS-1$            direction = entity.getOffBoardDirection();            if ( IOffBoardDirections.NONE == direction ) {                direction = IOffBoardDirections.NORTH;            }            choOffBoardDirection.select( direction );            tempPanel.add(choOffBoardDirection);                        c.gridwidth = 1;            c.anchor = GridBagConstraints.EAST;            gridbag.setConstraints(labOffBoardDistance, c);            tempPanel.add(labOffBoardDistance);                        c.gridwidth = GridBagConstraints.REMAINDER;            c.anchor = GridBagConstraints.WEST;                        butOffBoardDistance.addActionListener(this);            gridbag.setConstraints(butOffBoardDistance, c);            butOffBoardDistance.setLabel(Integer.toString(distance));            tempPanel.add(butOffBoardDistance);        }        if (!(entity.hasTargComp()) && (clientgui.getClient().game.getOptions().booleanOption("allow_level_3_targsys")) && (entity instanceof Mech)) {            c.gridwidth = 1;            c.anchor = GridBagConstraints.EAST;            gridbag.setConstraints(labTargSys, c);            tempPanel.add(labTargSys);            c.gridwidth = GridBagConstraints.REMAINDER;            c.anchor = GridBagConstraints.WEST;            choTargSys.add(MiscType.getTargetSysName(MiscType.T_TARGSYS_STANDARD));            choTargSys.add(MiscType.getTargetSysName(MiscType.T_TARGSYS_LONGRANGE));            choTargSys.add(MiscType.getTargetSysName(MiscType.T_TARGSYS_SHORTRANGE));            choTargSys.add(MiscType.getTargetSysName(MiscType.T_TARGSYS_ANTI_AIR));//            choTargSys.add(MiscType.getTargetSysName(MiscType.T_TARGSYS_MULTI_TRAC));            gridbag.setConstraints(choTargSys, c);            tempPanel.add(choTargSys);            choTargSys.select(MiscType.getTargetSysName(entity.getTargSysType()));        }        if ( entity instanceof Protomech ) {            // All Protomechs have a callsign.            StringBuffer callsign = new StringBuffer(Messages.getString("CustomMechDialog.Callsign")); //$NON-NLS-1$            callsign.append(": ");  //$NON-NLS-1$            callsign.append( (char) (this.entity.getUnitNumber() +                    PreferenceManager.getClientPreferences().getUnitStartChar()) )                .append( '-' )

⌨️ 快捷键说明

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