Skip to content
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

Replaced CargoCapacityNagDialog functionality #4388

Merged
merged 2 commits into from
Jul 14, 2024
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
4 changes: 0 additions & 4 deletions MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,6 @@ EndContractNagDialog.text=A contract has concluded and needs resolution. Do you
UnresolvedStratConContactsNagDialog.title=Unresolved StratCon Contacts
UnresolvedStratConContactsNagDialog.text=You have unresolved contacts on the StratCon interface:\n%s\nAdvance day anyway?

### CargoCapacityNagDialog Class
cargoCapacityNagDialog.title=Exceeded Cargo Capacity
cargoCapacityNagDialog.text=You have exceeded your available cargo capacity. Do you really wish to advance the day?

### FactionDestroyedNagDialog Class
InvalidFactionNagDialog.title=Invalid Faction
InvalidFactionNagDialog.text=Your campaign faction is invalid. Either it has not yet been created, or it has been destroyed.\n\nPlease pick a new faction in campaign options.\nAdvance day anyway?
Expand Down
1 change: 0 additions & 1 deletion MekHQ/src/mekhq/MHQConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public final class MHQConstants extends SuiteConstants {
public static final String NAG_SHORT_DEPLOYMENT = "nagShortDeployment";
public static final String NAG_UNRESOLVED_STRATCON_CONTACTS = "nagUnresolvedStratConContacts";
public static final String NAG_OUTSTANDING_SCENARIOS = "nagOutstandingScenarios";
public static final String NAG_CARGO_CAPACITY = "nagCargoCapacity";
public static final String NAG_INVALID_FACTION = "nagInvalidFaction";
// endregion Nag Tab

Expand Down
34 changes: 26 additions & 8 deletions MekHQ/src/mekhq/campaign/CampaignSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import megamek.common.Entity;
import megamek.common.Infantry;
import megamek.common.UnitType;
import mekhq.MekHQ;
import mekhq.campaign.mission.Mission;
import mekhq.campaign.mission.enums.MissionStatus;
import mekhq.campaign.personnel.Person;
Expand Down Expand Up @@ -255,16 +256,33 @@ public String getMissionSuccessReport() {
* A report that gives capacity and existing tonnage of all cargo
* @return a <code>String</code> of the report
*/
public String getCargoCapacityReport() {
return (int) Math.round(cargoTons) + " tons (" + (int) Math.round(cargoCapacity) + " tons capacity)";
}
public StringBuilder getCargoCapacityReport() {
int cargoTonsRounded = (int) Math.round(cargoTons);
int cargoCapacityRounded = (int) Math.round(cargoCapacity);
StringBuilder report = new StringBuilder("<html>");

if (cargoTonsRounded > cargoCapacityRounded) {
report.append("<font color='")
.append(MekHQ.getMHQOptions().getFontColorNegativeHexColor())
.append("'>");
} else if (cargoTonsRounded == cargoCapacityRounded) {
report.append("<font color='")
.append(MekHQ.getMHQOptions().getFontColorWarningHexColor())
.append("'>");
}

public int getCargoTons() {
return (int) Math.round(cargoTons);
}
report.append(cargoTonsRounded)
.append(" tons (")
.append(cargoCapacityRounded)
.append(" tons capacity)");

if (!report.toString().equals(cargoTonsRounded + " tons (" + cargoCapacityRounded + " tons capacity)")) {
report.append("</font></html>");
} else {
report.append("</html>");
}

public int getCargoCapacity() {
return (int) Math.round(cargoCapacity);
return report;
}

/**
Expand Down
25 changes: 10 additions & 15 deletions MekHQ/src/mekhq/gui/CampaignGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1613,10 +1613,10 @@ public void refitUnit(Refit r, boolean selectModelName) {
if (getCampaign().isWorkingOnRefit(tech) || tech.isEngineer()) {
continue;
}
name = tech.getFullName() + ", " + tech.getSkillLevel(getCampaign(), false) + " "
name = tech.getFullName() + ", " + tech.getSkillLevel(getCampaign(), false) + ' '
+ tech.getPrimaryRoleDesc() + " ("
+ getCampaign().getTargetFor(r, tech).getValueAsString() + "+), "
+ tech.getMinutesLeft() + "/" + tech.getDailyAvailableTechTime() + " minutes";
+ tech.getMinutesLeft() + '/' + tech.getDailyAvailableTechTime() + " minutes";
techHash.put(name, tech);
if (tech.isRightTechTypeFor(r)) {
techList.add(lastRightTech++, name);
Expand Down Expand Up @@ -1673,7 +1673,7 @@ public void refitUnit(Refit r, boolean selectModelName) {
}
if (0 != JOptionPane
.showConfirmDialog(null, RefitRefurbish
+ r.getUnit().getName() + "?", "Proceed?",
+ r.getUnit().getName() + '?', "Proceed?",
JOptionPane.YES_NO_OPTION)) {
return;
}
Expand Down Expand Up @@ -1729,7 +1729,7 @@ public void refitUnit(Refit r, boolean selectModelName) {
Object[] nameArray = techHash.keySet().toArray();

String s = (String) JOptionPane.showInputDialog(frame,
"Which tech should work on " + desc + "?", "Select Tech",
"Which tech should work on " + desc + '?', "Select Tech",
JOptionPane.PLAIN_MESSAGE, null, nameArray, nameArray[0]);
if (null == s) {
return null;
Expand Down Expand Up @@ -1782,7 +1782,7 @@ protected void exportPersonnel(FileType format, String dialogTitle, String filen
dialogTitle,
format,
MekHQ.getPersonnelDirectory().getValue(),
filename + "." + format.getRecommendedExtension())
filename + '.' + format.getRecommendedExtension())
.ifPresent(f -> {
MekHQ.getPersonnelDirectory().setValue(f.getParent());
File file = checkFileEnding(f, format.getRecommendedExtension());
Expand Down Expand Up @@ -1814,7 +1814,7 @@ protected void exportUnits(FileType format, String dialogTitle, String filename)
dialogTitle,
format,
MekHQ.getUnitsDirectory().getValue(),
filename + "." + format.getRecommendedExtension())
filename + '.' + format.getRecommendedExtension())
.ifPresent(f -> {
MekHQ.getUnitsDirectory().setValue(f.getParent());
File file = checkFileEnding(f, format.getRecommendedExtension());
Expand Down Expand Up @@ -1846,7 +1846,7 @@ protected void exportFinances(FileType format, String dialogTitle, String filena
dialogTitle,
format,
MekHQ.getFinancesDirectory().getValue(),
filename + "." + format.getRecommendedExtension())
filename + '.' + format.getRecommendedExtension())
.ifPresent(f -> {
MekHQ.getFinancesDirectory().setValue(f.getParent());
File file = checkFileEnding(f, format.getRecommendedExtension());
Expand Down Expand Up @@ -1888,8 +1888,8 @@ private void checkToBackupFile(File file, String path) {
*/
private File checkFileEnding(File file, String format) {
String path = file.getPath();
if (!path.endsWith("." + format)) {
path += "." + format;
if (!path.endsWith('.' + format)) {
path += '.' + format;
file = new File(path);
}
return file;
Expand Down Expand Up @@ -1962,7 +1962,7 @@ protected void loadPersonFile() {
Person p = Person.generateInstanceFromXML(wn2, getCampaign(), version);
if ((p != null) && (getCampaign().getPerson(p.getId()) != null)) {
LogManager.getLogger().error("ERROR: Cannot load person who exists, ignoring. (Name: "
+ p.getFullName() + ", Id " + p.getId() + ")");
+ p.getFullName() + ", Id " + p.getId() + ')');
p = null;
}

Expand Down Expand Up @@ -2442,11 +2442,6 @@ public void handleDayEnding(DayEndingEvent evt) {
return;
}

if (new CargoCapacityNagDialog(getFrame(), getCampaign()).showDialog().isCancelled()) {
evt.cancel();
return;
}

if (new InvalidFactionNagDialog(getFrame(), getCampaign()).showDialog().isCancelled()) {
evt.cancel();
return;
Expand Down
10 changes: 5 additions & 5 deletions MekHQ/src/mekhq/gui/CommandCenterTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public final class CommandCenterTab extends CampaignGuiTab {

// objectives panel
private JPanel panObjectives;
java.awt.List listObjectives;
List listObjectives;

// daily report
private DailyReportLogPanel panLog;
Expand All @@ -95,7 +95,7 @@ public final class CommandCenterTab extends CampaignGuiTab {
private JPanel panIcon;
private JLabel lblIcon;

private static final transient ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.CampaignGUI",
private static final ResourceBundle resourceMap = ResourceBundle.getBundle("mekhq.resources.CampaignGUI",
MekHQ.getMHQOptions().getLocale());

/**
Expand Down Expand Up @@ -313,7 +313,7 @@ private void initInfoPanel() {
gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new Insets(1, 5, 1, 5);
panInfo.add(lblCargoSummaryHead, gridBagConstraints);
lblCargoSummary = new JLabel(getCampaign().getCampaignSummary().getCargoCapacityReport());
lblCargoSummary = new JLabel(getCampaign().getCampaignSummary().getCargoCapacityReport().toString());
lblCargoSummaryHead.setLabelFor(lblCargoSummary);
gridBagConstraints.gridx = 1;
gridBagConstraints.weightx = 1.0;
Expand Down Expand Up @@ -345,7 +345,7 @@ private void initInfoPanel() {
private void initObjectivesPanel() {
panObjectives = new JPanel(new BorderLayout());
panObjectives.setBorder(BorderFactory.createTitledBorder(resourceMap.getString("panObjectives.title")));
listObjectives = new java.awt.List();
listObjectives = new List();
for (String objective : getCampaign().getCurrentObjectives()) {
listObjectives.add(objective);
}
Expand Down Expand Up @@ -546,7 +546,7 @@ private void refreshBasicInfo() {
lblMissionSuccess.setText(getCampaign().getCampaignSummary().getMissionSuccessReport());
lblExperience.setText(getCampaign().getUnitRating().getAverageExperience().toString());
lblComposition.setText(getCampaign().getCampaignSummary().getForceCompositionReport());
lblCargoSummary.setText(getCampaign().getCampaignSummary().getCargoCapacityReport());
lblCargoSummary.setText(getCampaign().getCampaignSummary().getCargoCapacityReport().toString());
lblRepairStatus.setText(getCampaign().getCampaignSummary().getForceRepairReport());
lblTransportCapacity.setText(getCampaign().getCampaignSummary().getTransportCapacity());

Expand Down
Loading