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

Added Ability to Define Skill Levels When Using GM Hire Minimum Complement #4885

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ removePregnancy.text=Remove Pregnancy
removePregnancies.text=Remove Pregnancies
regenerateLoyalty.text=Regenerate Loyalty
regeneratePersonality.text=Regenerate Personality
addMinimumComplement.text=Add minimum complement
addMinimumComplementRandom.text=Random
addMinimumComplementElite.text=Elite
addMinimumComplementVeteran.text=Veteran
addMinimumComplementRegular.text=Regular
addMinimumComplementGreen.text=Green
addMinimumComplementUltraGreen.text=Ultra Green

#### ProcurementTableMouseAdapter Class
miClearItems.text=Clear All Items
Expand All @@ -278,7 +285,6 @@ deleteUnitsCount.text=%d units
removeQ.title=Remove?
confirmRemove.text=Do you really want to remove %s?
hireMinimumComplement.text=Hire minimum complement
addMinimumComplement.text=Add minimum complement



Expand Down
119 changes: 75 additions & 44 deletions MekHQ/src/mekhq/gui/adapter/UnitTableMouseAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,12 @@
*/
package mekhq.gui.adapter;

import static megamek.client.ui.WrapLayout.wordWrap;

import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.UUID;
import java.util.Vector;
import java.util.stream.Stream;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JSplitPane;
import javax.swing.JTable;

import megamek.client.ui.dialogs.BVDisplayDialog;
import megamek.client.ui.dialogs.CamoChooserDialog;
import megamek.client.ui.swing.UnitEditorDialog;
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.enums.SkillLevel;
import megamek.common.icons.Camouflage;
import megamek.common.loaders.BLKFile;
import megamek.common.loaders.EntityLoadingException;
Expand All @@ -65,24 +42,11 @@
import mekhq.campaign.parts.equipment.AmmoBin;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.unit.Unit;
import mekhq.campaign.unit.actions.ActivateUnitAction;
import mekhq.campaign.unit.actions.CancelMothballUnitAction;
import mekhq.campaign.unit.actions.HirePersonnelUnitAction;
import mekhq.campaign.unit.actions.IUnitAction;
import mekhq.campaign.unit.actions.MothballUnitAction;
import mekhq.campaign.unit.actions.RestoreUnitAction;
import mekhq.campaign.unit.actions.StripUnitAction;
import mekhq.campaign.unit.actions.SwapAmmoTypeAction;
import mekhq.campaign.unit.actions.*;
import mekhq.gui.CampaignGUI;
import mekhq.gui.HangarTab;
import mekhq.gui.MekLabTab;
import mekhq.gui.dialog.BombsDialog;
import mekhq.gui.dialog.ChooseRefitDialog;
import mekhq.gui.dialog.LargeCraftAmmoSwapDialog;
import mekhq.gui.dialog.MarkdownEditorDialog;
import mekhq.gui.dialog.MassMothballDialog;
import mekhq.gui.dialog.QuirksDialog;
import mekhq.gui.dialog.SmallSVAmmoSwapDialog;
import mekhq.gui.dialog.*;
import mekhq.gui.dialog.reportDialogs.MaintenanceReportDialog;
import mekhq.gui.dialog.reportDialogs.MonthlyUnitCostReportDialog;
import mekhq.gui.enums.MHQTabType;
Expand All @@ -92,6 +56,19 @@
import mekhq.gui.utilities.JMenuHelpers;
import mekhq.gui.utilities.StaticChecks;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Stream;

import static megamek.client.ui.WrapLayout.wordWrap;
import static mekhq.gui.dialog.HireBulkPersonnelDialog.overrideSkills;

