Search in sources :

Example 16 with CriticalSlot

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

the class DropTargetCriticalList method getCrit.

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

Example 17 with CriticalSlot

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

the class DropTargetCriticalList method mousePressed.

public void mousePressed(MouseEvent e) {
    if (buildView) {
        if (e.getButton() == MouseEvent.BUTTON2) {
            setSelectedIndex(locationToIndex(e.getPoint()));
            removeCrit();
        } else if (e.getButton() == MouseEvent.BUTTON3) {
            setSelectedIndex(locationToIndex(e.getPoint()));
            if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
                removeCrit();
                return;
            }
            int location = getCritLocation();
            JPopupMenu popup = new JPopupMenu();
            CriticalSlot cs = getCrit();
            Mounted mount = getMounted();
            if ((e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
                changeWeaponFacing(!mount.isRearMounted());
                return;
            }
            if ((e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
                changeOmniMounting(!mount.isOmniPodMounted());
                return;
            }
            if (mount != null) {
                popup.setAutoscrolls(true);
                JMenuItem info;
                if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType())) {
                    info = new JMenuItem("Remove " + mount.getName());
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            removeCrit();
                        }
                    });
                    popup.add(info);
                }
                info = new JMenuItem("Delete " + mount.getName());
                info.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        removeMount();
                    }
                });
                popup.add(info);
                if ((mount.getType() instanceof WeaponType) && getUnit().hasWorkingMisc(MiscType.F_SPONSON_TURRET) && ((mount.getLocation() == Tank.LOC_LEFT) || (mount.getLocation() == Tank.LOC_RIGHT))) {
                    if (!mount.isSponsonTurretMounted()) {
                        info = new JMenuItem("Mount " + mount.getName() + " in Sponson Turret");
                        info.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                changeSponsonTurretMount(true);
                            }
                        });
                        popup.add(info);
                    } else {
                        info = new JMenuItem("Remove " + mount.getName() + " from Sponson Turret");
                        info.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                changeSponsonTurretMount(false);
                            }
                        });
                        popup.add(info);
                    }
                }
                if ((mount.getType() instanceof WeaponType) && getUnit().hasWorkingMisc(MiscType.F_PINTLE_TURRET, mount.getLocation())) {
                    if (!mount.isPintleTurretMounted()) {
                        info = new JMenuItem("Mount " + mount.getName() + " in Pintle Turret");
                        info.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                changePintleTurretMount(true);
                            }
                        });
                        popup.add(info);
                    } else {
                        info = new JMenuItem("Remove " + mount.getName() + " from Pintle Turret");
                        info.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                changePintleTurretMount(false);
                            }
                        });
                        popup.add(info);
                    }
                }
                if (getUnit().isOmni() && !mount.getType().isOmniFixedOnly()) {
                    if (mount.isOmniPodMounted()) {
                        info = new JMenuItem("Change to fixed mount");
                        info.addActionListener(ev -> changeOmniMounting(false));
                        popup.add(info);
                    } else if (UnitUtil.canPodMount(getUnit(), mount)) {
                        info = new JMenuItem("Change to pod mount");
                        info.addActionListener(ev -> changeOmniMounting(true));
                        popup.add(info);
                    }
                }
            }
            if (UnitUtil.isArmorable(cs) && ((UnitUtil.getUnitTechType(getUnit()) == UnitUtil.TECH_EXPERIMENTAL) || (UnitUtil.getUnitTechType(getUnit()) == UnitUtil.TECH_UNOFFICAL))) {
                popup.addSeparator();
                if (cs.isArmored()) {
                    JMenuItem info = new JMenuItem("Remove Armoring");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            changeArmoring();
                        }
                    });
                    popup.add(info);
                } else {
                    JMenuItem info = new JMenuItem("Add Armoring");
                    info.setActionCommand(Integer.toString(location));
                    info.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            changeArmoring();
                        }
                    });
                    popup.add(info);
                }
            }
            if (popup.getComponentCount() > 0) {
                popup.show(this, e.getX(), e.getY());
            }
        }
    }
}
Also used : InputEvent(java.awt.event.InputEvent) MechFileParser(megamek.common.MechFileParser) ActionListener(java.awt.event.ActionListener) CriticalSlot(megamek.common.CriticalSlot) DropTargetDragEvent(java.awt.dnd.DropTargetDragEvent) JPopupMenu(javax.swing.JPopupMenu) JList(javax.swing.JList) EntityLoadingException(megamek.common.loaders.EntityLoadingException) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) EntitySource(megameklab.com.ui.EntitySource) Vector(java.util.Vector) WeaponType(megamek.common.WeaponType) JMenuItem(javax.swing.JMenuItem) DropTargetEvent(java.awt.dnd.DropTargetEvent) MiscType(megamek.common.MiscType) Tank(megamek.common.Tank) Mounted(megamek.common.Mounted) Entity(megamek.common.Entity) MouseListener(java.awt.event.MouseListener) ActionListener(java.awt.event.ActionListener) CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) ActionEvent(java.awt.event.ActionEvent) WeaponType(megamek.common.WeaponType) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 18 with CriticalSlot

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

