From d7eb29b541b7e4f14917341a16d000cb54f0e02a Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Thu, 9 Jan 2025 21:21:01 -0600 Subject: [PATCH 1/3] Refactored scenario reset logic for StratCon missions Updated the unit clearing functionality to reset StratCon scenarios when applicable. Introduced a new method in `AtBScenario` to retrieve the associated StratCon scenario. Adjusted UI text and button enable logic to reflect changes and restrict deployment reset to GM mode. --- .../mekhq/resources/CampaignGUI.properties | 2 +- .../mekhq/campaign/mission/AtBScenario.java | 50 +++++++++++++++++++ MekHQ/src/mekhq/gui/BriefingTab.java | 19 +++++-- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/MekHQ/resources/mekhq/resources/CampaignGUI.properties b/MekHQ/resources/mekhq/resources/CampaignGUI.properties index 941f8120c4..1f93a8bbe9 100644 --- a/MekHQ/resources/mekhq/resources/CampaignGUI.properties +++ b/MekHQ/resources/mekhq/resources/CampaignGUI.properties @@ -180,7 +180,7 @@ btnPrintRS.text=Print Sheets btnGetMul.toolTipText=Get a MUL file of all assigned units that can be loaded into MegaMek btnGetMul.text=Export MUL File btnClearAssignedUnits.toolTipText=Clear all assigned units for this scenario -btnClearAssignedUnits.text=Clear Units +btnClearAssignedUnits.text=Reset Deployment (GM) btnResolveScenario.toolTipText=Bring up a wizard that will guide you through the process of resolving this scenario either by MUL files from a MegaMek game or by manually editing for tabletop games. btnResolveScenario.text=Resolve Manually btnAutoResolveScenario.toolTipText=Start a game of MegaMek with all the assigned units played by bots.
At the game's conclusion, you will be presented with a series of dialogs for resolving the scenario. diff --git a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java index 0e96989611..6a2cabc31d 100644 --- a/MekHQ/src/mekhq/campaign/mission/AtBScenario.java +++ b/MekHQ/src/mekhq/campaign/mission/AtBScenario.java @@ -50,6 +50,9 @@ import mekhq.campaign.rating.IUnitRating; import mekhq.campaign.stratcon.StratconBiomeManifest; import mekhq.campaign.stratcon.StratconBiomeManifest.MapTypeList; +import mekhq.campaign.stratcon.StratconCampaignState; +import mekhq.campaign.stratcon.StratconScenario; +import mekhq.campaign.stratcon.StratconTrackState; import mekhq.campaign.unit.Unit; import mekhq.campaign.universe.*; import mekhq.utilities.MHQXMLUtility; @@ -2116,4 +2119,51 @@ public String getDeploymentInstructions() { public boolean canStartScenario(Campaign c) { return c.getLocalDate().equals(getDate()) && super.canStartScenario(c); } + + /** + * Retrieves the {@link StratconScenario} associated with the current mission ID. + * + *

