From 6c596d00853e83aae3529e0790c13bce85e623be Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Thu, 9 Jan 2025 10:57:40 -0600 Subject: [PATCH 1/4] Handle unsupported units during campaign loading Added functionality to automatically sell unsupported units, such as gun emplacements, upon campaign load. Affected units are listed in a notification to the user, and their assigned personnel are unassigned. Updated resource bundle and supporting methods to accommodate this change. --- .../resources/mekhq/resources/GUI.properties | 6 +++ .../mekhq/gui/dialog/DataLoadingDialog.java | 53 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/MekHQ/resources/mekhq/resources/GUI.properties b/MekHQ/resources/mekhq/resources/GUI.properties index 1cc6ced859..5581abcbe4 100644 --- a/MekHQ/resources/mekhq/resources/GUI.properties +++ b/MekHQ/resources/mekhq/resources/GUI.properties @@ -593,6 +593,12 @@ DataLoadingDialog.OutOfMemoryError.text=MekHQ ran out of memory attempting to lo DataLoadingDialog.ExecutionException.title=Campaign Loading Error DataLoadingDialog.ExecutionException.text=The campaign file couldn't be loaded. \nPlease check the MekHQ.log file for details. +## Unsupported Units +unsupportedUnits.title=Unsupported Units Detected +unsupportedUnits.body=The following units are not supported by MekHQ and have been sold.\ +
\ +
All assigned personnel have been unassigned.

+ ### GMToolsDialog Class GMToolsDialog.title=GM Tools ## General Tab diff --git a/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java b/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java index fc713154ed..ad7d4b19d6 100644 --- a/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/DataLoadingDialog.java @@ -21,6 +21,8 @@ import megamek.client.generator.RandomCallsignGenerator; import megamek.client.generator.RandomNameGenerator; import megamek.client.ui.swing.util.UIUtil; +import megamek.common.Entity; +import megamek.common.GunEmplacement; import megamek.common.MekSummaryCache; import megamek.common.annotations.Nullable; import megamek.common.options.OptionsConstants; @@ -44,6 +46,7 @@ import mekhq.campaign.rating.CamOpsReputation.ReputationController; import mekhq.campaign.storyarc.StoryArc; import mekhq.campaign.storyarc.StoryArcStub; +import mekhq.campaign.unit.Unit; import mekhq.campaign.universe.Factions; import mekhq.campaign.universe.RATManager; import mekhq.campaign.universe.Systems; @@ -58,6 +61,8 @@ import java.io.File; import java.io.FileInputStream; import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -422,12 +427,60 @@ public Campaign doInBackground() throws Exception { reputationController.initializeReputation(campaign); campaign.setReputation(reputationController); } + + sellUnsupportedUnits(campaign); // endregion Progress 7 } campaign.setApp(getApplication()); return campaign; } + + + /** + * Sells unsupported units. + *

+ * This method checks all units in the specified campaign and determines if they are unsupported. + * Currently, only gun emplacements are identified as unsupported and are sold upon campaign load. + * If unsupported units are sold, a notification is displayed to the user detailing the sold units, + * including their names and IDs. Additionally, personnel assigned to these units are + * automatically unassigned. + *

