Skip to content

Commit 3a7f22b

Browse files
authored
Merge pull request #6382 from IllianiCBT/DeploymentShortfallNagDialogNew
Updated Deployment Shortfall Nag To Use Immersive Dialog
2 parents f7e5f11 + 4b18ab6 commit 3a7f22b

File tree

5 files changed

+94
-29
lines changed

5 files changed

+94
-29
lines changed

MekHQ/resources/mekhq/resources/GUI.properties

-7
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,6 @@ OutstandingScenariosNagDialog.stratCon=<br>\
354354
PregnantCombatantNagDialog.text=%s, pregnant personnel have been identified in our TO&E, putting\
355355
\ them at risk of harm. Reassignment is advised. Do you wish to advance the day without\
356356
\ addressing this concern?
357-
DeploymentShortfallNagDialog.text=%s, deployment levels fall below requirements for one or more active\
358-
\ contracts. While advancing the day is an option, it may strain relations with our employer. Do\
359-
\ you wish to continue without addressing this?\
360-
<br>\
361-
<br><i>You should head to the Briefing Room and address this shortfall. Remember, Combat Teams\
362-
\ assigned to the Auxiliary or Reserve roles do not count towards deployment levels. Nor do\
363-
\ Combat Teams assigned to the Training role, unless the contract is Cadre Duty.</i>
364357
PrisonersNagDialog.text=%s, our forces are still holding prisoners of war. It is important to\
365358
\ consider their status before advancing the day. Do you wish to continue without resolving this?\
366359
<br>\
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
# Buttons
12
button.cancel=I better take a look.
23
button.continue=Continue as ordered.
34
button.suppress=Continue and don''t bother me with future issues of this type.
5+
# Admin Strain
46
AdminStrainNagDialog.ic={0}, my team is buckling under the strain. Memos are going unanswered. We''ve got people queuing\
57
\ up outside with complaints. We''ve even got reports of unpaid salaries. People are getting angry, and if we don''t\
68
\ solve the problem soon, they''re liable to quit.
79
AdminStrainNagDialog.ooc=Excess <a href=''GLOSSARY:ADMIN_STRAIN''>Administrative Strain</a> is addressed by hiring more\
810
\ Admin/HR personnel. If that isn''t viable, consider assigning your current Admin personnel to multiple roles.</p>\
911
<p>For more information, please see <i>MekHQ/docs/Personnel Modules/Turnover & Retention Module (feat. Fatigue).pdf</i></p>\
1012
<p>If you accidentally suppress this warning, you can re-enable it in MekHQ Options.</p>
13+
# Deployment Shortfall
14+
DeploymentShortfallNagDialog.ic={0}, deployment levels have fallen below contractual requirements\
15+
\ for one or more contracts. While advancing the day is an option, it may strain relations with\
16+
\ our employer. Do you wish to continue without addressing this?
17+
DeploymentShortfallNagDialog.ooc=You should head to the Briefing Room and address this shortfall.\
18+
\ Remember, <a href=''GLOSSARY:COMBAT_TEAMS''>Combat Teams</a> assigned to the Auxiliary or\
19+
\ Reserve roles do not count towards deployment levels. Nor do Combat Teams assigned to the\
20+
\ Training role, unless the contract is Cadre Duty.\
21+
<p>If you accidentally suppress this warning, you can re-enable it in MekHQ Options.</p>

MekHQ/src/mekhq/gui/dialog/nagDialogs/AdminStrainNagDialog.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public AdminStrainNagDialog(final Campaign campaign) {
8585
MekHQ.getMHQOptions().setNagDialogIgnore(NAG_ADMIN_STRAIN, true);
8686
cancelAdvanceDay = false;
8787
}
88-
default -> throw new IllegalStateException("Unexpected value in AdminStrainNagDialog: " + choiceIndex);
88+
default -> throw new IllegalStateException("Unexpected value in " +
89+
getClass().getSimpleName() +
90+
": " +
91+
choiceIndex);
8992
}
9093
}
9194

MekHQ/src/mekhq/gui/dialog/nagDialogs/DeploymentShortfallNagDialog.java

+78-20
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,101 @@
2727
*/
2828
package mekhq.gui.dialog.nagDialogs;
2929

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+
3138
import mekhq.MekHQ;
3239
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;
3641

3742
/**
3843
* A nag dialog that alerts the user if short deployments are detected in the campaign's active contracts.
3944
*
4045
* <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.
4549
* </p>
4650
*/
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+
4861
/**
4962
* Constructs the shortfall deployment nag dialog for a given campaign.
5063
*
5164
* <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.
5467
* </p>
5568
*
5669
* @param campaign The {@link Campaign} object representing the current campaign.
5770
*/
5871
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+
}
6099

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;
65125
}
66126

67127
/**
@@ -80,10 +140,8 @@ public DeploymentShortfallNagDialog(final Campaign campaign) {
80140
* @return {@code true} if the nag dialog should be displayed due to deployment shortfalls; {@code false} otherwise.
81141
*/
82142
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;
84144

85-
return isUseAtB
86-
&& !MekHQ.getMHQOptions().getNagDialogIgnore(NAG_KEY)
87-
&& hasDeploymentShortfall(campaign);
145+
return isUseAtB && !MekHQ.getMHQOptions().getNagDialogIgnore(NAG_KEY) && hasDeploymentShortfall(campaign);
88146
}
89147
}

MekHQ/src/mekhq/gui/dialog/nagDialogs/NagController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static boolean triggerDailyNags(Campaign campaign) {
205205

206206
if (DeploymentShortfallNagDialog.checkNag(isUseAtB, campaign)) {
207207
DeploymentShortfallNagDialog deploymentShortfallNagDialog = new DeploymentShortfallNagDialog(campaign);
208-
if (deploymentShortfallNagDialog.wasAdvanceDayCanceled()) {
208+
if (deploymentShortfallNagDialog.shouldCancelAdvanceDay()) {
209209
return true;
210210
}
211211
}

0 commit comments

Comments
 (0)