Search in sources :

Example 11 with CriticalSlot

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

the class CritListCellRenderer method getCrit.

private CriticalSlot getCrit(int slot) {
    int location = getCritLocation();
    CriticalSlot crit = null;
    if ((slot >= 0) && (slot < unit.getNumberOfCriticals(location))) {
        crit = unit.getCritical(location, slot);
    }
    return crit;
}
Also used : CriticalSlot(megamek.common.CriticalSlot)

Example 12 with CriticalSlot

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

the class CriticalTransferHandler method importData.

@Override
public boolean importData(TransferSupport info) {
    if (!info.isDrop()) {
        return false;
    }
    if (info.getComponent() instanceof DropTargetCriticalList) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) info.getComponent();
        location = Integer.parseInt(list.getName());
        Transferable t = info.getTransferable();
        try {
            Mounted mount = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
            if (!UnitUtil.isValidLocation(getUnit(), mount.getType(), location)) {
                JOptionPane.showMessageDialog(null, mount.getName() + " can't be placed in " + getUnit().getLocationName(location) + "!", "Invalid Location", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }
            if (!getUnit().addCritical(location, new CriticalSlot(mount))) {
                JOptionPane.showMessageDialog(null, "Location Full", "Location Full", JOptionPane.INFORMATION_MESSAGE);
            } else {
                changeMountStatus(mount, location, false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
    if ((info.getComponent() instanceof JTable) || (info.getComponent() instanceof JScrollPane)) {
        try {
            Transferable t = info.getTransferable();
            Mounted mount = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
            if (getUnit() instanceof BattleArmor) {
                mount.setBaMountLoc(BattleArmor.MOUNT_LOC_NONE);
            } else {
                UnitUtil.removeCriticals(getUnit(), mount);
                changeMountStatus(mount, Entity.LOC_NONE, false);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
    return false;
}
Also used : JScrollPane(javax.swing.JScrollPane) Mounted(megamek.common.Mounted) CriticalSlot(megamek.common.CriticalSlot) JTable(javax.swing.JTable) Transferable(java.awt.datatransfer.Transferable) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) EntityLoadingException(megamek.common.loaders.EntityLoadingException) IOException(java.io.IOException) BattleArmor(megamek.common.BattleArmor)

Example 13 with CriticalSlot

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

the class DropTargetCriticalList method removeCrit.

private void removeCrit() {
    CriticalSlot crit = getCrit();
    Mounted mounted = getMounted();
    if ((mounted == null)) {
        return;
    }
    // Cannot remove a mast mount
    if (mounted.getType().hasFlag(MiscType.F_MAST_MOUNT)) {
        return;
    }
    UnitUtil.removeCriticals(getUnit(), mounted);
    if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
        changeMountStatus(mounted, Entity.LOC_NONE, false);
    }
    UnitUtil.compactCriticals(getUnit());
    // Check linkings after you remove everything.
    try {
        MechFileParser.postLoadInit(getUnit());
    } catch (EntityLoadingException ele) {
    // do nothing.
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 14 with CriticalSlot

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

the class DropTargetCriticalList method changeArmoring.

private void changeArmoring() {
    CriticalSlot cs = getCrit();
    if (cs != null) {
        if (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) {
            Mounted mount = getMounted();
            mount.setArmored(!cs.isArmored());
            UnitUtil.updateCritsArmoredStatus(getUnit(), mount);
        } else {
            cs.setArmored(!cs.isArmored());
            UnitUtil.updateCritsArmoredStatus(getUnit(), cs, getCritLocation());
        }
    }
    // Check linkings after you remove everything.
    try {
        MechFileParser.postLoadInit(getUnit());
    } catch (EntityLoadingException ele) {
    // do nothing.
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    if (refresh != null) {
        refresh.refreshAll();
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 15 with CriticalSlot

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

the class DropTargetCriticalList method getMounted.

private Mounted getMounted() {
    CriticalSlot crit = getCrit();
    Mounted mount = null;
    try {
        if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
            return crit.getMount();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return mount;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Aggregations

CriticalSlot (megamek.common.CriticalSlot)38 Mounted (megamek.common.Mounted)28 EntityLoadingException (megamek.common.loaders.EntityLoadingException)11 BattleArmor (megamek.common.BattleArmor)7 MiscType (megamek.common.MiscType)7 Vector (java.util.Vector)6 TestBattleArmor (megamek.common.verifier.TestBattleArmor)6 WeaponType (megamek.common.WeaponType)5 Font (java.awt.Font)4 ArrayList (java.util.ArrayList)4 EquipmentType (megamek.common.EquipmentType)4 LocationFullException (megamek.common.LocationFullException)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 IOException (java.io.IOException)3 AmmoType (megamek.common.AmmoType)3 Dimension (java.awt.Dimension)2 Transferable (java.awt.datatransfer.Transferable)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 InputEvent (java.awt.event.InputEvent)2