Search in sources :

Example 1 with BAManipulator

use of megamek.common.verifier.TestBattleArmor.BAManipulator in project megameklab by MegaMek.

the class StructureTab method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    removeAllListeners();
    if (e.getSource() instanceof JComboBox) {
        @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) e.getSource();
        if (combo.equals(leftManipSelect)) {
            // If the BA already had a manipulator here, we'll need to
            // remove it
            Mounted leftManip = getBattleArmor().getLeftManipulator();
            BAManipulator manipType;
            if (leftManip != null) {
                UnitUtil.removeMounted(getBattleArmor(), leftManip);
                manipType = BAManipulator.getManipulator(leftManip.getType().getInternalName());
                // remove the paired manipulator
                if (manipType.pairMounted) {
                    Mounted rightManip = getBattleArmor().getRightManipulator();
                    if (rightManip != null) {
                        UnitUtil.removeMounted(getBattleArmor(), rightManip);
                        rightManipSelect.setSelectedIndex(0);
                    }
                }
            }
            // If we selected something other than "None", mount it
            if (leftManipSelect.getSelectedIndex() != 0) {
                String manipName = (String) leftManipSelect.getSelectedItem();
                manipType = BAManipulator.getManipulator(manipName);
                EquipmentType et = EquipmentType.get(manipType.internalName);
                leftManip = new Mounted(getBattleArmor(), et);
                leftManip.setBaMountLoc(BattleArmor.MOUNT_LOC_LARM);
                try {
                    // Add the manipulator
                    getBattleArmor().addEquipment(leftManip, BattleArmor.LOC_SQUAD, false);
                    // Check to see if we need to add its mate
                    manipType = BAManipulator.getManipulator(leftManip.getType().getInternalName());
                    // remove the paired manipulator
                    if (manipType.pairMounted) {
                        Mounted rightManip = new Mounted(getBattleArmor(), et);
                        rightManip.setBaMountLoc(BattleArmor.MOUNT_LOC_RARM);
                        getBattleArmor().addEquipment(rightManip, BattleArmor.LOC_SQUAD, false);
                    }
                } catch (LocationFullException ex) {
                    // This shouldn't happen
                    ex.printStackTrace();
                }
            }
        } else if (combo.equals(rightManipSelect)) {
            // If the BA already had a manipulator here, we'll need to
            // remove it
            Mounted rightManip = getBattleArmor().getRightManipulator();
            BAManipulator manipType;
            if (rightManip != null) {
                UnitUtil.removeMounted(getBattleArmor(), rightManip);
                manipType = BAManipulator.getManipulator(rightManip.getType().getInternalName());
                // remove the paired manipulator
                if (manipType.pairMounted) {
                    Mounted leftManip = getBattleArmor().getLeftManipulator();
                    if (leftManip != null) {
                        UnitUtil.removeMounted(getBattleArmor(), leftManip);
                        leftManipSelect.setSelectedIndex(0);
                    }
                }
            }
            // If we selected something other than "None", mount it
            if (rightManipSelect.getSelectedIndex() != 0) {
                String manipName = (String) rightManipSelect.getSelectedItem();
                manipType = BAManipulator.getManipulator(manipName);
                EquipmentType et = EquipmentType.get(manipType.internalName);
                rightManip = new Mounted(getBattleArmor(), et);
                rightManip.setBaMountLoc(BattleArmor.MOUNT_LOC_RARM);
                try {
                    // Add the manipulator
                    getBattleArmor().addEquipment(rightManip, BattleArmor.LOC_SQUAD, false);
                    // Check to see if we need to add its mate
                    manipType = BAManipulator.getManipulator(rightManip.getType().getInternalName());
                    // remove the paired manipulator
                    if (manipType.pairMounted) {
                        Mounted leftManip = new Mounted(getBattleArmor(), et);
                        leftManip.setBaMountLoc(BattleArmor.MOUNT_LOC_LARM);
                        getBattleArmor().addEquipment(leftManip, BattleArmor.LOC_SQUAD, false);
                    }
                } catch (LocationFullException ex) {
                    // This shouldn't happen
                    ex.printStackTrace();
                }
            }
        }
    }
    refresh.refreshAll();
}
Also used : LocationFullException(megamek.common.LocationFullException) JComboBox(javax.swing.JComboBox) Mounted(megamek.common.Mounted) BAManipulator(megamek.common.verifier.TestBattleArmor.BAManipulator) EquipmentType(megamek.common.EquipmentType)

Example 2 with BAManipulator

use of megamek.common.verifier.TestBattleArmor.BAManipulator in project megameklab by MegaMek.

the class StructureTab method refresh.

public void refresh() {
    panBasicInfo.setFromEntity(getBattleArmor());
    panChassis.setFromEntity(getBattleArmor());
    panMovement.setFromEntity(getBattleArmor());
    panArmor.setFromEntity(getBattleArmor());
    panEnhancements.setFromEntity(getBattleArmor());
    removeAllListeners();
    // Manipulators
    leftManipSelect.removeAllItems();
    rightManipSelect.removeAllItems();
    leftManipSelect.addItem(BattleArmor.MANIPULATOR_TYPE_STRINGS[BattleArmor.MANIPULATOR_NONE]);
    rightManipSelect.addItem(BattleArmor.MANIPULATOR_TYPE_STRINGS[BattleArmor.MANIPULATOR_NONE]);
    for (BAManipulator manip : BAManipulator.values()) {
        EquipmentType et = EquipmentType.get(manip.internalName);
        if ((null != et) && getTechManager().isLegal(et)) {
            leftManipSelect.addItem(et.getName());
            rightManipSelect.addItem(et.getName());
        }
    }
    int manipType = BAManipulator.getManipulator(getBattleArmor().getLeftManipulatorName()).type;
    leftManipSelect.setSelectedItem(BattleArmor.MANIPULATOR_NAME_STRINGS[manipType]);
    manipType = BAManipulator.getManipulator(getBattleArmor().getRightManipulatorName()).type;
    rightManipSelect.setSelectedItem(BattleArmor.MANIPULATOR_NAME_STRINGS[manipType]);
    refreshPreview();
    addAllListeners();
}
Also used : BAManipulator(megamek.common.verifier.TestBattleArmor.BAManipulator) EquipmentType(megamek.common.EquipmentType)

Aggregations

EquipmentType (megamek.common.EquipmentType)2 BAManipulator (megamek.common.verifier.TestBattleArmor.BAManipulator)2 JComboBox (javax.swing.JComboBox)1 LocationFullException (megamek.common.LocationFullException)1 Mounted (megamek.common.Mounted)1