Skip to content

Commit

Permalink
Merge branch 'MegaMek:master' into wvr-4986-camops-pmarket-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WeaverThree authored Oct 9, 2024
2 parents 981e08c + 2a8f5f5 commit 3c8794d
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 92 deletions.
2 changes: 2 additions & 0 deletions MekHQ/docs/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ MEKHQ VERSION HISTORY:
+ PR #4981: Implemented Campaign Options IIC Preset Picker #4981
+ PR #4984: Refactored Daily Personnel Processing Logic.
+ PR #4989: Adaptation to MM #6068 Replace Manual GUI scaling with FlatLaf Scaling
+ PR #5002: Correct issues with fixed map generation #5002
+ PR #4992: Add Customization Option to Refit Dialog

0.50.0 (2024-09-01 2000 UTC) (THIS MARKS THE START OF JAVA 17 AS THE MINIMUM REQUIRED)
+ PR #4332: CI Updates for windows build and normalizing
Expand Down
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
34 changes: 1 addition & 33 deletions MekHQ/src/mekhq/campaign/mission/AtBDynamicScenarioFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static void finalizeScenario(AtBDynamicScenario scenario, AtBContract con
// approximate estimate, anyway.
scenario.setLanceCount(generatedLanceCount + (playerForceUnitCount / 4));
setScenarioMapSize(scenario);
setScenarioMap(scenario, campaign.getCampaignOptions().getFixedMapChance());
scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance());
setDeploymentZones(scenario);
setDestinationZones(scenario);

Expand Down Expand Up @@ -1387,38 +1387,6 @@ public static void setScenarioMapSize(AtBDynamicScenario scenario) {
scenario.setMapSizeY(mapSizeY);
}

/**
* If there are maps of the appropriate size available and we roll higher than
* the given threshold, replace the scenario's generated map with a fixed map
* from data/boards
*/
private static void setScenarioMap(AtBDynamicScenario scenario, int mapChance) {
if (scenario.getBoardType() != Scenario.T_SPACE
&& scenario.getTerrainType().equals("Space")
&& (scenario.getMapSizeX() > 0)
&& (scenario.getMapSizeY() > 0)
&& (Compute.randomInt(100) <= mapChance)) {
BoardClassifier bc = BoardClassifier.getInstance();
List<String> maps = bc.getMatchingBoards(scenario.getMapSizeX(), scenario.getMapSizeY(), 5, 5,
new ArrayList<>());

if (!maps.isEmpty()) {
String mapPath = ObjectUtility.getRandomItem(maps);
MegaMekFile mapFile = new MegaMekFile(mapPath);
BoardDimensions dimensions = Board.getSize(mapFile.getFile());

scenario.setMap(bc.getBoardPaths().get(mapPath));
scenario.setMapSizeX(dimensions.width());
scenario.setMapSizeY(dimensions.height());
scenario.setUsingFixedMap(true);
return;
}
}

scenario.setUsingFixedMap(false);
scenario.setMapFile();
}

/**
* Randomly generates the number of scenario modifiers for a scenario,
* for each random scenario in the count a random modifier is applied to the
Expand Down
43 changes: 35 additions & 8 deletions MekHQ/src/mekhq/campaign/mission/AtBScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@
import java.time.LocalDate;
import java.util.*;

import megamek.common.*;
import megamek.common.util.fileUtils.MegaMekFile;
import megamek.utilities.BoardClassifier;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import megamek.Version;
import megamek.client.generator.TeamLoadOutGenerator;
import megamek.codeUtilities.ObjectUtility;
import megamek.common.Board;
import megamek.common.Compute;
import megamek.common.Entity;
import megamek.common.EntityWeightClass;
import megamek.common.Infantry;
import megamek.common.TargetRoll;
import megamek.common.UnitType;
import megamek.common.WeatherRestriction;
import megamek.common.annotations.Nullable;
import megamek.common.enums.SkillLevel;
import megamek.common.icons.Camouflage;
Expand Down Expand Up @@ -492,6 +487,38 @@ public void setMapFile() {
setMapFile(getTerrainType());
}

/**
* If there are maps of the appropriate size available and we roll higher than
* the given threshold, replace the scenario's generated map with a fixed map
* from data/boards
*/
public void setScenarioMap(int mapChance) {
if (getBoardType() != Scenario.T_SPACE
&& !getTerrainType().equals("Space")
&& (getMapSizeX() > 0)
&& (getMapSizeY() > 0)
&& (Compute.randomInt(100) <= mapChance)) {
BoardClassifier bc = BoardClassifier.getInstance();
List<String> maps = bc.getMatchingBoards(getMapSizeX(), getMapSizeY(), 7, 7,
new ArrayList<>());

if (!maps.isEmpty()) {
String mapPath = ObjectUtility.getRandomItem(maps);
MegaMekFile mapFile = new MegaMekFile(mapPath);
BoardDimensions dimensions = Board.getSize(mapFile.getFile());

setMap(bc.getBoardPaths().get(mapPath));
setMapSizeX(dimensions.width());
setMapSizeY(dimensions.height());
setUsingFixedMap(true);
return;
}
}

setUsingFixedMap(false);
setMapFile();
}

public boolean canRerollTerrain() {
return canRerollMap();
}
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
12 changes: 8 additions & 4 deletions MekHQ/src/mekhq/gui/view/AtBScenarioViewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -797,22 +797,26 @@ private void countRerollBoxes() {
private void rerollBattleConditions() {
if (chkReroll[REROLL_TERRAIN] != null && chkReroll[REROLL_TERRAIN].isSelected()) {
scenario.setTerrain();
scenario.setMapFile();
scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance());
scenario.useReroll();
chkReroll[REROLL_TERRAIN].setSelected(false);
lblTerrainDesc.setText(scenario.getTerrainType());
lblMapDesc.setText(scenario.getMap());
lblMapDesc.setText(scenario.getMapForDisplay());
lblMapSizeDesc.setText(scenario.getMapSizeX() + "x" + scenario.getMapSizeY());
}
if (chkReroll[REROLL_MAP] != null && chkReroll[REROLL_MAP].isSelected()) {
scenario.setMapFile();
scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance());
scenario.useReroll();
chkReroll[REROLL_MAP].setSelected(false);
lblMapDesc.setText(scenario.getMap());
lblMapDesc.setText(scenario.getMapForDisplay());
lblMapSizeDesc.setText(scenario.getMapSizeX() + "x" + scenario.getMapSizeY());
}
if (chkReroll[REROLL_MAPSIZE] != null && chkReroll[REROLL_MAPSIZE].isSelected()) {
scenario.setMapSize();
scenario.setScenarioMap(campaign.getCampaignOptions().getFixedMapChance());
scenario.useReroll();
chkReroll[REROLL_MAPSIZE].setSelected(false);
lblMapDesc.setText(scenario.getMapForDisplay());
lblMapSizeDesc.setText(scenario.getMapSizeX() + "x" + scenario.getMapSizeY());
}
if (chkReroll[REROLL_LIGHT] != null && chkReroll[REROLL_LIGHT].isSelected()) {
Expand Down
Loading

0 comments on commit 3c8794d

Please sign in to comment.