📄 mechselectordialog.java
字号:
boolean weaponLine1Active = false; boolean weaponLine2Active = false; boolean foundWeapon1 = false; boolean foundWeapon2 = false; int count = 0; int weapon1 = -1; try { weapon1 = Integer.parseInt(m_tWeapons1.getText()); } catch (NumberFormatException ne) { //never get here } if (weapon1 > -1) { weaponLine1Active = true; for (int i = 0; i < entity.getWeaponList().size(); i++) { WeaponType wt = (WeaponType) (entity.getWeaponList().get(i)).getType(); if (wt.getName().equals(m_cWeapons1.getSelectedItem())) { count++; } } if (count >= weapon1) foundWeapon1 = true; } count = 0; int weapon2 = -1; try { weapon2 = Integer.parseInt(m_tWeapons2.getText()); } catch (NumberFormatException ne) { //never get here } if (weapon2 > -1) { weaponLine2Active = true; for (int i = 0; i < entity.getWeaponList().size(); i++) { WeaponType wt = (WeaponType) (entity.getWeaponList().get(i)).getType(); if (wt.getName().equals(m_cWeapons2.getSelectedItem())) { count++; } } if (count >= weapon2) foundWeapon2 = true; } if (weaponLine1Active && !weaponLine2Active && !foundWeapon1) return false; if (weaponLine2Active && !weaponLine1Active && !foundWeapon2) return false; if (weaponLine1Active && weaponLine2Active) { if (m_cOrAnd.getSelectedIndex() == 0 /* 0 is "or" choice */) { if (!foundWeapon1 && !foundWeapon2) return false; } else { //"and" choice in effect if (!foundWeapon1 || !foundWeapon2) return false; } } count = 0; if (m_chkEquipment.isSelected()) { for (Mounted m : entity.getMisc()) { MiscType mt = (MiscType) m.getType(); if (mt.getName().equals(m_cEquipment.getSelectedItem())) { count++; } } if (count < 1) return false; } return true; } private void resetSearch() { m_cWalk.setSelectedIndex(0); m_tWalk.setText(""); m_cJump.setSelectedIndex(0); m_tJump.setText(""); m_cArmor.setSelectedIndex(0); m_tWeapons1.setText(""); m_cWeapons1.setSelectedIndex(0); m_cOrAnd.setSelectedIndex(0); m_tWeapons2.setText(""); m_cWeapons2.setSelectedIndex(0); m_chkEquipment.setSelected(false); m_cEquipment.setSelectedIndex(0); filterMechs(false); } private Point computeDesiredLocation() { int desiredX = m_clientgui.frame.getLocation().x + m_clientgui.frame.getSize().width / 2 - getSize().width / 2; if (desiredX < 0) desiredX = 0; int desiredY = m_clientgui.frame.getLocation().y + m_clientgui.frame.getSize().height / 2 - getSize().height / 2; if (desiredY < 0) desiredY = 0; return new Point(desiredX, desiredY); } public void setVisible(boolean visible) { updatePlayerChoice(); updateTechChoice(); setLocation(computeDesiredLocation()); super.setVisible(visible); } private String formatMech(MechSummary ms) { String val = ""; String levelOrValid; if (!ms.getLevel().equals("F")) { levelOrValid = TechConstants.T_SIMPLE_LEVEL[ms.getType()]; } else { levelOrValid = "F"; } if (GUIPreferences.getInstance().getMechSelectorIncludeModel()) val += makeLength(ms.getModel(), 10) + " "; //$NON-NLS-1$ //$NON-NLS-2$ if (GUIPreferences.getInstance().getMechSelectorIncludeName()) val += makeLength(ms.getChassis(), 20) + " "; //$NON-NLS-1$ //$NON-NLS-2$ if (GUIPreferences.getInstance().getMechSelectorIncludeTons()) val += makeLength("" + ms.getTons(), 3) + " "; //$NON-NLS-1$ //$NON-NLS-2$ if (GUIPreferences.getInstance().getMechSelectorIncludeBV()) val += makeLength("" + ms.getBV(), 5) + " "; //$NON-NLS-1$ //$NON-NLS-2$ if (GUIPreferences.getInstance().getMechSelectorIncludeYear()) val += ms.getYear() + " "; if (GUIPreferences.getInstance().getMechSelectorIncludeLevel()) val += levelOrValid + " "; if (GUIPreferences.getInstance().getMechSelectorIncludeCost()) val += ms.getCost() + " "; return val; } public void actionPerformed(ActionEvent ae) { if (ae.getSource().equals(m_bCancel)) { setVisible(false); } else if (ae.getSource().equals(m_bPick) || ae.getSource().equals(m_bPickClose)) { int x = m_mechList.getSelectedIndex(); if (x == -1) { return; } MechSummary ms = m_mechsCurrent[m_mechList.getSelectedIndex()]; try { Entity e = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); Client c = null; if (m_chPlayer.getSelectedIndex() > 0) { String name = (String) m_chPlayer.getSelectedItem(); c = (Client) m_clientgui.getBots().get(name); } if (c == null) { c = m_client; } e.setOwner(c.getLocalPlayer()); c.sendAddEntity(e); } catch (EntityLoadingException ex) { System.out.println("Unable to load mech: " + ms.getSourceFile() + ": " + ms.getEntryName() + ": " + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ex.printStackTrace(); return; } if (ae.getSource().equals(m_bPickClose)) { setVisible(false); } } else if (ae.getSource().equals(m_bSearch)) { advancedSearch(); } else if (ae.getSource().equals(m_bReset)) { resetSearch(); } else if (ae.getSource().equals(m_bToggleAdvanced)) { toggleAdvanced(); } } public void itemStateChanged(ItemEvent ie) { if (ie.getSource().equals(m_chSort)) { clearMechPreview(); sortMechs(); } else if (ie.getSource().equals(m_chWeightClass) || ie.getSource().equals(m_chType) || ie.getSource().equals(m_chUnitType)) { clearMechPreview(); filterMechs(false); } else if (ie.getSource().equals(m_cModel) || ie.getSource().equals(m_cName) || ie.getSource().equals(m_cTons) || ie.getSource().equals(m_cBV) || ie.getSource().equals(m_cYear) || ie.getSource().equals(m_cLevel) || ie.getSource().equals(m_cCost)) { GUIPreferences.getInstance().setMechSelectorIncludeModel(m_cModel.isSelected()); GUIPreferences.getInstance().setMechSelectorIncludeName(m_cName.isSelected()); GUIPreferences.getInstance().setMechSelectorIncludeTons(m_cTons.isSelected()); GUIPreferences.getInstance().setMechSelectorIncludeBV(m_cBV.isSelected()); GUIPreferences.getInstance().setMechSelectorIncludeYear(m_cYear.isSelected()); GUIPreferences.getInstance().setMechSelectorIncludeLevel(m_cLevel.isSelected()); GUIPreferences.getInstance().setMechSelectorIncludeCost(m_cCost.isSelected()); clearMechPreview(); sortMechs(); // sorting has side-effect of repopulating list m_mechList.invalidate(); // force re-layout of window pack(); setLocation(computeDesiredLocation()); } } void clearMechPreview() { m_mechView.setEditable(false); m_mechView.setText(""); //$NON-NLS-1$ // Remove preview image. if (MechSummaryCache.getInstance().isInitialized()) { //m_pPreview.removeBgDrawers(); m_pPreview.repaint(); } } void previewMech(Entity entity) { MechView mechView = new MechView(entity); m_mechView.setEditable(false); m_mechView.setText(mechView.getMechReadout()); m_mechView.setCaretPosition(0); // Preview image of the unit... m_clientgui.loadPreviewImage(m_pPreview, entity, m_client.getLocalPlayer()); m_pPreview.repaint(); } private static final String SPACES = " "; //$NON-NLS-1$ private String makeLength(String s, int nLength) { if (s.length() == nLength) { return s; } else if (s.length() > nLength) { return s.substring(0, nLength - 2) + ".."; //$NON-NLS-1$ } else { return s + SPACES.substring(0, nLength - s.length()); } } public void keyReleased(KeyEvent ke) { } public void keyPressed(KeyEvent ke) { if (ke.getKeyCode() == KeyEvent.VK_ENTER) { ActionEvent event = new ActionEvent(m_bPick, ActionEvent.ACTION_PERFORMED, ""); //$NON-NLS-1$ actionPerformed(event); } long curTime = System.currentTimeMillis(); if (curTime - m_nLastSearch > KEY_TIMEOUT) { m_sbSearch = new StringBuffer(); } m_nLastSearch = curTime; m_sbSearch.append(ke.getKeyChar()); searchFor(m_sbSearch.toString().toLowerCase()); } public void keyTyped(KeyEvent ke) { } // // WindowListener // public void windowActivated(WindowEvent windowEvent) { } public void windowClosed(WindowEvent windowEvent) { } public void windowClosing(WindowEvent windowEvent) { setVisible(false); } public void windowDeactivated(WindowEvent windowEvent) { } public void windowDeiconified(WindowEvent windowEvent) { } public void windowIconified(WindowEvent windowEvent) { } public void windowOpened(WindowEvent windowEvent) { } private void updateWidgetEnablements() { final boolean enable = m_mechList.getSelectedIndex() != -1; m_bPick.setEnabled(enable); m_bPickClose.setEnabled(enable); } public void valueChanged(ListSelectionEvent event) { if (event.getSource().equals(m_mechList)) { updateWidgetEnablements(); int selected = m_mechList.getSelectedIndex(); if (selected == -1) { clearMechPreview(); return; } MechSummary ms = m_mechsCurrent[selected]; try { Entity entity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); previewMech(entity); } catch (EntityLoadingException ex) { System.out.println("Unable to load mech: " + ms.getSourceFile() + ": " + ms.getEntryName() + ": " + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ex.printStackTrace(); clearMechPreview(); return; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -