📄 mechselectordialog.java
字号:
private void toggleAdvanced() { m_pUpper.remove(m_pSouthParams); m_pSouthParams = new JPanel(); if (GUIPreferences.getInstance().getMechSelectorShowAdvanced()) { buildSouthParams(false); GUIPreferences.getInstance().setMechSelectorShowAdvanced(false); } else { buildSouthParams(true); GUIPreferences.getInstance().setMechSelectorShowAdvanced(true); } m_pUpper.add(m_pSouthParams, BorderLayout.SOUTH); invalidate(); pack(); } private void updateTechChoice() { boolean maxTechOption = m_client.game.getOptions().booleanOption("allow_level_3_units"); int maxTech = (maxTechOption ? TechConstants.SIZE : TechConstants.SIZE_LEVEL_2); if (includeMaxTech == maxTechOption) { return; } includeMaxTech = maxTechOption; m_chType.removeAll(); for (int i = 0; i < maxTech; i++) { m_chType.addItem(TechConstants.getLevelDisplayableName(i)); } } private void updatePlayerChoice() { String lastChoice = (String) m_chPlayer.getSelectedItem(); m_chPlayer.removeAllItems(); m_chPlayer.setEnabled(true); m_chPlayer.addItem(m_clientgui.getClient().getName()); for (Iterator i = m_clientgui.getBots().values().iterator(); i.hasNext();) { m_chPlayer.addItem(((Client) i.next()).getName()); } if (m_chPlayer.getItemCount() == 1) { m_chPlayer.setEnabled(false); } else { m_chPlayer.setSelectedItem(lastChoice); } } public void run() { // Loading mechs can take a while, so it will have its own thread. // This prevents the UI from freezing, and allows the // "Please wait..." dialog to behave properly on various Java VMs. filterMechs(false); m_mechList.invalidate(); // force re-layout of window pack(); setLocation(computeDesiredLocation()); unitLoadingDialog.setVisible(false); final Hashtable hFailedFiles = MechSummaryCache.getInstance().getFailedFiles(); if (hFailedFiles != null && hFailedFiles.size() > 0) { new UnitFailureDialog(m_clientgui.frame, hFailedFiles); // self-showing dialog } } private void populateChoices() { for (int i = 0; i < EntityWeightClass.SIZE; i++) { m_chWeightClass.addItem(EntityWeightClass.getClassName(i)); } m_chWeightClass.addItem(Messages.getString("MechSelectorDialog.All")); //$NON-NLS-1$ m_chWeightClass.setSelectedIndex(0); includeMaxTech = m_client.game.getOptions().booleanOption("allow_level_3_units"); int maxTech = (includeMaxTech ? TechConstants.SIZE : TechConstants.SIZE_LEVEL_2); for (int i = 0; i < maxTech; i++) { m_chType.addItem(TechConstants.getLevelDisplayableName(i)); } // m_chType.addItem(Messages.getString("MechSelectorDialog.ISAll")); //$NON-NLS-1$ // m_chType.addItem(Messages.getString("MechSelectorDialog.ISAndClan")); //$NON-NLS-1$ // More than 8 items causes the drop down to sprout a vertical // scroll bar. I guess we'll sacrifice this next one to stay // under the limit. Stupid AWT Choice class! // m_chType.addItem("Mixed All"); // m_chType.addItem(Messages.getString("MechSelectorDialog.All")); //$NON-NLS-1$ m_chType.setSelectedIndex(0); for (int i = 0; i < UnitType.SIZE; i++) { m_chUnitType.addItem(UnitType.getTypeDisplayableName(i)); } m_chUnitType.addItem(Messages.getString("MechSelectorDialog.All")); //$NON-NLS-1$ m_chUnitType.setSelectedIndex(0); m_cWalk.addItem(Messages.getString("MechSelectorDialog.Search.AtLeast")); m_cWalk.addItem(Messages.getString("MechSelectorDialog.Search.EqualTo")); m_cWalk.addItem(Messages.getString("MechSelectorDialog.Search.NoMoreThan")); m_cJump.addItem(Messages.getString("MechSelectorDialog.Search.AtLeast")); m_cJump.addItem(Messages.getString("MechSelectorDialog.Search.EqualTo")); m_cJump.addItem(Messages.getString("MechSelectorDialog.Search.NoMoreThan")); m_cArmor.addItem(Messages.getString("MechSelectorDialog.Search.Any")); m_cArmor.addItem(Messages.getString("MechSelectorDialog.Search.Armor25")); m_cArmor.addItem(Messages.getString("MechSelectorDialog.Search.Armor50")); m_cArmor.addItem(Messages.getString("MechSelectorDialog.Search.Armor75")); m_cArmor.addItem(Messages.getString("MechSelectorDialog.Search.Armor90")); m_cOrAnd.addItem(Messages.getString("MechSelectorDialog.Search.or")); m_cOrAnd.addItem(Messages.getString("MechSelectorDialog.Search.and")); populateWeaponsAndEquipmentChoices(); } private void populateWeaponsAndEquipmentChoices() { m_cWeapons1.removeAll(); m_cWeapons2.removeAll(); m_cEquipment.removeAll(); m_tWeapons1.setText(""); m_tWeapons2.setText(""); m_chkEquipment.setSelected(false); int nType = m_chType.getSelectedIndex(); int nUnitType = m_chUnitType.getSelectedIndex(); for (Enumeration e = EquipmentType.getAllTypes(); e.hasMoreElements();) { EquipmentType et = (EquipmentType) e.nextElement(); if (et instanceof WeaponType && (et.getTechLevel() == nType || ((nType == TechConstants.T_LEVEL_2_ALL) && ((et.getTechLevel() == TechConstants.T_IS_LEVEL_1) || (et.getTechLevel() == TechConstants.T_IS_LEVEL_2) || (et.getTechLevel() == TechConstants.T_CLAN_LEVEL_2))) || ((nType == TechConstants.T_IS_LEVEL_2_ALL || nType == TechConstants.T_IS_LEVEL_2) && ((et.getTechLevel() == TechConstants.T_IS_LEVEL_1) || (et.getTechLevel() == TechConstants.T_IS_LEVEL_2))))) { if (!(nUnitType == UnitType.SIZE) && ((UnitType.getTypeName(nUnitType).equals("Mek") || UnitType.getTypeName(nUnitType).equals("Tank")) && (et.hasFlag(WeaponType.F_PROTOMECH) || et.hasFlag(WeaponType.F_INFANTRY) || et.hasFlag(WeaponType.F_BATTLEARMOR)))) { continue; } m_cWeapons1.addItem(et.getName()); m_cWeapons2.addItem(et.getName()); } if (et instanceof MiscType && (et.getTechLevel() == nType || ((nType == TechConstants.T_LEVEL_2_ALL) && ((et.getTechLevel() == TechConstants.T_IS_LEVEL_1) || (et.getTechLevel() == TechConstants.T_IS_LEVEL_2) || (et.getTechLevel() == TechConstants.T_CLAN_LEVEL_2))) || ((nType == TechConstants.T_IS_LEVEL_2_ALL || nType == TechConstants.T_IS_LEVEL_2) && ((et.getTechLevel() == TechConstants.T_IS_LEVEL_1) || (et.getTechLevel() == TechConstants.T_IS_LEVEL_2))))) { m_cEquipment.addItem(et.getName()); } } m_cWeapons1.invalidate(); m_cWeapons2.invalidate(); m_cEquipment.invalidate(); pack(); } private void filterMechs(boolean calledByAdvancedSearch) { ArrayList<MechSummary> vMechs = new ArrayList<MechSummary>(); int nClass = m_chWeightClass.getSelectedIndex(); int nType = m_chType.getSelectedIndex(); int nUnitType = m_chUnitType.getSelectedIndex(); MechSummary[] mechs = MechSummaryCache.getInstance().getAllMechs(); if (mechs == null) { System.err.println("No units to filter!"); //$NON-NLS-1$ return; } for (int x = 0; x < mechs.length; x++) { if (/* Weight */ (nClass == EntityWeightClass.SIZE || mechs[x].getWeightClass() == nClass) && /* Technology Level */ ((nType == TechConstants.T_ALL) || (nType == mechs[x].getType()) || ((nType == TechConstants.T_LEVEL_2_ALL) && ((mechs[x].getType() == TechConstants.T_IS_LEVEL_1) || (mechs[x].getType() == TechConstants.T_IS_LEVEL_2) || (mechs[x].getType() == TechConstants.T_CLAN_LEVEL_2))) || ((nType == TechConstants.T_IS_LEVEL_2_ALL) && ((mechs[x].getType() == TechConstants.T_IS_LEVEL_1) || (mechs[x].getType() == TechConstants.T_IS_LEVEL_2)))) && /* Unit Type (Mek, Infantry, etc.) */ (nUnitType == UnitType.SIZE || mechs[x].getUnitType().equals(UnitType.getTypeName(nUnitType))) && /*canon required*/ (!m_client.game.getOptions().booleanOption("canon_only") || mechs[x].isCanon())) { vMechs.add(mechs[x]); } } m_mechsCurrent = vMechs.toArray(new MechSummary[0]); m_count = vMechs.size(); if (!calledByAdvancedSearch && (m_old_nType != nType || m_old_nUnitType != nUnitType)) { populateWeaponsAndEquipmentChoices(); } m_old_nType = nType; m_old_nUnitType = nUnitType; sortMechs(); } private void sortMechs() { Arrays.sort(m_mechsCurrent, new MechSummaryComparator(m_chSort.getSelectedIndex())); ((DefaultComboBoxModel) m_mechList.getModel()).removeAllElements(); try { m_mechList.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (int x = 0; x < m_mechsCurrent.length; x++) { ((DefaultComboBoxModel) m_mechList.getModel()).addElement(formatMech(m_mechsCurrent[x])); } } finally { setCursor(Cursor.getDefaultCursor()); m_mechList.setEnabled(true); //workaround for bug 1263380 m_mechList.setFont(m_mechList.getFont()); } updateWidgetEnablements(); m_lCount.setText(m_mechsCurrent.length + "/" + m_count); m_mechList.setPreferredSize(new Dimension(180, m_mechsCurrent.length * 19)); repaint(); } private void searchFor(String search) { for (int i = 0; i < m_mechsCurrent.length; i++) { if (m_mechsCurrent[i].getName().toLowerCase().startsWith(search)) { m_mechList.setSelectedIndex(i);// ItemEvent event = new ItemEvent(m_mechList, ItemEvent.ITEM_STATE_CHANGED, m_mechList, ItemEvent.SELECTED);// itemStateChanged(event); break; } } } private void advancedSearch() { String s = m_lCount.getText(); int first = Integer.parseInt(s.substring(0, s.indexOf('/'))); int second = Integer.parseInt(s.substring(s.indexOf('/') + 1)); if (first != second) { //Search already active, reset list before starting new one. filterMechs(true); } ArrayList<MechSummary> vMatches = new ArrayList<MechSummary>(); for (int i = 0; i < m_mechsCurrent.length; i++) { MechSummary ms = m_mechsCurrent[i]; try { Entity entity = new MechFileParser(ms.getSourceFile(), ms.getEntryName()).getEntity(); if (isMatch(entity)) { vMatches.add(ms); } } catch (EntityLoadingException ex) { //do nothing, I guess } } m_mechsCurrent = vMatches.toArray(new MechSummary[0]); clearMechPreview(); sortMechs(); } private boolean isMatch(Entity entity) { int walk = -1; try { walk = Integer.parseInt(m_tWalk.getText()); } catch (NumberFormatException ne) { //never get here } if (walk > -1) { if (m_cWalk.getSelectedIndex() == 0) { //at least if (entity.getWalkMP() < walk) return false; } else if (m_cWalk.getSelectedIndex() == 1) { //equal to if (walk != entity.getWalkMP()) return false; } else if (m_cWalk.getSelectedIndex() == 2) { //not more than if (entity.getWalkMP() > walk) return false; } } int jump = -1; try { jump = Integer.parseInt(m_tJump.getText()); } catch (NumberFormatException ne) { //never get here } if (jump > -1) { if (m_cJump.getSelectedIndex() == 0) { //at least if (entity.getJumpMP() < jump) return false; } else if (m_cJump.getSelectedIndex() == 1) { //equal to if (jump != entity.getJumpMP()) return false; } else if (m_cJump.getSelectedIndex() == 2) { //not more than if (entity.getJumpMP() > jump) return false; } } int sel = m_cArmor.getSelectedIndex(); if (sel > 0) { int armor = entity.getTotalArmor(); int maxArmor = entity.getTotalInternal() * 2 + 3; if (sel == 1) { if (armor < (maxArmor * .25)) return false; } else if (sel == 2) { if (armor < (maxArmor * .5)) return false; } else if (sel == 3) { if (armor < (maxArmor * .75)) return false; } else if (sel == 4) { if (armor < (maxArmor * .9)) return false; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -