27
27
*/
28
28
package mekhq .gui .campaignOptions .contents ;
29
29
30
+ import static megamek .client .generator .RandomGenderGenerator .getPercentFemale ;
31
+ import static mekhq .gui .campaignOptions .CampaignOptionsUtilities .createParentPanel ;
32
+ import static mekhq .gui .campaignOptions .CampaignOptionsUtilities .getImageDirectory ;
33
+
34
+ import java .awt .Component ;
35
+ import java .awt .GridBagConstraints ;
36
+ import java .awt .GridLayout ;
37
+ import java .util .ArrayList ;
38
+ import java .util .Comparator ;
39
+ import java .util .HashMap ;
40
+ import java .util .Map ;
41
+ import java .util .ResourceBundle ;
42
+ import javax .swing .*;
43
+
30
44
import megamek .client .generator .RandomGenderGenerator ;
31
45
import megamek .client .generator .RandomNameGenerator ;
32
46
import megamek .client .ui .baseComponents .MMComboBox ;
42
56
import mekhq .campaign .universe .Faction ;
43
57
import mekhq .campaign .universe .Planet ;
44
58
import mekhq .campaign .universe .PlanetarySystem ;
45
- import mekhq .gui .campaignOptions .components .*;
59
+ import mekhq .campaign .universe .Systems ;
60
+ import mekhq .gui .campaignOptions .components .CampaignOptionsButton ;
61
+ import mekhq .gui .campaignOptions .components .CampaignOptionsCheckBox ;
62
+ import mekhq .gui .campaignOptions .components .CampaignOptionsGridBagConstraints ;
63
+ import mekhq .gui .campaignOptions .components .CampaignOptionsHeaderPanel ;
64
+ import mekhq .gui .campaignOptions .components .CampaignOptionsLabel ;
65
+ import mekhq .gui .campaignOptions .components .CampaignOptionsSpinner ;
66
+ import mekhq .gui .campaignOptions .components .CampaignOptionsStandardPanel ;
46
67
import mekhq .gui .panes .RankSystemsPane ;
47
68
48
- import javax .swing .*;
49
- import java .awt .*;
50
- import java .util .*;
51
-
52
- import static megamek .client .generator .RandomGenderGenerator .getPercentFemale ;
53
- import static mekhq .gui .campaignOptions .CampaignOptionsUtilities .createParentPanel ;
54
- import static mekhq .gui .campaignOptions .CampaignOptionsUtilities .getImageDirectory ;
55
-
56
69
/**
57
70
* The `BiographyTab` class is responsible for managing the biography-related settings in the campaign options tab
58
71
* within the MekHQ application. It provides an interface for configuring various campaign settings, such as:
@@ -74,6 +87,7 @@ public class BiographyTab {
74
87
private static final ResourceBundle resources = ResourceBundle .getBundle (RESOURCE_PACKAGE );
75
88
76
89
private Campaign campaign ;
90
+ private GeneralTab generalTab ;
77
91
private CampaignOptions campaignOptions ;
78
92
private RandomOriginOptions randomOriginOptions ;
79
93
@@ -178,11 +192,13 @@ public class BiographyTab {
178
192
/**
179
193
* Constructs the `BiographyTab` and initializes the campaign and its dependent options.
180
194
*
181
- * @param campaign The current `Campaign` object to which the BiographyTab is linked.
182
- * The campaign options and origin options are derived from this object.
195
+ * @param campaign The current `Campaign` object to which the BiographyTab is linked. The campaign
196
+ * options and origin options are derived from this object.
197
+ * @param generalTab The currently active General Tab.
183
198
*/
184
- public BiographyTab (Campaign campaign ) {
199
+ public BiographyTab (Campaign campaign , GeneralTab generalTab ) {
185
200
this .campaign = campaign ;
201
+ this .generalTab = generalTab ;
186
202
this .campaignOptions = campaign .getCampaignOptions ();
187
203
this .randomOriginOptions = campaignOptions .getRandomOriginOptions ();
188
204
@@ -581,15 +597,15 @@ private JPanel createRandomOriginOptionsPanel() {
581
597
582
598
lblSpecifiedSystem = new CampaignOptionsLabel ("SpecifiedSystem" );
583
599
comboSpecifiedSystem .setModel (new DefaultComboBoxModel <>(getPlanetarySystems (
584
- chkSpecifiedSystemFactionSpecific .isSelected () ? campaign .getFaction () : null )));
600
+ chkSpecifiedSystemFactionSpecific .isSelected () ? generalTab .getFaction () : null )));
585
601
comboSpecifiedSystem .setRenderer (new DefaultListCellRenderer () {
586
602
@ Override
587
603
public Component getListCellRendererComponent (final JList <?> list , final Object value ,
588
604
final int index , final boolean isSelected ,
589
605
final boolean cellHasFocus ) {
590
606
super .getListCellRendererComponent (list , value , index , isSelected , cellHasFocus );
591
607
if (value instanceof PlanetarySystem ) {
592
- setText (((PlanetarySystem ) value ).getName (campaign . getLocalDate ()));
608
+ setText (((PlanetarySystem ) value ).getName (generalTab . getDate ()));
593
609
}
594
610
return this ;
595
611
}
@@ -615,7 +631,7 @@ public Component getListCellRendererComponent(final JList<?> list, final Object
615
631
final boolean cellHasFocus ) {
616
632
super .getListCellRendererComponent (list , value , index , isSelected , cellHasFocus );
617
633
if (value instanceof Planet ) {
618
- setText (((Planet ) value ).getName (campaign . getLocalDate ()));
634
+ setText (((Planet ) value ).getName (generalTab . getDate ()));
619
635
}
620
636
return this ;
621
637
}
@@ -735,7 +751,7 @@ private void restoreComboSpecifiedSystem() {
735
751
comboSpecifiedSystem .removeAllItems ();
736
752
737
753
comboSpecifiedSystem .setModel (new DefaultComboBoxModel <>(getPlanetarySystems (
738
- chkSpecifiedSystemFactionSpecific .isSelected () ? campaign .getFaction () : null )));
754
+ chkSpecifiedSystemFactionSpecific .isSelected () ? generalTab .getFaction () : null )));
739
755
740
756
restoreComboSpecifiedPlanet ();
741
757
}
@@ -752,13 +768,13 @@ private PlanetarySystem[] getPlanetarySystems(final @Nullable Faction faction) {
752
768
753
769
// Filter systems
754
770
for (PlanetarySystem planetarySystem : systems ) {
755
- if ((faction == null ) || planetarySystem .getFactionSet (campaign . getLocalDate ()).contains (faction )) {
771
+ if ((faction == null ) || planetarySystem .getFactionSet (generalTab . getDate ()).contains (faction )) {
756
772
filteredSystems .add (planetarySystem );
757
773
}
758
774
}
759
775
760
776
// Sort systems
761
- filteredSystems .sort (Comparator .comparing (p -> p .getName (campaign . getLocalDate ())));
777
+ filteredSystems .sort (Comparator .comparing (p -> p .getName (generalTab . getDate ())));
762
778
763
779
// Convert to array
764
780
return filteredSystems .toArray (new PlanetarySystem [0 ]);
@@ -1421,7 +1437,9 @@ public void applyCampaignOptionsToCampaign(@Nullable CampaignOptions presetCampa
1421
1437
originOptions .setRandomizeAroundSpecifiedPlanet (chkRandomizeAroundSpecifiedPlanet .isSelected ());
1422
1438
1423
1439
Planet selectedPlanet = comboSpecifiedPlanet .getSelectedItem ();
1424
- originOptions .setSpecifiedPlanet (selectedPlanet );
1440
+ originOptions .setSpecifiedPlanet (selectedPlanet == null
1441
+ ? Systems .getInstance ().getSystemById ("Terra" ).getPrimaryPlanet ()
1442
+ : selectedPlanet );
1425
1443
1426
1444
originOptions .setOriginSearchRadius ((int ) spnOriginSearchRadius .getValue ());
1427
1445
originOptions .setOriginDistanceScale ((double ) spnOriginDistanceScale .getValue ());
0 commit comments