use of megamek.common.Mech in project megameklab by MegaMek.
the class DropTargetCriticalList method mousePressed.
public void mousePressed(MouseEvent e) {
if (buildView) {
if (e.getButton() == MouseEvent.BUTTON2) {
setSelectedIndex(locationToIndex(e.getPoint()));
removeCrit();
} else if (e.getButton() == MouseEvent.BUTTON3) {
setSelectedIndex(locationToIndex(e.getPoint()));
if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) {
removeCrit();
return;
}
int location = getCritLocation();
JPopupMenu popup = new JPopupMenu();
CriticalSlot cs = getCrit();
final Mounted mount = getMounted();
if ((e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
changeWeaponFacing(!mount.isRearMounted());
return;
}
if (mount != null && (e.getModifiersEx() & InputEvent.SHIFT_DOWN_MASK) != 0) {
changeOmniMounting(!mount.isOmniPodMounted());
return;
}
if (mount != null && !((getUnit().getEntityType() & Entity.ETYPE_QUADVEE) == Entity.ETYPE_QUADVEE && mount.getType() instanceof MiscType && mount.getType().hasFlag(MiscType.F_TRACKS))) {
JMenuItem info;
if (!UnitUtil.isFixedLocationSpreadEquipment(mount.getType())) {
popup.setAutoscrolls(true);
info = new JMenuItem("Remove " + mount.getName());
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeCrit();
}
});
popup.add(info);
}
info = new JMenuItem("Delete " + mount.getName());
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeMount();
}
});
if (!((getUnit() instanceof BattleArmor) && UnitUtil.isFixedLocationSpreadEquipment(mount.getType()))) {
popup.add(info);
}
// Allow making this a sort weapon
if ((mount.getType() instanceof WeaponType) && !mount.isSquadSupportWeapon() && mount.getLocation() == BattleArmor.LOC_SQUAD && (getUnit() instanceof BattleArmor) && ((BattleArmor) getUnit()).getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
info = new JMenuItem("Mount as squad support weapon");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mount.setSquadSupportWeapon(true);
if (refresh != null) {
refresh.refreshAll();
}
}
});
popup.add(info);
}
// Adding ammo as a squad support mount is slightly different
if ((mount.getType() instanceof AmmoType) && !mount.getType().hasFlag(WeaponType.F_MISSILE) && !mount.isSquadSupportWeapon() && mount.getLocation() == BattleArmor.LOC_SQUAD && (getUnit() instanceof BattleArmor) && ((BattleArmor) getUnit()).getChassisType() != BattleArmor.CHASSIS_TYPE_QUAD) {
boolean enabled = false;
for (Mounted weapon : getUnit().getWeaponList()) {
WeaponType wtype = (WeaponType) weapon.getType();
if (weapon.isSquadSupportWeapon() && AmmoType.isAmmoValid(mount, wtype)) {
enabled = true;
}
}
info = new JMenuItem("Mount as squad support weapon");
info.setEnabled(enabled);
info.setToolTipText("Ammo can only be squad mounted along " + "with a weapon that uses it");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mount.setSquadSupportWeapon(true);
if (refresh != null) {
refresh.refreshAll();
}
}
});
popup.add(info);
}
// Allow removing squad support weapon
if (mount.isSquadSupportWeapon()) {
info = new JMenuItem("Remove squad support weapon mount");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mount.setSquadSupportWeapon(false);
// squad support weapon
for (Mounted ammo : getUnit().getAmmo()) {
ammo.setSquadSupportWeapon(false);
}
if (refresh != null) {
refresh.refreshAll();
}
}
});
popup.add(info);
}
// Right-clicked on a DWP that has an attached weapon
if (mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && mount.getLinked() != null) {
info = new JMenuItem("Remove attached weapon");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Mounted attached = mount.getLinked();
attached.setDWPMounted(false);
mount.setLinked(null);
mount.setLinkedBy(null);
attached.setLinked(null);
attached.setLinkedBy(null);
if (refresh != null) {
refresh.refreshAll();
}
}
});
popup.add(info);
}
// Right-clicked on a AP Mount that has an attached weapon
if (mount.getType().hasFlag(MiscType.F_AP_MOUNT) && mount.getLinked() != null) {
info = new JMenuItem("Remove attached weapon");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Mounted attached = mount.getLinked();
attached.setAPMMounted(false);
mount.setLinked(null);
mount.setLinkedBy(null);
attached.setLinked(null);
attached.setLinkedBy(null);
if (refresh != null) {
refresh.refreshAll();
}
}
});
popup.add(info);
}
if ((mount.getLocation() != Mech.LOC_LARM) && (mount.getLocation() != Mech.LOC_RARM)) {
if (mount.getType() instanceof WeaponType) {
if (getUnit().hasWorkingMisc(MiscType.F_QUAD_TURRET, -1, mount.getLocation()) || getUnit().hasWorkingMisc(MiscType.F_SHOULDER_TURRET, -1, mount.getLocation()) || (getUnit().hasWorkingMisc(MiscType.F_HEAD_TURRET, -1, Mech.LOC_CT) && (mount.getLocation() == Mech.LOC_HEAD))) {
if (!mount.isMechTurretMounted()) {
info = new JMenuItem("Mount " + mount.getName() + " in Turret");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeTurretMount(true);
}
});
popup.add(info);
} else {
info = new JMenuItem("Remove " + mount.getName() + " from Turret");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeTurretMount(false);
}
});
popup.add(info);
}
}
}
if (!(getUnit() instanceof BattleArmor) && ((mount.getType() instanceof WeaponType) || ((mount.getType() instanceof MiscType) && mount.getType().hasFlag(MiscType.F_LIFTHOIST)))) {
if (!mount.isRearMounted()) {
info = new JMenuItem("Make " + mount.getName() + " Rear Facing");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeWeaponFacing(true);
}
});
popup.add(info);
} else {
info = new JMenuItem("Make " + mount.getName() + " Forward Facing");
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeWeaponFacing(false);
}
});
popup.add(info);
}
}
}
// Allow number of shots selection
if ((getUnit() instanceof BattleArmor) && mount.getType() instanceof AmmoType) {
AmmoType at = (AmmoType) mount.getType();
int maxNumShots = TestBattleArmor.NUM_SHOTS_PER_CRIT;
int stepSize = 1;
if (at.getAmmoType() == AmmoType.T_BA_TUBE) {
maxNumShots = TestBattleArmor.NUM_SHOTS_PER_CRIT_TA;
stepSize = 2;
}
for (int i = at.getShots(); i <= maxNumShots; i += stepSize) {
if (i == mount.getBaseShotsLeft()) {
continue;
}
info = new JMenuItem("Set Shots: " + i);
final int shots = i;
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mount.setShotsLeft(shots);
if (refresh != null) {
refresh.refreshAll();
}
}
});
popup.add(info);
}
}
if (getUnit().isOmni() && !mount.getType().isOmniFixedOnly()) {
if (mount.isOmniPodMounted()) {
info = new JMenuItem("Change to fixed mount");
info.addActionListener(ev -> changeOmniMounting(false));
popup.add(info);
} else if (UnitUtil.canPodMount(getUnit(), mount)) {
info = new JMenuItem("Change to pod mount");
info.addActionListener(ev -> changeOmniMounting(true));
popup.add(info);
}
}
}
if ((getUnit() instanceof BipedMech || getUnit() instanceof TripodMech) && ((location == Mech.LOC_LARM) || (location == Mech.LOC_RARM))) {
boolean canHaveLowerArm = true;
if (getUnit().isOmni()) {
int numCrits = getUnit().getNumberOfCriticals(location);
for (int slot = 0; slot < numCrits; slot++) {
CriticalSlot crit = getUnit().getCritical(location, slot);
if (crit == null) {
continue;
}
if (crit.getType() == CriticalSlot.TYPE_SYSTEM) {
continue;
}
Mounted m = crit.getMount();
if ((m.getType() instanceof GaussWeapon) || (m.getType() instanceof ACWeapon) || (m.getType() instanceof UACWeapon) || (m.getType() instanceof LBXACWeapon) || (m.getType() instanceof PPCWeapon)) {
canHaveLowerArm = false;
}
}
}
popup.addSeparator();
popup.setAutoscrolls(true);
if (canHaveLowerArm && ((getUnit().getCritical(location, 3) == null) || (getUnit().getCritical(location, 3).getType() != CriticalSlot.TYPE_SYSTEM))) {
JMenuItem info = new JMenuItem("Add Hand");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addHand(Integer.parseInt(e.getActionCommand()));
}
});
popup.add(info);
} else if ((getUnit().getCritical(location, 3) != null) && (getUnit().getCritical(location, 3).getType() == CriticalSlot.TYPE_SYSTEM)) {
JMenuItem info = new JMenuItem("Remove Hand");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeHand(Integer.parseInt(e.getActionCommand()));
}
});
popup.add(info);
}
if (canHaveLowerArm && ((getUnit().getCritical(location, 2) == null) || (getUnit().getCritical(location, 2).getType() != CriticalSlot.TYPE_SYSTEM))) {
JMenuItem info = new JMenuItem("Add Lower Arm");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addArm(Integer.parseInt(e.getActionCommand()));
}
});
popup.add(info);
} else if ((getUnit().getCritical(location, 2) != null) && (getUnit().getCritical(location, 2).getType() == CriticalSlot.TYPE_SYSTEM)) {
JMenuItem info = new JMenuItem("Remove Lower Arm");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
removeArm(Integer.parseInt(e.getActionCommand()));
}
});
popup.add(info);
}
}
if (UnitUtil.isArmorable(cs) && !(getUnit() instanceof BattleArmor) && eSource.getTechManager().isLegal(Entity.getArmoredComponentTechAdvancement())) {
popup.addSeparator();
if (cs.isArmored()) {
JMenuItem info = new JMenuItem("Remove Armoring");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeArmoring();
}
});
popup.add(info);
} else if (!(getUnit() instanceof Mech && ((Mech) getUnit()).isSuperHeavy())) {
JMenuItem info = new JMenuItem("Add Armoring");
info.setActionCommand(Integer.toString(location));
info.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
changeArmoring();
}
});
popup.add(info);
}
}
if (popup.getComponentCount() > 0) {
popup.show(this, e.getX(), e.getY());
}
}
}
}
use of megamek.common.Mech in project megameklab by MegaMek.
the class MenuBarCreator method jMenuSaveAsEntity_actionPerformed.
public void jMenuSaveAsEntity_actionPerformed(ActionEvent event) {
if (UnitUtil.validateUnit(parentFrame.getEntity()).length() > 0) {
JOptionPane.showMessageDialog(parentFrame, "Warning: Saving an invalid unit, it might load incorrectly!");
}
UnitUtil.compactCriticals(parentFrame.getEntity());
FileDialog fDialog = new FileDialog(parentFrame, "Save As", FileDialog.SAVE);
String filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_LOC);
fDialog.setDirectory(filePathName);
fDialog.setFile(parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + (parentFrame.getEntity() instanceof Mech ? ".mtf" : ".blk"));
fDialog.setLocationRelativeTo(parentFrame);
fDialog.setVisible(true);
if (fDialog.getFile() != null) {
filePathName = fDialog.getDirectory() + fDialog.getFile();
CConfig.setParam(CConfig.CONFIG_SAVE_LOC, fDialog.getDirectory());
} else {
return;
}
try {
if (parentFrame.getEntity() instanceof Mech) {
FileOutputStream out = new FileOutputStream(filePathName);
PrintStream p = new PrintStream(out);
p.println(((Mech) parentFrame.getEntity()).getMtf());
p.close();
out.close();
} else {
BLKFile.encode(filePathName, parentFrame.getEntity());
}
CConfig.updateSaveFiles(filePathName);
} catch (Exception ex) {
ex.printStackTrace();
}
JOptionPane.showMessageDialog(parentFrame, parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + " saved to " + filePathName);
}
use of megamek.common.Mech in project megameklab by MegaMek.
the class MenuBarCreator method jMenuResetEntity_actionPerformed.
public void jMenuResetEntity_actionPerformed(ActionEvent event) {
CConfig.updateSaveFiles("Reset Unit");
CConfig.setParam(CConfig.CONFIG_SAVE_FILE_1, "");
Entity en = parentFrame.getEntity();
if (en instanceof Tank) {
parentFrame.createNewUnit(Entity.ETYPE_TANK);
} else if (en instanceof Mech) {
parentFrame.createNewUnit(Entity.ETYPE_BIPED_MECH, ((Mech) en).isPrimitive(), ((Mech) en).isIndustrial());
} else if (en.hasETypeFlag(Entity.ETYPE_DROPSHIP)) {
parentFrame.createNewUnit(Entity.ETYPE_DROPSHIP);
} else if (en.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
parentFrame.createNewUnit(Entity.ETYPE_SMALL_CRAFT, ((Aero) en).isPrimitive());
} else if (parentFrame.getEntity() instanceof Aero) {
parentFrame.createNewUnit(Entity.ETYPE_AERO, ((Aero) en).isPrimitive());
} else if (parentFrame.getEntity() instanceof BattleArmor) {
parentFrame.createNewUnit(Entity.ETYPE_BATTLEARMOR);
} else if (parentFrame.getEntity() instanceof Infantry) {
parentFrame.createNewUnit(Entity.ETYPE_INFANTRY);
} else {
System.out.println("util.MenuBarCreatoer: " + "Received unknown entityType!");
}
setVisible(true);
reload();
refresh();
parentFrame.setVisible(true);
parentFrame.repaint();
}
use of megamek.common.Mech in project megameklab by MegaMek.
the class MVFArmorView method setFromEntity.
public void setFromEntity(Entity en) {
etype = en.getEntityType();
industrial = (en instanceof Mech) && ((Mech) en).isIndustrial();
movementMode = en.getMovementMode();
refresh();
cbArmorType.removeActionListener(this);
spnTonnage.removeChangeListener(this);
if (en.hasPatchworkArmor()) {
for (int i = 0; i < cbArmorType.getModel().getSize(); i++) {
if (cbArmorType.getItemAt(i) == null) {
cbArmorType.setSelectedIndex(i);
break;
}
}
tonnageModel.setValue(Math.min(UnitUtil.getMaximumArmorTonnage(en), en.getLabArmorTonnage()));
spnTonnage.setEnabled(false);
btnMaximize.setEnabled(false);
btnUseRemaining.setEnabled(false);
} else {
String name = EquipmentType.getArmorTypeName(en.getArmorType(0), TechConstants.isClan(en.getArmorTechLevel(0)));
EquipmentType eq = EquipmentType.get(name);
cbArmorType.setSelectedItem(eq);
tonnageModel.setValue(Math.min(UnitUtil.getMaximumArmorTonnage(en), en.getLabArmorTonnage()));
tonnageModel.setMaximum(UnitUtil.getMaximumArmorTonnage(en));
spnTonnage.setEnabled(true);
btnMaximize.setEnabled(true);
btnUseRemaining.setEnabled(true);
}
cbArmorType.addActionListener(this);
spnTonnage.addChangeListener(this);
}
use of megamek.common.Mech in project megameklab by MegaMek.
the class MovementView method setMovementModToolTips.
private void setMovementModToolTips(Entity en) {
StringJoiner walkTooltip = new StringJoiner(", ");
StringJoiner runTooltip = new StringJoiner(", ");
StringJoiner jumpTooltip = new StringJoiner(", ");
if (en.hasModularArmor()) {
walkTooltip.add("-1 (Modular armor)");
jumpTooltip.add("-1 (Modular armor)");
}
if (en instanceof Mech) {
if (((Mech) en).hasMPReducingHardenedArmor()) {
runTooltip.add("-1 (Hardened armor)");
}
if (((Mech) en).hasArmedMASC()) {
runTooltip.add("MASC/Supercharger");
}
int medShields = ((Mech) en).getNumberOfShields(MiscType.S_SHIELD_MEDIUM);
int lgShields = ((Mech) en).getNumberOfShields(MiscType.S_SHIELD_LARGE);
if (lgShields + medShields > 0) {
walkTooltip.add(String.format("-%d (Shield)", lgShields + medShields));
}
if (lgShields > 0) {
jumpTooltip.add("No Jump (Large Shield)");
}
} else if (en.hasWorkingMisc(MiscType.F_MASC)) {
runTooltip.add("Supercharger");
} else if (en.hasWorkingMisc(MiscType.F_JET_BOOSTER)) {
runTooltip.add("Jet Booster");
}
Optional<Mounted> partialWing = en.getMisc().stream().filter(m -> m.getType().hasFlag(MiscType.F_PARTIAL_WING)).findAny();
if (partialWing.isPresent()) {
int bonus = 2;
if (en instanceof Mech) {
bonus = ((Mech) en).getPartialWingJumpBonus(partialWing.get());
}
jumpTooltip.add(String.format("+%d (Partial wing)", bonus));
}
txtWalkFinal.setToolTipText(walkTooltip.length() > 0 ? walkTooltip.toString() : null);
txtRunFinal.setToolTipText(runTooltip.length() > 0 ? runTooltip.toString() : null);
txtJumpFinal.setToolTipText(jumpTooltip.length() > 0 && en.getOriginalJumpMP(true) > 0 ? jumpTooltip.toString() : null);
}
Aggregations