Search in sources :

Example 1 with LandAirMech

use of megamek.common.LandAirMech 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)

Example 2 with LandAirMech

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

the class MainUI method createNewUnit.

@Override
public void createNewUnit(long entityType, boolean isPrimitive, boolean isIndustrial, Entity oldEntity) {
    int cockpit = Mech.COCKPIT_STANDARD;
    int at = EquipmentType.T_ARMOR_STANDARD;
    int st = EquipmentType.T_STRUCTURE_STANDARD;
    if (isPrimitive && isIndustrial) {
        cockpit = Mech.COCKPIT_PRIMITIVE_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    } else if (isPrimitive) {
        cockpit = Mech.COCKPIT_PRIMITIVE;
        at = EquipmentType.T_ARMOR_PRIMITIVE;
    } else if (isIndustrial) {
        cockpit = Mech.COCKPIT_INDUSTRIAL;
        at = EquipmentType.T_ARMOR_INDUSTRIAL;
        st = EquipmentType.T_STRUCTURE_INDUSTRIAL;
    }
    if (entityType == Entity.ETYPE_TRIPOD_MECH) {
        setEntity(new TripodMech(Mech.GYRO_STANDARD, Mech.COCKPIT_TRIPOD));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_QUAD_MECH) {
        setEntity(new QuadMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    } else if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        setEntity(new LandAirMech(Mech.GYRO_STANDARD, Mech.COCKPIT_STANDARD, LandAirMech.LAM_STANDARD));
        getEntity().setTechLevel(TechConstants.T_IS_ADVANCED);
        getEntity().setManualBV(-1);
    } else if (entityType == Entity.ETYPE_QUADVEE) {
        setEntity(new QuadVee(Mech.GYRO_STANDARD, QuadVee.MOTIVE_TRACK));
        getEntity().setTechLevel(TechConstants.T_CLAN_ADVANCED);
        UnitUtil.createSpreadMounts((Mech) getEntity(), EquipmentType.get("Tracks"));
        getEntity().setManualBV(-1);
    } else {
        // type == 0
        setEntity(new BipedMech(Mech.GYRO_STANDARD, cockpit));
        getEntity().setTechLevel(TechConstants.T_IS_TW_NON_BOX);
    }
    Mech mech = (Mech) getEntity();
    getEntity().setWeight(25);
    if (entityType == Entity.ETYPE_LAND_AIR_MECH) {
        mech.setEngine(new Engine(75, Engine.NORMAL_ENGINE, 0));
        UnitUtil.updateJumpJets(((Mech) getEntity()), 3, Mech.JUMP_STANDARD);
    } else {
        mech.setEngine(new Engine(25, Engine.NORMAL_ENGINE, 0));
    }
    getEntity().setArmorType(at);
    getEntity().setArmorTechLevel(getEntity().getTechLevel());
    getEntity().setStructureType(st);
    mech.addGyro();
    mech.addEngineCrits();
    if (isPrimitive) {
        mech.addPrimitiveCockpit();
    } else if (isIndustrial) {
        mech.addIndustrialCockpit();
    } else if (Entity.ETYPE_QUADVEE == entityType) {
        mech.addQuadVeeCockpit();
    } else {
        mech.addCockpit();
    }
    UnitUtil.updateHeatSinks(mech, 10, "Single");
    getEntity().autoSetInternal();
    for (int loc = 0; loc < getEntity().locations(); loc++) {
        mech.initializeArmor(0, loc);
        mech.initializeRearArmor(0, loc);
    }
    if (null == oldEntity) {
        mech.setChassis("New");
        mech.setModel("Mek");
        mech.setYear(3145);
    } else {
        mech.setChassis(oldEntity.getChassis());
        mech.setModel(oldEntity.getModel());
        mech.setYear(Math.max(oldEntity.getYear(), mech.getConstructionTechAdvancement().getIntroductionDate()));
        mech.setSource(oldEntity.getSource());
        mech.setManualBV(oldEntity.getManualBV());
        SimpleTechLevel lvl = SimpleTechLevel.max(mech.getStaticTechLevel(), SimpleTechLevel.convertCompoundToSimple(oldEntity.getTechLevel()));
        mech.setTechLevel(lvl.getCompoundTechLevel(oldEntity.isClan()));
        mech.setMixedTech(oldEntity.isMixedTech());
    }
}
Also used : TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) SimpleTechLevel(megamek.common.SimpleTechLevel) BipedMech(megamek.common.BipedMech) Mech(megamek.common.Mech) LandAirMech(megamek.common.LandAirMech) TripodMech(megamek.common.TripodMech) QuadMech(megamek.common.QuadMech) QuadVee(megamek.common.QuadVee) BipedMech(megamek.common.BipedMech) Engine(megamek.common.Engine) LandAirMech(megamek.common.LandAirMech)

