📄 custommechdialog.java
字号:
choDeployment.select(0); for ( int i = 1; i <= 15; i++ ) { choDeployment.add(Messages.getString("CustomMechDialog.AfterRound") + i); //$NON-NLS-1$ if ( entity.getDeployRound() == i ) choDeployment.select(i); } } private void refreshC3() { choC3.removeAll(); int listIndex = 0; entityCorrespondance = new int[client.game.getNoOfEntities() + 2]; if(entity.hasC3i()) { choC3.add(Messages.getString("CustomMechDialog.CreateNewNetwork")); //$NON-NLS-1$ if(entity.getC3Master() == null) choC3.select(listIndex); entityCorrespondance[listIndex++] = entity.getId(); } else if ( entity.hasC3MM() ) { int mNodes = entity.calculateFreeC3MNodes(); int sNodes = entity.calculateFreeC3Nodes(); choC3.add(Messages.getString("CustomMechDialog.setCompanyMaster", new Object[]{new Integer(mNodes), new Integer(sNodes)})); //$NON-NLS-1$ if(entity.C3MasterIs(entity)) choC3.select(listIndex); entityCorrespondance[listIndex++] = entity.getId(); choC3.add(Messages.getString("CustomMechDialog.setIndependentMaster", new Object[]{new Integer(sNodes)})); //$NON-NLS-1$ if(entity.getC3Master() == null) choC3.select(listIndex); entityCorrespondance[listIndex++] = -1; } else if(entity.hasC3M()) { int nodes = entity.calculateFreeC3Nodes(); choC3.add(Messages.getString("CustomMechDialog.setCompanyMaster1", new Object[]{new Integer(nodes)})); //$NON-NLS-1$ if(entity.C3MasterIs(entity)) choC3.select(listIndex); entityCorrespondance[listIndex++] = entity.getId(); choC3.add(Messages.getString("CustomMechDialog.setIndependentMaster", new Object[]{new Integer(nodes)})); //$NON-NLS-1$ if(entity.getC3Master() == null) choC3.select(listIndex); entityCorrespondance[listIndex++] = -1; } for (Enumeration i = client.getEntities(); i.hasMoreElements();) { final Entity e = (Entity)i.nextElement(); // ignore enemies or self if(entity.isEnemyOf(e) || entity.equals(e)) { continue; } // c3i only links with c3i if (entity.hasC3i() != e.hasC3i()) { continue; } //maximum depth of a c3 network is 2 levels. Entity eCompanyMaster = e.getC3Master(); if ( eCompanyMaster != null && eCompanyMaster.getC3Master() != eCompanyMaster) { continue; } int nodes = e.calculateFreeC3Nodes(); if ( e.hasC3MM() && entity.hasC3M() && e.C3MasterIs(e) ) { nodes = e.calculateFreeC3MNodes(); } if (entity.C3MasterIs(e) && !entity.equals(e)) { nodes++; } if (entity.hasC3i() && (entity.onSameC3NetworkAs(e) || entity.equals(e))) { nodes++; } if (nodes == 0) { continue; } if(e.hasC3i()) { if (entity.onSameC3NetworkAs(e)) { choC3.add(Messages.getString("CustomMechDialog.join1", new Object[]{e.getDisplayName(), e.getC3NetId(), new Integer(nodes - 1)})); //$NON-NLS-1$ choC3.select(listIndex); } else { choC3.add(Messages.getString("CustomMechDialog.join2", new Object[]{e.getDisplayName(), e.getC3NetId(), new Integer(nodes)})); //$NON-NLS-1$ } entityCorrespondance[listIndex++] = e.getId(); } else if ( e.C3MasterIs(e) && e.hasC3MM()) { // Company masters with 2 computers can have // *both* sub-masters AND slave units. choC3.add(Messages.getString("CustomMechDialog.connect2", new Object[]{e.getDisplayName(), e.getC3NetId(), new Integer(nodes)})); //$NON-NLS-1$ entityCorrespondance[listIndex] = e.getId(); if (entity.C3MasterIs(e)) { choC3.select(listIndex); } listIndex++; } else if ( e.C3MasterIs(e) && !entity.hasC3M() ) { // If we're a slave-unit, we can only connect to sub-masters, // not main masters likewise, if we're a master unit, we can // only connect to main master units, not sub-masters. } else if (entity.C3MasterIs(e)) { choC3.add(Messages.getString("CustomMechDialog.connect1", new Object[]{e.getDisplayName(), e.getC3NetId(), new Integer(nodes-1)})); //$NON-NLS-1$ choC3.select(listIndex); entityCorrespondance[listIndex++] = e.getId(); } else { choC3.add(Messages.getString("CustomMechDialog.connect2", new Object[]{e.getDisplayName(), e.getC3NetId(), new Integer(nodes)})); //$NON-NLS-1$ entityCorrespondance[listIndex++] = e.getId(); } } } /** * Populate the list of entities in other units from the given enumeration. * * @param others the <code>Enumeration</code> containing entities in * other units. */ private void refreshUnitNum( Enumeration others ) { // Clear the list of old values choUnitNum.removeAll(); entityUnitNum.removeAllElements(); // Make an entry for "no change". choUnitNum.add( Messages.getString("CustomMechDialog.doNotSwapUnits") ); //$NON-NLS-1$ entityUnitNum.addElement( this.entity ); // Walk through the other entities. while ( others.hasMoreElements() ) { // Track the position of the next other entity. final Entity other = (Entity) others.nextElement(); entityUnitNum.addElement( other ); // Show the other entity's name and callsign. StringBuffer callsign = new StringBuffer( other.getDisplayName() ); callsign.append( " (" ) //$NON-NLS-1$ .append( (char) (other.getUnitNumber() + PreferenceManager.getClientPreferences().getUnitStartChar()) ) .append( '-' ) .append( other.getId() ) .append( ')' ); choUnitNum.add( callsign.toString() ); } choUnitNum.select(0); } public void actionPerformed(java.awt.event.ActionEvent actionEvent) { if (actionEvent.getSource() == butOffBoardDistance) { int maxDistance = 19*17; // Long Tom for (Mounted wep : entity.getWeaponList()) { EquipmentType e = wep.getType(); WeaponType w = (WeaponType)e; if (w.hasFlag(WeaponType.F_ARTILLERY)) { int nDistance = (w.getLongRange()-1)*17; if (nDistance<maxDistance) { maxDistance = nDistance; } } } Slider sl = new Slider (clientgui.frame, Messages.getString("CustomMechDialog.offboardDistanceTitle"), Messages.getString("CustomMechDialog.offboardDistanceQuestion"), entity.getOffBoardDistance(), 17, maxDistance); if (!sl.showDialog()) return; distance = sl.getValue(); butOffBoardDistance.setLabel(Integer.toString(distance)); // butOffBoardDistance = new Button (Integer.toString(sl.getValue())); // butOffBoardDistance.addActionListener(this); return; } if (actionEvent.getSource() != butCancel) { // get values String name = fldName.getText(); int gunnery; int piloting; int offBoardDistance; boolean autoEject = chAutoEject.getState(); try { gunnery = Integer.parseInt(fldGunnery.getText()); piloting = Integer.parseInt(fldPiloting.getText()); } catch (NumberFormatException e) { new AlertDialog(clientgui.frame, Messages.getString("CustomMechDialog.NumberFormatError"), Messages.getString("CustomMechDialog.EnterValidSkills")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$ return; } // keep these reasonable, please if (gunnery < 0 || gunnery > 7 || piloting < 0 || piloting > 7) { new AlertDialog(clientgui.frame, Messages.getString("CustomMechDialog.NumberFormatError"), Messages.getString("CustomMechDialog.EnterSkillsBetween0_7")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$ return; } if (chOffBoard.getState()){ try { offBoardDistance = distance; } catch (NumberFormatException e) { new AlertDialog(clientgui.frame, Messages.getString("CustomMechDialog.NumberFormatError"), Messages.getString("CustomMechDialog.EnterValidSkills")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$ return; } if (offBoardDistance < 17) { new AlertDialog(clientgui.frame, Messages.getString("CustomMechDialog.NumberFormatError"), Messages.getString("CustomMechDialog.OffboardDistance")).setVisible(true); //$NON-NLS-1$ //$NON-NLS-2$ return; } entity.setOffBoard( offBoardDistance, choOffBoardDirection.getSelectedIndex() ); } else { entity.setOffBoard( 0, Entity.NONE ); } // change entity entity.setCrew(new Pilot(name, gunnery, piloting)); if (entity instanceof Mech) { Mech mech = (Mech)entity; mech.setAutoEject(!autoEject); } if (entity.hasC3() && choC3.getSelectedIndex() > -1) { Entity chosen = client.getEntity ( entityCorrespondance[choC3.getSelectedIndex()] ); int entC3nodeCount = client.game.getC3SubNetworkMembers( entity ).size(); int choC3nodeCount = client.game.getC3NetworkMembers( chosen ).size(); if ( entC3nodeCount + choC3nodeCount <= Entity.MAX_C3_NODES ) { entity.setC3Master( chosen ); } else { String message = Messages.getString("CustomMechDialog.NetworkTooBig.message", new Object[]{ //$NON-NLS-1$ entity.getShortName(), chosen.getShortName(), new Integer(entC3nodeCount), new Integer(choC3nodeCount), new Integer(Entity.MAX_C3_NODES)}); clientgui.doAlertDialog( Messages.getString("CustomMechDialog.NetworkTooBig.title"), //$NON-NLS-1$ message); refreshC3(); } } else if (entity.hasC3i() && choC3.getSelectedIndex() > -1) { entity.setC3NetId(client.getEntity(entityCorrespondance[choC3.getSelectedIndex()])); } // Update the entity's targeting system type. if (!(entity.hasTargComp()) && (clientgui.getClient().game.getOptions().booleanOption("allow_level_3_targsys"))) { int targSysIndex = MiscType.T_TARGSYS_STANDARD; if (choTargSys.getSelectedItem() != null) targSysIndex = MiscType.getTargetSysType(choTargSys.getSelectedItem()); if (targSysIndex >= 0) entity.setTargSysType(targSysIndex); else { System.err.println("Illegal targeting system index: "+targSysIndex); entity.setTargSysType(MiscType.T_TARGSYS_STANDARD); } } // If the player wants to swap unit numbers, update both // entities and send an update packet for the other entity. if ( !entityUnitNum.isEmpty() && choUnitNum.getSelectedIndex() > 0 ) { Entity other = (Entity) this.entityUnitNum.elementAt ( choUnitNum.getSelectedIndex() ); char temp = this.entity.getUnitNumber(); this.entity.setUnitNumber( other.getUnitNumber() ); other.setUnitNumber( temp ); client.sendUpdateEntity( other ); } // Set the entity's deployment round. //entity.setDeployRound((choDeployment.getSelectedIndex() == 0?0:choDeployment.getSelectedIndex()+1)); entity.setDeployRound(choDeployment.getSelectedIndex()); // update munitions selections for (Enumeration e = m_vMunitions.elements(); e.hasMoreElements(); ) { ((MunitionChoicePanel)e.nextElement()).applyChoice(); } // update MG rapid fire settings for (Enumeration e = m_vMGs.elements(); e.hasMoreElements(); ) { ((RapidfireMGPanel)e.nextElement()).applyChoice(); } // update mines setting for (Enumeration e = m_vMines.elements(); e.hasMoreElements(); ) { ((MineChoicePanel)e.nextElement()).applyChoice(); } // update searchlight setting entity.setSpotlight(chSearchlight.getState()); entity.setSpotlightState(chSearchlight.getState()); setOptions(); okay = true; clientgui.chatlounge.refreshEntities(); } this.setVisible(false); Entity nextOne = null; if (actionEvent.getSource() == butPrev) { nextOne = getNextEntity(false); } else if (actionEvent.getSource() == butNext) { nextOne = getNextEntity(true); } if (nextOne!=null) { clientgui.chatlounge.customizeMech(nextOne); } } private Entity getNextEntity(boolean forward){ IGame game = client.game; boolean bd = game.getOptions().booleanOption("blind_drop"); //$NON-NLS-1$ boolean rbd = game.getOptions().booleanOption("real_blind_drop"); //$NON-NLS-1$ Player p = client.getLocalPlayer(); Entity nextOne = null; if (forward) { nextOne = game.getNextEntityFromList(entity); } else { nextOne = game.getPreviousEntityFromList(entity); } while(nextOne != entity && nextOne != null) { if (nextOne.getOwner().equals(p) || !(bd || rbd)) { return nextOne; } if (forward) { nextOne = game.getNextEntityFromList(nextOne); } else { nextOne = game.getPreviousEntityFromList(nextOne); } } return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -