Skip to content

Commit

Permalink
Merge pull request #4856 from IllianiCBT/stratCon_reinforcementVictor…
Browse files Browse the repository at this point in the history
…yPointUsage

Removed Automatic Conversion of CVP into SP when Reinforcing in StratCon
  • Loading branch information
HammerGS authored Sep 25, 2024
2 parents a3aca01 + a22f4d6 commit 118921e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 58 deletions.
12 changes: 7 additions & 5 deletions MekHQ/src/mekhq/campaign/stratcon/StratconRulesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,13 @@ private static void increaseFatigue(int forceID, Campaign campaign) {
}

/**
* Worker function that processes the effects of deploying a reinforcement force
* to a scenario
* Worker function that processes the effects of deploying a reinforcement force to a scenario
*
* @param reinforcementType the type of reinforcement being deployed
* @param campaignState the state of the campaign
* @param scenario the current scenario
* @param campaign the campaign instance
* @return {@code true} if the reinforcement deployment is successful, {@code false} otherwise
*/
public static boolean processReinforcementDeployment(ReinforcementEligibilityType reinforcementType,
StratconCampaignState campaignState, StratconScenario scenario, Campaign campaign) {
Expand All @@ -590,9 +595,6 @@ public static boolean processReinforcementDeployment(ReinforcementEligibilityTyp
if (campaignState.getSupportPoints() > 0) {
campaignState.useSupportPoint();
return true;
} else if (campaignState.getVictoryPoints() > 0) {
campaignState.updateVictoryPoints(-1);
return true;
}

int tactics = scenario.getBackingScenario().getLanceCommanderSkill(SkillType.S_TACTICS, campaign);
Expand Down
91 changes: 38 additions & 53 deletions MekHQ/src/mekhq/gui/stratcon/StratconScenarioWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,6 @@
*/
package mekhq.gui.stratcon;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.UUID;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;

import megamek.common.Minefield;
import mekhq.MekHQ;
import mekhq.campaign.Campaign;
Expand All @@ -52,7 +32,15 @@
import mekhq.campaign.stratcon.StratconScenario.ScenarioState;
import mekhq.campaign.stratcon.StratconTrackState;
import mekhq.campaign.unit.Unit;
import mekhq.utilities.ReportingUtilities;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.*;

import static mekhq.utilities.ReportingUtilities.messageSurroundedBySpanWithColor;

/**
* UI for managing force/unit assignments for individual StratCon scenarios.
Expand Down Expand Up @@ -306,25 +294,26 @@ private JList<Force> addAvailableForceList(JPanel parent, GridBagConstraints gbc
* Adds an individual unit selector, given a list of individual units, a global
* grid bag constraint set
* and a maximum selection size.
*
* @param units The list of units to use as data source.
* @param gbc Gridbag constraints to indicate where the control
* will go
*
* @param units The list of units to use as a data source.
* @param gridBagConstraints Gridbag constraints to indicate where the control will go
* @param maxSelectionSize Maximum number of units that can be selected
*/
private JList<Unit> addIndividualUnitSelector(List<Unit> units, GridBagConstraints gbc, int maxSelectionSize) {
private JList<Unit> addIndividualUnitSelector(List<Unit> units, GridBagConstraints gridBagConstraints,
int maxSelectionSize) {
JPanel unitPanel = new JPanel();
unitPanel.setLayout(new GridBagLayout());
GridBagConstraints localGbc = new GridBagConstraints();
GridBagConstraints localGridBagConstraints = new GridBagConstraints();

localGbc.gridx = 0;
localGbc.gridy = 0;
localGbc.anchor = GridBagConstraints.WEST;
localGridBagConstraints.gridx = 0;
localGridBagConstraints.gridy = 0;
localGridBagConstraints.anchor = GridBagConstraints.WEST;
JLabel instructions = new JLabel();
instructions.setText(String.format(resourceMap.getString("lblSelectIndividualUnits.text"), maxSelectionSize));
instructions.setText(String.format(resourceMap.getString("lblSelectIndividualUnits.text"),
maxSelectionSize));
unitPanel.add(instructions);

localGbc.gridy++;
localGridBagConstraints.gridy++;
DefaultListModel<Unit> availableModel = new DefaultListModel<>();
availableModel.addAll(units);

Expand All @@ -334,8 +323,8 @@ private JList<Unit> addIndividualUnitSelector(List<Unit> units, GridBagConstrain
JLabel unitSelectionLabel = new JLabel();
unitSelectionLabel.setText("0 selected");

localGbc.gridy++;
unitPanel.add(unitSelectionLabel, localGbc);
localGridBagConstraints.gridy++;
unitPanel.add(unitSelectionLabel, localGridBagConstraints);

JList<Unit> availableUnits = new JList<>();
availableUnits.setModel(availableModel);
Expand All @@ -345,15 +334,15 @@ private JList<Unit> addIndividualUnitSelector(List<Unit> units, GridBagConstrain

JScrollPane infantryContainer = new JScrollPane();
infantryContainer.setViewportView(availableUnits);
localGbc.gridy++;
unitPanel.add(infantryContainer, localGbc);
localGridBagConstraints.gridy++;
unitPanel.add(infantryContainer, localGridBagConstraints);

// add the 'status display' control
localGbc.gridx++;
localGbc.anchor = GridBagConstraints.NORTHWEST;
unitPanel.add(unitStatusLabel, localGbc);
localGridBagConstraints.gridx++;
localGridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
unitPanel.add(unitStatusLabel, localGridBagConstraints);

getContentPane().add(unitPanel, gbc);
getContentPane().add(unitPanel, gridBagConstraints);

return availableUnits;
}
Expand Down Expand Up @@ -412,22 +401,18 @@ private String buildUnitStatus(Unit u) {
*/
private String buildForceCost(int forceID) {
StringBuilder costBuilder = new StringBuilder();
costBuilder.append("(");
costBuilder.append('(');

switch (StratconRulesManager.getReinforcementType(forceID, currentTrackState, campaign, currentCampaignState)) {
case SupportPoint:
costBuilder.append(resourceMap.getString("supportPoint.text"));

if (currentCampaignState.getSupportPoints() <= 0) {
costBuilder.append(", ");

if (currentCampaignState.getVictoryPoints() <= 1) {
costBuilder.append("<span color='").append(MekHQ.getMHQOptions().getFontColorNegativeHexColor())
.append("'>")
.append(resourceMap.getString("reinforcementRoll.Text"))
.append(ReportingUtilities.CLOSING_SPAN_TAG);
} else {
costBuilder.append(resourceMap.getString("supportPointConvert.text"));
}
costBuilder.append(messageSurroundedBySpanWithColor(
MekHQ.getMHQOptions().getFontColorNegativeHexColor(),
resourceMap.getString("reinforcementRoll.Text")));
}
break;
case ChainedScenario:
Expand All @@ -441,7 +426,7 @@ private String buildForceCost(int forceID) {
break;
}

costBuilder.append(")");
costBuilder.append(')');
return costBuilder.toString();
}

Expand Down Expand Up @@ -538,7 +523,7 @@ private void btnCommitClicked(ActionEvent e) {
/**
* Event handler for when the user makes a selection on the available force
* selector.
*
*
* @param e The event fired.
*/
private void availableForceSelectorChanged(ListSelectionEvent e, JLabel forceStatusLabel, boolean reinforcements) {
Expand Down Expand Up @@ -569,7 +554,7 @@ private void availableForceSelectorChanged(ListSelectionEvent e, JLabel forceSta
* Event handler for when an available unit selector's selection changes.
* Updates the "# units selected" label and the unit status label.
* Also checks maximum selection size and disables commit button (TBD).
*
*
* @param e
* @param selectionCountLabel Which label to update with how many items are
* selected
Expand Down Expand Up @@ -625,7 +610,7 @@ private void availableUnitSelectorChanged(ListSelectionEvent e, JLabel selection

/**
* Worker function that de-selects duplicate units.
*
*
* @param listToProcess
* @param selectedUnits
*/
Expand Down

0 comments on commit 118921e

Please sign in to comment.