Example 3 with LandAirMech

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

the class BuildView method mousePressed.

public void mousePressed(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem item;
        final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
        Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
        final int totalCrits = UnitUtil.getCritsUsed(getMech(), eq.getType());
        String[] locations = getMech().getLocationNames();
        String[] abbrLocations = getMech().getLocationAbbrs();
        if ((eq.getType().isSpreadable() || eq.isSplitable()) && (totalCrits > 1) && !((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_TARGCOMP)) && !(getMech() instanceof LandAirMech)) {
            int[] critSpace = UnitUtil.getHighestContinuousNumberOfCritsArray(getMech());
            if ((critSpace[Mech.LOC_RT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RT)) {
                JMenu rtMenu = new JMenu(locations[Mech.LOC_RT]);
                if (critSpace[Mech.LOC_RT] >= totalCrits) {
                    item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RT]));
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(Mech.LOC_RT, selectedRow);
                        }
                    });
                    rtMenu.add(item);
                }
                int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_RARM, Mech.LOC_RLEG };
                for (int location = 0; location < 3; location++) {
                    JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_RT], abbrLocations[splitLocations[location]]));
                    int subCrits = critSpace[splitLocations[location]];
                    for (int slots = 1; slots <= subCrits; slots++) {
                        final int primarySlots = totalCrits - slots;
                        item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_RT], primarySlots, abbrLocations[splitLocations[location]], slots));
                        final int secondaryLocation = splitLocations[location];
                        item.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RT, secondaryLocation, primarySlots, selectedRow);
                            }
                        });
                        subMenu.add(item);
                    }
                    rtMenu.add(subMenu);
                }
                popup.add(rtMenu);
            }
            if ((critSpace[Mech.LOC_RARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RARM)) {
                item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RARM]));
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RARM, Mech.LOC_RARM, totalCrits, selectedRow);
                    }
                });
                popup.add(item);
            }
            if ((critSpace[Mech.LOC_LT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LT)) {
                JMenu ltMenu = new JMenu(locations[Mech.LOC_LT]);
                if (critSpace[Mech.LOC_LT] >= totalCrits) {
                    item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LT]));
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(Mech.LOC_LT, selectedRow);
                        }
                    });
                    ltMenu.add(item);
                }
                int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_LARM, Mech.LOC_LLEG };
                for (int location = 0; location < 3; location++) {
                    JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_LT], abbrLocations[splitLocations[location]]));
                    int subCrits = critSpace[splitLocations[location]];
                    for (int slots = 1; slots <= subCrits; slots++) {
                        final int primarySlots = totalCrits - slots;
                        item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_LT], primarySlots, abbrLocations[splitLocations[location]], slots));
                        final int secondaryLocation = splitLocations[location];
                        item.addActionListener(new ActionListener() {

                            public void actionPerformed(ActionEvent e) {
                                jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LT, secondaryLocation, primarySlots, selectedRow);
                            }
                        });
                        subMenu.add(item);
                    }
                    ltMenu.add(subMenu);
                }
                popup.add(ltMenu);
            }
            if ((critSpace[Mech.LOC_LARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LARM)) {
                item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LARM]));
                item.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LARM, Mech.LOC_LARM, totalCrits, selectedRow);
                    }
                });
                popup.add(item);
            }
        } else {
            for (int location = 0; location < getMech().locations(); location++) {
                if ((UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location) >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), location)) {
                    item = new JMenuItem("Add to " + locations[location]);
                    final int loc = location;
                    item.addActionListener(new ActionListener() {

                        public void actionPerformed(ActionEvent e) {
                            jMenuLoadComponent_actionPerformed(loc, selectedRow);
                        }
                    });
                    popup.add(item);
                }
            }
        }
        popup.show(this, e.getX(), e.getY());
    }
}
Also used : ActionListener(java.awt.event.ActionListener) Mounted(megamek.common.Mounted) ActionEvent(java.awt.event.ActionEvent) MiscType(megamek.common.MiscType) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JMenu(javax.swing.JMenu) LandAirMech(megamek.common.LandAirMech)

Example 4 with LandAirMech

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

the class PrintMech method writeTextFields.

