27
27
*/
28
28
package mekhq .gui .dialog .nagDialogs ;
29
29
30
- import mekhq .MHQConstants ;
30
+ import static mekhq .MHQConstants .NAG_SHORT_DEPLOYMENT ;
31
+ import static mekhq .campaign .Campaign .AdministratorSpecialization .COMMAND ;
32
+ import static mekhq .gui .dialog .nagDialogs .nagLogic .DeploymentShortfallNagLogic .hasDeploymentShortfall ;
33
+ import static mekhq .utilities .MHQInternationalization .getFormattedTextAt ;
34
+
35
+ import java .util .ArrayList ;
36
+ import java .util .List ;
37
+
31
38
import mekhq .MekHQ ;
32
39
import mekhq .campaign .Campaign ;
33
- import mekhq .gui .baseComponents .AbstractMHQNagDialog ;
34
-
35
- import static mekhq .gui .dialog .nagDialogs .nagLogic .DeploymentShortfallNagLogic .hasDeploymentShortfall ;
40
+ import mekhq .gui .baseComponents .immersiveDialogs .ImmersiveDialogSimple ;
36
41
37
42
/**
38
43
* A nag dialog that alerts the user if short deployments are detected in the campaign's active contracts.
39
44
*
40
45
* <p>
41
- * This dialog checks whether any active AtB (Against the Bot) contracts have a deployment deficit
42
- * and alerts the player to address the issue. The check is performed weekly (on Sundays) and only
43
- * when the campaign is currently located on a planet. If deployment requirements are not met,
44
- * the dialog is displayed to prompt the user to correct the situation.
46
+ * This dialog checks whether any active AtB (Against the Bot) contracts have a deployment deficit and alerts the player
47
+ * to address the issue. The check is performed weekly (on Sundays) and only when the campaign is currently located on a
48
+ * planet. If deployment requirements are not met, the dialog is displayed to prompt the user to correct the situation.
45
49
* </p>
46
50
*/
47
- public class DeploymentShortfallNagDialog extends AbstractMHQNagDialog {
51
+ public class DeploymentShortfallNagDialog {
52
+ private final String RESOURCE_BUNDLE = "mekhq.resources.NagDialogs" ;
53
+
54
+ private final int CHOICE_CANCEL = 0 ;
55
+ private final int CHOICE_CONTINUE = 1 ;
56
+ private final int CHOICE_SUPPRESS = 2 ;
57
+
58
+ private final Campaign campaign ;
59
+ private boolean cancelAdvanceDay ;
60
+
48
61
/**
49
62
* Constructs the shortfall deployment nag dialog for a given campaign.
50
63
*
51
64
* <p>
52
- * This constructor initializes the dialog with the specified campaign and
53
- * formats the resource message to display information about deployment shortfalls.
65
+ * This constructor initializes the dialog with the specified campaign and formats the resource message to display
66
+ * information about deployment shortfalls.
54
67
* </p>
55
68
*
56
69
* @param campaign The {@link Campaign} object representing the current campaign.
57
70
*/
58
71
public DeploymentShortfallNagDialog (final Campaign campaign ) {
59
- super (campaign , MHQConstants .NAG_SHORT_DEPLOYMENT );
72
+ this .campaign = campaign ;
73
+
74
+ ImmersiveDialogSimple dialog = new ImmersiveDialogSimple (campaign ,
75
+ campaign .getSeniorAdminPerson (COMMAND ),
76
+ null ,
77
+ getFormattedTextAt (RESOURCE_BUNDLE ,
78
+ "DeploymentShortfallNagDialog.ic" ,
79
+ campaign .getCommanderAddress (false )),
80
+ getButtonLabels (),
81
+ getFormattedTextAt (RESOURCE_BUNDLE , "DeploymentShortfallNagDialog.ooc" ),
82
+ true );
83
+
84
+ int choiceIndex = dialog .getDialogChoice ();
85
+
86
+ switch (choiceIndex ) {
87
+ case CHOICE_CANCEL -> cancelAdvanceDay = true ;
88
+ case CHOICE_CONTINUE -> cancelAdvanceDay = false ;
89
+ case CHOICE_SUPPRESS -> {
90
+ MekHQ .getMHQOptions ().setNagDialogIgnore (NAG_SHORT_DEPLOYMENT , true );
91
+ cancelAdvanceDay = false ;
92
+ }
93
+ default -> throw new IllegalStateException ("Unexpected value in " +
94
+ getClass ().getSimpleName () +
95
+ ": " +
96
+ choiceIndex );
97
+ }
98
+ }
60
99
61
- final String DIALOG_BODY = "DeploymentShortfallNagDialog.text" ;
62
- setRightDescriptionMessage (String .format (resources .getString (DIALOG_BODY ),
63
- campaign .getCommanderAddress (false )));
64
- showDialog ();
100
+ /**
101
+ * Retrieves a list of button labels from the resource bundle.
102
+ *
103
+ * <p>The method collects and returns button labels such as "Cancel", "Continue", and "Suppress" after
104
+ * formatting them using the provided resource bundle.</p>
105
+ *
106
+ * @return a {@link List} of formatted button labels as {@link String}.
107
+ */
108
+ private List <String > getButtonLabels () {
109
+ List <String > buttonLabels = new ArrayList <>();
110
+
111
+ buttonLabels .add (getFormattedTextAt (RESOURCE_BUNDLE , "button.cancel" ));
112
+ buttonLabels .add (getFormattedTextAt (RESOURCE_BUNDLE , "button.continue" ));
113
+ buttonLabels .add (getFormattedTextAt (RESOURCE_BUNDLE , "button.suppress" ));
114
+
115
+ return buttonLabels ;
116
+ }
117
+
118
+ /**
119
+ * Determines whether the advance day operation should be canceled.
120
+ *
121
+ * @return {@code true} if advancing the day should be canceled, {@code false} otherwise.
122
+ */
123
+ public boolean shouldCancelAdvanceDay () {
124
+ return cancelAdvanceDay ;
65
125
}
66
126
67
127
/**
@@ -80,10 +140,8 @@ public DeploymentShortfallNagDialog(final Campaign campaign) {
80
140
* @return {@code true} if the nag dialog should be displayed due to deployment shortfalls; {@code false} otherwise.
81
141
*/
82
142
public static boolean checkNag (boolean isUseAtB , Campaign campaign ) {
83
- final String NAG_KEY = MHQConstants . NAG_SHORT_DEPLOYMENT ;
143
+ final String NAG_KEY = NAG_SHORT_DEPLOYMENT ;
84
144
85
- return isUseAtB
86
- && !MekHQ .getMHQOptions ().getNagDialogIgnore (NAG_KEY )
87
- && hasDeploymentShortfall (campaign );
145
+ return isUseAtB && !MekHQ .getMHQOptions ().getNagDialogIgnore (NAG_KEY ) && hasDeploymentShortfall (campaign );
88
146
}
89
147
}
0 commit comments