Search in sources :

Example 26 with Mounted

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

the class DropTargetCriticalList method removeMount.

private void removeMount() {
    Mounted mounted = getMounted();
    if (mounted == null) {
        return;
    }
    UnitUtil.removeMounted(getUnit(), mounted);
    UnitUtil.compactCriticals(getUnit());
    // 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();
    }
}
Also used : Mounted(megamek.common.Mounted) EntityLoadingException(megamek.common.loaders.EntityLoadingException) EntityLoadingException(megamek.common.loaders.EntityLoadingException)

Example 27 with Mounted

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

Example 28 with Mounted

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

Example 29 with Mounted

use of megamek.common.Mounted 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 30 with Mounted

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

the class ImageHelper method printMechWeaponsNEquipment.

public static void printMechWeaponsNEquipment(Mech mech, Graphics2D g2d, int leftMargin, int topMargin) {
    int qtyPoint = 26 + leftMargin;
    int typePoint = 38 + leftMargin;
    int locPoint = 105 + leftMargin;
    int heatPoint = 118 + leftMargin;
    int damagePoint = 145 + leftMargin;
    int minPoint = 167 + leftMargin;
    int shtPoint = 183 + leftMargin;
    int medPoint = 199 + leftMargin;
    int longPoint = 215 + leftMargin;
    float linePoint = 202f + topMargin;
    float lineFeed = 6.7f;
    boolean newLineNeeded = false;
    ArrayList<Hashtable<String, EquipmentInfo>> equipmentLocations = new ArrayList<Hashtable<String, EquipmentInfo>>(Mech.LOC_LLEG + 1);
    for (int pos = 0; pos <= Mech.LOC_LLEG; pos++) {
        equipmentLocations.add(pos, new Hashtable<String, EquipmentInfo>());
    }
    for (Mounted eq : mech.getEquipment()) {
        if ((eq.getType() instanceof AmmoType) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType(), true)) {
            continue;
        }
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(eq.getLocation());
        String equipmentName = eq.getName();
        if (eq.isRearMounted()) {
            equipmentName += " (R)";
        }
        if (eq.isMechTurretMounted()) {
            equipmentName += " (T)";
        }
        if (eqHash.containsKey(equipmentName)) {
            EquipmentInfo eqi = eqHash.get(equipmentName);
            if (eq.getType().getTechLevel(mech.getTechLevelYear()) != eqi.techLevel) {
                eqi = new EquipmentInfo(mech, eq);
            } else {
                eqi.count++;
            }
            eqHash.put(equipmentName, eqi);
        } else {
            EquipmentInfo eqi = new EquipmentInfo(mech, eq);
            eqHash.put(equipmentName, eqi);
        }
    }
    Font font = UnitUtil.deriveFont(true, 10.0f);
    g2d.setFont(font);
    HashMap<TextAttribute, Object> strikeThroughAttr = new HashMap<TextAttribute, Object>();
    strikeThroughAttr.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
    for (int pos = Mech.LOC_HEAD; pos <= Mech.LOC_LLEG; pos++) {
        Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(pos);
        if (eqHash.size() < 1) {
            continue;
        }
        int count = 0;
        ArrayList<EquipmentInfo> equipmentList = new ArrayList<EquipmentInfo>();
        for (EquipmentInfo eqi : eqHash.values()) {
            equipmentList.add(eqi);
        }
        Collections.sort(equipmentList, StringUtils.equipmentInfoComparator());
        for (EquipmentInfo eqi : equipmentList) {
            newLineNeeded = false;
            if (count >= 12) {
                break;
            }
            font = UnitUtil.deriveFont(7.0f);
            g2d.setFont(font);
            g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
            String name = eqi.name.trim();
            Font nameFont = UnitUtil.getNewFont(g2d, name, false, 60, 7.0f);
            if (eqi.isDestroyed) {
                nameFont = nameFont.deriveFont(strikeThroughAttr);
            }
            g2d.setFont(nameFont);
            if (eqi.c3Level == EquipmentInfo.C3I) {
                ImageHelper.printC3iName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3EM) {
                ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3S) {
                ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3M) {
                ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3SB) {
                ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3MB) {
                ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
                ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, mech.isMixedTech() && TechConstants.isClan(mech.getTechLevel()));
            } else {
                g2d.drawString(name, typePoint, linePoint);
            }
            Font locFont = UnitUtil.getNewFont(g2d, eqi.loc, false, 15, 7.0f);
            g2d.setFont(locFont);
            ImageHelper.printCenterString(g2d, eqi.loc, font, locPoint, linePoint);
            g2d.setFont(UnitUtil.deriveFont(7));
            if (eqi.isWeapon) {
                g2d.drawString(Integer.toString(eqi.heat), heatPoint, linePoint);
                if (eqi.isMML) {
                    ImageHelper.printCenterString(g2d, "[M,C,S]", font, damagePoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("LRM", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
                    g2d.drawString("6", minPoint, linePoint);
                    g2d.drawString("7", shtPoint, linePoint);
                    g2d.drawString("14", medPoint, linePoint);
                    g2d.drawString("21", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("SRM", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                    // + 6, (int) linePoint - 2);
                    g2d.drawString("3", shtPoint, linePoint);
                    g2d.drawString("6", medPoint, linePoint);
                    g2d.drawString("9", longPoint, linePoint);
                } else if (eqi.isATM) {
                    ImageHelper.printCenterString(g2d, "[M,C,S]", font, damagePoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("Standard", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "2/Msl", font, damagePoint, linePoint);
                    g2d.drawString("4", minPoint, linePoint);
                    g2d.drawString("5", shtPoint, linePoint);
                    g2d.drawString("10", medPoint, linePoint);
                    g2d.drawString("15", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("Extended-Range", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "1/Msl", font, damagePoint, linePoint);
                    g2d.drawString("4", minPoint, linePoint);
                    g2d.drawString("9", shtPoint, linePoint);
                    g2d.drawString("18", medPoint, linePoint);
                    g2d.drawString("27", longPoint, linePoint);
                    linePoint += lineFeed - 1.0f;
                    g2d.drawString("High-Explosive", typePoint, linePoint);
                    ImageHelper.printCenterString(g2d, "3/Msl", font, damagePoint, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                    // + 6, (int) linePoint - 2);
                    g2d.drawString("3", shtPoint, linePoint);
                    g2d.drawString("6", medPoint, linePoint);
                    g2d.drawString("9", longPoint, linePoint);
                } else if (eqi.isAMS) {
                    ImageHelper.printCenterString(g2d, "\u2014 [PD]", font, damagePoint, linePoint);
                    // g2d.drawLine(damagePoint - 9, (int) linePoint - 2,
                    // damagePoint - 3, (int) linePoint - 2);
                    // ImageHelper.printCenterString(g2d, "[PD]", font,
                    // damagePoint+4, linePoint);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    g2d.drawString("\u2014", shtPoint, linePoint);
                    g2d.drawString("\u2014", medPoint, linePoint);
                    g2d.drawString("\u2014", longPoint, linePoint);
                // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                // + 6, (int) linePoint - 2);
                // g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint
                // + 6, (int) linePoint - 2);
                // g2d.drawLine(medPoint, (int) linePoint - 2, medPoint
                // + 6, (int) linePoint - 2);
                // g2d.drawLine(longPoint, (int) linePoint - 2,
                // longPoint + 6, (int) linePoint - 2);
                } else if (eqi.isCenturion) {
                    ImageHelper.printCenterString(g2d, "0", font, damagePoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2, minPoint
                    // + 6, (int) linePoint - 2);
                    g2d.drawString("\u2014", minPoint, linePoint);
                    g2d.drawString("6(1)", shtPoint - 1, linePoint);
                    g2d.drawString("12(2)", medPoint - 6, linePoint);
                    g2d.drawString("18(3)", longPoint - 4, linePoint);
                } else {
                    if (ImageHelper.getStringWidth(g2d, eqi.damage.trim(), font) > 22) {
                        font = UnitUtil.deriveFont(6.0f);
                        g2d.setFont(font);
                        ImageHelper.printCenterString(g2d, eqi.damage.substring(0, eqi.damage.indexOf('[')), font, damagePoint, linePoint);
                        font = UnitUtil.deriveFont(7.0f);
                        g2d.setFont(font);
                        ImageHelper.printCenterString(g2d, eqi.damage.substring(eqi.damage.indexOf('[')), font, damagePoint, (linePoint + lineFeed) - 1.0f);
                        newLineNeeded = true;
                    } else {
                        ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint, linePoint);
                    }
                    if (eqi.minRange > 0) {
                        g2d.drawString(Integer.toString(eqi.minRange), minPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", minPoint, linePoint);
                    // g2d.drawLine(minPoint, (int) linePoint - 2,
                    // minPoint + 6, (int) linePoint - 2);
                    }
                    if (eqi.shtRange > 0) {
                        g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", shtPoint, linePoint);
                    // g2d.drawLine(shtPoint, (int) linePoint - 2,
                    // shtPoint + 6, (int) linePoint - 2);
                    }
                    if (eqi.medRange > 0) {
                        g2d.drawString(Integer.toString(eqi.medRange), medPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", medPoint, linePoint);
                    // g2d.drawLine(medPoint, (int) linePoint - 2,
                    // medPoint + 6, (int) linePoint - 2);
                    }
                    if (eqi.longRange > 0) {
                        g2d.drawString(Integer.toString(eqi.longRange), longPoint, linePoint);
                    } else {
                        g2d.drawString("\u2014", longPoint, linePoint);
                    // g2d.drawLine(longPoint, (int) linePoint - 2,
                    // longPoint + 6, (int) linePoint - 2);
                    }
                }
            } else {
                if (eqi.heat > 0) {
                    g2d.drawString(Integer.toString(eqi.heat), heatPoint, linePoint);
                } else {
                    g2d.drawString("\u2014", heatPoint, linePoint);
                // g2d.drawLine(heatPoint, (int) linePoint - 2,
                // heatPoint + 6, (int) linePoint - 2);
                }
                ImageHelper.printCenterString(g2d, eqi.damage, font, damagePoint - 2, linePoint);
                g2d.drawString("\u2014", minPoint, linePoint);
                g2d.drawString("\u2014", shtPoint, linePoint);
                g2d.drawString("\u2014", medPoint, linePoint);
                // (int) linePoint - 2);
                if (eqi.longRange > 0) {
                    g2d.drawString(Integer.toString(eqi.longRange), longPoint, linePoint);
                } else {
                    g2d.drawString("\u2014", longPoint, linePoint);
                // g2d.drawLine(longPoint, (int) linePoint - 2,
                // longPoint + 6, (int) linePoint - 2);
                }
            }
            if (eqi.hasArtemis) {
                g2d.drawString("w/Artemis IV FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasArtemisV) {
                g2d.drawString("w/Artemis V FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            } else if (eqi.hasApollo) {
                g2d.drawString("w/Apollo FCS", typePoint, linePoint + lineFeed);
                newLineNeeded = true;
            }
            linePoint += lineFeed;
            if (newLineNeeded) {
                linePoint += lineFeed;
            }
            count++;
        }
    }
    if (mech instanceof LandAirMech) {
        ImageHelper.printLAMFuel((LandAirMech) mech, g2d, qtyPoint);
    }
}
Also used : HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) TextAttribute(java.awt.font.TextAttribute) ArrayList(java.util.ArrayList) Font(java.awt.Font) AmmoType(megamek.common.AmmoType) Mounted(megamek.common.Mounted) LandAirMech(megamek.common.LandAirMech)

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