@Override
protected void writeTextFields() {
    super.writeTextFields();
    if (mech.hasUMU()) {
        Element svgEle = getSVGDocument().getElementById("mpJumpLabel");
        if (null != svgEle) {
            svgEle.setTextContent("Underwater:");
        }
    }
    hideElement("warriorDataSingle", mech.getCrew().getSlotCount() != 1);
    hideElement("warriorDataDual", mech.getCrew().getSlotCount() != 2);
    hideElement("warriorDataTriple", mech.getCrew().getSlotCount() != 3);
    setTextField("hsType", formatHeatSinkType());
    setTextField("hsCount", formatHeatSinkCount());
    if (mech instanceof LandAirMech) {
        LandAirMech lam = (LandAirMech) mech;
        if (lam.getLAMType() == LandAirMech.LAM_BIMODAL) {
            // em dash
            setTextField("mpAirMechWalk", "\u2014");
            setTextField("mpAirMechRun", "\u2014");
            setTextField("mpAirMechCruise", "\u2014");
            setTextField("mpAirMechFlank", "\u2014");
        } else {
            setTextField("mpAirMechWalk", Integer.toString(lam.getAirMechWalkMP()));
            setTextField("mpAirMechRun", Integer.toString(lam.getAirMechRunMP()));
            setTextField("mpAirMechCruise", Integer.toString(lam.getAirMechCruiseMP()));
            setTextField("mpAirMechFlank", Integer.toString(lam.getAirMechFlankMP()));
        }
        setTextField("mpSafeThrust", Integer.toString(lam.getJumpMP()));
        setTextField("mpMaxThrust", Integer.toString((int) Math.ceil(lam.getJumpMP() * 1.5)));
        if (!lam.getCrew().getName().equalsIgnoreCase("unnamed") && (lam.getCrew() instanceof LAMPilot)) {
            setTextField("asfGunnerySkill", Integer.toString(((LAMPilot) mech.getCrew()).getGunneryAero()));
            setTextField("asfPilotingSkill", Integer.toString(((LAMPilot) mech.getCrew()).getPilotingAero()));
        } else {
            hideElement("asfGunnerySkill");
            hideElement("asfPilotingSkill");
        }
    } else if (mech instanceof QuadVee) {
        setTextField("mpCruise", Integer.toString(((QuadVee) mech).getCruiseMP(false, false, false)));
        setTextField("mpFlank", formatQuadVeeFlank());
        setTextField("lblVeeMode", ((QuadVee) mech).getMotiveTypeString() + "s");
    }
}
Also used : SVGRectElement(org.w3c.dom.svg.SVGRectElement) Element(org.w3c.dom.Element) QuadVee(megamek.common.QuadVee) LAMPilot(megamek.common.LAMPilot) LandAirMech(megamek.common.LandAirMech)

Example 5 with LandAirMech

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

the class CriticalTransferHandler method addEquipmentMech.

/**
 * @param mech
 * @param eq
 * @return
 */
