Skip to content

Commit

Permalink
Merge pull request #4698 from IllianiCBT/personnel_setSalary
Browse files Browse the repository at this point in the history
Refactored Salary Editing Logic
This PR fixes an NPE, although the bug was prematurely closed.
  • Loading branch information
Sleet01 authored Sep 1, 2024
2 parents e88a590 + 9e1de6f commit a60aaa1
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions MekHQ/src/mekhq/gui/adapter/PersonnelTableMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import megamek.client.generator.RandomCallsignGenerator;
import megamek.client.generator.RandomNameGenerator;
import megamek.client.ui.dialogs.PortraitChooserDialog;
import megamek.codeUtilities.MathUtility;
import megamek.common.Compute;
import megamek.common.Crew;
import megamek.common.EntityWeightClass;
Expand Down Expand Up @@ -1046,19 +1047,30 @@ public void actionPerformed(ActionEvent action) {
break;
}
case CMD_EDIT_SALARY: {
PopupValueChoiceDialog pcvd = new PopupValueChoiceDialog(gui.getFrame(), true,
int originalSalary = selectedPerson.getSalary(gui.getCampaign()).getAmount().intValue();

PopupValueChoiceDialog salaryDialog = new PopupValueChoiceDialog(
gui.getFrame(),
true,
resources.getString("changeSalary.text"),
selectedPerson.getSalary(gui.getCampaign()).getAmount().intValue(),
-1, 100000);
pcvd.setVisible(true);
int salary = pcvd.getValue();
if (salary < -1) {
MathUtility.clamp(originalSalary, -1, 1000000000),
-1,
1000000000
);

salaryDialog.setVisible(true);

int newSalary = salaryDialog.getValue();

if (newSalary < -1) {
return;
}

for (Person person : people) {
person.setSalary(Money.of(salary));
person.setSalary(Money.of(newSalary));
MekHQ.triggerEvent(new PersonChangedEvent(person));
}

break;
}
case CMD_GIVE_PAYMENT: {
Expand Down

0 comments on commit a60aaa1

Please sign in to comment.