use of megamek.common.Entity in project megameklab by MegaMek.
the class MenuBarCreator method jMenuGetUnitWeightBreakdownFromFile_actionPerformed.
private void jMenuGetUnitWeightBreakdownFromFile_actionPerformed() {
Entity tempEntity = null;
String filePathName = System.getProperty("user.dir").toString() + "/data/mechfiles/";
File unitFile = new File(filePathName);
JFileChooser f = new JFileChooser(filePathName);
f.setLocation(parentFrame.getLocation().x + 150, parentFrame.getLocation().y + 100);
f.setDialogTitle("Choose Unit");
f.setDialogType(JFileChooser.OPEN_DIALOG);
f.setMultiSelectionEnabled(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("Unit Files", "blk", "mtf", "hmp");
// Add a filter for mul files
f.setFileFilter(filter);
int returnVal = f.showOpenDialog(parentFrame);
if ((returnVal != JFileChooser.APPROVE_OPTION) || (f.getSelectedFile() == null)) {
// I want a file, y'know!
return;
}
unitFile = f.getSelectedFile();
try {
tempEntity = new MechFileParser(unitFile).getEntity();
} catch (Exception ex) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
} finally {
UnitUtil.showUnitWeightBreakDown(tempEntity, parentFrame);
}
}
use of megamek.common.Entity in project megameklab by MegaMek.
the class MenuBarCreator method jMenuGetUnitSpecsFromCache_actionPerformed.
private void jMenuGetUnitSpecsFromCache_actionPerformed() {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(parentFrame);
unitLoadingDialog.setVisible(true);
UnitSelectorDialog viewer = new UnitSelectorDialog(parentFrame, unitLoadingDialog, true);
Entity tempEntity = viewer.getChosenEntity();
if (null == tempEntity) {
return;
}
UnitUtil.showUnitSpecs(tempEntity, parentFrame);
}
use of megamek.common.Entity 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.Entity in project megameklab by MegaMek.
the class UnitPrintManager method selectUnitToPrint.
public static void selectUnitToPrint(JFrame parent) {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(parent);
UnitSelectorDialog viewer = new UnitSelectorDialog(parent, unitLoadingDialog, true);
Entity entity = null;
entity = viewer.getChosenEntity();
viewer.setVisible(false);
viewer.dispose();
if (null != entity) {
UnitPrintManager.printEntity(entity);
}
}
use of megamek.common.Entity in project megameklab by MegaMek.
the class UnitUtil method removeMounted.
public static void removeMounted(Entity unit, Mounted mount) {
UnitUtil.removeCriticals(unit, mount);
// Some special checks for BA
if (unit instanceof BattleArmor) {
// to detach the weapon
if (mount.getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK) && (mount.getLinked() != null)) {
Mounted link = mount.getLinked();
link.setDWPMounted(false);
link.setLinked(null);
link.setLinkedBy(null);
}
// to clear the mounted status of the DWP
if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_DETACHABLE_WEAPON_PACK)) {
Mounted dwp = mount.getLinkedBy();
dwp.setLinked(null);
dwp.setLinkedBy(null);
}
// to detach the weapon
if (mount.getType().hasFlag(MiscType.F_AP_MOUNT) && (mount.getLinked() != null)) {
Mounted link = mount.getLinked();
link.setAPMMounted(false);
link.setLinked(null);
link.setLinkedBy(null);
}
// to clear the mounted status of the AP Mount
if ((mount.getLinkedBy() != null) && mount.getLinkedBy().getType().hasFlag(MiscType.F_AP_MOUNT)) {
Mounted apm = mount.getLinkedBy();
apm.setLinked(null);
apm.setLinkedBy(null);
}
}
// Some special checks for Aeros
if (unit instanceof Aero) {
if (mount.getType() instanceof WeaponType) {
// Aeros have additional weapon lists that need to be cleared
((Aero) unit).getTotalWeaponList().remove(mount);
((Aero) unit).getWeaponBayList().remove(mount);
((Aero) unit).getWeaponGroupList().remove(mount);
}
}
// We will need to reset the equipment numbers of the bay ammo and weapons
Map<Mounted, List<Mounted>> bayWeapons = new HashMap<>();
Map<Mounted, List<Mounted>> bayAmmo = new HashMap<>();
for (Mounted bay : unit.getWeaponBayList()) {
List<Mounted> list = bay.getBayWeapons().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
bayWeapons.put(bay, list);
list = bay.getBayAmmo().stream().map(n -> unit.getEquipment(n)).collect(Collectors.toList());
bayAmmo.put(bay, list);
}
unit.getEquipment().remove(mount);
if (mount.getType() instanceof MiscType) {
unit.getMisc().remove(mount);
} else if (mount.getType() instanceof AmmoType) {
unit.getAmmo().remove(mount);
} else {
unit.getWeaponList().remove(mount);
unit.getTotalWeaponList().remove(mount);
}
for (Mounted bay : bayWeapons.keySet()) {
bay.getBayWeapons().clear();
for (Mounted w : bayWeapons.get(bay)) {
if (mount != w) {
bay.getBayWeapons().add(unit.getEquipmentNum(w));
}
}
}
for (Mounted bay : bayAmmo.keySet()) {
bay.getBayAmmo().clear();
for (Mounted a : bayAmmo.get(bay)) {
if (mount != a) {
bay.getBayAmmo().add(unit.getEquipmentNum(a));
}
}
}
// An example of this would be removing a linked Artemis IV FCS
for (Mounted m : unit.getEquipment()) {
if (mount.equals(m.getLinkedBy())) {
m.setLinkedBy(null);
}
}
}
Aggregations