27
27
*/
28
28
package mekhq .gui .dialog .nagDialogs ;
29
29
30
- import mekhq .MHQConstants ;
31
- import mekhq .MekHQ ;
32
- import mekhq .campaign .Campaign ;
33
- import mekhq .campaign .universe .Faction ;
34
- import mekhq .gui .baseComponents .AbstractMHQNagDialog ;
30
+ import static mekhq .MHQConstants .NAG_INVALID_FACTION ;
31
+ import static mekhq .campaign .Campaign .AdministratorSpecialization .COMMAND ;
32
+ import static mekhq .gui .dialog .nagDialogs .nagLogic .InvalidFactionNagLogic .isFactionInvalid ;
33
+ import static mekhq .utilities .MHQInternationalization .getFormattedTextAt ;
35
34
36
35
import java .time .LocalDate ;
36
+ import java .util .ArrayList ;
37
+ import java .util .List ;
37
38
38
- import static mekhq .gui .dialog .nagDialogs .nagLogic .InvalidFactionNagLogic .isFactionInvalid ;
39
+ import mekhq .MekHQ ;
40
+ import mekhq .campaign .Campaign ;
41
+ import mekhq .campaign .universe .Faction ;
42
+ import mekhq .gui .baseComponents .immersiveDialogs .ImmersiveDialogSimple ;
39
43
40
44
/**
41
45
* A dialog used to notify the user about an invalid faction in the current campaign.
42
46
*
43
47
* <p>
44
- * This nag dialog is triggered when the campaign's selected faction is determined to be invalid
45
- * for the current campaign date. It evaluates the validity of the faction based on the campaign
46
- * date and displays a localized message warning the user about the issue.
48
+ * This nag dialog is triggered when the campaign's selected faction is determined to be invalid for the current
49
+ * campaign date. It evaluates the validity of the faction based on the campaign date and displays a localized message
50
+ * warning the user about the issue.
47
51
* </p>
48
52
*
49
53
* <strong>Features:</strong>
50
54
* <ul>
51
55
* <li>Checks whether the campaign's faction is valid based on the current in-game date.</li>
52
56
* <li>Displays a warning dialog to alert the user when an invalid faction is detected.</li>
53
- * <li>Extends {@link AbstractMHQNagDialog} to ensure consistent behavior with other nag dialogs.</li>
54
57
* </ul>
55
58
*/
56
- public class InvalidFactionNagDialog extends AbstractMHQNagDialog {
59
+ public class InvalidFactionNagDialog {
60
+ private final String RESOURCE_BUNDLE = "mekhq.resources.NagDialogs" ;
61
+
62
+ private final int CHOICE_CANCEL = 0 ;
63
+ private final int CHOICE_CONTINUE = 1 ;
64
+ private final int CHOICE_SUPPRESS = 2 ;
65
+
66
+ private boolean cancelAdvanceDay ;
67
+
57
68
/**
58
69
* Constructs an {@code InvalidFactionNagDialog} for the given campaign.
59
70
*
60
71
* <p>
61
- * This dialog initializes with the campaign information and sets a localized
62
- * message to notify the user about the potential issue involving an invalid faction.
63
- * The message includes the commander's address for better clarity.
72
+ * This dialog initializes with the campaign information and sets a localized message to notify the user about the
73
+ * potential issue involving an invalid faction. The message includes the commander's address for better clarity.
64
74
* </p>
65
75
*
66
- * @param campaign The {@link Campaign} associated with this nag dialog.
67
- * The campaign provides the faction and other details for evaluation.
76
+ * @param campaign The {@link Campaign} associated with this nag dialog. The campaign provides the faction and other
77
+ * details for evaluation.
68
78
*/
69
79
public InvalidFactionNagDialog (final Campaign campaign ) {
70
- super (campaign , MHQConstants .NAG_INVALID_FACTION );
80
+ ImmersiveDialogSimple dialog = new ImmersiveDialogSimple (campaign ,
81
+ campaign .getSeniorAdminPerson (COMMAND ),
82
+ null ,
83
+ getFormattedTextAt (RESOURCE_BUNDLE , "InvalidFactionNagDialog.ic" , campaign .getCommanderAddress (false )),
84
+ getButtonLabels (),
85
+ getFormattedTextAt (RESOURCE_BUNDLE , "InvalidFactionNagDialog.ooc" ),
86
+ true );
87
+
88
+ int choiceIndex = dialog .getDialogChoice ();
89
+
90
+ switch (choiceIndex ) {
91
+ case CHOICE_CANCEL -> cancelAdvanceDay = true ;
92
+ case CHOICE_CONTINUE -> cancelAdvanceDay = false ;
93
+ case CHOICE_SUPPRESS -> {
94
+ MekHQ .getMHQOptions ().setNagDialogIgnore (NAG_INVALID_FACTION , true );
95
+ cancelAdvanceDay = false ;
96
+ }
97
+ default -> throw new IllegalStateException ("Unexpected value in InvalidFactionNagDialog: " + choiceIndex );
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Retrieves a list of button labels from the resource bundle.
103
+ *
104
+ * <p>The method collects and returns button labels such as "Cancel", "Continue", and "Suppress" after
105
+ * formatting them using the provided resource bundle.</p>
106
+ *
107
+ * @return a {@link List} of formatted button labels as {@link String}.
108
+ */
109
+ private List <String > getButtonLabels () {
110
+ List <String > buttonLabels = new ArrayList <>();
111
+
112
+ buttonLabels .add (getFormattedTextAt (RESOURCE_BUNDLE , "button.cancel" ));
113
+ buttonLabels .add (getFormattedTextAt (RESOURCE_BUNDLE , "button.continue" ));
114
+ buttonLabels .add (getFormattedTextAt (RESOURCE_BUNDLE , "button.suppress" ));
71
115
72
- final String DIALOG_BODY = "InvalidFactionNagDialog.text" ;
73
- setRightDescriptionMessage (String .format (resources .getString (DIALOG_BODY ),
74
- campaign .getCommanderAddress (false )));
75
- showDialog ();
116
+ return buttonLabels ;
117
+ }
118
+
119
+ /**
120
+ * Determines whether the advance day operation should be canceled.
121
+ *
122
+ * @return {@code true} if advancing the day should be canceled, {@code false} otherwise.
123
+ */
124
+ public boolean shouldCancelAdvanceDay () {
125
+ return cancelAdvanceDay ;
76
126
}
77
127
78
128
/**
@@ -86,12 +136,12 @@ public InvalidFactionNagDialog(final Campaign campaign) {
86
136
*
87
137
* @param campaignFaction The {@link Faction} associated with the campaign to be checked.
88
138
* @param today The {@link LocalDate} representing the current in-game date.
139
+ *
89
140
* @return {@code true} if the nag dialog should be displayed, {@code false} otherwise.
90
141
*/
91
142
public static boolean checkNag (Faction campaignFaction , LocalDate today ) {
92
- final String NAG_KEY = MHQConstants . NAG_INVALID_FACTION ;
143
+ final String NAG_KEY = NAG_INVALID_FACTION ;
93
144
94
- return !MekHQ .getMHQOptions ().getNagDialogIgnore (NAG_KEY )
95
- && (isFactionInvalid (campaignFaction , today ));
145
+ return !MekHQ .getMHQOptions ().getNagDialogIgnore (NAG_KEY ) && (isFactionInvalid (campaignFaction , today ));
96
146
}
97
147
}
0 commit comments