Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle for RS adjusted BV printing, and set default export filename #1582

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

import megamek.client.ui.baseComponents.MMButton;
import megamek.client.ui.swing.UnitLoadingDialog;
import megamek.common.BTObject;
import megamek.common.Configuration;
import megamek.common.Entity;
import megamek.common.MechFileParser;
import megamek.common.*;
import megamek.common.util.C3Util;
import megameklab.printing.PageBreak;
import megameklab.util.UnitPrintManager;
import org.apache.commons.io.FilenameUtils;
import org.apache.logging.log4j.LogManager;

import javax.swing.*;
Expand Down Expand Up @@ -65,17 +64,21 @@ public class PrintQueueDialog extends AbstractMMLButtonDialog {
private final JButton moveBottomButton = new JButton(icon("moveBottom.png"));

private final JCheckBox oneUnitPerSheetCheck = new JCheckBox("Print each unit to a separate page");
private final JCheckBox adjustedBvCheck = new JCheckBox("Print force-adjusted BV");
private final JFrame parent;
private final List<BTObject> units = new ArrayList<>();
private final JList<String> queuedUnitList = new JList<>();

private final boolean fromMul;

public PrintQueueDialog(JFrame parent, boolean printToPdf, List<? extends BTObject> units, boolean fromMul) {
private final String mulFileName;

public PrintQueueDialog(JFrame parent, boolean printToPdf, List<? extends BTObject> units, boolean fromMul, String mulFileName) {
super(parent, true, "PrintQueueDialog", "PrintQueueDialog.windowName.text");
this.parent = parent;
this.printToPdf = printToPdf;
this.fromMul = fromMul;
this.mulFileName = mulFileName;
initialize();
if (units != null) {
this.units.addAll(units);
Expand All @@ -84,7 +87,7 @@ public PrintQueueDialog(JFrame parent, boolean printToPdf, List<? extends BTObje
}

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

private static ImageIcon icon(String name) {
Expand Down Expand Up @@ -124,6 +127,11 @@ protected Container createCenterPane() {
oneUnitPerSheetCheck.setAlignmentX(JComponent.CENTER_ALIGNMENT);
oneUnitPerSheetCheck.setToolTipText("When unchecked, the record sheets for some unit types may be printed on the same page. " +
"Note that the result may depend on whether reference tables are printed. This can be changed in the Settings.");

adjustedBvCheck.setAlignmentX(JComponent.CENTER_ALIGNMENT);
adjustedBvCheck.setToolTipText("When checked, printed BV is adjusted for force modifiers (C3, TAG, etc.). " +
"BV is always adjusted for pilot skill.");

queuedUnitList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
queuedUnitList.addListSelectionListener(new OnSelectionChanged());
queuedUnitList.setVisibleRowCount(15);
Expand Down Expand Up @@ -158,6 +166,9 @@ protected Container createCenterPane() {
Box panel = Box.createVerticalBox();
panel.add(centerPanel);
panel.add(oneUnitPerSheetCheck);
if (fromMul) {
panel.add(adjustedBvCheck);
}
panel.add(Box.createVerticalStrut(20));
return panel;
}
Expand Down Expand Up @@ -194,8 +205,25 @@ private void refresh() {

@Override
protected void okButtonActionPerformed(ActionEvent evt) {
if (fromMul) {
if (adjustedBvCheck.isSelected()) {
Game g = new Game();
Player p = new Player(1, "Nobody");
for (Entity e : units.stream().filter(i -> i instanceof Entity).map(i -> (Entity) i).toList()) {
e.setOwner(p);
g.addEntity(e);
C3Util.wireC3(g, e);
}
}
}

if (printToPdf) {
File exportFile = UnitPrintManager.getExportFile(parent);
File exportFile;
if (mulFileName.isBlank()) {
exportFile = UnitPrintManager.getExportFile(parent);
} else {
exportFile = UnitPrintManager.getExportFile(parent, FilenameUtils.removeExtension(mulFileName) + ".pdf");
}
if (exportFile != null) {
UnitPrintManager.exportUnits(units, exportFile, oneUnitPerSheetCheck.isSelected());
} else {
Expand Down
13 changes: 2 additions & 11 deletions megameklab/src/megameklab/util/UnitPrintManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,14 @@ 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);
new PrintQueueDialog(parent, printToPdf, loadedUnits, true, f.getSelectedFile().getName()).setVisible(true);
}

public static File getExportFile(Frame parent) {
return getExportFile(parent, "");
}

private static File getExportFile(Frame parent, String suggestedFileName) {
public static File getExportFile(Frame parent, String suggestedFileName) {
JFileChooser f = new JFileChooser(System.getProperty("user.dir"));
f.setLocation(parent.getLocation().x + 150, parent.getLocation().y + 100);
f.setDialogTitle("Choose export file name");
Expand Down