Search in sources :

Example 41 with EquipmentType

use of megamek.common.EquipmentType in project megameklab by MegaMek.

the class EquipmentTab method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ADD_COMMAND)) {
        int view = masterEquipmentTable.getSelectedRow();
        if (view < 0) {
            // selection got filtered away
            return;
        }
        int selected = masterEquipmentTable.convertRowIndexToModel(view);
        EquipmentType equip = masterEquipmentList.getType(selected);
        addEquipment(equip);
    } else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
        int[] selectedRows = equipmentTable.getSelectedRows();
        for (Integer row : selectedRows) {
            equipmentList.removeMounted(row);
        }
        equipmentList.removeCrits(selectedRows);
        if (getAero().usesWeaponBays()) {
            removeEmptyBays();
        }
    } else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
        removeAllEquipment();
        if (getAero().usesWeaponBays()) {
            removeEmptyBays();
        }
    } else {
        return;
    }
    fireTableRefresh();
}
Also used : EquipmentType(megamek.common.EquipmentType)

Example 42 with EquipmentType

use of megamek.common.EquipmentType in project megameklab by MegaMek.

the class EquipmentTab method actionPerformed.

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ADD_COMMAND)) {
        int view = masterEquipmentTable.getSelectedRow();
        if (view < 0) {
            // selection got filtered away
            return;
        }
        int selected = masterEquipmentTable.convertRowIndexToModel(view);
        EquipmentType equip = masterEquipmentList.getType(selected);
        addEquipment(equip);
    } else if (e.getActionCommand().equals(REMOVE_COMMAND)) {
        int[] selectedRows = equipmentTable.getSelectedRows();
        for (Integer row : selectedRows) {
            equipmentList.removeMounted(row);
        }
        equipmentList.removeCrits(selectedRows);
    } else if (e.getActionCommand().equals(REMOVEALL_COMMAND)) {
        removeAllEquipment();
    } else {
        return;
    }
    fireTableRefresh();
}
Also used : EquipmentType(megamek.common.EquipmentType)

Example 43 with EquipmentType

use of megamek.common.EquipmentType 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)

Example 44 with EquipmentType

use of megamek.common.EquipmentType in project megameklab by MegaMek.

the class BuildView method mousePressed.

