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;
}
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;
}
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();
}
}
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();
}
}
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;
}
Aggregations