use of megamek.common.MiscType in project megameklab by MegaMek.
the class AerospaceBuildView method mousePressed.
public void mousePressed(MouseEvent e) {
// locations, but only if those locations are make sense
if (e.getButton() == MouseEvent.BUTTON3) {
JPopupMenu popup = new JPopupMenu();
JMenuItem item = null;
if (equipmentTable.getSelectedRowCount() > 1) {
List<Mounted> list = new ArrayList<>();
for (int row : equipmentTable.getSelectedRows()) {
list.add((Mounted) equipmentTable.getModel().getValueAt(row, CriticalTableModel.EQUIPMENT));
}
for (BayWeaponCriticalTree l : arcViews) {
// Aerodyne small craft and dropships skip the aft side arcs
if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
continue;
}
if (list.stream().anyMatch(eq -> l.canAdd(eq))) {
item = new JMenuItem(l.getLocationName());
item.addActionListener(ev -> l.addToLocation(list));
popup.add(item);
}
}
} else {
final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
for (BayWeaponCriticalTree l : arcViews) {
// Aerodyne small craft and dropships skip the aft side arcs
if (getAero().hasETypeFlag(Entity.ETYPE_SMALL_CRAFT) && !getAero().isSpheroid() && !l.validForAerodyne()) {
continue;
}
if (getAero().usesWeaponBays()) {
JMenu menu = new JMenu(l.getLocationName());
for (Mounted bay : l.baysFor(eq)) {
if (eq.getType() instanceof AmmoType) {
final int shotCount = ((AmmoType) eq.getType()).getShots();
JMenu locMenu = new JMenu(bay.getName());
for (int shots = shotCount; shots <= eq.getUsableShotsLeft(); shots += shotCount) {
item = new JMenuItem("Add " + shots + ((shots > 1) ? " shots" : " shot"));
final int addShots = shots;
item.addActionListener(ev -> l.addAmmoToBay(bay, eq, addShots));
locMenu.add(item);
}
menu.add(locMenu);
} else {
item = new JMenuItem(bay.getName());
item.addActionListener(ev -> l.addToBay(bay, eq));
menu.add(item);
}
}
if (eq.getType() instanceof WeaponType) {
final EquipmentType bayType = ((WeaponType) eq.getType()).getBayType();
item = new JMenuItem("New " + bayType.getName());
item.addActionListener(ev -> l.addToNewBay(bayType, eq));
menu.add(item);
}
if (menu.getItemCount() > 0) {
popup.add(menu);
} else if ((eq.getType() instanceof MiscType) && l.canAdd(eq)) {
item = new JMenuItem(l.getLocationName());
item.addActionListener(ev -> l.addToLocation(eq));
popup.add(item);
}
} else {
item = new JMenuItem(l.getLocationName());
item.addActionListener(ev -> l.addToLocation(eq));
popup.add(item);
}
}
}
popup.show(this, e.getX(), e.getY());
}
}
use of megamek.common.MiscType in project megameklab by MegaMek.
the class EquipmentTab method removeHeatSinks.
private void removeHeatSinks() {
int location = 0;
for (; location < equipmentList.getRowCount(); ) {
Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
EquipmentType eq = mount.getType();
if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
try {
equipmentList.removeCrit(location);
} catch (ArrayIndexOutOfBoundsException aioobe) {
return;
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
location++;
}
}
}
use of megamek.common.MiscType in project megameklab by MegaMek.
the class BuildView method mousePressed.
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
JPopupMenu popup = new JPopupMenu();
JMenuItem item;
final int selectedRow = equipmentTable.rowAtPoint(e.getPoint());
Mounted eq = (Mounted) equipmentTable.getModel().getValueAt(selectedRow, CriticalTableModel.EQUIPMENT);
final int totalCrits = UnitUtil.getCritsUsed(getMech(), eq.getType());
String[] locations = getMech().getLocationNames();
String[] abbrLocations = getMech().getLocationAbbrs();
if ((eq.getType().isSpreadable() || eq.isSplitable()) && (totalCrits > 1) && !((eq.getType() instanceof MiscType) && eq.getType().hasFlag(MiscType.F_TARGCOMP)) && !(getMech() instanceof LandAirMech)) {
int[] critSpace = UnitUtil.getHighestContinuousNumberOfCritsArray(getMech());
if ((critSpace[Mech.LOC_RT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RT)) {
JMenu rtMenu = new JMenu(locations[Mech.LOC_RT]);
if (critSpace[Mech.LOC_RT] >= totalCrits) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RT]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadComponent_actionPerformed(Mech.LOC_RT, selectedRow);
}
});
rtMenu.add(item);
}
int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_RARM, Mech.LOC_RLEG };
for (int location = 0; location < 3; location++) {
JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_RT], abbrLocations[splitLocations[location]]));
int subCrits = critSpace[splitLocations[location]];
for (int slots = 1; slots <= subCrits; slots++) {
final int primarySlots = totalCrits - slots;
item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_RT], primarySlots, abbrLocations[splitLocations[location]], slots));
final int secondaryLocation = splitLocations[location];
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RT, secondaryLocation, primarySlots, selectedRow);
}
});
subMenu.add(item);
}
rtMenu.add(subMenu);
}
popup.add(rtMenu);
}
if ((critSpace[Mech.LOC_RARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_RARM)) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_RARM]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_RARM, Mech.LOC_RARM, totalCrits, selectedRow);
}
});
popup.add(item);
}
if ((critSpace[Mech.LOC_LT] >= 1) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LT)) {
JMenu ltMenu = new JMenu(locations[Mech.LOC_LT]);
if (critSpace[Mech.LOC_LT] >= totalCrits) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LT]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadComponent_actionPerformed(Mech.LOC_LT, selectedRow);
}
});
ltMenu.add(item);
}
int[] splitLocations = new int[] { Mech.LOC_CT, Mech.LOC_LARM, Mech.LOC_LLEG };
for (int location = 0; location < 3; location++) {
JMenu subMenu = new JMenu(String.format("%1$s/%2$s", abbrLocations[Mech.LOC_LT], abbrLocations[splitLocations[location]]));
int subCrits = critSpace[splitLocations[location]];
for (int slots = 1; slots <= subCrits; slots++) {
final int primarySlots = totalCrits - slots;
item = new JMenuItem(String.format("%1$s (%2$s)/%3$s (%4$s)", abbrLocations[Mech.LOC_LT], primarySlots, abbrLocations[splitLocations[location]], slots));
final int secondaryLocation = splitLocations[location];
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LT, secondaryLocation, primarySlots, selectedRow);
}
});
subMenu.add(item);
}
ltMenu.add(subMenu);
}
popup.add(ltMenu);
}
if ((critSpace[Mech.LOC_LARM] >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), Mech.LOC_LARM)) {
item = new JMenuItem(String.format("Add to %1$s", locations[Mech.LOC_LARM]));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadSplitComponent_actionPerformed(Mech.LOC_LARM, Mech.LOC_LARM, totalCrits, selectedRow);
}
});
popup.add(item);
}
} else {
for (int location = 0; location < getMech().locations(); location++) {
if ((UnitUtil.getHighestContinuousNumberOfCrits(getMech(), location) >= totalCrits) && UnitUtil.isValidLocation(getMech(), eq.getType(), location)) {
item = new JMenuItem("Add to " + locations[location]);
final int loc = location;
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jMenuLoadComponent_actionPerformed(loc, selectedRow);
}
});
popup.add(item);
}
}
}
popup.show(this, e.getX(), e.getY());
}
}
use of megamek.common.MiscType in project megameklab by MegaMek.
the class EquipmentTab method addEquipment.
private void addEquipment(EquipmentType equip) {
Mounted mount = null;
boolean isMisc = equip instanceof MiscType;
if (isMisc && equip.hasFlag(MiscType.F_TARGCOMP)) {
if (!UnitUtil.hasTargComp(getAero())) {
mount = UnitUtil.updateTC(getAero(), equip);
if (null != mount) {
equipmentList.addCrit(mount);
}
}
} else {
int count = (Integer) spnAddCount.getValue();
if (getAero().usesWeaponBays() && (equip instanceof AmmoType)) {
Mounted aMount = UnitUtil.findUnallocatedAmmo(getAero(), equip);
if (null != aMount) {
aMount.setShotsLeft(aMount.getUsableShotsLeft() + ((AmmoType) equip).getShots() * count);
return;
} else {
mount = new Mounted(getAero(), equip);
mount.setShotsLeft(((AmmoType) equip).getShots() * count);
try {
getAero().addEquipment(mount, Entity.LOC_NONE, false);
equipmentList.addCrit(mount);
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
} else {
try {
for (int i = 0; i < count; i++) {
mount = new Mounted(getAero(), equip);
getAero().addEquipment(mount, Entity.LOC_NONE, false);
equipmentList.addCrit(mount);
}
} catch (LocationFullException lfe) {
// this can't happen, we add to Entity.LOC_NONE
}
}
}
}
use of megamek.common.MiscType in project megameklab by MegaMek.
the class EquipmentTab method removeHeatSinks.
private void removeHeatSinks() {
int location = 0;
for (; location < equipmentList.getRowCount(); ) {
Mounted mount = (Mounted) equipmentList.getValueAt(location, CriticalTableModel.EQUIPMENT);
EquipmentType eq = mount.getType();
if ((eq instanceof MiscType) && (UnitUtil.isHeatSink(mount))) {
try {
equipmentList.removeCrit(location);
} catch (ArrayIndexOutOfBoundsException aioobe) {
return;
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
location++;
}
}
}
Aggregations