Skip to content

Commit

Permalink
Merge pull request #1462 from pavelbraginskiy/force_bv_modifiers
Browse files Browse the repository at this point in the history
When printing from MUL, calculate BV from C3/Tag
  • Loading branch information
HammerGS authored Mar 19, 2024
2 parents d142c96 + 2973298 commit d9b7936
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ConfigurationDialog.chkShowCondensedTables.text=Print Mech hit location and clus
ConfigurationDialog.chkShowCondensedTables.tooltip=Include hit location and cluster hits tables in the space where the fluff image normally goes.
ConfigurationDialog.chkShowQuirks.text=Print design quirks
ConfigurationDialog.chkShowQuirks.tooltip=Displays featured design quirks
ConfigurationDialog.chkShowPilotData.text=Include pilot data when printing from a MUL
ConfigurationDialog.chkShowPilotData.text=Include pilot and force data when printing from a MUL
ConfigurationDialog.chkShowPilotData.tooltip=When using a MUL file for batch printing, unchecking this option ignores the generated crew information.
ConfigurationDialog.chkShowEraIcon.text=Print era icon
ConfigurationDialog.chkShowEraIcon.tooltip=Includes the icon associated with the era the unit was constructed.
Expand Down
15 changes: 1 addition & 14 deletions megameklab/src/megameklab/ui/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import megamek.common.annotations.Nullable;
import megamek.common.loaders.BLKFile;
import megamek.common.templates.TROView;
import megamek.common.util.ImageUtil;
import megameklab.MMLConstants;
import megameklab.ui.dialog.MMLFileChooser;
import megameklab.ui.dialog.MegaMekLabUnitSelectorDialog;
Expand Down Expand Up @@ -394,15 +393,9 @@ private JMenu createPDFUnitExportMenu() {
final JMenuItem miExportUnitsFromMULFileToPDF = new JMenuItem(resources.getString("FromMUL.text"));
miExportUnitsFromMULFileToPDF.setName("miExportUnitsFromMULFileToPDF");
miExportUnitsFromMULFileToPDF.setMnemonic(KeyEvent.VK_M);
miExportUnitsFromMULFileToPDF.addActionListener(evt -> UnitPrintManager.exportMUL(owner.getFrame(), false));
miExportUnitsFromMULFileToPDF.addActionListener(evt -> UnitPrintManager.printMUL(owner.getFrame(), true));
pdfUnitExportMenu.add(miExportUnitsFromMULFileToPDF);

final JMenuItem miExportUnitsFromMULFileToSinglePDFPages = new JMenuItem(resources.getString("FromMULSingle.text"));
miExportUnitsFromMULFileToSinglePDFPages.setName("miExportUnitsFromMULFileToSinglePDFPages");
miExportUnitsFromMULFileToSinglePDFPages.setMnemonic(KeyEvent.VK_L);
miExportUnitsFromMULFileToSinglePDFPages.addActionListener(evt -> UnitPrintManager.exportMUL(owner.getFrame(), true));
pdfUnitExportMenu.add(miExportUnitsFromMULFileToSinglePDFPages);

return pdfUnitExportMenu;
}

Expand Down Expand Up @@ -509,12 +502,6 @@ private JMenu createPrintMenu() {
miPrintUnitsFromMULFile.addActionListener(evt -> UnitPrintManager.printMUL(owner.getFrame(), false));
printMenu.add(miPrintUnitsFromMULFile);

final JMenuItem miPrintUnitsFromMULFileToSinglePages = new JMenuItem(resources.getString("FromMULSingle.text"));
miPrintUnitsFromMULFileToSinglePages.setName("miPrintUnitsFromMULFileToSinglePages");
miPrintUnitsFromMULFileToSinglePages.setMnemonic(KeyEvent.VK_L);
miPrintUnitsFromMULFileToSinglePages.addActionListener(evt -> UnitPrintManager.printMUL(owner.getFrame(), true));
printMenu.add(miPrintUnitsFromMULFileToSinglePages);

return printMenu;
}

