Search in sources :

Example 21 with Mounted

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;
}
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 22 with Mounted

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)));
}
Also used : Mounted(megamek.common.Mounted) JTable(javax.swing.JTable) StringSelection(java.awt.datatransfer.StringSelection)

Example 23 with Mounted

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;
}
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 24 with Mounted

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);
}
Also used : Mounted(megamek.common.Mounted)

Example 25 with Mounted

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();
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Aggregations

Mounted (megamek.common.Mounted)131 MiscType (megamek.common.MiscType)38 LocationFullException (megamek.common.LocationFullException)34 AmmoType (megamek.common.AmmoType)32 CriticalSlot (megamek.common.CriticalSlot)31 EquipmentType (megamek.common.EquipmentType)27 ArrayList (java.util.ArrayList)25 WeaponType (megamek.common.WeaponType)25 Vector (java.util.Vector)21 EntityLoadingException (megamek.common.loaders.EntityLoadingException)17 Font (java.awt.Font)14 BattleArmor (megamek.common.BattleArmor)11 JMenuItem (javax.swing.JMenuItem)9 JPopupMenu (javax.swing.JPopupMenu)9 Entity (megamek.common.Entity)9 TestBattleArmor (megamek.common.verifier.TestBattleArmor)9 Dimension (java.awt.Dimension)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)7 List (java.util.List)6