the class UnitUtil method removeCriticals.

/**
 * Sets the corresponding critical slots to null for the Mounted object.
 *
 * @param unit
 * @param eq
 */
public static void removeCriticals(Entity unit, Mounted eq) {
    if (eq.getLocation() == Entity.LOC_NONE) {
        return;
    }
    for (int loc = 0; loc < unit.locations(); loc++) {
        for (int slot = 0; slot < unit.getNumberOfCriticals(loc); slot++) {
            CriticalSlot cs = unit.getCritical(loc, slot);
            if ((cs != null) && (cs.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
                if (cs.getMount().equals(eq)) {
                    // remove first one, and replace it with the second
                    if (cs.getMount2() != null) {
                        cs.setMount(cs.getMount2());
                        cs.setMount2(null);
                    } else {
                        // If it's the only Mounted, clear the slot
                        cs = null;
                        unit.setCritical(loc, slot, cs);
                    }
                } else if ((cs.getMount2() != null) && cs.getMount2().equals(eq)) {
                    cs.setMount2(null);
                }
            }
        }
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot)

Example 19 with CriticalSlot

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

the class UnitUtil method removeISorArmorCrits.

/**
 * remove all CriticalSlots on the passed unit that are internal structure or
 * armor
 *
 * @param unit
 *            the Entity
 * @param internalStructure
 *            true to remove IS, false to remove armor
 */
public static void removeISorArmorCrits(Entity unit, boolean internalStructure) {
    ArrayList<String> mountList = new ArrayList<String>();
    if (internalStructure) {
        for (String struc : EquipmentType.structureNames) {
            mountList.add("IS " + struc);
            mountList.add("Clan " + struc);
        }
    } else {
        for (String armor : EquipmentType.armorNames) {
            mountList.add("IS " + armor);
            mountList.add("Clan " + armor);
        }
    }
    for (int location = Mech.LOC_HEAD; location < unit.locations(); location++) {
        for (int slot = 0; slot < unit.getNumberOfCriticals(location); slot++) {
            CriticalSlot crit = unit.getCritical(location, slot);
            if ((crit != null) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT)) {
                Mounted mount = crit.getMount();
                if ((mount != null) && (mount.getType() instanceof MiscType) && mountList.contains(mount.getType().getInternalName())) {
                    crit = null;
                    unit.setCritical(location, slot, crit);
                }
            }
        }
    }
}
Also used : CriticalSlot(megamek.common.CriticalSlot) Mounted(megamek.common.Mounted) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList)

Example 20 with CriticalSlot

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

the class UnitUtil method resetArmor.

/**
 * Remove all mounts for the current armor type from a single location on the passed unit
 * and sets the armor type in that location to standard.
 *
 * @param unit The <code>Entity</code>
 * @param loc  The location from which to remove the armor mounts.
 */
public static void resetArmor(Entity unit, int loc) {
    String name = EquipmentType.getArmorTypeName(unit.getArmorType(loc), TechConstants.isClan(unit.getArmorTechLevel(loc)));
    EquipmentType eq = EquipmentType.get(name);
    if (null != eq) {
        for (int slot = 0; slot < unit.getNumberOfCriticals(loc); slot++) {
            final CriticalSlot crit = unit.getCritical(loc, slot);
            if ((null != crit) && (crit.getType() == CriticalSlot.TYPE_EQUIPMENT) && (null != crit.getMount()) && crit.getMount().getType().equals(eq)) {
                unit.getMisc().remove(crit.getMount());
                unit.setCritical(loc, slot, null);
            }
        }
    }
    unit.setArmorType(EquipmentType.T_ARMOR_STANDARD, loc);
    unit.setArmorTechLevel(TechConstants.T_INTRO_BOXSET, loc);
}
Also used : CriticalSlot(megamek.common.CriticalSlot) EquipmentType(megamek.common.EquipmentType)

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