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

MML portion of fix for #1537: Disable Tech Rating chooser for non-BAR armor in SVs #1538

Merged
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
51 changes: 28 additions & 23 deletions megameklab/src/megameklab/ui/generalUnit/MVFArmorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

/**
* Panel for assigning armor type and tonnage for mechs, (combat) vehicles, and fighters.
*
*
* @author Neoancient
*/
public class MVFArmorView extends BuildView implements ActionListener, ChangeListener {
Expand All @@ -49,10 +49,10 @@ public void addListener(ArmorAllocationListener l) {
public void removeListener(ArmorAllocationListener l) {
listeners.remove(l);
}

private final static String CMD_MAXIMIZE = "MAXIMIZE";
private final static String CMD_REMAINING = "REMAINING";

private final TechComboBox<EquipmentType> cbArmorType = new TechComboBox<>(EquipmentType::getName);
private final CustomComboBox<Integer> cbSVTechRating = new CustomComboBox<>(ITechnology::getRatingName);
private final SpinnerNumberModel tonnageModel = new SpinnerNumberModel(0.0, 0.0, null, 0.5);
Expand All @@ -62,9 +62,9 @@ public void removeListener(ArmorAllocationListener l) {
private final JButton btnMaximize = new JButton();
private final JButton btnUseRemaining = new JButton();
private final JLabel lblArmorTonnage = createLabel("lblArmorTonnage", "", labelSizeLg);

private final ITechManager techManager;

private long etype;
private boolean industrial;
private boolean primitive;
Expand Down Expand Up @@ -146,7 +146,7 @@ private void initUI(boolean supportVee) {
chkPatchwork.setToolTipText(resourceMap.getString("ArmorView.chkPatchwork.tooltip"));
add(chkPatchwork, gbc);
chkPatchwork.addActionListener(this);

gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 3;
Expand All @@ -156,7 +156,7 @@ private void initUI(boolean supportVee) {
btnMaximize.setToolTipText(resourceMap.getString("ArmorView.btnMaximize.tooltip"));
add(btnMaximize, gbc);
btnMaximize.addActionListener(this);

gbc.gridx = 0;
gbc.gridy++;
gbc.gridwidth = 3;
Expand All @@ -167,21 +167,21 @@ private void initUI(boolean supportVee) {
add(btnUseRemaining, gbc);
btnUseRemaining.addActionListener(this);
}

/**
* Sets the values of all fields from the current Entity.
* @param en The Entity currently being edited
*/
public void setFromEntity(Entity en) {
setFromEntity(en, false);
}

/**
* Sets the values of all fields from the current Entity, with the option of ignoring
* whether the {@code Entity} has patchwork armor. This is because the Entity does not
* report patchwork armor unless it actually has multiple armor types, and we don't want
* to clear the patchwork checkbox unless we're loading a new unit.
*
*
* @param en The Entity being edited
* @param ignoreEntityPatchwork Whether to ignore whether the Entity has patchwork armor.
*/
Expand All @@ -193,6 +193,7 @@ public void setFromEntity(Entity en, boolean ignoreEntityPatchwork) {
svLimitedArmor = en.isSupportVehicle() && !en.hasArmoredChassis();
refresh();
cbArmorType.removeActionListener(this);
cbSVTechRating.setEnabled(true);
spnTonnage.removeChangeListener(this);
chkPatchwork.removeActionListener(this);
cbArmorType.setSelectedItem(ArmorType.forEntity(en));
Expand All @@ -219,11 +220,15 @@ public void setFromEntity(Entity en, boolean ignoreEntityPatchwork) {
btnMaximize.setEnabled(true);
btnUseRemaining.setEnabled(true);
}
if (en.isSupportVehicle() && !en.hasPatchworkArmor()
&& ArmorType.forEntity(en).hasFlag(MiscType.F_SUPPORT_VEE_BAR_ARMOR)) {
cbSVTechRating.removeActionListener(this);
cbSVTechRating.setSelectedItem(en.getArmorTechRating());
cbSVTechRating.addActionListener(this);
if (en.isSupportVehicle() && !en.hasPatchworkArmor()) {
if (ArmorType.forEntity(en).hasFlag(MiscType.F_SUPPORT_VEE_BAR_ARMOR)) {
cbSVTechRating.removeActionListener(this);
cbSVTechRating.setSelectedItem(en.getArmorTechRating());
cbSVTechRating.addActionListener(this);
} else {
// Disable for non-BAR armor
cbSVTechRating.setEnabled(false);
}
}
if (en.getWeightClass() == EntityWeightClass.WEIGHT_SMALL_SUPPORT) {
lblArmorTonnage.setText(resourceMap.getString("ArmorView.spnFactor.text"));
Expand All @@ -239,7 +244,7 @@ public void setFromEntity(Entity en, boolean ignoreEntityPatchwork) {
spnTonnage.addChangeListener(this);
chkPatchwork.addActionListener(this);
}

public void refresh() {
EquipmentType prev = (EquipmentType) cbArmorType.getSelectedItem();
cbArmorType.removeActionListener(this);
Expand Down Expand Up @@ -277,31 +282,31 @@ public void refresh() {
}
cbArmorType.showTechBase(techManager.useMixedTech());
}

/**
* @return The selected armor equipment
*/
public EquipmentType getArmor() {
return (EquipmentType)cbArmorType.getSelectedItem();
}

/**
* Enables or disables the patchwork checkbox and refreshes
*
*
* @param patchwork Whether the patchwork checkbox should be enabled
*/
public void setPatchwork(boolean patchwork) {
chkPatchwork.setSelected(patchwork);
refresh();
}

/**
* @return Whether the patchwork checkbox is selected
*/
public boolean isPatchwork() {
return chkPatchwork.isSelected();
}

/**
* @return The armor type constant for the selected armor
*/
Expand All @@ -313,7 +318,7 @@ public int getArmorType() {
return (armor == null) ? EquipmentType.T_ARMOR_UNKNOWN : armor.getArmorType();
}
}

public int getArmorTechConstant() {
EquipmentType armor = (EquipmentType) cbArmorType.getSelectedItem();
if (null == armor) {
Expand Down Expand Up @@ -361,5 +366,5 @@ public void actionPerformed(ActionEvent e) {
listeners.forEach(l -> l.armorTechRatingChanged(getTechRating()));
}
}

}
Loading