public void mousePressed(MouseEvent e) {
    // locations, but only if those locations are make sense
    if (e.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item;
        final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
        final Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
        final String[] locNames = BattleArmor.MOUNT_LOC_NAMES;
        // A list of the valid locations we can add the selected eq to
        ArrayList<Integer> validLocs = new ArrayList<Integer>();
        int numLocs = BattleArmor.MOUNT_NUM_LOCS;
        for (int loc = 0; loc < numLocs; loc++) {
            if (TestBattleArmor.isMountLegal(getBattleArmor(), eq, loc)) {
                validLocs.add(loc);
            }
        }
        if (eq.getLocation() == BattleArmor.LOC_SQUAD && !(eq.getType() instanceof InfantryWeapon)) {
            // Add a menu item for each potential location
            for (Integer location : validLocs) {
                if (UnitUtil.isValidLocation(getBattleArmor(), eq.getType(), location)) {
                    item = new JMenuItem("Add to " + locNames[location]);
                    final int loc = location;
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            mountEquipmentInLocation(loc, selectedRow);
                        }
                    });
                    popup.add(item);
                }
            }
            if (!UnitUtil.isArmor(eq.getType()) && !eq.isSquadSupportWeapon()) {
                item = new JMenuItem("Make individual weapon");
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLocation(BattleArmor.LOC_TROOPER_1);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        } else {
            if (!UnitUtil.isArmor(eq.getType()) && !(eq.getType() instanceof InfantryWeapon) && !((eq.getType() instanceof WeaponType) && (eq.getType().hasFlag(WeaponType.F_TASER) || ((WeaponType) eq.getType()).getAmmoType() == AmmoType.T_NARC))) {
                item = new JMenuItem("Make squad weapon");
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLocation(BattleArmor.LOC_SQUAD);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Allow number of shots selection
        if ((getBattleArmor() instanceof BattleArmor) && eq.getType() instanceof AmmoType) {
            AmmoType at = (AmmoType) eq.getType();
            int maxNumShots = 4;
            int stepSize = 1;
            if (at.getAmmoType() == AmmoType.T_BA_TUBE) {
                maxNumShots = 8;
                stepSize = 2;
            }
            for (int i = at.getShots(); i <= maxNumShots; i += stepSize) {
                if (i == eq.getBaseShotsLeft()) {
                    continue;
                }
                item = new JMenuItem("Set Shots: " + i);
                final int shots = i;
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setShotsLeft(shots);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Allow making this a squad support weapon
        if ((eq.getType() instanceof WeaponType) && !eq.isSquadSupportWeapon() && !eq.getType().hasFlag(WeaponType.F_INFANTRY) && eq.getLocation() == BattleArmor.LOC_SQUAD && getBattleArmor().getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
            item = new JMenuItem("Mount as squad support weapon");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    eq.setSquadSupportWeapon(true);
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // Adding ammo as a squad support mount is slightly different
        if ((eq.getType() instanceof AmmoType) && !eq.getType().hasFlag(WeaponType.F_MISSILE) && !eq.isSquadSupportWeapon() && eq.getLocation() == BattleArmor.LOC_SQUAD && getBattleArmor().getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
            boolean enabled = false;
            for (Mounted weapon : getBattleArmor().getWeaponList()) {
                WeaponType wtype = (WeaponType) weapon.getType();
                if (weapon.isSquadSupportWeapon() && AmmoType.isAmmoValid(eq, wtype)) {
                    enabled = true;
                }
            }
            item = new JMenuItem("Mount as squad support weapon");
            item.setEnabled(enabled);
            item.setToolTipText("Ammo can only be squad mounted along " + "with a weapon that uses it");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    eq.setSquadSupportWeapon(true);
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // Allow removing squad support weapon
        if (eq.isSquadSupportWeapon()) {
            item = new JMenuItem("Remove squad support weapon mount");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    eq.setSquadSupportWeapon(false);
                    // squad support weapon
                    for (Mounted ammo : getBattleArmor().getAmmo()) {
                        ammo.setSquadSupportWeapon(false);
                    }
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // See if we should allow linking this to a DWP
        if (getBattleArmor().hasWorkingMisc(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.getType().hasFlag(WeaponType.F_MISSILE) && !(eq.getType() instanceof AmmoType) && !eq.isDWPMounted() && (getBattleArmor()).canMountDWP()) {
            for (Mounted m : getBattleArmor().getMisc()) {
                // If this isn't a DWP or it's a full DWP, skip
                if (!m.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) || m.getLinked() != null) {
                    continue;
                }
                String locName;
                if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
                    locName = "None";
                } else {
                    locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
                }
                item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
                final Mounted dwp = m;
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLinked(dwp);
                        dwp.setLinked(eq);
                        eq.setDWPMounted(true);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Should we allow mounting Ammo in a DWP?
        if ((eq.getType() instanceof AmmoType) && getBattleArmor().hasWorkingMisc(MiscType.F_DETACHABLE_WEAPON_PACK) && !eq.isDWPMounted() && (getBattleArmor()).canMountDWP()) {
            for (final Mounted m : getBattleArmor().getMisc()) {
                // If this isn't a DWP, skip
                if (!m.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK)) {
                    continue;
                }
                // We only want to enable the menu item if the DWP has a
                // mounted weapon and we clicked on a valid ammo type
                boolean enabled = false;
                if (m.getLinked() != null) {
                    EquipmentType etype = m.getLinked().getType();
                    if (etype instanceof WeaponType) {
                        WeaponType wtype = (WeaponType) etype;
                        if (AmmoType.isAmmoValid(eq, wtype)) {
                            enabled = true;
                        }
                    }
                }
                String locName;
                if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
                    locName = "None";
                } else {
                    locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
                }
                item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
                item.setToolTipText("Ammo can only be mounted in a DWP " + "with a valid weapon.");
                item.setEnabled(enabled);
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        m.getLinked().setLinked(eq);
                        eq.setDWPMounted(true);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Right-clicked on a DWP that has an attached weapon
        if (eq.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && eq.getLinked() != null) {
            item = new JMenuItem("Remove attached weapon");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    Mounted attached = eq.getLinked();
                    attached.setDWPMounted(false);
                    eq.setLinked(null);
                    eq.setLinkedBy(null);
                    attached.setLinked(null);
                    attached.setLinkedBy(null);
                    // Remove any attached ammo
                    for (Mounted ammo : getBattleArmor().getAmmo()) {
                        if (attached.equals(ammo.getLinkedBy())) {
                            ammo.setDWPMounted(false);
                            ammo.setLinked(null);
                            ammo.setLinkedBy(null);
                        }
                    }
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        // See if we should allow linking this to an AP Mount
        if (getBattleArmor().hasWorkingMisc(MiscType.F_AP_MOUNT) && eq.getType().hasFlag(WeaponType.F_INFANTRY) && !eq.isAPMMounted()) {
            for (Mounted m : getBattleArmor().getMisc()) {
                // If this isn't an AP Mount or it's a full AP Mount, skip
                if (!m.getType().hasFlag(MiscType.F_AP_MOUNT) || m.getLinked() != null) {
                    continue;
                }
                // regardless of the number of gloves
                if (m.getType().hasFlag(MiscType.F_ARMORED_GLOVE)) {
                    boolean hasUsedGlove = false;
                    for (Mounted m2 : getBattleArmor().getMisc()) {
                        if (m2.getType().hasFlag(MiscType.F_ARMORED_GLOVE) && (m2.getLinked() != null)) {
                            hasUsedGlove = true;
                        }
                    }
                    if (hasUsedGlove) {
                        continue;
                    }
                }
                // Only armored gloves can carry infantry support weapons
                if (!m.getType().hasFlag(MiscType.F_ARMORED_GLOVE) && eq.getType().hasFlag(WeaponType.F_INF_SUPPORT)) {
                    continue;
                }
                String locName;
                if (m.getBaMountLoc() == BattleArmor.MOUNT_LOC_NONE) {
                    locName = "None";
                } else {
                    locName = BattleArmor.MOUNT_LOC_NAMES[m.getBaMountLoc()];
                }
                item = new JMenuItem("Mount in " + m.getName() + " (" + locName + ")");
                final Mounted apm = m;
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        eq.setLinked(apm);
                        apm.setLinked(eq);
                        eq.setAPMMounted(true);
                        ((BuildTab) getParent().getParent()).refreshAll();
                    }
                });
                popup.add(item);
            }
        }
        // Right-clicked on a AP Mount that has an attached weapon
        if (eq.getType().hasFlag(MiscType.F_AP_MOUNT) && eq.getLinked() != null) {
            item = new JMenuItem("Remove attached weapon");
            item.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    Mounted attached = eq.getLinked();
                    attached.setAPMMounted(false);
                    eq.setLinked(null);
                    eq.setLinkedBy(null);
                    attached.setLinked(null);
                    attached.setLinkedBy(null);
                    ((BuildTab) getParent().getParent()).refreshAll();
                }
            });
            popup.add(item);
        }
        popup.show(this, e.getX(), e.getY());
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) EquipmentType(megamek.common.EquipmentType) JPopupMenu(javax.swing.JPopupMenu) AmmoType(megamek.common.AmmoType) ActionListener(java.awt.event.ActionListener) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) JMenuItem(javax.swing.JMenuItem) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Example 45 with EquipmentType

use of megamek.common.EquipmentType in project megameklab by MegaMek.

the class EquipmentTab method loadEquipmentTable.

private void loadEquipmentTable() {
    for (Mounted mount : getTank().getWeaponList()) {
        equipmentList.addCrit(mount);
    }
    for (Mounted mount : getTank().getAmmo()) {
        equipmentList.addCrit(mount);
    }
    List<EquipmentType> spreadAlreadyAdded = new ArrayList<EquipmentType>();
    for (Mounted mount : getTank().getMisc()) {
        EquipmentType etype = mount.getType();
        if (UnitUtil.isHeatSink(mount) || etype.hasFlag(MiscType.F_JUMP_JET) || etype.hasFlag(MiscType.F_JUMP_BOOSTER) || etype.hasFlag(MiscType.F_TSM) || etype.hasFlag(MiscType.F_INDUSTRIAL_TSM) || (etype.hasFlag(MiscType.F_MASC) && !etype.hasSubType(MiscType.S_SUPERCHARGER)) || UnitUtil.isArmorOrStructure(etype)) {
            continue;
        }
        // if (UnitUtil.isUnitEquipment(mount.getType(), unit) || UnitUtil.isUn) {
        if (UnitUtil.isFixedLocationSpreadEquipment(etype) && !spreadAlreadyAdded.contains(etype)) {
            equipmentList.addCrit(mount);
            // keep track of spreadable equipment here, so it doesn't
            // show up multiple times in the table
            spreadAlreadyAdded.add(etype);
        } else {
            equipmentList.addCrit(mount);
        }
    // }
    }
}
Also used : Mounted(megamek.common.Mounted) ArrayList(java.util.ArrayList) EquipmentType(megamek.common.EquipmentType)

Aggregations

EquipmentType (megamek.common.EquipmentType)49 Mounted (megamek.common.Mounted)24 MiscType (megamek.common.MiscType)14 LocationFullException (megamek.common.LocationFullException)10 ArrayList (java.util.ArrayList)8 JLabel (javax.swing.JLabel)6 AmmoType (megamek.common.AmmoType)6 CriticalSlot (megamek.common.CriticalSlot)6 WeaponType (megamek.common.WeaponType)5 Dimension (java.awt.Dimension)4 List (java.util.List)4 Vector (java.util.Vector)4 BattleArmor (megamek.common.BattleArmor)4 Mech (megamek.common.Mech)4 EntitySource (megameklab.com.ui.EntitySource)4 RefreshListener (megameklab.com.util.RefreshListener)4 GridBagConstraints (java.awt.GridBagConstraints)3 GridBagLayout (java.awt.GridBagLayout)3 ActionEvent (java.awt.event.ActionEvent)3 StringJoiner (java.util.StringJoiner)3