Skip to content

Commit

Permalink
Refactored force handling logic in convoy and combat contexts
Browse files Browse the repository at this point in the history
Replaced iterations over strategic formations with all forces to streamline convoy checks. Modified setting of convoy status to ensure accurate force representation, including parents and sub-forces. Simplified force name formatting by consolidating logic into a single string format.
  • Loading branch information
IllianiCBT committed Dec 6, 2024
1 parent 55a041b commit f20a101
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import mekhq.campaign.Campaign;
import mekhq.campaign.finances.Money;
import mekhq.campaign.force.Force;
import mekhq.campaign.force.StrategicFormation;
import mekhq.campaign.icons.StandardForceIcon;
import mekhq.campaign.market.procurement.Procurement;
import mekhq.campaign.mission.AtBContract;
Expand Down Expand Up @@ -2035,10 +2034,9 @@ private void calculatePlayerConvoyValues() {
playerConvoys = new HashMap<>();
totalPlayerCargoCapacity = 0;

for (StrategicFormation formation : campaign.getStrategicFormationsTable().values()) {
Force force = campaign.getForce(formation.getForceId());
for (Force force : campaign.getAllForces()) {

if (force == null) {
if (!force.isConvoyForce()) {
continue;
}

Expand Down
19 changes: 9 additions & 10 deletions MekHQ/src/mekhq/gui/ForceRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,15 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
setOpaque(true);
}

String format;
if (force.isStrategicFormation()) {
format = (force.getOverrideStrategicFormation() != STRATEGIC_FORMATION_OVERRIDE_NONE) ?
"<html><b><u>%s</u></b></html>" : "<html><b>%s</b></html>";
} else {
format = (force.getOverrideStrategicFormation() != STRATEGIC_FORMATION_OVERRIDE_NONE) ?
"<html><u>%s</u></html>" : "%s";
}

setText(String.format(format, force.getName()));
String formattedForceName = String.format("<html>%s%s%s%s%s%s</html>",
force.isStrategicFormation() ? "<b>" : "",
force.getOverrideStrategicFormation() != STRATEGIC_FORMATION_OVERRIDE_NONE ? "<u>" : "",
force.getName(),
force.isStrategicFormation() ? "</b>" : "",
force.getOverrideStrategicFormation() != STRATEGIC_FORMATION_OVERRIDE_NONE ? "</u>" : "",
force.isConvoyForce() ? " &#926;" : force.isCombatForce() ? "" : " &#8709;");

setText(formattedForceName);
} else {
logger.error("Attempted to render node with unknown node class of "
+ ((value != null) ? value.getClass() : "null"));
Expand Down
11 changes: 10 additions & 1 deletion MekHQ/src/mekhq/gui/adapter/TOEMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void actionPerformed(ActionEvent action) {
final boolean subforces = command.contains(TOEMouseAdapter.CHANGE_COMBAT_STATUSES);
for (final Force force : forces) {
force.setCombatForce(combatForce, subforces);
force.setConvoyForce(!combatForce);
force.setConvoyForce(false);
}
gui.getTOETab().refreshForceView();
} else if (command.contains(TOEMouseAdapter.CHANGE_CONVOY_STATUS)) {
Expand All @@ -450,6 +450,15 @@ public void actionPerformed(ActionEvent action) {
for (final Force force : forces) {
force.setConvoyForce(convoyForce);
}

for (Force parentForce : singleForce.getAllParents()) {
parentForce.setConvoyForce(false);
}

for (Force childForce : singleForce.getAllSubForces()) {
childForce.setConvoyForce(false);
}

gui.getTOETab().refreshForceView();

for (Force formation : gui.getCampaign().getAllForces()) {
Expand Down

0 comments on commit f20a101

Please sign in to comment.