Search in sources :

Example 1 with IOption

use of megamek.common.options.IOption in project megameklab by MegaMek.

the class AugmentationView method refresh.

public void refresh() {
    handleEvents = false;
    for (IOption opt : options.keySet()) {
        options.get(opt).setSelected(getInfantry().getCrew().getOptions().booleanOption(opt.getName()));
    }
    handleEvents = true;
}
Also used : IOption(megamek.common.options.IOption)

Example 2 with IOption

use of megamek.common.options.IOption in project megameklab by MegaMek.

the class PrintEntity method writeTextFields.

protected void writeTextFields() {
    setTextField("title", getRecordSheetTitle().toUpperCase());
    setTextField("type", getEntity().getShortNameRaw());
    setTextField("mpWalk", formatWalk());
    setTextField("mpRun", formatRun());
    setTextField("mpJump", formatJump());
    setTextField("tonnage", Integer.toString((int) getEntity().getWeight()));
    setTextField("techBase", formatTechBase());
    setTextField("rulesLevel", formatRulesLevel());
    setTextField("era", formatEra(getEntity().getYear()));
    setTextField("cost", formatCost());
    setTextField("bv", Integer.toString(getEntity().calculateBattleValue()));
    UnitRole role = UnitRoleHandler.getRoleFor(getEntity());
    if (role == UnitRole.UNDETERMINED) {
        hideElement("lblRole", true);
        hideElement("role", true);
    } else {
        setTextField("role", role.toString());
    }
    // This will require building the graphics tree so we measure the elements.
    if (getEntity().getCrew().getCrewType() != CrewType.SINGLE) {
        build();
    }
    for (int i = 0; i < getEntity().getCrew().getSlotCount(); i++) {
        // If we have multiple named crew for the unit, change the "Name:" label to
        // the label of the slot. This will usually require adjusting the position of the
        // name or the length of the blank.
        double nameOffset = 0;
        if (getEntity().getCrew().getSlotCount() > 1) {
            Element element = getSVGDocument().getElementById("crewName" + i);
            if (null != element) {
                float oldWidth = ((SVGTextContentElement) element).getComputedTextLength();
                element.setTextContent(getEntity().getCrew().getCrewType().getRoleName(i) + ":");
                nameOffset = SVGLocatableSupport.getBBox(element).getWidth() - oldWidth;
            }
        }
        if (!getEntity().getCrew().getName().equalsIgnoreCase("unnamed")) {
            Element element = getSVGDocument().getElementById("blanksCrew" + i);
            if (null != element) {
                hideElement(element);
            }
            if (nameOffset != 0) {
                element = getSVGDocument().getElementById("pilotName" + i);
                if (null != element) {
                    double offset = nameOffset;
                    String prev = element.getAttribute(SVGConstants.SVG_X_ATTRIBUTE);
                    if (null != prev) {
                        offset += Double.parseDouble(prev);
                    } else {
                        offset += ((SVGTextContentElement) element).getStartPositionOfChar(0).getX();
                    }
                    element.setAttributeNS(null, SVGConstants.SVG_X_ATTRIBUTE, Double.toString(offset));
                }
            }
            setTextField("pilotName" + i, getEntity().getCrew().getName(i), true);
            setTextField("gunnerySkill" + i, Integer.toString(getEntity().getCrew().getGunnery(i)), true);
            setTextField("pilotingSkill" + i, Integer.toString(getEntity().getCrew().getPiloting(i)), true);
            StringJoiner spaList = new StringJoiner(", ");
            PilotOptions spas = getEntity().getCrew().getOptions();
            for (Enumeration<IOptionGroup> optionGroups = spas.getGroups(); optionGroups.hasMoreElements(); ) {
                IOptionGroup optiongroup = optionGroups.nextElement();
                if (spas.count(optiongroup.getKey()) > 0) {
                    for (Enumeration<IOption> options = optiongroup.getOptions(); options.hasMoreElements(); ) {
                        IOption option = options.nextElement();
                        if (option != null && option.booleanValue()) {
                            spaList.add(option.getDisplayableNameWithValue().replaceAll(" \\(.*?\\)", ""));
                        }
                    }
                }
            }
            if (spaList.length() > 0) {
                Element rect = getSVGDocument().getElementById("spas" + getEntity().getCrew().getSlotCount());
                if ((null != rect) && (rect instanceof SVGRectElement)) {
                    Rectangle2D bbox = getRectBBox((SVGRectElement) rect);
                    Element canvas = (Element) ((Node) rect).getParentNode();
                    String spaText = "Abilities: " + spaList.toString();
                    float fontSize = FONT_SIZE_MEDIUM;
                    if (getTextLength(spaText, fontSize) > bbox.getWidth()) {
                        fontSize = (float) bbox.getHeight() / 2.4f;
                    }
                    double lineHeight = fontSize * 1.2;
                    addMultilineTextElement(canvas, bbox.getX(), bbox.getY() + lineHeight, bbox.getWidth(), lineHeight, spaText, fontSize, "start", "normal", "black", ' ');
                }
            }
        } else {
            setTextField("pilotName" + i, null);
            setTextField("gunnerySkill" + i, null);
            setTextField("pilotingSkill" + i, null);
            if (nameOffset != 0) {
                Element element = getSVGDocument().getElementById("blankCrewName" + i);
                if (null != element) {
                    float w = ((SVGGraphicsElement) element).getBBox().getWidth();
                    element.setAttributeNS(null, SVGConstants.SVG_D_ATTRIBUTE, String.format("M %f,0 %f,0", nameOffset, w - nameOffset));
                }
            }
        }
    }
}
Also used : IOptionGroup(megamek.common.options.IOptionGroup) PilotOptions(megamek.common.options.PilotOptions) SVGGraphicsElement(org.apache.batik.anim.dom.SVGGraphicsElement) SVGRectElement(org.w3c.dom.svg.SVGRectElement) Element(org.w3c.dom.Element) SVGTextContentElement(org.w3c.dom.svg.SVGTextContentElement) SVGTextContentElement(org.w3c.dom.svg.SVGTextContentElement) IOption(megamek.common.options.IOption) Rectangle2D(java.awt.geom.Rectangle2D) SVGRectElement(org.w3c.dom.svg.SVGRectElement) UnitRole(megamek.common.UnitRole) StringJoiner(java.util.StringJoiner)

