diff --git a/MekHQ/resources/mekhq/resources/CampaignGUI.properties b/MekHQ/resources/mekhq/resources/CampaignGUI.properties index 941f8120c4..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=Clear Units +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=<html>Start a game of MegaMek with all the assigned units played by bots.<br>At the game's conclusion, you will be presented with a series of dialogs for resolving the scenario.</html> 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. + * + * <p>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<StratconScenario> 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..165241e711 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,27 @@ 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; } + + // This handles StratCon undeployment + if (scenario instanceof AtBScenario) { + StratconScenario stratConScenario = ((AtBScenario) scenario).getStratconScenario(getCampaign()); + + if (stratConScenario != null) { + stratConScenario.resetScenario(getCampaign()); + return; + } + } + + // This handles Legacy AtB undeployment scenario.clearAllForcesAndPersonnel(getCampaign()); } } @@ -1282,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); + + 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);