Skip to content

Commit

Permalink
MegaMek#3763 reversing quality names in unit set quality GM menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jackreichelt committed Jan 30, 2024
1 parent 08e2f2c commit 959c445
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions MekHQ/src/mekhq/gui/adapter/UnitTableMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,43 +176,28 @@ public void actionPerformed(ActionEvent action) {
} else if (command.equals(COMMAND_SUPPLY_COST)) { // Single Unit only
new MonthlyUnitCostReportDialog(gui.getFrame(), selectedUnit).setVisible(true);
} else if (command.equals(COMMAND_SET_QUALITY)) {
int q;
Object[] possibilities = { "F", "E", "D", "C", "B", "A" }; // TODO : this probably shouldn't be inline
String quality = (String) JOptionPane.showInputDialog(gui.getFrame(),
"Choose the new quality level", "Set Quality",
JOptionPane.PLAIN_MESSAGE, null, possibilities, "F");

// showInputDialog returns null when cancel is clicked, so we set a default here
if (quality == null) {
quality = "CANCELED";
}

switch (quality) {
case "A":
q = 0;
break;
case "B":
q = 1;
break;
case "C":
q = 2;
break;
case "D":
q = 3;
break;
case "E":
q = 4;
break;
case "F":
q = 5;
break;
default:
q = -1;
// TODO : Duplicated in PartsTableMouseAdapter#actionPerformed
int q = -1;
boolean reverse = gui.getCampaign().getCampaignOptions().isReverseQualityNames();
Object[] possibilities = { Part.getQualityName(Part.QUALITY_A, reverse),
Part.getQualityName(Part.QUALITY_B, reverse), Part.getQualityName(Part.QUALITY_C, reverse),
Part.getQualityName(Part.QUALITY_D, reverse), Part.getQualityName(Part.QUALITY_E, reverse),
Part.getQualityName(Part.QUALITY_F, reverse) };
String quality = (String) JOptionPane.showInputDialog(gui.getFrame(), "Choose the new quality level",
"Set Quality", JOptionPane.PLAIN_MESSAGE, null, possibilities,
Part.getQualityName(Part.QUALITY_D, reverse));
for (int i = 0; i < possibilities.length; i++) {
if (possibilities[i].equals(quality)) {
q = i;
break;
}
}
if (q != -1) {
for (Unit unit : units) {
unit.setQuality(q);
if (unit != null) {
unit.setQuality(q);
MekHQ.triggerEvent(new UnitChangedEvent(unit));
}
}
}
} else if (command.equals(COMMAND_SELL)) {
Expand Down

0 comments on commit 959c445

Please sign in to comment.