28
28
*/
29
29
package mekhq .gui .view ;
30
30
31
+ import static megamek .client .ui .WrapLayout .wordWrap ;
32
+ import static mekhq .campaign .mission .enums .CombatRole .FRONTLINE ;
33
+ import static mekhq .campaign .mission .enums .CombatRole .MANEUVER ;
34
+ import static mekhq .campaign .mission .enums .CombatRole .PATROL ;
35
+ import static mekhq .campaign .mission .enums .CombatRole .TRAINING ;
36
+
37
+ import java .awt .Component ;
38
+ import java .awt .Dimension ;
39
+ import java .util .ArrayList ;
40
+ import java .util .Comparator ;
41
+ import java .util .List ;
42
+ import javax .swing .*;
43
+ import javax .swing .RowSorter .SortKey ;
44
+ import javax .swing .event .TableModelEvent ;
45
+ import javax .swing .event .TableModelListener ;
46
+ import javax .swing .table .TableColumn ;
47
+ import javax .swing .table .TableRowSorter ;
48
+
31
49
import megamek .client .ui .models .XTableColumnModel ;
32
50
import megamek .common .util .sorter .NaturalOrderComparator ;
33
51
import mekhq .MekHQ ;
40
58
import mekhq .gui .model .DataTableModel ;
41
59
import mekhq .gui .utilities .MekHqTableCellRenderer ;
42
60
43
- import javax .swing .*;
44
- import javax .swing .RowSorter .SortKey ;
45
- import javax .swing .event .TableModelEvent ;
46
- import javax .swing .event .TableModelListener ;
47
- import javax .swing .table .TableColumn ;
48
- import javax .swing .table .TableRowSorter ;
49
- import java .awt .*;
50
- import java .util .ArrayList ;
51
- import java .util .Comparator ;
52
- import java .util .List ;
53
-
54
- import static megamek .client .ui .WrapLayout .wordWrap ;
55
- import static mekhq .campaign .mission .enums .CombatRole .FRONTLINE ;
56
- import static mekhq .campaign .mission .enums .CombatRole .MANEUVER ;
57
- import static mekhq .campaign .mission .enums .CombatRole .PATROL ;
58
- import static mekhq .campaign .mission .enums .CombatRole .TRAINING ;
59
-
60
61
/**
61
- * Against the Bot
62
- * Shows how many lances are required to be deployed on active contracts and
63
- * in what roles and allows the player to assign units to those roles.
62
+ * Against the Bot Shows how many lances are required to be deployed on active contracts and in what roles and allows
63
+ * the player to assign units to those roles.
64
64
*
65
65
* @author Neoancient
66
66
*/
@@ -83,8 +83,7 @@ private void initComponents() {
83
83
cbContract = new JComboBox <>();
84
84
cbContract .setRenderer (new DefaultListCellRenderer () {
85
85
@ Override
86
- public Component getListCellRendererComponent (JList <?> list , Object value , int index ,
87
- boolean isSelected , boolean cellHasFocus ) {
86
+ public Component getListCellRendererComponent (JList <?> list , Object value , int index , boolean isSelected , boolean cellHasFocus ) {
88
87
return new JLabel ((null == value ) ? "None" : ((AtBContract ) value ).getName ());
89
88
}
90
89
});
@@ -93,9 +92,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
93
92
cbRole .setName ("cbRole" );
94
93
cbRole .setRenderer (new DefaultListCellRenderer () {
95
94
@ Override
96
- public Component getListCellRendererComponent (final JList <?> list , final Object value ,
97
- final int index , final boolean isSelected ,
98
- final boolean cellHasFocus ) {
95
+ public Component getListCellRendererComponent (final JList <?> list , final Object value , final int index , final boolean isSelected , final boolean cellHasFocus ) {
99
96
super .getListCellRendererComponent (list , value , index , isSelected , cellHasFocus );
100
97
if (value instanceof CombatRole ) {
101
98
list .setToolTipText (wordWrap (((CombatRole ) value ).getToolTipText ()));
@@ -117,12 +114,10 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
117
114
column .setPreferredWidth (rlModel .getColumnWidth (i ));
118
115
column .setCellRenderer (new MekHqTableCellRenderer () {
119
116
@ Override
120
- public Component getTableCellRendererComponent (JTable table , Object value ,
121
- boolean isSelected , boolean hasFocus ,
122
- int row , int column ) {
117
+ public Component getTableCellRendererComponent (JTable table , Object value , boolean isSelected , boolean hasFocus , int row , int column ) {
123
118
super .getTableCellRendererComponent (table , value , isSelected , hasFocus , row , column );
124
- setHorizontalAlignment (((RequiredLancesTableModel ) table .getModel ()).
125
- getAlignment ( table . convertColumnIndexToModel ( column )));
119
+ setHorizontalAlignment (((RequiredLancesTableModel ) table .getModel ()).getAlignment ( table . convertColumnIndexToModel (
120
+ column )));
126
121
if (table .convertColumnIndexToModel (column ) > RequiredLancesTableModel .COL_CONTRACT ) {
127
122
if (((String ) value ).indexOf ('/' ) >= 0 ) {
128
123
setForeground (MekHQ .getMHQOptions ().getBelowContractMinimumForeground ());
@@ -132,7 +127,7 @@ public Component getTableCellRendererComponent(JTable table, Object value,
132
127
}
133
128
});
134
129
}
135
- TableRowSorter <RequiredLancesTableModel >sorter = new TableRowSorter <>(rlModel );
130
+ TableRowSorter <RequiredLancesTableModel > sorter = new TableRowSorter <>(rlModel );
136
131
tblRequiredLances .setRowSorter (sorter );
137
132
138
133
tblRequiredLances .setIntercellSpacing (new Dimension (0 , 0 ));
@@ -148,9 +143,7 @@ public Component getTableCellRendererComponent(JTable table, Object value,
148
143
column .setPreferredWidth (rlModel .getColumnWidth (i ));
149
144
column .setCellRenderer (new MekHqTableCellRenderer () {
150
145
@ Override
151
- public Component getTableCellRendererComponent (JTable table , Object value ,
152
- boolean isSelected , boolean hasFocus ,
153
- int row , int column ) {
146
+ public Component getTableCellRendererComponent (JTable table , Object value , boolean isSelected , boolean hasFocus , int row , int column ) {
154
147
switch (column ) {
155
148
case LanceAssignmentTableModel .COL_FORCE :
156
149
if (null != value ) {
@@ -169,7 +162,7 @@ public Component getTableCellRendererComponent(JTable table, Object value,
169
162
break ;
170
163
default :
171
164
super .getTableCellRendererComponent (table , value , isSelected , hasFocus , row , column );
172
- }
165
+ }
173
166
return this ;
174
167
}
175
168
});
@@ -191,13 +184,13 @@ public boolean include(Entry<? extends LanceAssignmentTableModel, ? extends Inte
191
184
}
192
185
};
193
186
final NaturalOrderComparator noc = new NaturalOrderComparator ();
194
- TableRowSorter <LanceAssignmentTableModel >laSorter = new TableRowSorter <>(laModel );
187
+ TableRowSorter <LanceAssignmentTableModel > laSorter = new TableRowSorter <>(laModel );
195
188
laSorter .setRowFilter (laFilter );
196
189
laSorter .setComparator (LanceAssignmentTableModel .COL_FORCE , forceComparator );
197
- laSorter .setComparator (LanceAssignmentTableModel .COL_CONTRACT , ( c1 , c2 ) ->
198
- noc .compare (((AtBContract ) c1 ).getName (), ((AtBContract ) c2 ).getName ()));
199
- laSorter .setComparator (LanceAssignmentTableModel .COL_ROLE , ( r1 , r2 ) ->
200
- noc .compare (r1 .toString (), r2 .toString ()));
190
+ laSorter .setComparator (LanceAssignmentTableModel .COL_CONTRACT ,
191
+ ( c1 , c2 ) -> noc .compare (((AtBContract ) c1 ).getName (), ((AtBContract ) c2 ).getName ()));
192
+ laSorter .setComparator (LanceAssignmentTableModel .COL_ROLE ,
193
+ ( r1 , r2 ) -> noc .compare (r1 .toString (), r2 .toString ()));
201
194
List <SortKey > sortKeys = new ArrayList <>();
202
195
sortKeys .add (new SortKey (LanceAssignmentTableModel .COL_FORCE , SortOrder .ASCENDING ));
203
196
sorter .setSortKeys (sortKeys );
@@ -214,12 +207,12 @@ public boolean include(Entry<? extends LanceAssignmentTableModel, ? extends Inte
214
207
add (panRequiredLances );
215
208
216
209
int cmdrStrategy = 0 ;
217
- if ((campaign .getFlaggedCommander () != null )
218
- && (campaign .getFlaggedCommander ().getSkill (SkillType .S_STRATEGY ) != null )) {
210
+ if ((campaign .getFlaggedCommander () != null ) &&
211
+ (campaign .getFlaggedCommander ().getSkill (SkillType .S_STRATEGY ) != null )) {
219
212
cmdrStrategy = campaign .getFlaggedCommander ().getSkill (SkillType .S_STRATEGY ).getLevel ();
220
213
}
221
214
int maxDeployedLances = campaign .getCampaignOptions ().getBaseStrategyDeployment () +
222
- campaign .getCampaignOptions ().getAdditionalStrategyDeployment () * cmdrStrategy ;
215
+ campaign .getCampaignOptions ().getAdditionalStrategyDeployment () * cmdrStrategy ;
223
216
add (new JLabel ("Maximum Deployed Forces: " + maxDeployedLances ));
224
217
225
218
panAssignments = new JPanel ();
@@ -241,8 +234,8 @@ public void refresh() {
241
234
}
242
235
AtBContract defaultContract = activeContracts .isEmpty () ? null : activeContracts .get (0 );
243
236
for (CombatTeam combatTeam : campaign .getCombatTeamsTable ().values ()) {
244
- if ((combatTeam .getContract (campaign ) == null )
245
- || !combatTeam .getContract (campaign ).isActiveOn (campaign .getLocalDate (), true )) {
237
+ if ((combatTeam .getContract (campaign ) == null ) ||
238
+ !combatTeam .getContract (campaign ).isActiveOn (campaign .getLocalDate (), true )) {
246
239
combatTeam .setContract (defaultContract );
247
240
}
248
241
}
@@ -307,8 +300,8 @@ class RequiredLancesTableModel extends DataTableModel {
307
300
public RequiredLancesTableModel (final Campaign campaign ) {
308
301
this .campaign = campaign ;
309
302
data = new ArrayList <AtBContract >();
310
- columnNames = new String []{ "Contract" , "Total" , MANEUVER .toString (), FRONTLINE .toString (),
311
- PATROL . toString (), TRAINING .toString ()};
303
+ columnNames = new String [] { "Contract" , "Total" , MANEUVER .toString (), FRONTLINE . toString (), PATROL .toString (),
304
+ TRAINING .toString () };
312
305
}
313
306
314
307
@ Override
@@ -363,9 +356,13 @@ public Object getValueAt(int row, int column) {
363
356
if (column == COL_TOTAL ) {
364
357
int t = 0 ;
365
358
for (CombatTeam combatTeam : campaign .getAllCombatTeams ()) {
366
- if (data .get (row ).equals (combatTeam .getContract (campaign ))
367
- && (combatTeam .getRole () != CombatRole .RESERVE )
368
- && combatTeam .isEligible (campaign )) {
359
+ AtBContract assignedContract = combatTeam .getContract (campaign );
360
+ boolean isCadreDuty = assignedContract .getContractType ().isCadreDuty ();
361
+ CombatRole role = combatTeam .getRole ();
362
+ boolean isRoleSuitable = (isCadreDuty && role .isTraining ()) || role .isCombatRole ();
363
+ boolean isDeploymentEligible = combatTeam .isEligible (campaign );
364
+
365
+ if ((data .get (row ).equals (assignedContract )) && isRoleSuitable && isDeploymentEligible ) {
369
366
t ++;
370
367
}
371
368
}
@@ -376,9 +373,10 @@ public Object getValueAt(int row, int column) {
376
373
} else if (contract .getContractType ().getRequiredCombatRole ().ordinal () == column - 2 ) {
377
374
int t = 0 ;
378
375
for (CombatTeam combatTeam : campaign .getAllCombatTeams ()) {
379
- if (data .get (row ).equals (combatTeam .getContract (campaign ))
380
- && (combatTeam .getRole () == combatTeam .getContract (campaign ).getContractType ().getRequiredCombatRole ())
381
- && combatTeam .isEligible (campaign )) {
376
+ if (data .get (row ).equals (combatTeam .getContract (campaign )) &&
377
+ (combatTeam .getRole () ==
378
+ combatTeam .getContract (campaign ).getContractType ().getRequiredCombatRole ()) &&
379
+ combatTeam .isEligible (campaign )) {
382
380
t ++;
383
381
}
384
382
}
@@ -405,7 +403,7 @@ class LanceAssignmentTableModel extends DataTableModel {
405
403
public LanceAssignmentTableModel (Campaign campaign ) {
406
404
this .campaign = campaign ;
407
405
data = new ArrayList <>();
408
- columnNames = new String []{ "Force" , "Weight Class" , "Mission" , "Role" };
406
+ columnNames = new String [] { "Force" , "Weight Class" , "Mission" , "Role" };
409
407
}
410
408
411
409
@ Override
@@ -447,7 +445,7 @@ public CombatTeam getRow(int row) {
447
445
448
446
@ Override
449
447
public Object getValueAt (int row , int column ) {
450
- final String [] WEIGHT_CODES = {"Ultra-Light" , "Light" , "Medium" , "Heavy" , "Assault" , "Super Heavy" };
448
+ final String [] WEIGHT_CODES = { "Ultra-Light" , "Light" , "Medium" , "Heavy" , "Assault" , "Super Heavy" };
451
449
452
450
if (row >= getRowCount ()) {
453
451
return "" ;
0 commit comments