private boolean addEquipmentMech(Mech mech, Mounted eq, int slotNumber) throws LocationFullException {
    int totalCrits = UnitUtil.getCritsUsed(getUnit(), eq.getType());
    // How much space we have in the selected location
    int primaryLocSpace = UnitUtil.getContiguousNumberOfCrits(getUnit(), location, slotNumber);
    if ((eq.getType().isSpreadable() || eq.isSplitable()) && (totalCrits > 1)) {
        int critsUsed = 0;
        int primaryLocation = location;
        int nextLocation = getUnit().getTransferLocation(location);
        // Determine if we should spread equipment over multiple locations
        if ((eq.getType().getCriticals(getUnit()) > primaryLocSpace) && !((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_TARGCOMP)) && !(getUnit() instanceof LandAirMech)) {
            if (location == Mech.LOC_RT) {
                String[] locations = { "Center Torso", "Right Leg", "Right Arm" };
                JComboBox<String> combo = new JComboBox<String>(locations);
                JOptionPane jop = new JOptionPane(combo, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
                JDialog dlg = jop.createDialog("Select secondary location.");
                combo.grabFocus();
                combo.getEditor().selectAll();
                dlg.setVisible(true);
                int value = ((Integer) jop.getValue()).intValue();
                if (value == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (combo.getSelectedIndex() == 1) {
                    nextLocation = Mech.LOC_RLEG;
                } else if (combo.getSelectedIndex() == 2) {
                    nextLocation = Mech.LOC_RARM;
                }
            } else if (location == Mech.LOC_LT) {
                String[] locations = { "Center Torso", "Left Leg", "Left Arm" };
                JComboBox<String> combo = new JComboBox<String>(locations);
                JOptionPane jop = new JOptionPane(combo, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
                JDialog dlg = jop.createDialog("Select secondary location.");
                combo.grabFocus();
                combo.getEditor().selectAll();
                dlg.setVisible(true);
                int value = ((Integer) jop.getValue()).intValue();
                if (value == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (combo.getSelectedIndex() == 1) {
                    nextLocation = Mech.LOC_LLEG;
                } else if (combo.getSelectedIndex() == 2) {
                    nextLocation = Mech.LOC_LARM;
                }
            } else if (location == Mech.LOC_CT) {
                String[] locations = { "Left Torso", "Right Torso" };
                JComboBox<String> combo = new JComboBox<String>(locations);
                JOptionPane jop = new JOptionPane(combo, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
                JDialog dlg = jop.createDialog(null, "Select secondary location.");
                combo.grabFocus();
                combo.getEditor().selectAll();
                dlg.setVisible(true);
                int value = ((Integer) jop.getValue()).intValue();
                if (value == JOptionPane.CANCEL_OPTION) {
                    return false;
                }
                if (combo.getSelectedIndex() == 1) {
                    nextLocation = Mech.LOC_RT;
                } else {
                    nextLocation = Mech.LOC_LT;
                }
            }
        }
        // Determine how much usable space we have in both locations
        int secondarySpace = UnitUtil.getHighestContinuousNumberOfCrits(getUnit(), nextLocation);
        // Check for available space
        if ((primaryLocSpace < totalCrits) && ((nextLocation == Entity.LOC_DESTROYED) || ((primaryLocSpace + secondarySpace) < totalCrits))) {
            throw new LocationFullException(eq.getName() + " does not fit there in " + getUnit().getLocationAbbr(location) + " on " + getUnit().getDisplayName());
        }
        int currLoc = location;
        for (; critsUsed < totalCrits; critsUsed++) {
            mech.addEquipment(eq, currLoc, false, slotNumber);
            slotNumber = (slotNumber + 1) % mech.getNumberOfCriticals(currLoc);
            primaryLocSpace--;
            if (primaryLocSpace == 0) {
                slotNumber = 0;
                currLoc = nextLocation;
                totalCrits -= critsUsed;
                critsUsed = 0;
            }
        }
        int secondary = Entity.LOC_NONE;
        if ((primaryLocSpace <= 0) && (slotNumber > 0)) {
            secondary = nextLocation;
        }
        changeMountStatus(eq, primaryLocation, secondary, false);
    } else if (primaryLocSpace >= totalCrits) {
        if ((eq.getType() instanceof WeaponType) && eq.getType().hasFlag(WeaponType.F_VGL)) {
            String[] facings;
            if (location == Mech.LOC_LT) {
                facings = new String[4];
                facings[0] = "Front";
                facings[1] = "Front-Left";
                facings[2] = "Rear-Left";
                facings[3] = "Rear";
            } else if (location == Mech.LOC_RT) {
                facings = new String[4];
                facings[0] = "Front";
                facings[1] = "Front-Right";
                facings[2] = "Rear-Right";
                facings[3] = "Rear";
            } else if (location == Mech.LOC_CT) {
                facings = new String[2];
                facings[0] = "Front";
                facings[1] = "Rear";
            } else {
                JOptionPane.showMessageDialog(null, "VGL must be placed in torso location!", "Invalid location", JOptionPane.WARNING_MESSAGE);
                return false;
            }
            String facing = (String) JOptionPane.showInputDialog(null, "Please choose the facing of the VGL", "Choose Facing", JOptionPane.QUESTION_MESSAGE, null, facings, facings[0]);
            if (facing == null) {
                return false;
            }
            mech.addEquipment(eq, location, false, slotNumber);
            if (facing.equals("Front-Left")) {
                eq.setFacing(5);
            } else if (facing.equals("Front-Right")) {
                eq.setFacing(1);
            } else if (facing.equals("Rear-Right")) {
                eq.setFacing(2);
            } else if (facing.equals("Rear-Left")) {
                eq.setFacing(4);
            } else if (facing.equals("Rear")) {
                eq.setFacing(3);
                UnitUtil.changeMountStatus(getUnit(), eq, location, -1, true);
            }
        } else {
            mech.addEquipment(eq, location, false, slotNumber);
        }
        changeMountStatus(eq, location, false);
    } else {
        throw new LocationFullException(eq.getName() + " does not fit there in " + getUnit().getLocationAbbr(location) + " on " + getUnit().getDisplayName());
    }
    return true;
}
Also used : LocationFullException(megamek.common.LocationFullException) JComboBox(javax.swing.JComboBox) MiscType(megamek.common.MiscType) WeaponType(megamek.common.WeaponType) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog) LandAirMech(megamek.common.LandAirMech)

Aggregations

LandAirMech (megamek.common.LandAirMech)5 MiscType (megamek.common.MiscType)2 Mounted (megamek.common.Mounted)2 QuadVee (megamek.common.QuadVee)2 Font (java.awt.Font)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 TextAttribute (java.awt.font.TextAttribute)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 JComboBox (javax.swing.JComboBox)1 JDialog (javax.swing.JDialog)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JOptionPane (javax.swing.JOptionPane)1 JPopupMenu (javax.swing.JPopupMenu)1 AmmoType (megamek.common.AmmoType)1 BipedMech (megamek.common.BipedMech)1 Engine (megamek.common.Engine)1