📄 custombattlearmordialog.java
字号:
m_chLeftArmEquipment.setSelectedItem(value); m_chLeftArmCurrentEquipment.removeAll(); if (leftArmEquipment != null) { Iterator tmpEE = leftArmEquipment.iterator(); while (tmpEE.hasNext()) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpEE.next()); m_chLeftArmCurrentEquipment.addItem(tmpBAE.name); } } m_chRightArmCurrentEquipment.removeAll(); if (rightArmEquipment != null) { Iterator tmpEE = rightArmEquipment.iterator(); while (tmpEE.hasNext()) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpEE.next()); m_chRightArmCurrentEquipment.addItem(tmpBAE.name); } } m_chTorsoCurrentEquipment.removeAll(); if (torsoEquipment != null) { Iterator tmpEE = torsoEquipment.iterator(); while (tmpEE.hasNext()) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpEE.next()); m_chTorsoCurrentEquipment.addItem(tmpBAE.name); } } } private boolean hasConflictFlag(int testFlags) { return ((stateConflictFlags & testFlags) > 0); } private void updateGroundMPChoices() { m_chGroundMP.removeAll(); if (stateChassisType == CHASSIS_TYPE_BIPED) { // Biped BA m_chGroundMP.addItem("1"); m_chGroundMP.addItem("2"); if ((stateWeightClass == WEIGHT_CLASS_PAL) || (stateWeightClass == WEIGHT_CLASS_LIGHT) || (stateWeightClass == WEIGHT_CLASS_MEDIUM)) { m_chGroundMP.addItem("3"); } } else { // Quad BA m_chGroundMP.addItem("2"); m_chGroundMP.addItem("3"); m_chGroundMP.addItem("4"); if ((stateWeightClass == WEIGHT_CLASS_LIGHT) || (stateWeightClass == WEIGHT_CLASS_MEDIUM)) { m_chGroundMP.addItem("5"); } } m_chGroundMP.setSelectedIndex(0); stateGroundMP = Integer.parseInt((String) m_chGroundMP.getSelectedItem()); } private void updateJumpMPChoices() { int tmp = m_chJumpValue.getSelectedIndex(); m_chJumpValue.removeAll(); for (int x = 0; x <= JUMP_MP_LIMITS[stateJumpType][stateWeightClass]; x++) m_chJumpValue.addItem(Integer.toString(x)); if (tmp >= m_chJumpValue.getItemCount()) { m_chJumpValue.setSelectedIndex(m_chJumpValue.getItemCount() - 1); stateJumpMP = m_chJumpValue.getSelectedIndex(); } else { m_chJumpValue.setSelectedIndex(tmp); } } private void updateArmorValueChoices() { int tmp = m_chArmorValue.getSelectedIndex(); m_chArmorValue.removeAll(); m_chArmorValue.addItem("0"); m_chArmorValue.addItem("1"); m_chArmorValue.addItem("2"); if (stateWeightClass > 0) { m_chArmorValue.addItem("3"); m_chArmorValue.addItem("4"); m_chArmorValue.addItem("5"); m_chArmorValue.addItem("6"); if (stateWeightClass > 1) { m_chArmorValue.addItem("7"); m_chArmorValue.addItem("8"); m_chArmorValue.addItem("9"); m_chArmorValue.addItem("10"); if (stateWeightClass > 2) { m_chArmorValue.addItem("11"); m_chArmorValue.addItem("12"); m_chArmorValue.addItem("13"); m_chArmorValue.addItem("14"); if (stateWeightClass > 3) { m_chArmorValue.addItem("15"); m_chArmorValue.addItem("16"); m_chArmorValue.addItem("17"); m_chArmorValue.addItem("18"); } } } } if (tmp >= m_chArmorValue.getItemCount()) { m_chArmorValue.setSelectedIndex(m_chArmorValue.getItemCount() - 1); stateArmorValue = m_chArmorValue.getSelectedIndex(); } else { m_chArmorValue.setSelectedIndex(tmp); } } 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(); setLocation(computeDesiredLocation()); super.setVisible(visible); m_BAView.setCaretPosition(0); } public void actionPerformed(ActionEvent ae) { if (ae.getSource().equals(m_buttonReset)) { resetState(); return; } else if (ae.getSource().equals(m_buttonAddTorso)) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (equipmentTypes.get(equipmentNames.indexOf(m_chTorsoEquipment.getSelectedItem()))); if (torsoEquipment == null) torsoEquipment = new ArrayList(); torsoEquipment.add(tmpBAE); stateConflictFlags |= tmpBAE.conflictFlag; // Make sure the BA preview is now correct... previewBA(); // Make sure we update the equpment choices, since they may have now changed... updateEquipmentChoices(); // Nothing else in actionPerformed will matter, so lets move on! return; } else if (ae.getSource().equals(m_buttonAddRightArm)) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (equipmentTypes.get(equipmentNames.indexOf(m_chRightArmEquipment.getSelectedItem()))); if (rightArmEquipment == null) rightArmEquipment = new ArrayList(); rightArmEquipment.add(tmpBAE); stateConflictFlags |= tmpBAE.conflictFlag; // Make sure the BA preview is now correct... previewBA(); // Make sure we update the equpment choices, since they may have now changed... updateEquipmentChoices(); // Nothing else in actionPerformed will matter, so lets move on! return; } else if (ae.getSource().equals(m_buttonAddLeftArm)) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (equipmentTypes.get(equipmentNames.indexOf(m_chLeftArmEquipment.getSelectedItem()))); if (leftArmEquipment == null) leftArmEquipment = new ArrayList(); leftArmEquipment.add(tmpBAE); stateConflictFlags |= tmpBAE.conflictFlag; // Make sure the BA preview is now correct... previewBA(); // Make sure we update the equpment choices, since they may have now changed... updateEquipmentChoices(); // Nothing else in actionPerformed will matter, so lets move on! return; } else if (ae.getSource().equals(m_buttonRemoveTorso)) { if (torsoEquipment != null) { String removeItem = (String) m_chTorsoCurrentEquipment.getSelectedItem(); Iterator tmpE = torsoEquipment.iterator(); while (tmpE.hasNext()) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next()); if (tmpBAE.name.equals(removeItem)) { torsoEquipment.remove(tmpBAE); break; } } if (torsoEquipment.size() <= 0) torsoEquipment = null; // Make sure the BA preview is now correct... previewBA(); // Make sure we update the equpment choices, since they may have now changed... updateEquipmentChoices(); } // Nothing else in actionPerformed will matter, so lets move on! return; } else if (ae.getSource().equals(m_buttonRemoveRightArm)) { if (rightArmEquipment != null) { String removeItem = (String) m_chRightArmCurrentEquipment.getSelectedItem(); Iterator tmpE = rightArmEquipment.iterator(); while (tmpE.hasNext()) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next()); if (tmpBAE.name.equals(removeItem)) { rightArmEquipment.remove(tmpBAE); break; } } if (rightArmEquipment.size() <= 0) rightArmEquipment = null; // Make sure the BA preview is now correct... previewBA(); // Make sure we update the equpment choices, since they may have now changed... updateEquipmentChoices(); } // Nothing else in actionPerformed will matter, so lets move on! return; } else if (ae.getSource().equals(m_buttonRemoveLeftArm)) { if (leftArmEquipment != null) { String removeItem = (String) m_chLeftArmCurrentEquipment.getSelectedItem(); Iterator tmpE = leftArmEquipment.iterator(); while (tmpE.hasNext()) { BattleArmorEquipment tmpBAE = (BattleArmorEquipment) (tmpE.next()); if (tmpBAE.name.equals(removeItem)) { leftArmEquipment.remove(tmpBAE); break; } } if (leftArmEquipment.size() <= 0) leftArmEquipment = null; // Make sure the BA preview is now correct... previewBA(); // Make sure we update the equpment choices, since they may have now changed... updateEquipmentChoices(); } // Nothing else in actionPerformed will matter, so lets move on! return; } else if ((ae.getSource().equals(m_bPick)) || (ae.getSource().equals(m_bPickClose))) { // Here, we need to add the current BA as a new entity, if it can legally do so... if (!isValid()) { JOptionPane.showMessageDialog(m_clientgui.frame, "You can't add an invalid unit.", "Can't do that!", JOptionPane.ERROR_MESSAGE); return; } try { Entity e = 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 (Exception ex) { System.err.println("Error while loading custom BattleArmor!"); ex.printStackTrace(); return; } } // Specifically NOT an else/if, because this can happen at the same time as one option above. if ((ae.getSource().equals(m_bCancel)) || (ae.getSource().equals(m_bPickClose))) { setVisible(false); } } public void itemStateChanged(ItemEvent ie) { if (ie.getSource().equals(m_cbJumpQuery)) { if (m_cbJumpQuery.isSelected()) { stateJumpType = JUMP_TYPE_JUMP; updateJumpMPChoices(); m_labelJumpValue.setText(Messages.getString("CustomBattleArmorDialog.m_labelJumpValue")); } } else if (ie.getSource().equals(m_cbVTOLQuery)) { if (m_cbVTOLQuery.isSelected()) { stateJumpType = JUMP_TYPE_VTOL; updateJumpMPChoices(); m_labelJumpValue.setText(Messages.getString("CustomBattleArmorDialog.m_labelVTOLValue")); } } else if (ie.getSource().equals(m_cbUMUQuery)) { if (m_cbUMUQuery.isSelected()) { stateJumpType = JUMP_TYPE_UMU; updateJumpMPChoices(); m_labelJumpValue.setText(Messages.getString("CustomBattleArmorDialog.m_labelUMUValue")); } } else if (ie.getSource().equals(m_chMenPerSquad)) { if (stateMenPerSquad != Integer.parseInt((String) m_chMenPerSquad.getSelectedItem())) { // Does this actually affect anything else? I'm not sure. stateMenPerSquad = Integer.parseInt((String) m_chMenPerSquad.getSelectedItem()); } } else if (ie.getSource().equals(m_chTechBase)) { if (stateTechBase != m_chTechBase.getSelectedIndex()) { // If the tech base actually changed, we might have to re-calculate things. stateTechBase = m_chTechBase.getSelectedIndex();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -