@@ -160,9 +160,9 @@ public class CustomMekDialog extends AbstractButtonDialog
160160 private boolean okay ;
161161 private int status = CustomMekDialog .DONE ;
162162
163- private final ClientGUI clientGUI ;
163+ private ClientGUI clientGUI ;
164164 private final Client client ;
165- private final boolean space ;
165+ private boolean space ;
166166
167167 private PilotOptions options ;
168168 private PartialRepairs partReps ;
@@ -188,12 +188,19 @@ public CustomMekDialog(ClientGUI clientgui, Client client, List<Entity> entities
188188 */
189189 public CustomMekDialog (ClientGUI clientgui , Client client , List <Entity > entities , boolean editable ,
190190 boolean editableDeployment ) {
191- super (clientgui .getFrame (), "CustomizeMekDialog" , "CustomMekDialog.title" );
191+ this (clientgui .getFrame (), client , entities , editable , editableDeployment );
192+ this .clientGUI = clientgui ;
193+ this .space = clientgui .getClient ().getMapSettings ().getMedium () == Board .T_SPACE ;
194+ }
195+
196+ public CustomMekDialog (JFrame frame , Client client , List <Entity > entities , boolean editable ,
197+ boolean editableDeployment ) {
198+ super (frame , "CustomizeMekDialog" , "CustomMekDialog.title" );
192199
193200 this .entities = entities ;
194- this .clientGUI = clientgui ;
201+ this .clientGUI = null ;
195202 this .client = client ;
196- this .space = clientgui . getClient (). getMapSettings (). getMedium () == Board . T_SPACE ;
203+ this .space = false ;
197204 this .editable = editable ;
198205 this .editableDeployment = editableDeployment ;
199206
@@ -231,6 +238,14 @@ public ClientGUI getClientGUI() {
231238 return clientGUI ;
232239 }
233240
241+ public Client getClient () {
242+ if (clientGUI != null ) {
243+ return clientGUI .getClient ();
244+ } else {
245+ return client ;
246+ }
247+ }
248+
234249 private void setOptions () {
235250 Entity entity = entities .get (0 );
236251 IOption option ;
@@ -437,6 +452,9 @@ public int getStatus() {
437452 }
438453
439454 private void refreshDeployment () {
455+ if (this .clientGUI == null ) {
456+ return ;
457+ }
440458 Entity entity = entities .get (0 );
441459
442460 if (entity instanceof QuadVee ) {
@@ -707,25 +725,25 @@ protected void okAction() {
707725 if ((velocity > (2 * entities .get (0 ).getWalkMP ())) || (velocity < 0 )) {
708726 msg = Messages .getString ("CustomMekDialog.EnterCorrectVelocity" );
709727 title = Messages .getString ("CustomMekDialog.NumberFormatError" );
710- JOptionPane .showMessageDialog (clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
728+ JOptionPane .showMessageDialog (clientGUI == null ? this : clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
711729 return ;
712730 } else if ((altitude < 0 ) || (altitude > 10 )) {
713731 msg = Messages .getString ("CustomMekDialog.EnterCorrectAltitude" );
714732 title = Messages .getString ("CustomMekDialog.NumberFormatError" );
715- JOptionPane .showMessageDialog (clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
733+ JOptionPane .showMessageDialog (clientGUI == null ? this : clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
716734 return ;
717735 } else if ((currentFuel < 0 ) || (currentFuel > fuel )) {
718736 msg = (Messages .getString ("CustomMekDialog.EnterCorrectFuel" ) + fuel + "." );
719737 title = Messages .getString ("CustomMekDialog.NumberFormatError" );
720- JOptionPane .showMessageDialog (clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
738+ JOptionPane .showMessageDialog (clientGUI == null ? this : clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
721739 return ;
722740 }
723741 }
724742
725743 if ((isVTOL && height > 50 ) || (isAirMek && height > 25 ) || (isGlider && height > 12 )) {
726744 msg = Messages .getString ("CustomMekDialog.EnterCorrectHeight" );
727745 title = Messages .getString ("CustomMekDialog.NumberFormatError" );
728- JOptionPane .showMessageDialog (clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
746+ JOptionPane .showMessageDialog (clientGUI == null ? this : clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
729747 return ;
730748 }
731749 // Apply single-entity settings
@@ -795,7 +813,7 @@ protected void okAction() {
795813 (artillery > 8 )) {
796814 msg = Messages .getString ("CustomMekDialog.EnterSkillsBetween0_8" );
797815 title = Messages .getString ("CustomMekDialog.NumberFormatError" );
798- JOptionPane .showMessageDialog (clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
816+ JOptionPane .showMessageDialog (clientGUI == null ? this : clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
799817 return ;
800818 }
801819
@@ -849,7 +867,9 @@ protected void okAction() {
849867 entity .getCrew ().setHits (MathUtility .parseInt (hits , 0 ), i );
850868 entity .getCrew ().setGender (gender , i );
851869 entity .getCrew ().setClanPilot (panCrewMember [i ].isClanPilot (), i );
852- entity .getCrew ().setPortrait (panCrewMember [i ].getPortrait ().clone (), i );
870+ if (clientGUI != null ) {
871+ entity .getCrew ().setPortrait (panCrewMember [i ].getPortrait ().clone (), i );
872+ }
853873 if (backup >= 0 ) {
854874 if (i == entity .getCrew ().getCrewType ().getPilotPos ()) {
855875 entity .getCrew ().setBackupPilotPos (backup );
@@ -899,7 +919,7 @@ protected void okAction() {
899919 if (offBoardDistance < 17 ) {
900920 msg = Messages .getString ("CustomMekDialog.OffboardDistance" );
901921 title = Messages .getString ("CustomMekDialog.NumberFormatError" );
902- JOptionPane .showMessageDialog (clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
922+ JOptionPane .showMessageDialog (clientGUI == null ? this : clientGUI .frame , msg , title , JOptionPane .ERROR_MESSAGE );
903923 return ;
904924 }
905925 entity .setOffBoard (offBoardDistance ,
@@ -989,7 +1009,7 @@ protected void okAction() {
9891009 }
9901010
9911011 okay = true ;
992- if (clientGUI .chatlounge != null ) {
1012+ if (( clientGUI != null ) && ( clientGUI .chatlounge != null ) ) {
9931013 clientGUI .chatlounge .refreshEntities ();
9941014 }
9951015
@@ -1115,10 +1135,17 @@ protected Container createCenterPane() {
11151135 final boolean isGlider = entities .stream ()
11161136 .allMatch (e -> (e instanceof ProtoMek ) && e .getMovementMode ().isWiGE ());
11171137 final boolean hasStealth = entities .stream ().allMatch (Entity ::hasStealth );
1118- boolean eligibleForOffBoard = true ;
11191138
1120- int bh = clientGUI .getClient ().getMapSettings ().getBoardHeight ();
1121- int bw = clientGUI .getClient ().getMapSettings ().getBoardWidth ();
1139+ boolean eligibleForOffBoard = true ;
1140+ int bh = 0 ;
1141+ int bw = 0 ;
1142+ if (this .clientGUI != null ) {
1143+ bh = clientGUI .getClient ().getMapSettings ().getBoardHeight ();
1144+ bw = clientGUI .getClient ().getMapSettings ().getBoardWidth ();
1145+ } else {
1146+ bh = client .getMapSettings ().getBoardHeight ();
1147+ bw = client .getMapSettings ().getBoardWidth ();
1148+ }
11221149 int x = Math .min (entity .getStartingAnyNWx (false ) + 1 , bw );
11231150 SpinnerNumberModel mStartingAnyNWx = new SpinnerNumberModel (x , 0 , bw , 1 );
11241151 spinStartingAnyNWx = new JSpinner (mStartingAnyNWx );
@@ -1135,7 +1162,6 @@ protected Container createCenterPane() {
11351162 SpinnerNumberModel mStartingAnySEy = new SpinnerNumberModel (y , 0 , bh , 1 );
11361163 spinStartingAnySEy = new JSpinner (mStartingAnySEy );
11371164 spinStartingAnySEy .setValue (y );
1138-
11391165 for (Entity e : entities ) {
11401166 // TODO : This check is good for now, but at some point we want atmospheric flying droppers to be able to
11411167 // lob offboard missiles and we could use it in space for extreme range bearings-only fights, plus
@@ -1145,13 +1171,12 @@ protected Container createCenterPane() {
11451171 (e .getAltitude () == 0 ) &&
11461172 !(e instanceof GunEmplacement ) &&
11471173 e .getWeaponList ()
1148- .stream ()
1149- .map (Mounted ::getType )
1150- .anyMatch (weaponType -> weaponType .hasFlag (WeaponType .F_ARTILLERY ) ||
1174+ .stream ()
1175+ .map (Mounted ::getType )
1176+ .anyMatch (weaponType -> weaponType .hasFlag (WeaponType .F_ARTILLERY ) ||
11511177 (weaponType instanceof CapitalMissileBayWeapon ));
11521178 eligibleForOffBoard &= entityEligibleForOffBoard ;
11531179 }
1154-
11551180 // set up the panels
11561181 JPanel mainPanel = new JPanel (new GridBagLayout ());
11571182 tabAll = new JTabbedPane ();
@@ -1189,17 +1214,20 @@ protected Container createCenterPane() {
11891214 }
11901215 tabAll .addTab (Messages .getString ("CustomMekDialog.tabEquipment" ), scrEquip );
11911216 }
1192- tabAll .addTab (Messages .getString (editableDeployment ?
1193- "CustomMekDialog.tabDeployment" :
1194- "CustomMekDialog.tabState" ), new JScrollPane (panDeploy ));
1195- if (quirksEnabled && !multipleEntities ) {
1196- JScrollPane scrQuirks = new JScrollPane (panQuirks );
1197- scrQuirks .getVerticalScrollBar ().setUnitIncrement (16 );
1198- scrQuirks .setPreferredSize (scrEquip .getPreferredSize ());
1199- tabAll .addTab ("Quirks" , scrQuirks );
1200- }
1201- if (partialRepairsEnabled && !multipleEntities ) {
1202- tabAll .addTab (Messages .getString ("CustomMekDialog.tabPartialRepairs" ), new JScrollPane (panPartReps ));
1217+
1218+ if (this .clientGUI != null ) {
1219+ tabAll .addTab (Messages .getString (editableDeployment ?
1220+ "CustomMekDialog.tabDeployment" :
1221+ "CustomMekDialog.tabState" ), new JScrollPane (panDeploy ));
1222+ if (quirksEnabled && !multipleEntities ) {
1223+ JScrollPane scrQuirks = new JScrollPane (panQuirks );
1224+ scrQuirks .getVerticalScrollBar ().setUnitIncrement (16 );
1225+ scrQuirks .setPreferredSize (scrEquip .getPreferredSize ());
1226+ tabAll .addTab ("Quirks" , scrQuirks );
1227+ }
1228+ if (partialRepairsEnabled && !multipleEntities ) {
1229+ tabAll .addTab (Messages .getString ("CustomMekDialog.tabPartialRepairs" ), new JScrollPane (panPartReps ));
1230+ }
12031231 }
12041232
12051233 options = entity .getCrew ().getOptions ();
@@ -1422,6 +1450,9 @@ protected JPanel createButtonPanel() {
14221450 }
14231451
14241452 private GameOptions gameOptions () {
1453+ if (clientGUI == null ) {
1454+ return client .getGame ().getOptions ();
1455+ }
14251456 return clientGUI .getClient ().getGame ().getOptions ();
14261457 }
14271458}
0 commit comments