public class UnitTableMouseAdapter extends JPopupMenuAdapter {
private static final MMLogger logger = MMLogger.create(UnitTableMouseAdapter.class);

Expand Down Expand Up @@ -148,7 +125,12 @@ public class UnitTableMouseAdapter extends JPopupMenuAdapter {
public static final String COMMAND_GM_MOTHBALL = COMMAND_MOTHBALL + COMMAND_GM;
public static final String COMMAND_GM_ACTIVATE = COMMAND_ACTIVATE + COMMAND_GM;
public static final String COMMAND_UNDEPLOY = "UNDEPLOY";
public static final String COMMAND_HIRE_FULL_GM = COMMAND_HIRE_FULL + COMMAND_GM;
public static final String COMMAND_HIRE_FULL_GM_RANDOM = COMMAND_HIRE_FULL + COMMAND_GM;
public static final String COMMAND_HIRE_FULL_GM_ELITE = COMMAND_HIRE_FULL + COMMAND_GM + "ELITE";
public static final String COMMAND_HIRE_FULL_GM_VETERAN = COMMAND_HIRE_FULL + COMMAND_GM + "VETERAN";
public static final String COMMAND_HIRE_FULL_GM_REGULAR = COMMAND_HIRE_FULL + COMMAND_GM + "REGULAR";
public static final String COMMAND_HIRE_FULL_GM_GREEN = COMMAND_HIRE_FULL + COMMAND_GM + "GREEN";
public static final String COMMAND_HIRE_FULL_GM_ULTRA_GREEN = COMMAND_HIRE_FULL + COMMAND_GM +"ULTRA_GREEN";
public static final String COMMAND_EDIT_DAMAGE = "EDIT_DAMAGE";
public static final String COMMAND_RESTORE_UNIT = "RESTORE_UNIT";
public static final String COMMAND_SET_QUALITY = "SET_QUALITY";
Expand Down Expand Up @@ -345,10 +327,30 @@ public void actionPerformed(ActionEvent action) {
}
}
} else if (command.contains(COMMAND_HIRE_FULL)) {
boolean isGM = command.equals(COMMAND_HIRE_FULL_GM);
boolean isGM = command.contains("GM");
HirePersonnelUnitAction hireAction = new HirePersonnelUnitAction(isGM);
for (Unit unit : units) {
hireAction.execute(gui.getCampaign(), unit);

if (command.contains("RANDOM")) {
continue;
}

SkillLevel skillLevel = SkillLevel.REGULAR;
if (command.contains("ELITE")) {
skillLevel = SkillLevel.ELITE;
} else if (command.contains("VETERAN")) {
skillLevel = SkillLevel.VETERAN;
} else if (command.contains("GREEN")) {
skillLevel = SkillLevel.GREEN;
} else if (command.contains("ULTRA_GREEN")) {
skillLevel = SkillLevel.ULTRA_GREEN;
}

for (Person person : unit.getCrew()) {
overrideSkills(gui.getCampaign(), person, person.getPrimaryRole(), skillLevel.ordinal());
}

}
} else if (command.equals(COMMAND_CUSTOMIZE)) { // Single Unit only
((MekLabTab) gui.getTab(MHQTabType.MEK_LAB)).loadUnit(selectedUnit);
Expand Down Expand Up @@ -992,10 +994,39 @@ protected Optional<JPopupMenu> createPopupMenu() {
}

if (oneAvailableUnitBelowMaxCrew) {
menuItem = new JMenuItem(resources.getString("addMinimumComplement.text"));
menuItem.setActionCommand(COMMAND_HIRE_FULL_GM);
JMenu menuMinimumComplement = new JMenu(resources.getString("addMinimumComplement.text"));

menuItem = new JMenuItem(resources.getString("addMinimumComplementRandom.text"));
menuItem.setActionCommand(COMMAND_HIRE_FULL_GM_RANDOM);
menuItem.addActionListener(this);
menu.add(menuItem);
menuMinimumComplement.add(menuItem);

menuItem = new JMenuItem(resources.getString("addMinimumComplementElite.text"));
menuItem.setActionCommand(COMMAND_HIRE_FULL_GM_ELITE);
menuItem.addActionListener(this);
menuMinimumComplement.add(menuItem);

menuItem = new JMenuItem(resources.getString("addMinimumComplementVeteran.text"));
menuItem.setActionCommand(COMMAND_HIRE_FULL_GM_VETERAN);
menuItem.addActionListener(this);
menuMinimumComplement.add(menuItem);

menuItem = new JMenuItem(resources.getString("addMinimumComplementRegular.text"));
menuItem.setActionCommand(COMMAND_HIRE_FULL_GM_REGULAR);
menuItem.addActionListener(this);
menuMinimumComplement.add(menuItem);

menuItem = new JMenuItem(resources.getString("addMinimumComplementGreen.text"));
menuItem.setActionCommand(COMMAND_HIRE_FULL_GM_GREEN);
menuItem.addActionListener(this);
menuMinimumComplement.add(menuItem);

menuItem = new JMenuItem(resources.getString("addMinimumComplementUltraGreen.text"));
menuItem.setActionCommand(COMMAND_HIRE_FULL_GM_ULTRA_GREEN);
menuItem.addActionListener(this);
menuMinimumComplement.add(menuItem);

menu.add(menuMinimumComplement);
}

if (oneSelected) {
Expand Down
44 changes: 20 additions & 24 deletions MekHQ/src/mekhq/gui/dialog/HireBulkPersonnelDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,6 @@
*/
package mekhq.gui.dialog;

import static mekhq.campaign.personnel.SkillType.*;
import static mekhq.campaign.personnel.generator.AbstractSkillGenerator.addSkill;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
import java.util.ResourceBundle;

import javax.swing.*;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.JSpinner.NumberEditor;

import megamek.client.ui.baseComponents.MMComboBox;
import megamek.client.ui.preferences.JWindowPreference;
import megamek.client.ui.preferences.PreferencesNode;
Expand All @@ -53,6 +36,20 @@
import mekhq.gui.CampaignGUI;
import mekhq.gui.displayWrappers.RankDisplay;

import javax.swing.*;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.JSpinner.NumberEditor;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
import java.util.ResourceBundle;

import static mekhq.campaign.personnel.SkillType.*;
import static mekhq.campaign.personnel.generator.AbstractSkillGenerator.addSkill;

/**
* @author Jay Lawson
*/
Expand Down Expand Up @@ -341,10 +338,8 @@ private void hire(boolean isGmHire) {
Person person = campaign.newPerson(selectedItem.getRole());

if ((useSkill) && (!selectedItem.getRole().isCivilian()) && (!selectedItem.getRole().isAssistant())) {
overrideSkills(
person,
selectedItem.getRole(),
Objects.requireNonNull(skillLevel.getSelectedItem()).ordinal());
overrideSkills(campaign, person, selectedItem.getRole(),
Objects.requireNonNull(skillLevel.getSelectedItem()).ordinal());
}

person.setRank(((RankDisplay) Objects.requireNonNull(choiceRanks.getSelectedItem())).getRankNumeric());
Expand Down Expand Up @@ -379,15 +374,16 @@ private void hire(boolean isGmHire) {
}

/**
* Replaces the skills for a {@link Person} based on their primary role and
* desired experience level.
* Replaces the skills for a {@link Person} based on their primary role and desired experience level.
*
* @param campaign The current campaign
* @param person The {@link Person} to add default skills.
* @param primaryRole The primary role of the person
* @param expLvl The experience level of the person (e.g.
* {@link SkillType#EXP_GREEN}).
*/
protected void overrideSkills(Person person, PersonnelRole primaryRole, int expLvl) {
public static void overrideSkills(Campaign campaign, Person person, PersonnelRole primaryRole,
int expLvl) {
switch (primaryRole) {
case MEKWARRIOR:
addSkillFixedExperienceLevel(person, S_PILOT_MEK, expLvl);
Expand Down