8000 Refactored Untreated Personnel Nag Dialog To Use Immersive Dialog Framework by IllianiBird · Pull Request #6414 · MegaMek/mekhq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactored Untreated Personnel Nag Dialog To Use Immersive Dialog Framework #6414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,6 @@ NoCommanderNagDialog.text=Please be advised that no commanding officer is curren
UnresolvedStratConContactsNagDialog.report=<br><b>- {0}</b>, {1}, {2}-{3} {4}
UnresolvedStratConContactsNagDialog.turningPoint=(Turning Point)
UnresolvedStratConContactsNagDialog.crisis=(Crisis)
UntreatedPersonnelNagDialog.text=%s, there are medically untreated personnel under our command.\
\ Advancing the day without addressing this may result in worsened conditions or operational\
\ inefficiencies. Confirm if you wish to proceed regardless.\
<br>\
<br><i>You should go to the Infirmary tab and assign your wounded personnel to Doctors. If you\
\ have insufficient Doctors, consider reassigning personnel so that the most critically injured\
\ or essential personnel are treated first. Alternatively, hire more Doctors.</i>
#### Report Dialogs
### CargoReportDialog Class
CargoReportDialog.title=Cargo Report
Expand Down
10 changes: 10 additions & 0 deletions MekHQ/resources/mekhq/resources/NagDialogs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,13 @@ UnresolvedStratConContactsNagDialog.ooc=If using <a href=''GLOSSARY:STRATCON''>S
\ marked as a <a href=''GLOSSARY:TURNING_POINT''>Turning Point</a> or\
\ <a href=''GLOSSARY:CRISIS_SCENARIO''>Crisis</a>. Withdrawal is free for all other scenarios.\
<p>If you accidentally suppress this warning, you can re-enable it in MekHQ Options.</p>
# Untreated Personnel
UntreatedPersonnelNagDialog.ic={0}, there are medically untreated personnel under our command.\
\ Advancing the day without addressing this may result in worsened conditions or operational\
\ inefficiencies. Confirm if you wish to proceed regardless.
UntreatedPersonnelNagDialog.ooc=You should go to the Infirmary tab and assign your wounded personnel\
\ to Doctors. If you have insufficient Doctors, consider reassigning personnel so that the most\
\ critically injured or essential personnel are treated first. Alternatively, hire more Doctors.\
<p>If you don't want to manually assign Doctors, you can enable the automatic assignment of injured\
\ personnel in MekHQ Options.</p>\
<p>If you accidentally suppress this warning, you can re-enable it in MekHQ Options.</p>
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/gui/dialog/nagDialogs/NagController.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static boolean triggerDailyNags(Campaign campaign) {
// Untreated personnel
if (UntreatedPersonnelNagDialog.checkNag(activePersonnel, doctorCapacity)) {
UntreatedPersonnelNagDialog untreatedPersonnelNagDialog = new UntreatedPersonnelNagDialog(campaign);
if (untreatedPersonnelNagDialog.wasAdvanceDayCanceled()) {
if (untreatedPersonnelNagDialog.shouldCancelAdvanceDay()) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,101 @@
*/
package mekhq.gui.dialog.nagDialogs;

import static mekhq.MHQConstants.NAG_UNTREATED_PERSONNEL;
import static mekhq.campaign.Campaign.AdministratorSpecialization.COMMAND;
import static mekhq.campaign.Campaign.AdministratorSpecialization.HR;
import static mekhq.gui.dialog.nagDialogs.nagLogic.UntreatedPersonnelNagLogic.campaignHasUntreatedInjuries;

import java.util.List;

import mekhq.MHQConstants;
import megamek.common.annotations.Nullable;
import mekhq.MekHQ;
import mekhq.campaign.Campaign;
import mekhq.campaign.Campaign.AdministratorSpecialization;
import mekhq.campaign.personnel.Person;
import mekhq.gui.baseComponents.AbstractMHQNagDialog;
import mekhq.gui.baseComponents.immersiveDialogs.ImmersiveDialogNag;

public class UntreatedPersonnelNagDialog extends ImmersiveDialogNag {
public UntreatedPersonnelNagDialog(Campaign campaign) {
super(campaign, null, NAG_UNTREATED_PERSONNEL, "UntreatedPersonnelNagDialog");
}

/**
* A nag dialog that alerts the user about untreated injuries within the campaign's personnel.
*
* <p>
* This dialog checks for active, injured personnel who have not been assigned to a doctor,
* excluding those currently classified as prisoners. It provides a reminder to the player, ensuring
* that injured personnel receive immediate treatment.
* </p>
*/
public class UntreatedPersonnelNagDialog extends AbstractMHQNagDialog {
/**
* Constructs the nag dialog for untreated personnel injuries.
* Retrieves the appropriate speaker for a campaign dialog based on personnel specialization and rank.
*
* <p>This method evaluates the active personnel within the campaign to determine the most suitable speaker.
* It prioritizes personnel with doctor roles, using rank and skills to select the optimal candidate. If no medical
* specialist is available, the method falls back to senior administrators with the "HR" or "COMMAND"
* specialization, ensuring a valid speaker is selected whenever possible.</p>
*
* <p>
* This constructor initializes the dialog with relevant campaign details
* and formats the displayed message to include context for the commander.
* </p>
* <p>If the campaign instance is {@code null} or there are no active personnel available, a fallback mechanism is
* employed to determine the speaker based on senior administrators.</p>
*
* @param campaign The {@link Campaign} object representing the current campaign.
* @param campaign The {@link Campaign} instance providing access to personnel and administrator data.
* @param specialization The {@link AdministratorSpecialization} used as a criterion for selecting the speaker.
*
* @return The {@link Person} designated as the speaker, prioritizing medical specialists, then senior
* administrators with "HR" or "COMMAND" specializations. Returns {@code null} if no suitable speaker can be
* found.
*/
public UntreatedPersonnelNagDialog(Campaign campaign) {
super(campaign, MHQConstants.NAG_UNTREATED_PERSONNEL);
@Override
protected @Nullable Person getSpeaker(@Nullable Campaign campaign, @Nullable Campaign.AdministratorSpecialization specialization) {
if (campaign == null) {
return null;
}

List<Person> potentialSpeakers = campaign.getActivePersonnel(false);

if (potentialSpeakers.isEmpty()) {
return getFallbackSpeaker(campaign);
}

Person speaker = null;

for (Person person : potentialSpeakers) {
if (!person.isDoctor()) {
continue;
}

if (speaker == null) {
speaker = person;
continue;
}

if (person.outRanksUsingSkillTiebreaker(campaign, speaker)) {
speaker = person;
}
}

// First fallback
if (speaker == null) {
return getFallbackSpeaker(campaign);
} else {
return speaker;
}
}

/**
* Retrieves a fallback speaker based on senior administrators within the campaign.
*
* <p>This method attempts to retrieve a senior administrator with the "HR" specialization first.
* If no such administrator is available, it falls back to one with the "COMMAND" specialization.</p>
*
* @param campaign The {@link Campaign} instance providing access to administrator data.
*
* @return The {@link Person} designated as the fallback speaker. Returns {@code null} if no suitable administrator
* is available.
*/
private @Nullable Person getFallbackSpeaker(Campaign campaign) {
Person speaker = campaign.getSeniorAdminPerson(HR);

if (speaker == null) {
speaker = campaign.getSeniorAdminPerson(COMMAND);
} else {
return speaker;
}

final String DIALOG_BODY = "UntreatedPersonnelNagDialog.text";
setRightDescriptionMessage(String.format(resources.getString(DIALOG_BODY),
campaign.getCommanderAddress(false)));
showDialog();
return speaker;
}

/**
Expand All @@ -76,14 +134,14 @@ public UntreatedPersonnelNagDialog(Campaign campaign) {
* </ul>
*
* @param activePersonnel A {@link List} of active personnel in the campaign.
* @param doctorCapacity The maximum number of patients each doctor can medicate.
* @param doctorCapacity The maximum number of patients each doctor can medicate.
*
* @return {@code true} if the nag dialog should be displayed due to untreated injuries, {@code false} otherwise.
*/
public static boolean checkNag(List<Person> activePersonnel, int doctorCapacity) {
final String NAG_KEY = MHQConstants.NAG_UNTREATED_PERSONNEL;
final String NAG_KEY = NAG_UNTREATED_PERSONNEL;

return !MekHQ.getMHQOptions().getNagDialogIgnore(NAG_KEY)
&& campaignHasUntreatedInjuries(activePersonnel, doctorCapacity);
return !MekHQ.getMHQOptions().getNagDialogIgnore(NAG_KEY) &&
campaignHasUntreatedInjuries(activePersonnel, doctorCapacity);
}
}
0