From 108eda2ea6bfd7846feaba78b7fb563a76a662a4 Mon Sep 17 00:00:00 2001 From: Pavel Braginskiy Date: Sat, 16 Mar 2024 19:04:43 -0700 Subject: [PATCH 1/2] Use print queue dialog for printing mul files --- megameklab/src/megameklab/ui/MenuBar.java | 15 +------- .../ui/dialog/PrintQueueDialog.java | 30 ++++++++++++--- .../src/megameklab/util/UnitPrintManager.java | 38 ++----------------- 3 files changed, 29 insertions(+), 54 deletions(-) diff --git a/megameklab/src/megameklab/ui/MenuBar.java b/megameklab/src/megameklab/ui/MenuBar.java index 22dad71f4..7603ddf6a 100644 --- a/megameklab/src/megameklab/ui/MenuBar.java +++ b/megameklab/src/megameklab/ui/MenuBar.java @@ -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; @@ -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; } @@ -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; } diff --git a/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java b/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java index 025cd9746..b92fc0ba8 100644 --- a/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java +++ b/megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java @@ -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")); @@ -69,11 +69,22 @@ public class PrintQueueDialog extends AbstractMMLButtonDialog { private final List units = new ArrayList<>(); private final JList queuedUnitList = new JList<>(); - public PrintQueueDialog(JFrame parent, boolean printToPdf) { + private final boolean fromMul; + + public PrintQueueDialog(JFrame parent, boolean printToPdf, List 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) { @@ -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); @@ -164,7 +177,14 @@ protected JPanel createButtonPanel() { private void refresh() { List 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(); diff --git a/megameklab/src/megameklab/util/UnitPrintManager.java b/megameklab/src/megameklab/util/UnitPrintManager.java index b821d4f82..b18ee81cb 100644 --- a/megameklab/src/megameklab/util/UnitPrintManager.java +++ b/megameklab/src/megameklab/util/UnitPrintManager.java @@ -19,7 +19,7 @@ import megamek.common.*; 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; @@ -50,7 +50,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"); @@ -75,39 +75,7 @@ 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 loadedUnits; - try { - loadedUnits = new MULParser(mulFile, null).getEntities(); - loadedUnits.trimToSize(); - } catch (Exception ex) { - LogManager.getLogger().error("", ex); - return; - } - - 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) { From 2973298f60c404a5973df101b11b1178f73ceb88 Mon Sep 17 00:00:00 2001 From: Pavel Braginskiy Date: Sun, 17 Mar 2024 22:54:26 -0400 Subject: [PATCH 2/2] Calculate force modifiers (Tag/C3) when printing from MUL --- .../resources/megameklab/resources/Dialogs.properties | 2 +- megameklab/src/megameklab/util/UnitPrintManager.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/megameklab/resources/megameklab/resources/Dialogs.properties b/megameklab/resources/megameklab/resources/Dialogs.properties index 1593b1b72..16267f956 100644 --- a/megameklab/resources/megameklab/resources/Dialogs.properties +++ b/megameklab/resources/megameklab/resources/Dialogs.properties @@ -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. diff --git a/megameklab/src/megameklab/util/UnitPrintManager.java b/megameklab/src/megameklab/util/UnitPrintManager.java index b18ee81cb..b09c7c479 100644 --- a/megameklab/src/megameklab/util/UnitPrintManager.java +++ b/megameklab/src/megameklab/util/UnitPrintManager.java @@ -17,6 +17,7 @@ import megamek.client.ui.swing.UnitLoadingDialog; import megamek.common.*; +import megamek.common.util.C3Util; import megameklab.printing.*; import megameklab.ui.dialog.MegaMekLabUnitSelectorDialog; import megameklab.ui.dialog.PrintQueueDialog; @@ -75,6 +76,15 @@ public static void printMUL(JFrame parent, boolean printToPdf) { 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); + } + new PrintQueueDialog(parent, printToPdf, loadedUnits, true).setVisible(true); }