use of megamek.common.options.IOptionGroup 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));
}
}
}
}
}
use of megamek.common.options.IOptionGroup 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));
}
}
Aggregations