use of megamek.common.FixedWingSupport in project megameklab by MegaMek.
the class MenuBarCreator method loadUnitFromFile.
private void loadUnitFromFile(File unitFile) {
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
if (null == tempEntity) {
return;
}
if (UnitUtil.validateUnit(tempEntity).trim().length() > 0) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", UnitUtil.validateUnit(tempEntity)));
}
if (tempEntity.getEntityType() != parentFrame.getEntity().getEntityType()) {
MegaMekLabMainUI newUI = null;
if (tempEntity.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
newUI = new megameklab.com.ui.Dropship.MainUI(((Aero) tempEntity).isPrimitive());
} else if ((tempEntity instanceof Aero) && !((tempEntity instanceof Jumpship) || (tempEntity instanceof FixedWingSupport))) {
newUI = new megameklab.com.ui.Aero.MainUI(((Aero) tempEntity).isPrimitive());
} else if (tempEntity instanceof BattleArmor) {
newUI = new megameklab.com.ui.BattleArmor.MainUI();
} else if (tempEntity instanceof Infantry) {
newUI = new megameklab.com.ui.Infantry.MainUI();
} else if (tempEntity instanceof Mech) {
newUI = new megameklab.com.ui.Mek.MainUI();
} else if ((tempEntity instanceof Tank) && !(tempEntity instanceof GunEmplacement)) {
newUI = new megameklab.com.ui.Vehicle.MainUI();
}
if (null == newUI) {
JOptionPane.showMessageDialog(parentFrame, "Warning: Could not create new UI, aborting unit load!");
return;
}
parentFrame.dispose();
UnitUtil.updateLoadedUnit(tempEntity);
newUI.setEntity(tempEntity);
newUI.reloadTabs();
newUI.repaint();
newUI.refreshAll();
return;
}
parentFrame.setEntity(tempEntity);
UnitUtil.updateLoadedUnit(parentFrame.getEntity());
CConfig.updateSaveFiles(unitFile.getAbsolutePath());
} catch (Exception ex) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
}
reload();
refresh();
parentFrame.setVisible(true);
}
use of megamek.common.FixedWingSupport in project megameklab by MegaMek.
the class UnitPrintManager method printAllUnits.
public static boolean printAllUnits(Vector<Entity> loadedUnits, boolean singlePrint) {
Book book = new Book();
List<Infantry> infList = new ArrayList<>();
List<BattleArmor> baList = new ArrayList<>();
List<Protomech> protoList = new ArrayList<>();
List<Entity> unprintable = new ArrayList<>();
HashPrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.NA_LETTER);
aset.add(new MediaPrintableArea(0, 0, 8.5f, 11, MediaPrintableArea.INCH));
PrinterJob masterPrintJob = PrinterJob.getPrinterJob();
if (!masterPrintJob.printDialog(aset)) {
return true;
}
PageFormat pageFormat = new PageFormat();
pageFormat = masterPrintJob.getPageFormat(null);
Paper p = pageFormat.getPaper();
p.setImageableArea(0, 0, p.getWidth(), p.getHeight());
pageFormat.setPaper(p);
Tank tank1 = null;
Tank wige1 = null;
Tank dualTurret1 = null;
for (Entity unit : loadedUnits) {
if (unit instanceof Mech) {
UnitUtil.removeOneShotAmmo(unit);
UnitUtil.expandUnitMounts((Mech) unit);
book.append(new PrintMech((Mech) unit, book.getNumberOfPages()), pageFormat);
} else if ((unit instanceof LargeSupportTank) || ((unit instanceof Tank) && (unit.getMovementMode() != EntityMovementMode.VTOL) && ((Tank) unit).isSuperHeavy())) {
book.append(new PrintLargeSupportVehicle((Tank) unit), pageFormat);
} else if (unit instanceof VTOL) {
book.append(new PrintVTOL((VTOL) unit), pageFormat);
} else if (unit.getMovementMode() == EntityMovementMode.WIGE) {
if (singlePrint) {
book.append(new PrintVehicle((Tank) unit, null), pageFormat);
} else if (null != wige1) {
book.append(new PrintVehicle(wige1, (Tank) unit), pageFormat);
wige1 = null;
} else {
wige1 = (Tank) unit;
}
} else if ((unit instanceof Tank) && ((unit.getMovementMode() == EntityMovementMode.NAVAL) || (unit.getMovementMode() == EntityMovementMode.SUBMARINE) || (unit.getMovementMode() == EntityMovementMode.HYDROFOIL))) {
unprintable.add(unit);
// book.append(new PrintNavalVehicle((Tank) unit), pageFormat);
} else if (unit instanceof Tank) {
if (!((Tank) unit).hasNoDualTurret()) {
if (singlePrint) {
book.append(new PrintDualTurretVehicle((Tank) unit, null), pageFormat);
} else if (null != dualTurret1) {
book.append(new PrintDualTurretVehicle(dualTurret1, (Tank) unit), pageFormat);
dualTurret1 = null;
} else {
dualTurret1 = (Tank) unit;
}
} else {
if (singlePrint) {
book.append(new PrintVehicle((Tank) unit, null), pageFormat);
} else if (null != tank1) {
book.append(new PrintVehicle(tank1, (Tank) unit), pageFormat);
tank1 = null;
} else {
tank1 = (Tank) unit;
}
}
} else if (unit.hasETypeFlag(Entity.ETYPE_AERO) && !unit.hasETypeFlag(Entity.ETYPE_JUMPSHIP)) {
if (unit instanceof Dropship) {
if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
book.append(new PrintAerodyne((Dropship) unit), pageFormat);
} else {
book.append(new PrintSpheroid((Dropship) unit), pageFormat);
}
} else if (unit instanceof FixedWingSupport) {
book.append(new PrintFixedWingSupport((FixedWingSupport) unit), pageFormat);
} else if (unit instanceof ConvFighter) {
book.append(new PrintConventionalFighter((ConvFighter) unit), pageFormat);
} else if (unit instanceof SmallCraft) {
if (unit.getMovementMode() == EntityMovementMode.AERODYNE) {
book.append(new PrintSmallCraftAerodyne((SmallCraft) unit), pageFormat);
} else {
book.append(new PrintSmallCraftSpheroid((SmallCraft) unit), pageFormat);
}
} else {
book.append(new PrintAero((Aero) unit), pageFormat);
}
} else if (unit instanceof BattleArmor) {
baList.add((BattleArmor) unit);
if (singlePrint || baList.size() > 4) {
book.append(new PrintBattleArmor(baList), pageFormat);
baList = new ArrayList<>();
}
} else if (unit instanceof Infantry) {
infList.add((Infantry) unit);
if (singlePrint || infList.size() > 3) {
book.append(new PrintInfantry(infList), pageFormat);
infList = new ArrayList<>();
}
} else if (unit instanceof Protomech) {
protoList.add((Protomech) unit);
if (singlePrint || protoList.size() > 4) {
book.append(new PrintProtomech(protoList), pageFormat);
protoList = new ArrayList<>();
}
} else {
// TODO: show a message dialog that lists the unprintable units
unprintable.add(unit);
}
}
if (unprintable.size() > 0) {
JOptionPane.showMessageDialog(null, "Printing is not currently supported for the following units:\n" + unprintable.stream().map(en -> en.getChassis() + " " + en.getModel()).collect(Collectors.joining("\n")));
}
if (null != wige1) {
book.append(new PrintVehicle(wige1, null), pageFormat);
}
if (null != tank1) {
book.append(new PrintVehicle(tank1, null), pageFormat);
}
if (null != dualTurret1) {
book.append(new PrintDualTurretVehicle(dualTurret1, null), pageFormat);
}
if (baList.size() > 0) {
book.append(new PrintBattleArmor(baList), pageFormat);
}
if (infList.size() > 0) {
book.append(new PrintInfantry(infList), pageFormat);
}
if (protoList.size() > 0) {
book.append(new PrintProtomech(protoList), pageFormat);
}
masterPrintJob.setPageable(book);
if (loadedUnits.size() > 1) {
masterPrintJob.setJobName(loadedUnits.get(0).getShortNameRaw() + " etc");
} else if (loadedUnits.size() > 0) {
masterPrintJob.setJobName(loadedUnits.get(0).getShortNameRaw());
}
PrintTask task = new PrintTask(masterPrintJob, aset);
task.execute();
return true;
}
use of megamek.common.FixedWingSupport in project megameklab by MegaMek.
the class ImageHelperAero method printAeroWeaponsNEquipment.
public static void printAeroWeaponsNEquipment(Aero aero, Graphics2D g2d) {
int pointShift = 0;
if ((aero instanceof SmallCraft) && aero.isSpheroid()) {
pointShift = 11;
}
int qtyPoint = 30;
int typePoint = 42;
int locPoint = 112 + pointShift;
int heatPoint = 130 + pointShift;
int shtPoint = 147 + pointShift;
int medPoint = 170 + pointShift;
int longPoint = 190 + pointShift;
int erPoint = 210 + pointShift;
float linePoint = 204f;
float maxHeight = 97.0f;
float lineFeed = 6.7f;
boolean newLineNeeded = false;
ArrayList<Hashtable<String, EquipmentInfo>> equipmentLocations = new ArrayList<Hashtable<String, EquipmentInfo>>(aero.locations());
for (int pos = 0; pos <= aero.locations(); pos++) {
equipmentLocations.add(pos, new Hashtable<String, EquipmentInfo>());
}
for (Mounted eq : aero.getEquipment()) {
if ((eq.isWeaponGroup() || (eq.getType() instanceof AmmoType)) || (eq.getLocation() == Entity.LOC_NONE) || !UnitUtil.isPrintableEquipment(eq.getType())) {
continue;
}
Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(eq.getLocation());
String equipmentName = eq.getName();
if (eq.isRearMounted()) {
equipmentName += "(R)";
}
if (eqHash.containsKey(equipmentName)) {
EquipmentInfo eqi = eqHash.get(equipmentName);
if (eq.getType().getTechLevel(aero.getTechLevelYear()) != eqi.techLevel) {
eqi = new EquipmentInfo(aero, eq);
} else {
eqi.count++;
}
eqHash.put(equipmentName, eqi);
} else {
EquipmentInfo eqi = new EquipmentInfo(aero, eq);
eqHash.put(equipmentName, eqi);
}
}
if (aero.getTroopCarryingSpace() > 0) {
maxHeight -= lineFeed;
}
if (aero.hasWorkingMisc(MiscType.F_CHASSIS_MODIFICATION)) {
maxHeight -= lineFeed;
}
if (aero.getCockpitType() != Aero.COCKPIT_STANDARD) {
maxHeight -= lineFeed;
}
for (@SuppressWarnings("unused") Bay bay : aero.getTransportBays()) {
maxHeight -= lineFeed;
}
if (aero.getAmmo().size() > 0) {
maxHeight -= lineFeed;
}
g2d.setFont(UnitUtil.deriveFont(false, 7.0f));
Font font = ImageHelperAero.getAeroWeaponsNEquipmentFont(g2d, false, maxHeight, equipmentLocations, 7.0f);
g2d.setFont(font);
float stringHeight = ImageHelper.getStringHeight(g2d, "H", font);
lineFeed = stringHeight;
for (int pos = Aero.LOC_NOSE; pos <= aero.locations(); pos++) {
Hashtable<String, EquipmentInfo> eqHash = equipmentLocations.get(pos);
if (eqHash.size() < 1) {
continue;
}
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;
g2d.setFont(font);
g2d.drawString(Integer.toString(eqi.count), qtyPoint, linePoint);
String name = eqi.name.trim() + " " + eqi.damage.trim();
if (eqi.c3Level == EquipmentInfo.C3I) {
ImageHelper.printC3iName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3EM) {
ImageHelper.printC3EmName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3S) {
ImageHelper.printC3sName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3M) {
ImageHelper.printC3mName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3SB) {
ImageHelper.printC3sbName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3MB) {
ImageHelper.printC3mbName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
} else if (eqi.c3Level == EquipmentInfo.C3REMOTESENSOR) {
ImageHelper.printC3RemoteSensorName(g2d, typePoint, linePoint, font, false, aero.isMixedTech() && TechConstants.isClan(aero.getTechLevel()));
} else if (eqi.isMashCore) {
ImageHelper.printMashCore(g2d, typePoint, linePoint, font, false, aero);
} else if (eqi.isDroneControl) {
ImageHelper.printDroneControl(g2d, typePoint, linePoint, font, false, aero);
} else {
if (ImageHelper.getStringWidth(g2d, name, font) > 65) {
// g2d.setFont(UnitUtil.getNewFont(g2d, eqi.name.trim(),
// false, 65, font.getSize2D()));
g2d.drawString(eqi.name.trim(), typePoint, linePoint);
linePoint += lineFeed;
g2d.drawString(eqi.damage.trim(), typePoint, linePoint);
} else {
g2d.drawString(name, typePoint, linePoint);
}
}
g2d.setFont(font);
String location = ImageHelperAero.getLocationAbbrs(pos);
if ((aero instanceof SmallCraft) && (aero.getMovementMode() == EntityMovementMode.SPHEROID)) {
location = ImageHelperAero.getLocationAbbrsSmallCraft(pos);
}
g2d.drawString(location, locPoint, linePoint);
ImageHelper.printCenterString(g2d, Integer.toString(eqi.heat), font, heatPoint, linePoint);
if (eqi.isMML) {
linePoint += lineFeed;
g2d.drawString("SRM Ammo", typePoint, linePoint);
g2d.drawString(Integer.toString(eqi.shtRange * 2), shtPoint, (int) linePoint);
g2d.drawString("\u2014", medPoint, linePoint);
g2d.drawString("\u2014", longPoint, linePoint);
g2d.drawString("\u2014", erPoint, linePoint);
// g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
// g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
// g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
linePoint += lineFeed;
g2d.drawString("LRM Ammo", typePoint, linePoint);
g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
g2d.drawString("\u2014", erPoint, linePoint);
// g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 6, (int) linePoint - 2);
} else if (eqi.shtRange > 0) {
g2d.drawString(Integer.toString(eqi.shtRange), shtPoint, (int) linePoint);
} else {
g2d.drawString("\u2014", shtPoint, linePoint);
// g2d.drawLine(shtPoint, (int) linePoint - 2, shtPoint + 6, (int) linePoint - 2);
}
if ((eqi.medRange > 0) && !eqi.isMML) {
g2d.drawString(Integer.toString(eqi.medRange), medPoint, (int) linePoint);
} else if (!eqi.isMML) {
g2d.drawString("\u2014", medPoint, linePoint);
// g2d.drawLine(medPoint, (int) linePoint - 2, medPoint + 6, (int) linePoint - 2);
}
if ((eqi.longRange > 0) && !eqi.isMML) {
g2d.drawString(Integer.toString(eqi.longRange), longPoint, (int) linePoint);
} else if (!eqi.isMML) {
g2d.drawString("\u2014", longPoint, linePoint);
// g2d.drawLine(longPoint, (int) linePoint - 2, longPoint + 6, (int) linePoint - 2);
}
if ((eqi.erRange > 0) && !eqi.isMML) {
g2d.drawString(Integer.toString(eqi.erRange), erPoint, (int) linePoint);
} else if (!eqi.isMML) {
g2d.drawString("\u2014", erPoint, linePoint);
// g2d.drawLine(erPoint, (int) linePoint - 2, erPoint + 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;
}
}
}
if (aero.getCockpitType() != Aero.COCKPIT_STANDARD) {
g2d.drawString(aero.getCockpitTypeString(), 22, linePoint);
linePoint += lineFeed;
}
if (aero instanceof FixedWingSupport) {
ImageHelperAero.printFixedWingSupportCargoChassisMod((FixedWingSupport) aero, g2d, (int) linePoint);
} else {
ImageHelperAero.printCargo(aero, g2d, (int) linePoint);
}
ImageHelper.printVehicleAmmo(aero, g2d, -20, 8);
ImageHelperAero.printAeroFuel(aero, g2d, 8);
}
Aggregations