Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ public void mouseReleased(MouseEvent event) {
addPopupMenuListener(new PopupClosedListener());
}

/**
* Also puts the tooltip on the editor field, which is what the pointer is actually over on an editable combo box.
*
* <p>Without this, a caller's tooltip never shows: the constructor puts the "type to search" hint on the editor,
* and that hint sits in front of whatever the caller sets on the combo box itself.</p>
*
* @param text the tooltip to show, or {@code null} to fall back to the search hint
*/
@Override
public void setToolTipText(@Nullable String text) {
super.setToolTipText(text);
if (editorField != null) {
editorField.setToolTipText((text == null) ? Messages.getString("SearchableComboBox.tooltip") : text);
}
}

/**
* Sizes the box for its widest entry, so narrowing the list while typing does not make the box shrink and
* grow with every keystroke.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.util.HashMap;
import java.util.Map;
import java.awt.GridBagLayout;
Comment thread
HammerGS marked this conversation as resolved.
import java.awt.Rectangle;
import java.io.Serial;
Expand All @@ -61,16 +59,17 @@
import megamek.client.generator.RandomNameGenerator;
import megamek.client.ui.GBC;
import megamek.client.ui.Messages;
import megamek.common.units.CrewArmorKitRules;
import megamek.client.ui.comboBoxes.SearchableComboBox;
import megamek.client.ui.dialogs.iconChooser.PortraitChooserDialog;
import megamek.client.ui.util.UIUtil;
import megamek.common.annotations.Nullable;
import megamek.common.enums.Gender;
import megamek.common.equipment.EquipmentType;
import megamek.common.game.Game;
import megamek.common.enums.Gender;
import megamek.common.icons.Portrait;
import megamek.common.options.OptionsConstants;
import megamek.common.preference.PreferenceManager;
import megamek.common.units.CrewArmorKitRules;
import megamek.common.units.Entity;
import megamek.common.units.EntitySelector;
import megamek.common.units.Infantry;
Expand All @@ -96,9 +95,13 @@ public class CustomPilotViewPanel extends JPanel implements Scrollable {
private final JCheckBox chkMissing = new JCheckBox(Messages.getString("CustomMekDialog.chkMissing"));
private final JTextField fldName = new JTextField(30);
private final JTextField fldNick = new JTextField(30);
private final Map<String, String> armorKitNamesByDisplayName = new HashMap<>();
private final JCheckBox chkClanPilot = new JCheckBox(Messages.getString("CustomMekDialog.chkClanPilot"));
private final JComboBox<String> choArmorKit = new JComboBox<>();
/**
* The armor kit the crew member wears. Searchable because the list runs to dozens of kits, and typing a few
* letters beats scrolling for one, the same way the ammunition dropdowns work.
*/
private SearchableComboBox<ArmorKitChoice> choArmorKit = new SearchableComboBox<>("choArmorKit",
List.of(ArmorKitChoice.NONE), ArmorKitChoice::displayName);
private final JTextField fldGunnery = new JTextField(4);
private final JTextField fldGunneryL = new JTextField(4);
private final JTextField fldGunneryM = new JTextField(4);
Expand Down Expand Up @@ -241,18 +244,37 @@ private void attachAdvancedSection() {
* @param slot the crew slot this panel is for
*/
private void populateArmorKitChoices(Game game, Entity entity, int slot) {
String noKit = Messages.getString("CustomMekDialog.choArmorKit.none");
choArmorKit.addItem(noKit);
List<ArmorKitChoice> choices = new ArrayList<>();
choices.add(ArmorKitChoice.NONE);
for (EquipmentType armorKit : CrewArmorKitRules.availableArmorKits()) {
if (!CrewArmorKitRules.isAvailableIn(armorKit, entity, game)) {
continue;
}
armorKitNamesByDisplayName.put(armorKit.getName(), armorKit.getInternalName());
choArmorKit.addItem(armorKit.getName());
choices.add(new ArmorKitChoice(armorKit.getName(), armorKit.getInternalName()));
}
choArmorKit = new SearchableComboBox<>("choArmorKit", choices, ArmorKitChoice::displayName);

Comment thread
HammerGS marked this conversation as resolved.
String wornKitName = entity.getCrew().getArmorKitName(slot);
EquipmentType wornKit = (wornKitName == null) ? null : EquipmentType.get(wornKitName);
choArmorKit.setSelectedItem((wornKit == null) ? noKit : wornKit.getName());
ArmorKitChoice worn = (wornKit == null)
? ArmorKitChoice.NONE
: new ArmorKitChoice(wornKit.getName(), wornKit.getInternalName());
choArmorKit.setSelectedItem(choices.contains(worn) ? worn : ArmorKitChoice.NONE);
}

/**
* One entry in the armor kit dropdown: what the player reads, and the internal name the crew is given.
*
* <p>{@link #NONE} stands for wearing nothing, carrying a {@code null} internal name so the caller can hand it
* straight back without a special case.</p>
*
* @param displayName the kit's name as the player sees it
* @param internalName the name the crew records, or {@code null} for no kit
*/
private record ArmorKitChoice(String displayName, @Nullable String internalName) {

private static final ArmorKitChoice NONE =
new ArmorKitChoice(Messages.getString("CustomMekDialog.choArmorKit.none"), null);
}

/**
Expand Down Expand Up @@ -618,11 +640,8 @@ public boolean isClanPilot() {
* @return the internal name of the armor kit chosen for this crew member, or {@code null} for none
*/
public @Nullable String getArmorKitName() {
Object chosen = choArmorKit.getSelectedItem();
if ((chosen == null) || chosen.equals(Messages.getString("CustomMekDialog.choArmorKit.none"))) {
return null;
}
return armorKitNamesByDisplayName.get(chosen.toString());
ArmorKitChoice chosen = choArmorKit.getSelectedItem();
return (chosen == null) ? null : chosen.internalName();
}

public int getGunnery() {
Expand Down
Loading