Skip to content

Commit 197fdc7

Browse files
authored
Merge pull request #6398 from IllianiCBT/InvalidFactionNagNew
Updated Invalid Faction Nag To Use Immersive Dialog
2 parents bdbaa5f + 8ec04ee commit 197fdc7

File tree

6 files changed

+82
-36
lines changed

6 files changed

+82
-36
lines changed

MekHQ/resources/mekhq/resources/GUI.properties

-5
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ NoCommanderNagDialog.text=Please be advised that no commanding officer is curren
309309
<br>\
310310
<br><i>You can assign one of your personnel as the campaign commander by right-clicking on that\
311311
\ character, navigating to Flags and selecting the Commander flag.</i>
312-
InvalidFactionNagDialog.text=%s, reports indicate our parent faction is invalid. Possibly\
313-
\ destroyed. Confirm your intent to advance the day under these circumstances.\
314-
<br>\
315-
<br><i>You will need to select a new faction in the campaign options. Failure to do will result\
316-
\ in contracts no longer being generated.
317312
OutstandingScenariosNagDialog.text=%s, our forces are positioned for combat but await your commands to\
318313
\ proceed. Alternatively, you may order a tactical withdrawal by advancing the day. Do you wish\
319314
\ to proceed without addressing these engagements?\

MekHQ/resources/mekhq/resources/NagDialogs.properties

+7
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ InsufficientMedicsNagDialog.ic={0}, our medical teams are short by {1} {1, choic
5353
InsufficientMedicsNagDialog.ooc=You can resolve this issue by selecting 'Marketplace' in the taskbar,\
5454
\ then 'Medic Pool,' then selecting the option to bring all teams up to full strength.\
5555
<p>If you accidentally suppress this warning, you can re-enable it in MekHQ Options.</p>
56+
# Invalid Faction
57+
InvalidFactionNagDialog.ic={0}, reports indicate our parent faction is invalid. Possibly\
58+
\ destroyed. Confirm your intent to advance the day under these circumstances.
59+
InvalidFactionNagDialog.ooc=You will need to select a new faction in the campaign options. Failure\
60+
\ to do this while using <a href=''GLOSSARY:STRATCON''>StratCon</a> will prevent contracts from\
61+
\ being generated.\
62+
<p>If you accidentally suppress this warning, you can re-enable it in MekHQ Options.</p>

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

-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public class DeploymentShortfallNagDialog {
5555
private final int CHOICE_CONTINUE = 1;
5656
private final int CHOICE_SUPPRESS = 2;
5757

58-
private final Campaign campaign;
5958
private boolean cancelAdvanceDay;
6059

6160
/**
@@ -69,8 +68,6 @@ public class DeploymentShortfallNagDialog {
6968
* @param campaign The {@link Campaign} object representing the current campaign.
7069
*/
7170
public DeploymentShortfallNagDialog(final Campaign campaign) {
72-
this.campaign = campaign;
73-
7471
ImmersiveDialogSimple dialog = new ImmersiveDialogSimple(campaign,
7572
campaign.getSeniorAdminPerson(COMMAND),
7673
null,

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

-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class EndContractNagDialog {
6565
private final int CHOICE_CONTINUE = 1;
6666
private final int CHOICE_SUPPRESS = 2;
6767

68-
private final Campaign campaign;
6968
private boolean cancelAdvanceDay;
7069

7170
/**
@@ -80,8 +79,6 @@ public class EndContractNagDialog {
8079
* @param campaign The {@link Campaign} that the nag dialog is tied to.
8180
*/
8281
public EndContractNagDialog(final Campaign campaign) {
83-
this.campaign = campaign;
84-
8582
ImmersiveDialogSimple dialog = new ImmersiveDialogSimple(campaign,
8683
campaign.getSeniorAdminPerson(COMMAND),
8784
null,

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

+74-24
Original file line numberDiff line numberDiff line change
@@ -27,52 +27,102 @@
2727
*/
2828
package mekhq.gui.dialog.nagDialogs;
2929

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;
3534

3635
import java.time.LocalDate;
36+
import java.util.ArrayList;
37+
import java.util.List;
3738

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;
3943

4044
/**
4145
* A dialog used to notify the user about an invalid faction in the current campaign.
4246
*
4347
* <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.
4751
* </p>
4852
*
4953
* <strong>Features:</strong>
5054
* <ul>
5155
* <li>Checks whether the campaign's faction is valid based on the current in-game date.</li>
5256
* <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>
5457
* </ul>
5558
*/
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+
5768
/**
5869
* Constructs an {@code InvalidFactionNagDialog} for the given campaign.
5970
*
6071
* <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.
6474
* </p>
6575
*
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.
6878
*/
6979
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"));
71115

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;
76126
}
77127

78128
/**
@@ -86,12 +136,12 @@ public InvalidFactionNagDialog(final Campaign campaign) {
86136
*
87137
* @param campaignFaction The {@link Faction} associated with the campaign to be checked.
88138
* @param today The {@link LocalDate} representing the current in-game date.
139+
*
89140
* @return {@code true} if the nag dialog should be displayed, {@code false} otherwise.
90141
*/
91142
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;
93144

94-
return !MekHQ.getMHQOptions().getNagDialogIgnore(NAG_KEY)
95-
&& (isFactionInvalid(campaignFaction, today));
145+
return !MekHQ.getMHQOptions().getNagDialogIgnore(NAG_KEY) && (isFactionInvalid(campaignFaction, today));
96146
}
97147
}

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

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

8585
if (InvalidFactionNagDialog.checkNag(campaign.getFaction(), today)) {
8686
InvalidFactionNagDialog invalidFactionNagDialog = new InvalidFactionNagDialog(campaign);
87-
if (invalidFactionNagDialog.wasAdvanceDayCanceled()) {
87+
if (invalidFactionNagDialog.shouldCancelAdvanceDay()) {
8888
return true;
8989
}
9090
}

0 commit comments

Comments
 (0)