📄 mechdisplay.java
字号:
// update range int shortR = wtype.getShortRange(); int mediumR = wtype.getMediumRange(); int longR = wtype.getLongRange(); int extremeR = wtype.getExtremeRange(); if (entity.getLocationStatus(mounted.getLocation()) == ILocationExposureStatus.WET || longR == 0) { shortR = wtype.getWShortRange(); mediumR = wtype.getWMediumRange(); longR = wtype.getWLongRange(); extremeR = wtype.getWExtremeRange(); } if (wtype.getMinimumRange() > 0) { wMinR.setText(Integer.toString(wtype.getMinimumRange())); } else { wMinR.setText("---"); //$NON-NLS-1$ } if (shortR > 1) { wShortR.setText("1 - " + shortR); //$NON-NLS-1$ } else { wShortR.setText("" + shortR); //$NON-NLS-1$ } if (mediumR - shortR > 1) { wMedR.setText(shortR + 1 + " - " + mediumR); //$NON-NLS-1$ } else { wMedR.setText("" + mediumR); //$NON-NLS-1$ } if (longR - mediumR > 1) { wLongR.setText(mediumR + 1 + " - " + longR); //$NON-NLS-1$ } else { wLongR.setText("" + longR); //$NON-NLS-1$ } if (extremeR - longR > 1) { wExtR.setText(longR + 1 + " - " + extremeR); //$NON-NLS-1$ } else { wExtR.setText("" + extremeR); //$NON-NLS-1$ } // Update the range display to account for the weapon's loaded ammo. if (mounted.getLinked() != null) { updateRangeDisplayForAmmo(mounted.getLinked()); } // update ammo selector boolean bOwner = clientgui.getClient().getLocalPlayer().equals(entity.getOwner()); m_chAmmo.removeAll(); if (wtype.getAmmoType() == AmmoType.T_NA || !bOwner) { m_chAmmo.setEnabled(false); } else if (wtype.hasFlag(WeaponType.F_ONESHOT)) { if (mounted.getLinked().getShotsLeft() == 1) { m_chAmmo.addItem(formatAmmo(mounted.getLinked())); m_chAmmo.setEnabled(true); } else { m_chAmmo.setEnabled(false); } } else { if (!(entity instanceof Infantry)) { m_chAmmo.setEnabled(true); } else { m_chAmmo.setEnabled(false); } vAmmo = new ArrayList<Mounted>(); int nCur = -1; int i = 0; for (Mounted mountedAmmo : entity.getAmmo()) { AmmoType atype = (AmmoType) mountedAmmo.getType(); if (mountedAmmo.isAmmoUsable() && atype.getAmmoType() == wtype.getAmmoType() && atype.getRackSize() == wtype.getRackSize()) { vAmmo.add(mountedAmmo); m_chAmmo.addItem(formatAmmo(mountedAmmo)); if (mounted.getLinked().equals(mountedAmmo)) { nCur = i; } i++; } } if (nCur == -1) { // outcommenting this fixes bug 1041003 (if a linked ammobin // gets breached, it will continue to be used, and other ammo // can't be selected for the weapon that the breached ammo was // linked to), and did not cause anything to misbehave in my // testing, apart from the Choice being enabled even if there // is no ammo to choose from, but that is only a minor issue // m_chAmmo.setEnabled(false); } else { m_chAmmo.setSelectedIndex(nCur); } } //send event to other parts of the UI which care processMechDisplayEvent(new MechDisplayEvent(this, entity, mounted)); } private String formatAmmo(Mounted m) { StringBuffer sb = new StringBuffer(64); int ammoIndex = m.getDesc().indexOf(Messages.getString("MechDisplay.0")); //$NON-NLS-1$ int loc = m.getLocation(); if (loc != Entity.LOC_NONE) { sb.append('[').append(entity.getLocationAbbr(loc)).append("] "); //$NON-NLS-1$ //$NON-NLS-2$ } if (ammoIndex == -1) { sb.append(m.getDesc()); } else { sb.append(m.getDesc().substring(0, ammoIndex)); sb.append(m.getDesc().substring(ammoIndex + 4)); } return sb.toString(); } /** * Update the range display for the selected ammo. * * @param atype - the <code>AmmoType</code> of the weapon's loaded ammo. */ private void updateRangeDisplayForAmmo(Mounted mAmmo) { AmmoType atype = (AmmoType) mAmmo.getType(); // Only override the display for the various ATM ammos if (atype.getAmmoType() == AmmoType.T_ATM) { if (atype.getAmmoType() == AmmoType.T_ATM && atype.getMunitionType() == AmmoType.M_EXTENDED_RANGE) { wMinR.setText("4"); //$NON-NLS-1$ wShortR.setText("1 - 9"); //$NON-NLS-1$ wMedR.setText("10 - 18"); //$NON-NLS-1$ wLongR.setText("19 - 27"); //$NON-NLS-1$ wExtR.setText("28 - 36"); //$NON-NLS-1$ } else if (atype.getAmmoType() == AmmoType.T_ATM && atype.getMunitionType() == AmmoType.M_HIGH_EXPLOSIVE) { wMinR.setText("---"); //$NON-NLS-1$ wShortR.setText("1 - 3"); //$NON-NLS-1$ wMedR.setText("4 - 6"); //$NON-NLS-1$ wLongR.setText("7 - 9"); //$NON-NLS-1$ wExtR.setText("10 - 12"); //$NON-NLS-1$ } else { wMinR.setText("4"); //$NON-NLS-1$ wShortR.setText("1 - 5"); //$NON-NLS-1$ wMedR.setText("6 - 10"); //$NON-NLS-1$ wLongR.setText("11 - 15"); //$NON-NLS-1$ wExtR.setText("16 - 20"); //$NON-NLS-1$ } } // End weapon-is-ATM //Min range 0 for hotload if(mAmmo.isHotLoaded()) wMinR.setText("---"); } // End private void updateRangeDisplayForAmmo( AmmoType ) // // ItemListener // public void itemStateChanged(ItemEvent ev) { if (ev.getItemSelectable().equals(m_chAmmo)) { int n = weaponList.getSelectedIndex(); if (n == -1) { return; } Mounted mWeap = entity.getWeaponList().get(n); Mounted oldAmmo = mWeap.getLinked(); Mounted mAmmo = vAmmo.get(m_chAmmo.getSelectedIndex()); entity.loadWeapon(mWeap, mAmmo); // Refresh for hot load change if(((oldAmmo == null || !oldAmmo.isHotLoaded()) && mAmmo.isHotLoaded()) || (oldAmmo != null && oldAmmo.isHotLoaded() && !mAmmo.isHotLoaded())) { displayMech(entity); weaponList.setSelectedIndex(n); displaySelected(); } // Update the range display to account for the weapon's loaded ammo. updateRangeDisplayForAmmo(mAmmo); // When in the Firing Phase, update the targeting information. // TODO: make this an accessor function instead of a member access. if (clientgui.curPanel instanceof FiringDisplay) { ((FiringDisplay) clientgui.curPanel).updateTarget(); } else if (clientgui.curPanel instanceof TargetingPhaseDisplay) { ((TargetingPhaseDisplay) clientgui.curPanel).updateTarget(); } // Alert the server of the update. clientgui.getClient().sendAmmoChange(entity.getId(), entity.getEquipmentNum(mWeap), entity.getEquipmentNum(mAmmo)); } } public void valueChanged(ListSelectionEvent event) { if (event.getSource().equals(weaponList)) { displaySelected(); } } } /** * This class shows the critical hits and systems for a mech */ private class SystemPanel extends BufferedPanel implements ItemListener, ActionListener, ListSelectionListener { private static final String IMAGE_DIR = "data/images/widgets"; private JLabel locLabel; private JLabel slotLabel; private JLabel modeLabel; private JList slotList; private JList locList; private JComboBox m_chMode; private JButton m_bDumpAmmo; private Entity en; SystemPanel() { locLabel = new JLabel(Messages.getString("MechDisplay.Location"), JLabel.CENTER); //$NON-NLS-1$ locLabel.setOpaque(true); slotLabel = new JLabel(Messages.getString("MechDisplay.Slot"), JLabel.CENTER); //$NON-NLS-1$ slotLabel.setOpaque(true); locList = new JList(new DefaultListModel()); locList.addListSelectionListener(this); slotList = new JList(new DefaultListModel()); slotList.addListSelectionListener(this); m_chMode = new JComboBox(); m_chMode.addItem(" "); //$NON-NLS-1$ m_chMode.setEnabled(false); m_chMode.addItemListener(this); m_bDumpAmmo = new JButton(Messages.getString("MechDisplay.m_bDumpAmmo")); //$NON-NLS-1$ m_bDumpAmmo.setEnabled(false); m_bDumpAmmo.setActionCommand("dump"); //$NON-NLS-1$ m_bDumpAmmo.addActionListener(this); modeLabel = new JLabel(Messages.getString("MechDisplay.modeLabel"), JLabel.RIGHT); //$NON-NLS-1$ modeLabel.setOpaque(true); //modeLabel.setEnabled(false); // layout main panel GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(15, 9, 1, 1); c.gridy = 0; c.gridx = 0; c.weightx = 0.5; c.weighty = 0.0; c.gridwidth = 1; c.gridheight = 1; gridbag.setConstraints(locLabel, c); add(locLabel); c.weightx = 0.0; c.gridy = 0; c.gridx = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets(15, 1, 1, 9); gridbag.setConstraints(slotLabel, c); add(slotLabel); c.weightx = 0.5; //c.weighty = 1.0; c.gridy = 1; c.gridx = 0; c.gridwidth = 1; c.insets = new Insets(1, 9, 15, 1); c.gridheight = GridBagConstraints.REMAINDER; gridbag.setConstraints(locList, c); add(locList); c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 1; c.gridy = 1; c.gridx = 1; c.weightx = 0.0; c.weighty = 1.0; c.insets = new Insets(1, 1, 1, 9); gridbag.setConstraints(slotList, c); add(slotList); c.gridwidth = 1; c.gridy = 2; c.gridx = 1; c.weightx = 0.0; c.weighty = 0.0; gridbag.setConstraints(modeLabel, c); c.insets = new Insets(1, 1, 1, 1); add(modeLabel); c.weightx = 1.0; c.gridwidth = GridBagConstraints.REMAINDER; c.gridy = 2; c.gridx = 2; c.insets = new Insets(1, 1, 1, 9); gridbag.setConstraints(m_chMode, c); add(m_chMode); c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = GridBagConstraints.REMAINDER; c.gridy = 3; c.gridx = 1; c.insets = new Insets(4, 4, 15, 9); gridbag.setConstraints(m_bDumpAmmo, c); add(m_bDumpAmmo); setBackGround(); } private CriticalSlot getSelectedCritical() { int loc = locList.getSelectedIndex(); int slot = slotList.getSelectedIndex(); if (loc == -1 || slot == -1) { return null; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -