Search in sources :

Example 6 with BattleArmor

use of megamek.common.BattleArmor 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;
}
Also used : AmmoType(megamek.common.AmmoType) CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) BattleArmor(megamek.common.BattleArmor)

Example 7 with BattleArmor

use of megamek.common.BattleArmor 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 8 with BattleArmor

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

the class ImageHelper method getRecordSheet.

public static Image getRecordSheet(Entity unit, boolean advanced) {
    Image recordSheet = null;
    String path = new File(recordSheetPath).getAbsolutePath() + File.separatorChar;
    if (unit instanceof BipedMech) {
        if (advanced) {
            recordSheet = new ImageIcon(path + "tobiped.png").getImage();
        } else {
            recordSheet = new ImageIcon(path + "twbiped.png").getImage();
        }
    } else if (unit instanceof QuadMech) {
        if (advanced) {
            recordSheet = new ImageIcon(path + "toquad.png").getImage();
        } else {
            recordSheet = new ImageIcon(path + "twquad.png").getImage();
        }
    } else if (unit instanceof VTOL) {
        recordSheet = new ImageIcon(path + "twvee-vtol.png").getImage();
    } else if ((unit instanceof LargeSupportTank) || ((unit instanceof Tank) && ((Tank) unit).isSuperHeavy())) {
        if (unit.getOInternal(LargeSupportTank.LOC_TURRET) > 0) {
            recordSheet = new ImageIcon(path + "twvee-lgsupground-turret.png").getImage();
        } else {
            recordSheet = new ImageIcon(path + "twvee-lgsupground.png").getImage();
        }
    } else if (unit instanceof Tank) {
        if ((unit.getMovementMode() == EntityMovementMode.NAVAL) || (unit.getMovementMode() == EntityMovementMode.SUBMARINE) || (unit.getMovementMode() == EntityMovementMode.HYDROFOIL)) {
            if (unit.getOInternal(((Tank) unit).getLocTurret()) > 0) {
                recordSheet = new ImageIcon(path + "twnaval-turret.png").getImage();
            } else {
                recordSheet = new ImageIcon(path + "twnaval.png").getImage();
            }
        } else if (advanced) {
            String imageName = "twvee-" + unit.getMovementModeAsString().toLowerCase().trim() + "-dualturret.png";
            recordSheet = new ImageIcon(path + imageName).getImage();
        } else {
            String imageName = "twvee-" + unit.getMovementModeAsString().toLowerCase().trim() + ".png";
            recordSheet = new ImageIcon(path + imageName).getImage();
        }
    } else if (unit instanceof Aero) {
        if (unit instanceof Dropship) {
            if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
                recordSheet = new ImageIcon(path + "twaerodyneds.png").getImage();
            } else {
                recordSheet = new ImageIcon(path + "twspheroidds.png").getImage();
            }
        } else if (unit instanceof ConvFighter) {
            recordSheet = new ImageIcon(path + "twconventionalfighter.png").getImage();
        } else if (unit instanceof SmallCraft) {
            if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
                recordSheet = new ImageIcon(path + "twaero-smallcraft.png").getImage();
            } else {
                recordSheet = new ImageIcon(path + "twspheroid-smallcraft.png").getImage();
            }
        } else {
            recordSheet = new ImageIcon(path + "twaero.png").getImage();
        }
    } else if (unit instanceof BattleArmor) {
        recordSheet = new ImageIcon(path + "twba.png").getImage();
    } else if (unit instanceof Protomech) {
        recordSheet = new ImageIcon(path + "twproto.png").getImage();
    }
    return recordSheet;
}
Also used : QuadMech(megamek.common.QuadMech) ImageIcon(javax.swing.ImageIcon) LargeSupportTank(megamek.common.LargeSupportTank) Dropship(megamek.common.Dropship) ConvFighter(megamek.common.ConvFighter) Image(java.awt.Image) LargeSupportTank(megamek.common.LargeSupportTank) Tank(megamek.common.Tank) SmallCraft(megamek.common.SmallCraft) VTOL(megamek.common.VTOL) Protomech(megamek.common.Protomech) BipedMech(megamek.common.BipedMech) File(java.io.File) Aero(megamek.common.Aero) BattleArmor(megamek.common.BattleArmor)

Example 9 with BattleArmor

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

the class MainUI method createNewUnit.

@Override
public void createNewUnit(long entityType, boolean isPrimitive, boolean isIndustrial, Entity oldEntity) {
    setEntity(new BattleArmor());
    BattleArmor ba = (BattleArmor) getEntity();
    ba.setYear(3145);
    ba.setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    ba.setStructureType(EquipmentType.T_STRUCTURE_STANDARD);
    ba.setWeightClass(EntityWeightClass.WEIGHT_LIGHT);
    ba.setTroopers(4);
    ba.setChassisType(BattleArmor.CHASSIS_TYPE_BIPED);
    ba.autoSetInternal();
    for (int loc = 0; loc < ba.locations(); loc++) {
        ba.initializeArmor(0, loc);
    }
    ba.setChassis("New");
    ba.setModel("BattleArmor");
}
Also used : BattleArmor(megamek.common.BattleArmor)