+ * + * @param retVal The campaign being checked for unsupported units. This includes the unit list + * and the quartermaster who handles the selling process. + */ + private static void sellUnsupportedUnits(Campaign retVal) { + List soldUnits = new ArrayList<>(); + for (Unit unit : retVal.getUnits()) { + Entity entity = unit.getEntity(); + + if (entity == null) { + continue; + } + + // We don't support Gun Emplacements in mhq. + // If the user has somehow acquired one, it is sold on load. + if (entity instanceof GunEmplacement) { + soldUnits.add(unit); + } + } + + if (!soldUnits.isEmpty()) { + StringBuilder message = new StringBuilder(resources.getString("unsupportedUnits.body")); + + for (Unit soldUnit : soldUnits) { + retVal.getQuartermaster().sellUnit(soldUnit); + message.append("- ").append(soldUnit.getName()).append("
"); + } + + JOptionPane.showMessageDialog(null, + String.format("%s", message), + resources.getString("unsupportedUnits.title"), + JOptionPane.WARNING_MESSAGE); + } + } + /** * Executed in event dispatching thread */ From f259e90ec9330b6aee321e81ea3de41c7cdcc3e7 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Thu, 9 Jan 2025 11:21:35 -0600 Subject: [PATCH 2/4] Prevent salvage of gun emplacements in scenarios. Excluded gun emplacements from salvage as they are unsupported in MekHQ. This ensures consistency and avoids unintended gameplay behavior during scenario resolution. --- MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java b/MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java index 1f9ba00997..7ccce69170 100644 --- a/MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java +++ b/MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java @@ -368,6 +368,11 @@ public void processGame() { } } } else if (wreck.getOwner().isEnemyOf(client.getLocalPlayer())) { + // MekHQ doesn't support gun emplacements, so we don't want the player salvaging them + if (wreck instanceof GunEmplacement) { + continue; + } + if (wreck.isDropShip() && scenario.getBoardType() != Scenario.T_SPACE) { double dropShipBonusPercentage = (double) campaign.getCampaignOptions().getDropShipBonusPercentage() / 100; From 878f61be70267770521936ff0728327b33e8271c Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Thu, 9 Jan 2025 11:21:42 -0600 Subject: [PATCH 3/4] Block unsupported Gun Emplacement units in selector Prevented the selection of Gun Emplacement units in MekHQ if they are unsupported. Added a user-facing message indicating the restriction and integrated appropriate resource strings for localization. This ensures better handling of unsupported unit types. --- .../mekhq/resources/CampaignGUI.properties | 1 + .../gui/dialog/MekHQUnitSelectorDialog.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/MekHQ/resources/mekhq/resources/CampaignGUI.properties b/MekHQ/resources/mekhq/resources/CampaignGUI.properties index 389f30489e..941f8120c4 100644 --- a/MekHQ/resources/mekhq/resources/CampaignGUI.properties +++ b/MekHQ/resources/mekhq/resources/CampaignGUI.properties @@ -49,6 +49,7 @@ miMHQOptions.text=MekHQ Options... miMHQOptions.toolTipText=This launches the MekHQ Options Dialog. menuThemes.text=Themes menuExit.text=Exit +mekSelectorDialog.unsupported.gunEmplacement=Gun Emplacements are %snot supported%s by MekHQ. # Marketplace Menu menuMarket.text=Marketplace diff --git a/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java b/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java index be4e1940c1..0257d716d5 100644 --- a/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java +++ b/MekHQ/src/mekhq/gui/dialog/MekHQUnitSelectorDialog.java @@ -23,6 +23,7 @@ import megamek.client.ui.swing.UnitLoadingDialog; import megamek.client.ui.swing.dialog.AbstractUnitSelectorDialog; import megamek.common.*; +import mekhq.MekHQ; import mekhq.campaign.Campaign; import mekhq.campaign.parts.enums.PartQuality; import mekhq.campaign.unit.UnitOrder; @@ -32,8 +33,12 @@ import java.awt.*; import java.util.ArrayList; import java.util.List; +import java.util.ResourceBundle; import java.util.regex.PatternSyntaxException; +import static mekhq.utilities.ReportingUtilities.CLOSING_SPAN_TAG; +import static mekhq.utilities.ReportingUtilities.spanOpeningWithCustomColor; + public class MekHQUnitSelectorDialog extends AbstractUnitSelectorDialog { //region Variable Declarations private Campaign campaign; @@ -125,6 +130,20 @@ protected JPanel createButtonsPanel() { @Override protected void select(boolean isGM) { if (getSelectedEntity() != null) { + // Block the purchase if the unit type is unsupported + if (selectedUnit.getEntity() instanceof GunEmplacement) { + final ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.CampaignGUI", + MekHQ.getMHQOptions().getLocale()); + + campaign.addReport(String.format( + resources.getString("mekSelectorDialog.unsupported.gunEmplacement"), + spanOpeningWithCustomColor(MekHQ.getMHQOptions().getFontColorNegativeHexColor()), + CLOSING_SPAN_TAG)); + + dispose(); + return; + } + if (isGM) { PartQuality quality = PartQuality.QUALITY_D; From b6ce36e1373090fd13edbf0db4c6341be667613a Mon Sep 17 00:00:00 2001 From: Sleet01 Date: Thu, 9 Jan 2025 10:22:06 -0800 Subject: [PATCH 4/4] Update history.txt --- MekHQ/docs/history.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/MekHQ/docs/history.txt b/MekHQ/docs/history.txt index e2eef39fe2..b655783ed1 100644 --- a/MekHQ/docs/history.txt +++ b/MekHQ/docs/history.txt @@ -58,6 +58,7 @@ MEKHQ VERSION HISTORY: + Fix #5570: Fixed Maternity Leave Date Handling + PR #5699: Moved ACAR Module to MegaMek + PR #5709: Added MHQDialogImmersive for Immersive Dialog Functionality that Immersively Improves Immersion ++ Fix #3752: Added Handling for Unsupported Unit Types 0.50.02 (2024-12-30 2130 UTC) + Fix #846, #5185: Fix BattleArmor customization/refit overweight check.