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 Customization Option to Refit Dialog #4992

Merged
merged 4 commits into from
Oct 8, 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
3 changes: 2 additions & 1 deletion MekHQ/resources/mekhq/resources/ChooseRefitDialog.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
btnOK.text=Begin Refit
btnRefit.text=Acquire and Use Refit Kit
btnCustomize.text=Customize to Model
btnClose.text=Cancel
title.text=Available Refits for
refitTable.title=Available Refits
Expand Down
6 changes: 0 additions & 6 deletions MekHQ/src/mekhq/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ public static File[] getAllFiles(String dir, FilenameFilter filter) {
}

public static ArrayList<String> getAllVariants(Entity en, Campaign campaign) {
CampaignOptions options = campaign.getCampaignOptions();
ArrayList<String> variants = new ArrayList<>();

for (MekSummary summary : MekSummaryCache.getInstance().getAllMeks()) {
Expand All @@ -237,11 +236,6 @@ public static ArrayList<String> getAllVariants(Entity en, Campaign campaign) {
}
}

// If we only allow canon units and this isn't canon we continue
if (!summary.isCanon() && options.isAllowCanonRefitOnly()) {
continue;
}

// If the unit doesn't meet the tech filter criteria we continue
ITechnology techProg = UnitTechProgression.getProgression(summary, campaign.getTechFaction(), true);
if (techProg == null) {
Expand Down
6 changes: 4 additions & 2 deletions MekHQ/src/mekhq/campaign/parts/Refit.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class Refit extends Part implements IAcquisitionWork {
private boolean failedCheck;
private boolean customJob;
private boolean isRefurbishing;
private boolean isSavingFile;
private boolean kitFound;
private boolean replacingLocations;
private String fixableString;
Expand Down Expand Up @@ -128,10 +129,11 @@ public Refit() {
cost = Money.zero();
}

public Refit(Unit oUnit, Entity newEn, boolean custom, boolean refurbish) {
public Refit(Unit oUnit, Entity newEn, boolean custom, boolean refurbish, boolean saveFile) {
this();
isRefurbishing = refurbish;
customJob = custom;
isSavingFile = saveFile;
oldUnit = oUnit;
newEntity = newEn;
newEntity.setOwner(oldUnit.getEntity().getOwner());
Expand Down Expand Up @@ -1044,7 +1046,7 @@ public void calculate() {
}

public void begin() throws EntityLoadingException, IOException {
if (customJob) {
if (customJob && isSavingFile) {
saveCustomization();
}
oldUnit.setRefit(this);
Expand Down
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/MekLabTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void refreshRefitSummary() {
if (null == entity) {
return;
}
refit = new Refit(unit, entity, true, false);
refit = new Refit(unit, entity, true, false, true);
testEntity = null;
if (entity instanceof SmallCraft) {
testEntity = new TestSmallCraft((SmallCraft) entity, entityVerifier.aeroOption, null);
Expand Down
6 changes: 3 additions & 3 deletions MekHQ/src/mekhq/gui/adapter/UnitTableMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public void actionPerformed(ActionEvent action) {
Stream.of(units).filter(Unit::isRefitting).forEach(unit -> unit.getRefit().succeed());
} else if (command.equals(COMMAND_REFURBISH)) {
for (Unit unit : units) {
Refit refit = new Refit(unit, unit.getEntity(), false, true);
Refit refit = new Refit(unit, unit.getEntity(), false, true, false);
gui.refitUnit(refit, false);
}
} else if (command.equals(COMMAND_REFIT_KIT)) { // Single Unit or Multiple of Units of the same type only
Expand All @@ -381,7 +381,7 @@ public void actionPerformed(ActionEvent action) {
Entity refitEntity = new MekFileParser(summary.getSourceFile(), summary.getEntryName())
.getEntity();
if (refitEntity != null) {
Refit refit = new Refit(unit, refitEntity, false, false);
Refit refit = new Refit(unit, refitEntity, crd.isCustomize(), false, false);
if (refit.checkFixable() == null) {
gui.refitUnit(refit, false);
}
Expand Down Expand Up @@ -850,7 +850,7 @@ protected Optional<JPopupMenu> createPopupMenu() {
|| (unit.getEntity() instanceof Aero)
|| ((unit.getEntity() instanceof Infantry)))) {
menuItem = new JMenuItem(unit.getEntity().isOmni() ? "Choose configuration..."
: "Choose Refit Kit...");
: "Refit/Customize...");
menuItem.setActionCommand(COMMAND_REFIT_KIT);
menuItem.addActionListener(this);
menu.add(menuItem);
Expand Down
66 changes: 41 additions & 25 deletions MekHQ/src/mekhq/gui/dialog/ChooseRefitDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public class ChooseRefitDialog extends JDialog {
private RefitTableModel refitModel;

private JButton btnClose;
private JButton btnOK;
private JButton btnRefit;
private JButton btnCustomize;
private JTable refitTable;
private JScrollPane scrRefitTable;
private JList<String> lstShopping;
Expand All @@ -77,6 +78,7 @@ public class ChooseRefitDialog extends JDialog {
private JScrollPane scrNewUnit;

private boolean confirmed = false;
private boolean customize = false;
// endregion Variable Declarations

// region Constructors
Expand Down Expand Up @@ -162,7 +164,7 @@ private void initComponents() {
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridheight = 2;
gridBagConstraints.weightx = 0.0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
Expand All @@ -182,28 +184,20 @@ private void initComponents() {
getContentPane().add(scrNewUnit, gridBagConstraints);

JPanel panBtn = new JPanel(new GridBagLayout());
btnOK = new JButton(resourceMap.getString("btnOK.text"));
btnOK.setEnabled(false);
btnOK.addActionListener(evt -> confirm());
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.anchor = GridBagConstraints.EAST;
gridBagConstraints.insets = new Insets(5, 5, 5, 5);
panBtn.add(btnOK, gridBagConstraints);

btnRefit = new JButton(resourceMap.getString("btnRefit.text"));
btnRefit.setEnabled(false);
btnRefit.addActionListener(evt -> confirmRefit());
panBtn.add(btnRefit, new GridBagConstraints());

btnCustomize = new JButton(resourceMap.getString("btnCustomize.text"));
btnCustomize.setEnabled(false);
btnCustomize.addActionListener(evt -> confirmCustomize());
panBtn.add(btnCustomize, new GridBagConstraints());

btnClose = new JButton(resourceMap.getString("btnClose.text"));
btnClose.addActionListener(evt -> cancel());
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.fill = GridBagConstraints.NONE;
gridBagConstraints.anchor = GridBagConstraints.WEST;
gridBagConstraints.insets = new Insets(5, 5, 5, 5);
panBtn.add(btnClose, gridBagConstraints);
panBtn.add(btnClose, new GridBagConstraints());

gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
Expand Down Expand Up @@ -231,8 +225,15 @@ private void setUserPreferences() {
}
// endregion Initialization

private void confirm() {
private void confirmRefit() {
confirmed = getSelectedRefit() != null;
customize = false;
setVisible(false);
}

private void confirmCustomize() {
confirmed = getSelectedRefit() != null;
customize = true;
setVisible(false);
}

Expand All @@ -244,6 +245,11 @@ public boolean isConfirmed() {
return confirmed;
}

public boolean isCustomize() {
return customize;
}


public Refit getSelectedRefit() {
int selectedRow = refitTable.getSelectedRow();
if (selectedRow < 0) {
Expand All @@ -257,10 +263,20 @@ private void refitTableValueChanged() {
if (null == r) {
scrShoppingList.setViewportView(null);
txtNewUnit.setText("");
btnOK.setEnabled(false);
btnRefit.setEnabled(false);
btnCustomize.setEnabled(false);
return;
}
btnOK.setEnabled(true);

if (!campaign.getCampaignOptions().isAllowCanonRefitOnly() || r.getNewEntity().isCanon()) {
btnRefit.setEnabled(true);
} else {
btnRefit.setEnabled(false);
}
btnCustomize.setEnabled(true);



lstShopping = new JList<>(r.getShoppingListDescription());
scrShoppingList.setViewportView(lstShopping);
MekView mv = new MekView(r.getNewEntity(), false, true);
Expand All @@ -284,7 +300,7 @@ private void populateRefits() {
try {
Entity refitEn = new MekFileParser(summary.getSourceFile(), summary.getEntryName()).getEntity();
if (null != refitEn) {
Refit r = new Refit(unit, refitEn, false, false);
Refit r = new Refit(unit, refitEn, false, false, false);
if (null == r.checkFixable()) {
refits.add(r);
}
Expand Down
18 changes: 9 additions & 9 deletions MekHQ/unittests/mekhq/campaign/parts/RefitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void newRefitCtor() {
oldUnit.initializeParts(false);

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
assertEquals(mockCampaign, refit.getCampaign());

// Should be old parts...
Expand Down Expand Up @@ -156,7 +156,7 @@ public void locust1Vto1ETest() {
oldUnit.initializeParts(false);

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
assertEquals(mockCampaign, refit.getCampaign());

//
Expand Down Expand Up @@ -238,7 +238,7 @@ public void testLocust1Vto1EWriteToXml() throws ParserConfigurationException, SA
}

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);

// Write the Refit XML
StringWriter sw = new StringWriter();
Expand Down Expand Up @@ -345,7 +345,7 @@ public void javelinJVN10Nto10ATest() {
oldUnit.initializeParts(false);

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
assertEquals(mockCampaign, refit.getCampaign());

//
Expand Down Expand Up @@ -428,7 +428,7 @@ public void testJavelinJVN10Nto10AWriteToXml() throws ParserConfigurationExcepti
}

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
refit.setTech(mockTech);
refit.addTimeSpent(60); // 1 hour of work!

Expand Down Expand Up @@ -537,7 +537,7 @@ public void fleaFLE4toFLE15Test() {
oldUnit.initializeParts(false);

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
assertEquals(mockCampaign, refit.getCampaign());

//
Expand Down Expand Up @@ -647,7 +647,7 @@ public void testFleaFLE4toFLE15WriteToXml() throws ParserConfigurationException,
}

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
refit.setTech(mockTech);
refit.addTimeSpent(60); // 1 hour of work!

Expand Down Expand Up @@ -768,7 +768,7 @@ public void heavyTrackedApcMgToStandard() throws EntityLoadingException, IOExcep
oldUnit.initializeParts(false);

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
assertEquals(mockCampaign, refit.getCampaign());

// We're removing 4 Machine Guns and a Full Bin of Machine Gun Ammo
Expand Down Expand Up @@ -819,7 +819,7 @@ public void testMasakariAtoMasakariB() {
oldUnit.initializeParts(false);

// Create the Refit
Refit refit = new Refit(oldUnit, newEntity, false, false);
Refit refit = new Refit(oldUnit, newEntity, false, false, false);
assertEquals(mockCampaign, refit.getCampaign());

// Omni reconfiguration
Expand Down