Example 3 with IOption

use of megamek.common.options.IOption in project megameklab by MegaMek.

the class PrintMech method writeEquipment.

@Override
protected void writeEquipment(SVGRectElement svgRect) {
    Map<Integer, Map<RecordSheetEquipmentLine, Integer>> eqMap = new TreeMap<>();
    Map<String, Integer> ammo = new TreeMap<>();
    for (Mounted m : mech.getEquipment()) {
        if ((m.getType() instanceof AmmoType) && (((AmmoType) m.getType()).getAmmoType() != AmmoType.T_COOLANT_POD)) {
            if (m.getLocation() != Entity.LOC_NONE) {
                String shortName = m.getType().getShortName().replace("Ammo", "");
                shortName = shortName.replace("(Clan)", "");
                String munition = ((AmmoType) m.getType()).getSubMunitionName().replace("(Clan) ", "");
                shortName = shortName.replace(munition, "");
                ammo.merge(shortName.trim(), m.getBaseShotsLeft(), Integer::sum);
            }
            continue;
        }
        if ((m.getType() instanceof AmmoType) || (m.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(m.getType(), true)) {
            continue;
        }
        if (mech.hasETypeFlag(Entity.ETYPE_QUADVEE) && (m.getType() instanceof MiscType) && m.getType().hasFlag(MiscType.F_TRACKS)) {
            continue;
        }
        eqMap.putIfAbsent(m.getLocation(), new HashMap<>());
        RecordSheetEquipmentLine line = new RecordSheetEquipmentLine(m);
        eqMap.get(m.getLocation()).merge(line, 1, Integer::sum);
    }
    Rectangle2D bbox = getRectBBox(svgRect);
    Element canvas = (Element) ((Node) svgRect).getParentNode();
    int viewWidth = (int) bbox.getWidth();
    int viewHeight = (int) bbox.getHeight();
    int viewX = (int) bbox.getX();
    int viewY = (int) bbox.getY();
    int qtyX = (int) Math.round(viewX + viewWidth * 0.037);
    int nameX = (int) Math.round(viewX + viewWidth * 0.08);
    int locX = (int) Math.round(viewX + viewWidth * 0.41);
    int heatX = (int) Math.round(viewX + viewWidth * 0.48);
    int dmgX = (int) Math.round(viewX + viewWidth * 0.53);
    int minX = (int) Math.round(viewX + viewWidth * 0.75);
    int shortX = (int) Math.round(viewX + viewWidth * 0.82);
    int medX = (int) Math.round(viewX + viewWidth * 0.89);
    int longX = (int) Math.round(viewX + viewWidth * 0.96);
    int indent = (int) Math.round(viewWidth * 0.02);
    int currY = viewY + 10;
    float fontSize = FONT_SIZE_MEDIUM;
    float lineHeight = getFontHeight(fontSize) * 0.8f;
    addTextElement(canvas, qtyX, currY, "Qty", fontSize, "middle", "bold");
    addTextElement(canvas, nameX + indent, currY, "Type", fontSize, "start", "bold");
    addTextElement(canvas, locX, currY, "Loc", fontSize, "middle", "bold");
    addTextElement(canvas, heatX, currY, "Ht", fontSize, "middle", "bold");
    addTextElement(canvas, dmgX, currY, "Dmg", fontSize, "start", "bold");
    addTextElement(canvas, minX, currY, "Min", fontSize, "middle", "bold");
    addTextElement(canvas, shortX, currY, "Sht", fontSize, "middle", "bold");
    addTextElement(canvas, medX, currY, "Med", fontSize, "middle", "bold");
    addTextElement(canvas, longX, currY, "Lng", fontSize, "middle", "bold");
    currY += lineHeight * 1.2;
    int lines = 0;
    for (Integer loc : eqMap.keySet()) {
        for (RecordSheetEquipmentLine line : eqMap.get(loc).keySet()) {
            int rows = line.nRows();
            if ((rows == 1) && (getTextLength(line.getNameField(0, mech.isMixedTech()), fontSize) > locX - nameX)) {
                rows++;
            }
            lines += rows;
        }
    }
    if (lines > 12) {
        lineHeight = getFontHeight(fontSize) * 0.8f;
    }
    if (lines > 16) {
        fontSize = FONT_SIZE_SMALL;
    }
    if (lines > 20) {
        fontSize = FONT_SIZE_VSMALL;
    }
    for (Integer loc : eqMap.keySet()) {
        for (RecordSheetEquipmentLine line : eqMap.get(loc).keySet()) {
            for (int row = 0; row < line.nRows(); row++) {
                if (row == 0) {
                    addTextElement(canvas, qtyX, currY, Integer.toString(eqMap.get(loc).get(line)), fontSize, "middle", "normal");
                    lines = addMultilineTextElement(canvas, nameX, currY, locX - nameX - indent, lineHeight, line.getNameField(row, mech.isMixedTech()), fontSize, "start", "normal");
                } else {
                    lines = addMultilineTextElement(canvas, nameX + indent, currY, locX - nameX - indent, lineHeight, line.getNameField(row, mech.isMixedTech()), fontSize, "start", "normal");
                }
                addTextElement(canvas, locX, currY, line.getLocationField(row), fontSize, "middle", "normal");
                addTextElement(canvas, heatX, currY, line.getHeatField(row), fontSize, "middle", "normal");
                lines = Math.max(lines, addMultilineTextElement(canvas, dmgX, currY, minX - dmgX, lineHeight, line.getDamageField(row), fontSize, "start", "normal"));
                addTextElement(canvas, minX, currY, line.getMinField(row), fontSize, "middle", "normal");
                addTextElement(canvas, shortX, currY, line.getShortField(row), fontSize, "middle", "normal");
                addTextElement(canvas, medX, currY, line.getMediumField(row), fontSize, "middle", "normal");
                addTextElement(canvas, longX, currY, line.getLongField(row), fontSize, "middle", "normal");
                currY += lineHeight * lines;
            }
        }
    }
    StringJoiner quirksList = new StringJoiner(", ");
    Quirks quirks = mech.getQuirks();
    for (Enumeration<IOptionGroup> optionGroups = quirks.getGroups(); optionGroups.hasMoreElements(); ) {
        IOptionGroup optiongroup = optionGroups.nextElement();
        if (quirks.count(optiongroup.getKey()) > 0) {
            for (Enumeration<IOption> options = optiongroup.getOptions(); options.hasMoreElements(); ) {
                IOption option = options.nextElement();
                if (option != null && option.booleanValue()) {
                    quirksList.add(option.getDisplayableNameWithValue());
                }
            }
        }
    }
    if ((ammo.size() > 0) || (quirksList.length() > 0)) {
        Element svgGroup = getSVGDocument().createElementNS(svgNS, SVGConstants.SVG_G_TAG);
        canvas.appendChild(svgGroup);
        lines = 0;
        if (ammo.size() > 0) {
            lines = addMultilineTextElement(svgGroup, viewX + viewWidth * 0.025, 0, viewWidth * 0.95, lineHeight, "Ammo: " + ammo.entrySet().stream().map(e -> String.format("(%s) %d", e.getKey(), e.getValue())).collect(Collectors.joining(", ")), fontSize, "start", "normal");
        }
        if (quirksList.length() > 0) {
            lines += addMultilineTextElement(svgGroup, viewX + viewWidth * 0.025, lines * lineHeight, viewWidth * 0.95, lineHeight, "Quirks: " + quirksList.toString(), fontSize, "start", "normal");
        }
        svgGroup.setAttributeNS(null, SVGConstants.SVG_TRANSFORM_ATTRIBUTE, String.format("translate(0,%f)", viewY + viewHeight - lines * lineHeight));
    }
}
Also used : IOptionGroup(megamek.common.options.IOptionGroup) MiscType(megamek.common.MiscType) SVGRectElement(org.w3c.dom.svg.SVGRectElement) Element(org.w3c.dom.Element) Rectangle2D(java.awt.geom.Rectangle2D) IOption(megamek.common.options.IOption) TreeMap(java.util.TreeMap) Quirks(megamek.common.options.Quirks) AmmoType(megamek.common.AmmoType) RecordSheetEquipmentLine(megameklab.com.util.RecordSheetEquipmentLine) Mounted(megamek.common.Mounted) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) StringJoiner(java.util.StringJoiner)