The method first retrieves the {@link AtBContract} from the given campaign. + * If the contract, its {@link StratconCampaignState}, or any required track data + * is unavailable, the method returns {@code null}. It iterates through all + * {@link StratconTrackState} objects in the campaign state and their associated scenarios. + * If a {@link StratconScenario} contains a non-null {@link AtBDynamicScenario} whose + * mission ID matches the current mission ID, it is returned. + * + * @param campaign the {@link Campaign} instance being queried for the scenario + * @return the matching {@link StratconScenario} if found, or {@code null} if no match + * is found or any required data is missing + * @throws NullPointerException if {@code campaign} is {@code null} + */ + public @Nullable StratconScenario getStratconScenario(Campaign campaign) { + // Get contract + AtBContract contract = getContract(campaign); + if (contract == null) { + return null; + } + + // Fetch campaign state + StratconCampaignState campaignState = contract.getStratconCampaignState(); + if (campaignState == null) { + return null; + } + + // Find associated StratCon Scenario, if any + for (StratconTrackState track : campaignState.getTracks()) { + Collection trackScenarios = track.getScenarios().values(); + + for (StratconScenario scenario : trackScenarios) { + AtBDynamicScenario backingScenario = scenario.getBackingScenario(); + if (backingScenario == null) { + continue; + } + + if (backingScenario.getMissionId() == getMissionId()) { + return scenario; + } + } + } + + return null; + } } diff --git a/MekHQ/src/mekhq/gui/BriefingTab.java b/MekHQ/src/mekhq/gui/BriefingTab.java index f896d3b690..985255eeff 100644 --- a/MekHQ/src/mekhq/gui/BriefingTab.java +++ b/MekHQ/src/mekhq/gui/BriefingTab.java @@ -46,6 +46,7 @@ import mekhq.campaign.personnel.autoAwards.AutoAwardsController; import mekhq.campaign.personnel.enums.PersonnelRole; import mekhq.campaign.personnel.enums.PersonnelStatus; +import mekhq.campaign.stratcon.StratconScenario; import mekhq.campaign.unit.Unit; import mekhq.campaign.universe.Faction; import mekhq.campaign.universe.Factions; @@ -676,13 +677,25 @@ private void addScenario() { } private void clearAssignedUnits() { - if (0 == JOptionPane.showConfirmDialog(null, "Do you really want to remove all units from this scenario?", + if (0 == JOptionPane.showConfirmDialog(null, + "Do you really want to remove all units from this scenario?", "Clear Units?", JOptionPane.YES_NO_OPTION)) { int row = scenarioTable.getSelectedRow(); Scenario scenario = scenarioModel.getScenario(scenarioTable.convertRowIndexToModel(row)); - if (null == scenario) { + + if (scenario == null) { return; } + + if (scenario instanceof AtBScenario) { + StratconScenario stratConScenario = ((AtBScenario) scenario).getStratconScenario(getCampaign()); + + if (stratConScenario != null) { + stratConScenario.resetScenario(getCampaign()); + return; + } + } + scenario.clearAllForcesAndPersonnel(getCampaign()); } } @@ -1286,7 +1299,7 @@ public void refreshScenarioView() { btnJoinGame.setEnabled(canStartGame); btnLoadGame.setEnabled(canStartGame); btnGetMul.setEnabled(canStartGame); - btnClearAssignedUnits.setEnabled(canStartGame); + btnClearAssignedUnits.setEnabled(canStartGame && getCampaign().isGM()); btnResolveScenario.setEnabled(canStartGame); if (scenario instanceof AtBScenario) { btnAutoResolveScenario.setEnabled(canStartGame); From 0502a7b264ebbbdfa984d128e76a1e40e21467a7 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Thu, 9 Jan 2025 21:21:29 -0600 Subject: [PATCH 2/3] Handle StratCon and Legacy AtB scenario undeployment Added specific handling for StratCon undeployment and improved legacy AtB scenario cleanup by ensuring all forces and personnel are cleared. This enhances scenario management consistency during undeployment. --- MekHQ/src/mekhq/gui/BriefingTab.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MekHQ/src/mekhq/gui/BriefingTab.java b/MekHQ/src/mekhq/gui/BriefingTab.java index 985255eeff..82a07f7a15 100644 --- a/MekHQ/src/mekhq/gui/BriefingTab.java +++ b/MekHQ/src/mekhq/gui/BriefingTab.java @@ -687,6 +687,7 @@ private void clearAssignedUnits() { return; } + // This handles StratCon undeployment if (scenario instanceof AtBScenario) { StratconScenario stratConScenario = ((AtBScenario) scenario).getStratconScenario(getCampaign()); @@ -696,6 +697,7 @@ private void clearAssignedUnits() { } } + // This handles Legacy AtB undeployment scenario.clearAllForcesAndPersonnel(getCampaign()); } } From bab4c1f238cc3e758c597b466281a311529c6cd4 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Fri, 10 Jan 2025 10:08:29 -0600 Subject: [PATCH 3/3] Update deployment reset logic and clarify button text Adjusted `btnClearAssignedUnits` to allow usage outside GM mode if the scenario lacks a track. Updated the button tooltip and text for better clarity regarding GM restrictions and usage conditions. --- MekHQ/resources/mekhq/resources/CampaignGUI.properties | 5 +++-- MekHQ/src/mekhq/gui/BriefingTab.java | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/MekHQ/resources/mekhq/resources/CampaignGUI.properties b/MekHQ/resources/mekhq/resources/CampaignGUI.properties index 1f93a8bbe9..d0e434490c 100644 --- a/MekHQ/resources/mekhq/resources/CampaignGUI.properties +++ b/MekHQ/resources/mekhq/resources/CampaignGUI.properties @@ -179,8 +179,9 @@ btnPrintRS.toolTipText=Print record sheets for all currently assigned units. btnPrintRS.text=Print Sheets btnGetMul.toolTipText=Get a MUL file of all assigned units that can be loaded into MegaMek btnGetMul.text=Export MUL File -btnClearAssignedUnits.toolTipText=Clear all assigned units for this scenario -btnClearAssignedUnits.text=Reset Deployment (GM) +btnClearAssignedUnits.toolTipText=Clear all assigned units for this scenario. Restricted to GM Mode\ + \ if it is a scenario assigned to the Area of Operations. +btnClearAssignedUnits.text=Reset Deployment btnResolveScenario.toolTipText=Bring up a wizard that will guide you through the process of resolving this scenario either by MUL files from a MegaMek game or by manually editing for tabletop games. btnResolveScenario.text=Resolve Manually btnAutoResolveScenario.toolTipText=Start a game of MegaMek with all the assigned units played by bots.
At the game's conclusion, you will be presented with a series of dialogs for resolving the scenario. diff --git a/MekHQ/src/mekhq/gui/BriefingTab.java b/MekHQ/src/mekhq/gui/BriefingTab.java index 82a07f7a15..165241e711 100644 --- a/MekHQ/src/mekhq/gui/BriefingTab.java +++ b/MekHQ/src/mekhq/gui/BriefingTab.java @@ -1297,11 +1297,19 @@ public void refreshScenarioView() { SwingUtilities.invokeLater(() -> scrollScenarioView.getVerticalScrollBar().setValue(0)); final boolean canStartGame = scenario.canStartScenario(getCampaign()); + btnStartGame.setEnabled(canStartGame); btnJoinGame.setEnabled(canStartGame); btnLoadGame.setEnabled(canStartGame); btnGetMul.setEnabled(canStartGame); - btnClearAssignedUnits.setEnabled(canStartGame && getCampaign().isGM()); + + final boolean hasTrack = scenario.getHasTrack(); + if (hasTrack) { + btnClearAssignedUnits.setEnabled(canStartGame && getCampaign().isGM()); + } else { + btnClearAssignedUnits.setEnabled(canStartGame); + } + btnResolveScenario.setEnabled(canStartGame); if (scenario instanceof AtBScenario) { btnAutoResolveScenario.setEnabled(canStartGame);