use of megamek.common.Mounted in project megameklab by MegaMek.
the class CritListCellRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean hasFocus) {
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, hasFocus);
this.list = list;
setPreferredSize(new Dimension(110, 15));
setMaximumSize(new Dimension(110, 15));
setMinimumSize(new Dimension(110, 15));
String[] split = ((String) value).split(":");
label.setText(split[0]);
CriticalSlot cs;
if (split.length > 2) {
int eqId = Integer.parseInt(split[2]);
cs = new CriticalSlot(unit.getEquipment(eqId));
} else if (split.length > 1) {
cs = getCrit(Integer.parseInt(split[1]));
} else if (((String) value).equals("-Empty-")) {
cs = null;
} else {
cs = getCrit(index);
}
if (cs != null) {
if (cs.getType() == CriticalSlot.TYPE_SYSTEM) {
if (useColor) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_SYSTEMS));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_SYSTEMS));
}
if (cs.isArmored()) {
label.setText(label.getText() + " (A)");
}
} else if (cs.getMount() != null) {
Mounted mount = cs.getMount();
if (useColor) {
if (mount.getType() instanceof WeaponType) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_WEAPONS));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_WEAPONS));
} else if (mount.getType() instanceof AmmoType) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_AMMO));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_AMMO));
} else {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_EQUIPMENT));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_EQUIPMENT));
}
}
String name = UnitUtil.getCritName(unit, mount.getType());
if (mount.isRearMounted()) {
name += " (R)";
}
if (mount.isArmored()) {
name += " (A)";
}
if (mount.isMechTurretMounted()) {
name += " (T)";
}
if (mount.isSponsonTurretMounted()) {
name += " (ST)";
}
if (mount.isPintleTurretMounted()) {
name += " (PT)";
}
if (mount.isDWPMounted()) {
name += " (DWP)";
}
if (unit.isOmni() && !mount.getType().isOmniFixedOnly()) {
if (mount.isOmniPodMounted()) {
name += " (Pod)";
} else {
name += " (Fixed)";
label.setFont(label.getFont().deriveFont(Font.ITALIC));
}
}
if ((mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) || mount.getType().hasFlag(MiscType.F_AP_MOUNT)) && mount.getLinked() != null) {
name += " (attached " + mount.getLinked().getName() + ")";
}
// many shots are in this Critical
if ((unit instanceof BattleArmor) && (mount.getType() instanceof AmmoType)) {
name += " (" + mount.getBaseShotsLeft() + ")";
}
String toolTipText = UnitUtil.getToolTipInfo(unit, mount);
if (cs.getMount2() != null) {
mount = cs.getMount2();
name += " | " + UnitUtil.getCritName(unit, mount.getType());
}
label.setText(name);
label.setToolTipText(toolTipText);
}
} else if (useColor) {
label.setBackground(CConfig.getBackgroundColor(CConfig.CONFIG_EMPTY));
label.setForeground(CConfig.getForegroundColor(CConfig.CONFIG_EMPTY));
}
int loc = getCritLocation();
if ((cs != null) && UnitUtil.isLastCrit(unit, cs, index, loc) && UnitUtil.isPreviousCritEmpty(unit, cs, index, loc)) {
label.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, Color.black));
} else if ((cs != null) && UnitUtil.isLastCrit(unit, cs, index, loc)) {
label.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.black));
} else if ((cs != null) && UnitUtil.isPreviousCritEmpty(unit, cs, index, loc)) {
label.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.black));
}
return label;
}
use of megamek.common.Mounted in project megameklab by MegaMek.
the class CriticalTransferHandler method createTransferable.
@Override
protected Transferable createTransferable(JComponent c) {
JTable table = (JTable) c;
Mounted mount = (Mounted) ((CriticalTableModel) table.getModel()).getValueAt(table.getSelectedRow(), CriticalTableModel.EQUIPMENT);
return new StringSelection(Integer.toString(getUnit().getEquipmentNum(mount)));
}
use of megamek.common.Mounted 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.Mounted in project megameklab by MegaMek.
the class DropTargetCriticalList method changeWeaponFacing.
private void changeWeaponFacing(boolean rear) {
Mounted mount = getMounted();
int location = getCritLocation();
changeMountStatus(mount, location, rear);
}
use of megamek.common.Mounted 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();
}
}
Aggregations