Expand Down
30 changes: 25 additions & 5 deletions megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class PrintQueueDialog extends AbstractMMLButtonDialog {
private final JButton addFromCacheButton = new JButton("Add From Cache");
private final JButton addPageBreakButton = new JButton("Add Page Break");
private final JButton removeButton = new JButton("Remove Selected");

private final JButton moveTopButton = new JButton(icon("moveTop.png"));
private final JButton moveUpButton = new JButton(icon("moveUp.png"));
private final JButton moveDownButton = new JButton(icon("moveDown.png"));
Expand All @@ -69,11 +69,22 @@ public class PrintQueueDialog extends AbstractMMLButtonDialog {
private final List<BTObject> units = new ArrayList<>();
private final JList<String> queuedUnitList = new JList<>();

public PrintQueueDialog(JFrame parent, boolean printToPdf) {
private final boolean fromMul;

public PrintQueueDialog(JFrame parent, boolean printToPdf, List<? extends BTObject> units, boolean fromMul) {
super(parent, true, "PrintQueueDialog", "PrintQueueDialog.windowName.text");
this.parent = parent;
this.printToPdf = printToPdf;
this.fromMul = fromMul;
initialize();
if (units != null) {
this.units.addAll(units);
refresh();
}
}

public PrintQueueDialog(JFrame parent, boolean printToPdf) {
this(parent, printToPdf, null, false);
}

private static ImageIcon icon(String name) {
Expand Down Expand Up @@ -118,8 +129,10 @@ protected Container createCenterPane() {
queuedUnitList.setVisibleRowCount(15);

JPanel buttonPanel = new FixedXYPanel(new GridLayout(4, 1));
buttonPanel.add(addFromCacheButton);
buttonPanel.add(addFromFileButton);
if (!fromMul) {
buttonPanel.add(addFromCacheButton);
buttonPanel.add(addFromFileButton);
}
buttonPanel.add(addPageBreakButton);
buttonPanel.add(removeButton);
buttonPanel.setAlignmentY(JComponent.TOP_ALIGNMENT);
Expand Down Expand Up @@ -164,7 +177,14 @@ protected JPanel createButtonPanel() {

private void refresh() {
List<String> nameList = units.stream()
.map(unit -> ' ' + unit.generalName() + ' ' + unit.specificName())
.map(unit -> {
String title = String.format(" %s %s", unit.generalName(), unit.specificName());
if (fromMul && unit instanceof Entity) {
var crew = ((Entity) unit).getCrew();
title += String.format(" {%s %d/%d}", crew.getName(), crew.getGunnery(), crew.getPiloting());
}
return title;
})
.collect(toList());

var replacementModel = new DefaultListModel<String>();
Expand Down
44 changes: 11 additions & 33 deletions megameklab/src/megameklab/util/UnitPrintManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

import megamek.client.ui.swing.UnitLoadingDialog;
import megamek.common.*;
import megamek.common.util.C3Util;
import megameklab.printing.*;
import megameklab.ui.dialog.MegaMekLabUnitSelectorDialog;
import org.apache.commons.io.FilenameUtils;
import megameklab.ui.dialog.PrintQueueDialog;
import org.apache.logging.log4j.LogManager;

import javax.print.attribute.HashPrintRequestAttributeSet;
Expand Down Expand Up @@ -50,7 +51,7 @@ public static void exportEntity(Entity entity, JFrame parent) {
}
}

public static void printMUL(Frame parent, boolean singlePrint) {
public static void printMUL(JFrame parent, boolean printToPdf) {
JFileChooser f = new JFileChooser(System.getProperty("user.dir"));
f.setLocation(parent.getLocation().x + 150, parent.getLocation().y + 100);
f.setDialogTitle("Print From MUL");
Expand All @@ -75,39 +76,16 @@ public static void printMUL(Frame parent, boolean singlePrint) {
return;
}

printAllUnits(loadedUnits, singlePrint);
}

public static void exportMUL(Frame parent, boolean singlePrint) {
JFileChooser f = new JFileChooser(System.getProperty("user.dir"));
f.setLocation(parent.getLocation().x + 150, parent.getLocation().y + 100);
f.setDialogTitle("Export from MUL");
f.setMultiSelectionEnabled(false);

FileNameExtensionFilter filter = new FileNameExtensionFilter("Mul Files", "mul");

// Add a filter for mul files
f.setFileFilter(filter);

int returnVal = f.showOpenDialog(parent);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
File mulFile = f.getSelectedFile();
final Vector<Entity> loadedUnits;
try {
loadedUnits = new MULParser(mulFile, null).getEntities();
loadedUnits.trimToSize();
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
return;
// Dummy player and game allow bonus BV from C3 and TAG to be calculated
Game g = new Game();
Player p = new Player(1, "Nobody");
for (Entity e : loadedUnits) {
e.setOwner(p);
g.addEntity(e);
C3Util.wireC3(g, e);
}

File exportFile = getExportFile(parent, FilenameUtils.removeExtension(mulFile.getPath()) + ".pdf");
if (exportFile != null) {
exportUnits(loadedUnits, exportFile, singlePrint);
}
new PrintQueueDialog(parent, printToPdf, loadedUnits, true).setVisible(true);
}

public static File getExportFile(Frame parent) {
Expand Down

0 comments on commit d9b7936

Please sign in to comment.