|
35 | 35 | import megamek.client.ui.swing.DialogOptionComponent; |
36 | 36 | import megamek.client.ui.swing.DialogOptionListener; |
37 | 37 | import megamek.common.Crew; |
| 38 | +import megamek.common.Entity; |
38 | 39 | import megamek.common.EquipmentType; |
39 | 40 | import megamek.common.TechConstants; |
40 | 41 | import megamek.common.enums.Gender; |
@@ -787,8 +788,8 @@ public Component getListCellRendererComponent(JList<?> list, |
787 | 788 | return this; |
788 | 789 | } |
789 | 790 | }); |
790 | | - choiceOriginalUnit.addItem(null); |
791 | | - campaign.getHangar().forEachUnit(choiceOriginalUnit::addItem); |
| 791 | + populateUnitChoiceCombo(); |
| 792 | + |
792 | 793 | if (null == person.getOriginalUnitId() || null == campaign.getUnit(person.getOriginalUnitId())) { |
793 | 794 | choiceOriginalUnit.setSelectedItem(null); |
794 | 795 | } else { |
@@ -1067,6 +1068,42 @@ public Component getListCellRendererComponent(JList<?> list, |
1067 | 1068 | pack(); |
1068 | 1069 | } |
1069 | 1070 |
|
| 1071 | + /** |
| 1072 | + * Populates a combo box with a list of units that the specified person can interact with, |
| 1073 | + * based on their abilities to drive, gun, or tech the corresponding entities. |
| 1074 | + * |
| 1075 | + * <p>The method adds eligible units from the campaign's unit list to the combo box |
| 1076 | + * {@code choiceOriginalUnit}, and starts by adding a {@code null} entry to represent no selection.</p> |
| 1077 | + */ |
| 1078 | + private void populateUnitChoiceCombo() { |
| 1079 | + choiceOriginalUnit.addItem(null); // Add a null entry as the initial option |
| 1080 | + |
| 1081 | + // Iterate through all units in the campaign |
| 1082 | + for (Unit unit : campaign.getUnits()) { |
| 1083 | + Entity entity = unit.getEntity(); |
| 1084 | + |
| 1085 | + // Skip units without an associated entity |
| 1086 | + if (entity == null) { |
| 1087 | + continue; |
| 1088 | + } |
| 1089 | + |
| 1090 | + // Add units to the combo box based on the person's capabilities |
| 1091 | + if (person.canDrive(entity)) { |
| 1092 | + choiceOriginalUnit.addItem(unit); |
| 1093 | + continue; // Skip further checks if already added |
| 1094 | + } |
| 1095 | + |
| 1096 | + if (person.canGun(entity)) { |
| 1097 | + choiceOriginalUnit.addItem(unit); |
| 1098 | + continue; // Skip further checks if already added |
| 1099 | + } |
| 1100 | + |
| 1101 | + if (person.canTech(entity)) { |
| 1102 | + choiceOriginalUnit.addItem(unit); |
| 1103 | + } |
| 1104 | + } |
| 1105 | + } |
| 1106 | + |
1070 | 1107 | @Deprecated // These need to be migrated to the Suite Constants / Suite Options Setup |
1071 | 1108 | private void setUserPreferences() { |
1072 | 1109 | try { |
|
0 commit comments