Skip to content

Commit

Permalink
Preserve C3 state when saving a force
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbraginskiy committed Aug 21, 2024
1 parent 10bb5f3 commit 91bb560
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions megameklab/src/megameklab/ui/dialog/PrintQueueDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package megameklab.ui.dialog;

import megamek.client.Client;
import megamek.client.generator.RandomNameGenerator;
import megamek.client.ui.baseComponents.MMButton;
import megamek.client.ui.swing.ClientGUI;
import megamek.client.ui.swing.UnitLoadingDialog;
Expand All @@ -40,7 +41,6 @@
import java.awt.event.KeyEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -144,10 +144,10 @@ protected Container createCenterPane() {

JPanel buttonPanel = new FixedXYPanel(new GridLayout(5, 1));
if (!fromMul) {
buttonPanel.add(addFromCacheButton);
buttonPanel.add(addFromFileButton);
saveButton.setEnabled(false);
}
buttonPanel.add(addFromCacheButton);
buttonPanel.add(addFromFileButton);
buttonPanel.add(addPageBreakButton);
buttonPanel.add(removeButton);
buttonPanel.add(saveButton);
Expand Down Expand Up @@ -175,6 +175,7 @@ protected Container createCenterPane() {
checkboxPanel.add(oneUnitPerSheetCheck);
if (fromMul) {
checkboxPanel.add(adjustedBvCheck);
adjustedBvCheck.setSelected(true);
}

Box panel = Box.createVerticalBox();
Expand Down Expand Up @@ -203,7 +204,9 @@ private void refresh() {
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());
if (!crew.getName().startsWith(RandomNameGenerator.UNNAMED)) {
title += String.format(" {%s %d/%d}", crew.getName(), crew.getGunnery(), crew.getPiloting());
}
}
return title;
})
Expand All @@ -216,17 +219,30 @@ private void refresh() {
saveButton.setEnabled(units.stream().anyMatch(unit -> unit instanceof Entity));
}

private void linkForce() {
Game g = new Game();
Player p = new Player(1, "Nobody");
for (Entity e : getEntities()) {
e.setOwner(p);
g.addEntity(e);
C3Util.wireC3(g, e);
}
}

private void unlinkForce() {
int id = 1;
for (Entity e : getEntities()) {
e.setOwner(new Player(id++, "Nobody"));
}
}

@Override
protected void okButtonActionPerformed(ActionEvent evt) {
if (fromMul) {
if (adjustedBvCheck.isSelected()) {
Game g = new Game();
Player p = new Player(1, "Nobody");
for (Entity e : getEntities()) {
e.setOwner(p);
g.addEntity(e);
C3Util.wireC3(g, e);
}
linkForce();
} else {
unlinkForce();
}
}

Expand All @@ -251,6 +267,7 @@ protected void okButtonActionPerformed(ActionEvent evt) {
private void saveUnitList() {
// todo: Refactor saveListFile to be a static method of some util class
// --Pavel
linkForce();
new ClientGUI(new Client("", "", 0), null).saveListFile(getEntities(), "Units");
}

Expand Down

0 comments on commit 91bb560

Please sign in to comment.