Example 4 with IOption

use of megamek.common.options.IOption in project megameklab by MegaMek.

the class StructureTab method refresh.

public void refresh() {
    panBasicInfo.setFromEntity(getInfantry());
    panPlatoonType.setFromEntity(getInfantry());
    panWeapons.setFromEntity(getInfantry());
    removeAllListeners();
    EquipmentType armor = getInfantry().getArmorKit();
    if (null != armor) {
        txtArmor.setText(armor.getName());
    } else {
        String desc = getInfantry().getArmorDesc();
        if (desc.equals("1.0")) {
            txtArmor.setText("None");
        } else {
            txtArmor.setText(desc);
        }
    }
    updateSpecializations();
    StringJoiner sj = new StringJoiner("<br/>");
    for (Enumeration<IOption> e = getInfantry().getCrew().getOptions(PilotOptions.MD_ADVANTAGES); e.hasMoreElements(); ) {
        final IOption opt = e.nextElement();
        if (getInfantry().getCrew().getOptions().booleanOption(opt.getName())) {
            sj.add(opt.getDisplayableName());
        }
    }
    if (sj.length() > 0) {
        txtAugmentations.setText(sj.toString());
    } else {
        txtAugmentations.setText("None");
    }
    weaponView.refresh();
    fieldGunView.refresh();
    armorView.refresh();
    specializationView.refresh();
    augmentationView.refresh();
    enableTabs();
    addAllListeners();
}
Also used : IOption(megamek.common.options.IOption) EquipmentType(megamek.common.EquipmentType) StringJoiner(java.util.StringJoiner)

Aggregations

IOption (megamek.common.options.IOption)4 StringJoiner (java.util.StringJoiner)3 Rectangle2D (java.awt.geom.Rectangle2D)2 IOptionGroup (megamek.common.options.IOptionGroup)2 Element (org.w3c.dom.Element)2 SVGRectElement (org.w3c.dom.svg.SVGRectElement)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AmmoType (megamek.common.AmmoType)1 EquipmentType (megamek.common.EquipmentType)1 MiscType (megamek.common.MiscType)1 Mounted (megamek.common.Mounted)1 UnitRole (megamek.common.UnitRole)1 PilotOptions (megamek.common.options.PilotOptions)1 Quirks (megamek.common.options.Quirks)1 RecordSheetEquipmentLine (megameklab.com.util.RecordSheetEquipmentLine)1 SVGGraphicsElement (org.apache.batik.anim.dom.SVGGraphicsElement)1 SVGTextContentElement (org.w3c.dom.svg.SVGTextContentElement)1