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