Example 10 with BattleArmor

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

the class CriticalTransferHandler method importData.

/**
 */
@Override
public boolean importData(TransferSupport info) {
    if (!info.isDrop() || !((getUnit() instanceof Mech) || (getUnit() instanceof Aero) || (getUnit() instanceof BattleArmor))) {
        return false;
    }
    int trooper = 0;
    if (info.getComponent() instanceof DropTargetCriticalList) {
        DropTargetCriticalList<?> list = (DropTargetCriticalList<?>) info.getComponent();
        if (getUnit() instanceof BattleArmor) {
            String[] split = list.getName().split(":");
            if (split.length != 2) {
                return false;
            }
            location = Integer.parseInt(split[0]);
            trooper = Integer.parseInt(split[1]);
        } else {
            location = Integer.parseInt(list.getName());
        }
        Transferable t = info.getTransferable();
        int slotNumber = list.getDropLocation().getIndex();
        try {
            Mounted eq = getUnit().getEquipment(Integer.parseInt((String) t.getTransferData(DataFlavor.stringFlavor)));
            if (getUnit() instanceof BattleArmor) {
                if ((location == eq.getBaMountLoc()) && (trooper == eq.getLocation())) {
                    return false;
                }
            } else {
                // the criticals its mounted in
                if (eq.getLocation() != Entity.LOC_NONE || eq.getSecondLocation() != Entity.LOC_NONE) {
                    UnitUtil.removeCriticals(getUnit(), eq);
                    changeMountStatus(eq, Entity.LOC_NONE, false);
                } else {
                    eq.setOmniPodMounted(UnitUtil.canPodMount(getUnit(), eq));
                }
            }
            if (!UnitUtil.isValidLocation(getUnit(), eq.getType(), location)) {
                JOptionPane.showMessageDialog(null, eq.getName() + " can't be placed in " + getUnit().getLocationName(location) + "!", "Invalid Location", JOptionPane.INFORMATION_MESSAGE);
                return false;
            }
            if (getUnit() instanceof Aero) {
                return addEquipmentAero((Aero) getUnit(), eq);
            } else if (getUnit() instanceof Mech) {
                // superheavies can put 2 ammobins or heatsinks in one crit
                if ((getUnit() instanceof Mech) && ((Mech) getUnit()).isSuperHeavy()) {
                    CriticalSlot cs = getUnit().getCritical(location, slotNumber);
                    if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT) && (cs.getMount2() == null)) {
                        EquipmentType etype = cs.getMount().getType();
                        EquipmentType etype2 = eq.getType();
                        boolean canDouble = false;
                        if ((etype instanceof AmmoType) && (etype2 instanceof AmmoType)) {
                            canDouble = (((AmmoType) etype).getAmmoType() == ((AmmoType) etype2).getAmmoType()) && (((AmmoType) etype).getRackSize() == ((AmmoType) etype2).getRackSize());
                        } else if (etype.equals(etype2) && UnitUtil.isHeatSink(etype)) {
                            canDouble = etype.getCriticals(getUnit()) == 1;
                        }
                        if (canDouble) {
                            cs.setMount2(eq);
                            changeMountStatus(eq, location, false);
                            return true;
                        }
                    }
                }
                return addEquipmentMech((Mech) getUnit(), eq, slotNumber);
            } else if (getUnit() instanceof BattleArmor) {
                return addEquipmentBA((BattleArmor) getUnit(), eq, trooper);
            }
        } catch (LocationFullException lfe) {
            JOptionPane.showMessageDialog(null, lfe.getMessage(), "Location Full", JOptionPane.INFORMATION_MESSAGE);
            return false;
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return true;
    }
    return false;
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Transferable(java.awt.datatransfer.Transferable) EquipmentType(megamek.common.EquipmentType) EntityLoadingException(megamek.common.loaders.EntityLoadingException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) LocationFullException(megamek.common.LocationFullException) IOException(java.io.IOException) AmmoType(megamek.common.AmmoType) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted) Mech(megamek.common.Mech) LandAirMech(megamek.common.LandAirMech) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Aggregations

BattleArmor (megamek.common.BattleArmor)18 Mounted (megamek.common.Mounted)9 Aero (megamek.common.Aero)8 CriticalSlot (megamek.common.CriticalSlot)8 TestBattleArmor (megamek.common.verifier.TestBattleArmor)8 Mech (megamek.common.Mech)7 Tank (megamek.common.Tank)7 AmmoType (megamek.common.AmmoType)6 Entity (megamek.common.Entity)6 WeaponType (megamek.common.WeaponType)6 Infantry (megamek.common.Infantry)5 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 EquipmentType (megamek.common.EquipmentType)4 MiscType (megamek.common.MiscType)4 SmallCraft (megamek.common.SmallCraft)4 EntityLoadingException (megamek.common.loaders.EntityLoadingException)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 File (java.io.File)3 Vector (java.util.Vector)3