Search in sources :

Example 61 with Mounted

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

the class BuildView method jMenuLoadComponent_actionPerformed.

/**
 * When the user right-clicks on the equipment table, a context menu is
 * generated that his menu items for each possible location that is clicked.
 * When the location is clicked, this is the method that adds the selected
 * equipment to the desired location.
 *
 * @param location
 * @param selectedRow
 */
private void jMenuLoadComponent_actionPerformed(int location, int selectedRow) {
    Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
    try {
        getAero().addEquipment(eq, location, false);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    UnitUtil.changeMountStatus(getAero(), eq, location, -1, false);
    // go back up to grandparent build tab and fire a full refresh.
    ((BuildTab) getParent().getParent()).refreshAll();
}
Also used : BuildTab(megameklab.com.ui.Aero.tabs.BuildTab) Mounted(megamek.common.Mounted)

Example 62 with Mounted

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

the class EquipmentTab method addEquipment.

private void addEquipment(EquipmentType equip) {
    Mounted mount = null;
    boolean isMisc = equip instanceof MiscType;
    boolean multiMount = UnitUtil.isBAMultiMount(equip);
    if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
        if (!UnitUtil.hasTargComp(getBattleArmor())) {
            mount = UnitUtil.updateTC(getBattleArmor(), equip);
            if (mount != null) {
                equipmentList.addCrit(mount);
            }
        }
    } else {
        try {
            if (multiMount) {
                for (int t = 1; t <= getBattleArmor().getTroopers(); t++) {
                    mount = new Mounted(getBattleArmor(), equip);
                    mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
                    getBattleArmor().addEquipment(mount, t, false);
                    equipmentList.addCrit(mount);
                }
            } else {
                mount = new Mounted(getBattleArmor(), equip);
                mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
                getBattleArmor().addEquipment(mount, BattleArmor.LOC_SQUAD, false);
                equipmentList.addCrit(mount);
            }
        } catch (LocationFullException lfe) {
        // this can't happen, we add to Entity.LOC_NONE
        }
    }
}
Also used : LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType)

Example 63 with Mounted

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

the class EquipmentTab method loadEquipmentTable.

private void loadEquipmentTable() {
    for (Mounted mount : getBattleArmor().getWeaponList()) {
        if (UnitUtil.isBattleArmorWeapon(mount.getType(), getBattleArmor()) || UnitUtil.isBattleArmorAPWeapon(mount.getType())) {
            equipmentList.addCrit(mount);
        }
    }
    for (Mounted mount : getBattleArmor().getAmmo()) {
        // Ignore ammo for one-shot launchers
        if (mount.getLinkedBy() != null && mount.getLinkedBy().isOneShot()) {
            continue;
        }
        equipmentList.addCrit(mount);
    }
    List<EquipmentType> spreadAlreadyAdded = new ArrayList<EquipmentType>();
    for (Mounted mount : getBattleArmor().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)

Example 64 with Mounted

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

the class EquipmentTab method removeHeatSinks.

private void removeHeatSinks() {
    int location = 0;
    for (; location < equipmentList.getRowCount(); ) {
        Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
        EquipmentType eq = mount.getType();
        if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
            try {
                equipmentList.removeCrit(location);
            } catch (ArrayIndexOutOfBoundsException aioobe) {
                return;
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            location++;
        }
    }
}
Also used : Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) EquipmentType(megamek.common.EquipmentType) LocationFullException(megamek.common.LocationFullException)

Example 65 with Mounted

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

the class StructureTab method enhancementChanged.

@Override
public void enhancementChanged(EquipmentType eq, boolean selected) {
    if (selected) {
        try {
            int loc = BattleArmor.MOUNT_LOC_BODY;
            if (eq.hasFlag(MiscType.F_MASC)) {
                loc = BattleArmor.MOUNT_LOC_NONE;
            }
            int numTimesToAdd = 1;
            // for each critical
            if (eq.isSpreadable()) {
                numTimesToAdd = eq.getCriticals(getBattleArmor());
            }
            for (int i = 0; i < numTimesToAdd; i++) {
                Mounted newMount = new Mounted(getBattleArmor(), eq);
                newMount.setBaMountLoc(loc);
                getBattleArmor().addEquipment(newMount, BattleArmor.LOC_SQUAD, false);
            }
        } catch (LocationFullException exc) {
            // Shouldn't happen with BA
            exc.printStackTrace();
        }
    } else {
        List<Mounted> mounts = getBattleArmor().getMisc().stream().filter(m -> m.getType().equals(eq)).collect(Collectors.toList());
        for (Mounted mount : mounts) {
            UnitUtil.removeMounted(getBattleArmor(), mount);
        }
    }
    panMovement.setFromEntity(getBattleArmor());
    refresh.refreshSummary();
    refresh.refreshBuild();
    refresh.refreshPreview();
}
Also used : Insets(java.awt.Insets) MechViewPanel(megamek.client.ui.swing.MechViewPanel) ActionListener(java.awt.event.ActionListener) CriticalSlot(megamek.common.CriticalSlot) SwingConstants(javax.swing.SwingConstants) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.com.ui.EntitySource) BattleArmor(megamek.common.BattleArmor) BAChassisView(megameklab.com.ui.view.BAChassisView) CustomComboBox(megameklab.com.ui.util.CustomComboBox) Mounted(megamek.common.Mounted) UnitUtil(megameklab.com.util.UnitUtil) JComboBox(javax.swing.JComboBox) MechView(megamek.common.MechView) BAManipulator(megamek.common.verifier.TestBattleArmor.BAManipulator) ITechManager(megamek.common.ITechManager) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) LocationFullException(megamek.common.LocationFullException) BorderFactory(javax.swing.BorderFactory) EntityMovementMode(megamek.common.EntityMovementMode) GridBagConstraints(java.awt.GridBagConstraints) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) BAProtoArmorView(megameklab.com.ui.view.BAProtoArmorView) Box(javax.swing.Box) MovementView(megameklab.com.ui.view.MovementView) ITab(megameklab.com.util.ITab) Dimension(java.awt.Dimension) List(java.util.List) BAEnhancementView(megameklab.com.ui.view.BAEnhancementView) BasicInfoView(megameklab.com.ui.view.BasicInfoView) JLabel(javax.swing.JLabel) SimpleTechLevel(megamek.common.SimpleTechLevel) MiscType(megamek.common.MiscType) GridBagLayout(java.awt.GridBagLayout) BABuildListener(megameklab.com.ui.view.listeners.BABuildListener) JPanel(javax.swing.JPanel) RefreshListener(megameklab.com.util.RefreshListener) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Aggregations

Mounted (megamek.common.Mounted)162 MiscType (megamek.common.MiscType)50 LocationFullException (megamek.common.LocationFullException)39 AmmoType (megamek.common.AmmoType)36 EquipmentType (megamek.common.EquipmentType)34 CriticalSlot (megamek.common.CriticalSlot)31 ArrayList (java.util.ArrayList)30 WeaponType (megamek.common.WeaponType)29 Vector (java.util.Vector)25 EntityLoadingException (megamek.common.loaders.EntityLoadingException)21 Font (java.awt.Font)14 Entity (megamek.common.Entity)13 List (java.util.List)12 Dimension (java.awt.Dimension)11 JLabel (javax.swing.JLabel)11 JMenuItem (javax.swing.JMenuItem)11 JPopupMenu (javax.swing.JPopupMenu)11 BattleArmor (megamek.common.BattleArmor)11 ActionEvent (java.awt.event.ActionEvent)10 Weapon (megamek.common.weapons.Weapon)10