Skip to content

Commit

Permalink
Merge pull request #3953 from AaronGullickson/disable-personnel-market
Browse files Browse the repository at this point in the history
Add disabled option for Personnel Market
  • Loading branch information
AaronGullickson authored Apr 3, 2024
2 parents 70e8156 + 81d2d49 commit 6c11d3e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ mekhq.campaign.market.PersonnelMarketRandom
mekhq.campaign.market.PersonnelMarketFMMr
mekhq.campaign.market.PersonnelMarketStratOps
mekhq.campaign.market.PersonnelMarketDylan
mekhq.campaign.market.PersonnelMarketDisabled
mekhq.module.atb.PersonnelMarketAtB
2 changes: 1 addition & 1 deletion MekHQ/src/mekhq/campaign/CampaignOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ public CampaignOptions() {

//region Markets Tab
// Personnel Market
setPersonnelMarketName(PersonnelMarket.getTypeName(PersonnelMarket.TYPE_STRAT_OPS));
setPersonnelMarketName(PersonnelMarket.getTypeName(PersonnelMarket.TYPE_NONE));
setPersonnelMarketReportRefresh(true);
setPersonnelMarketRandomRemovalTargets(new HashMap<>());
getPersonnelMarketRandomRemovalTargets().put(SkillLevel.NONE, 3);
Expand Down
14 changes: 11 additions & 3 deletions MekHQ/src/mekhq/campaign/market/PersonnelMarket.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ public class PersonnelMarket {
private List<Person> personnel = new ArrayList<>();
private PersonnelMarketMethod method;


public static final int TYPE_RANDOM = 0;
public static final int TYPE_DYLANS = 1;
public static final int TYPE_FMMR = 2;
public static final int TYPE_STRAT_OPS = 3;
public static final int TYPE_ATB = 4;
public static final int TYPE_NUM = 5;
public static final int TYPE_NONE = 5;
public static final int TYPE_NUM = 6;

/* Used by AtB to track Units assigned to recruits; the key
* is the person UUID. */
Expand All @@ -60,7 +62,7 @@ public class PersonnelMarket {
private PersonnelRole paidRecruitRole = PersonnelRole.MECHWARRIOR;

public PersonnelMarket() {
method = new PersonnelMarketRandom();
method = new PersonnelMarketDisabled();
MekHQ.registerHandler(this);
}

Expand All @@ -77,7 +79,7 @@ public PersonnelMarket(Campaign c) {
public void setType(String key) {
method = PersonnelMarketServiceManager.getInstance().getService(key);
if (null == method) {
method = new PersonnelMarketRandom();
method = new PersonnelMarketDisabled();
}
}

Expand Down Expand Up @@ -301,11 +303,17 @@ public static String getTypeName(int type) {
return "Strat Ops";
case TYPE_ATB:
return "Against the Bot";
case TYPE_NONE:
return "Disabled";
default:
return "ERROR: Default case reached in PersonnelMarket.getTypeName()";
}
}

public boolean isNone() {
return null == method || method instanceof PersonnelMarketDisabled;
}

public static long getUnitMainForceType(Campaign c) {
long mostTypes = getUnitMainForceTypes(c);
if ((mostTypes & Entity.ETYPE_MECH) != 0) {
Expand Down
45 changes: 45 additions & 0 deletions MekHQ/src/mekhq/campaign/market/PersonnelMarketDisabled.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
* MekHQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MekHQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MekHQ. If not, see <http://www.gnu.org/licenses/>.
*/
package mekhq.campaign.market;

import mekhq.campaign.Campaign;
import mekhq.campaign.personnel.Person;
import mekhq.module.api.PersonnelMarketMethod;

import java.util.ArrayList;
import java.util.List;

public class PersonnelMarketDisabled implements PersonnelMarketMethod {


@Override
public String getModuleName() {
return "Disabled";
}

@Override
public List<Person> generatePersonnelForDay(Campaign c) {
return new ArrayList<Person>();
}

@Override
public List<Person> removePersonnelForDay(Campaign c, List<Person> current) {
return new ArrayList<Person>();
}
}
6 changes: 5 additions & 1 deletion MekHQ/src/mekhq/gui/CampaignGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public class CampaignGUI extends JPanel {
/* For the menu bar */
private JMenuBar menuBar;
private JMenu menuThemes;
private JMenuItem miPersonnelMarket;
private JMenuItem miContractMarket;
private JMenuItem miUnitMarket;
private JMenuItem miShipSearch;
Expand Down Expand Up @@ -673,10 +674,11 @@ private void initMenu() {
JMenu menuMarket = new JMenu(resourceMap.getString("menuMarket.text"));
menuMarket.setMnemonic(KeyEvent.VK_M);

JMenuItem miPersonnelMarket = new JMenuItem(resourceMap.getString("miPersonnelMarket.text"));
miPersonnelMarket = new JMenuItem(resourceMap.getString("miPersonnelMarket.text"));
miPersonnelMarket.setMnemonic(KeyEvent.VK_P);
miPersonnelMarket.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_DOWN_MASK));
miPersonnelMarket.addActionListener(evt -> hirePersonMarket());
miPersonnelMarket.setVisible(!getCampaign().getPersonnelMarket().isNone());
menuMarket.add(miPersonnelMarket);

miContractMarket = new JMenuItem(resourceMap.getString("miContractMarket.text"));
Expand Down Expand Up @@ -1504,6 +1506,8 @@ private void menuOptionsActionPerformed(final ActionEvent evt) {
}
}

miPersonnelMarket.setVisible(!getCampaign().getPersonnelMarket().isNone());

final AbstractUnitMarket unitMarket = getCampaign().getUnitMarket();
if (unitMarket.getMethod() != newOptions.getUnitMarketMethod()) {
getCampaign().setUnitMarket(newOptions.getUnitMarketMethod().getUnitMarket());
Expand Down

0 comments on commit 6c11d3e

Please sign in to comment.