Search in sources :

Example 6 with Entity

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);
    }
}
Also used : Entity(megamek.common.Entity) JFileChooser(javax.swing.JFileChooser) MechFileParser(megamek.common.MechFileParser) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) File(java.io.File) BLKFile(megamek.common.loaders.BLKFile)

Example 7 with Entity

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);
}
Also used : Entity(megamek.common.Entity) UnitLoadingDialog(megamek.client.ui.swing.UnitLoadingDialog) UnitSelectorDialog(megamek.client.ui.swing.UnitSelectorDialog)

Example 8 with Entity

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();
}
Also used : Entity(megamek.common.Entity) Infantry(megamek.common.Infantry) Mech(megamek.common.Mech) Tank(megamek.common.Tank) Aero(megamek.common.Aero) BattleArmor(megamek.common.BattleArmor)

Example 9 with Entity

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);
    }
}
Also used : Entity(megamek.common.Entity) UnitLoadingDialog(megamek.client.ui.swing.UnitLoadingDialog) UnitSelectorDialog(megamek.client.ui.swing.UnitSelectorDialog)

Example 10 with 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);
        }
    }
}
Also used : CapitalMissileWeapon(megamek.common.weapons.capitalweapons.CapitalMissileWeapon) Arrays(java.util.Arrays) Dropship(megamek.common.Dropship) RLWeapon(megamek.common.weapons.missiles.RLWeapon) CriticalSlot(megamek.common.CriticalSlot) TestTank(megamek.common.verifier.TestTank) StopSwarmAttack(megamek.common.weapons.StopSwarmAttack) Vector(java.util.Vector) BattleArmor(megamek.common.BattleArmor) HVACWeapon(megamek.common.weapons.autocannons.HVACWeapon) Map(java.util.Map) SRTWeapon(megamek.common.weapons.srms.SRTWeapon) BigInteger(java.math.BigInteger) SmallCraft(megamek.common.SmallCraft) AmmoWeapon(megamek.common.weapons.AmmoWeapon) JFrame(javax.swing.JFrame) Infantry(megamek.common.Infantry) LegAttack(megamek.common.weapons.LegAttack) StreakLRMWeapon(megamek.common.weapons.lrms.StreakLRMWeapon) EnergyWeapon(megamek.common.weapons.lasers.EnergyWeapon) Mech(megamek.common.Mech) GaussWeapon(megamek.common.weapons.gaussrifles.GaussWeapon) VTOL(megamek.common.VTOL) ISAPDS(megamek.common.weapons.other.ISAPDS) Protomech(megamek.common.Protomech) WeaponType(megamek.common.WeaponType) MPodWeapon(megamek.common.weapons.defensivepods.MPodWeapon) Tank(megamek.common.Tank) Entity(megamek.common.Entity) ISC3M(megamek.common.weapons.other.ISC3M) HAGWeapon(megamek.common.weapons.gaussrifles.HAGWeapon) LogLevel(megamek.common.logging.LogLevel) ThunderBoltWeapon(megamek.common.weapons.missiles.ThunderBoltWeapon) VehicleFlamerWeapon(megamek.common.weapons.flamers.VehicleFlamerWeapon) ArrayList(java.util.ArrayList) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) EquipmentType(megamek.common.EquipmentType) MegaMekLab(megameklab.com.MegaMekLab) JEditorPane(javax.swing.JEditorPane) JTextPane(javax.swing.JTextPane) ITechManager(megamek.common.ITechManager) TechConstants(megamek.common.TechConstants) TestMech(megamek.common.verifier.TestMech) Nullable(megamek.common.annotations.Nullable) ISC3MBS(megamek.common.weapons.other.ISC3MBS) SwarmAttack(megamek.common.weapons.SwarmAttack) File(java.io.File) JScrollPane(javax.swing.JScrollPane) PPCWeapon(megamek.common.weapons.ppc.PPCWeapon) EntityVerifier(megamek.common.verifier.EntityVerifier) JDialog(javax.swing.JDialog) DecimalFormatSymbols(java.text.DecimalFormatSymbols) Aero(megamek.common.Aero) ISAMS(megamek.common.weapons.other.ISAMS) EntityWeightClass(megamek.common.EntityWeightClass) ISTAG(megamek.common.weapons.tag.ISTAG) ISLaserAMS(megamek.common.weapons.other.ISLaserAMS) ISBALightTAG(megamek.common.weapons.battlearmor.ISBALightTAG) CLLightTAG(megamek.common.weapons.tag.CLLightTAG) TestEntity(megamek.common.verifier.TestEntity) StreakSRMWeapon(megamek.common.weapons.srms.StreakSRMWeapon) Bay(megamek.common.Bay) TestAero(megamek.common.verifier.TestAero) TestBattleArmor(megamek.common.verifier.TestBattleArmor) SwarmWeaponAttack(megamek.common.weapons.SwarmWeaponAttack) CLBALightTAG(megamek.common.weapons.battlearmor.CLBALightTAG) ScrollPaneConstants(javax.swing.ScrollPaneConstants) LocationFullException(megamek.common.LocationFullException) Font(java.awt.Font) MRMWeapon(megamek.common.weapons.missiles.MRMWeapon) TestInfantry(megamek.common.verifier.TestInfantry) BPodWeapon(megamek.common.weapons.defensivepods.BPodWeapon) TestSmallCraft(megamek.common.verifier.TestSmallCraft) Collectors(java.util.stream.Collectors) LBXACWeapon(megamek.common.weapons.autocannons.LBXACWeapon) Dimension(java.awt.Dimension) List(java.util.List) MiscType(megamek.common.MiscType) TripodMech(megamek.common.TripodMech) Optional(java.util.Optional) UACWeapon(megamek.common.weapons.autocannons.UACWeapon) SRMWeapon(megamek.common.weapons.srms.SRMWeapon) CLBALBX(megamek.common.weapons.battlearmor.CLBALBX) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CLChemicalLaserWeapon(megamek.common.weapons.lasers.CLChemicalLaserWeapon) CLTAG(megamek.common.weapons.tag.CLTAG) ISPlasmaRifle(megamek.common.weapons.ppc.ISPlasmaRifle) TestSupportVehicle(megamek.common.verifier.TestSupportVehicle) InfantryRifleAutoRifleWeapon(megamek.common.weapons.infantry.InfantryRifleAutoRifleWeapon) MGWeapon(megamek.common.weapons.mgs.MGWeapon) HashMap(java.util.HashMap) CLAMS(megamek.common.weapons.other.CLAMS) CLLaserAMS(megamek.common.weapons.other.CLLaserAMS) Graphics2D(java.awt.Graphics2D) BipedMech(megamek.common.BipedMech) Mounted(megamek.common.Mounted) MechView(megamek.common.MechView) AmmoType(megamek.common.AmmoType) ITechnology(megamek.common.ITechnology) CLPlasmaCannon(megamek.common.weapons.ppc.CLPlasmaCannon) LRTWeapon(megamek.common.weapons.lrms.LRTWeapon) DecimalFormat(java.text.DecimalFormat) LRMWeapon(megamek.common.weapons.lrms.LRMWeapon) FileInputStream(java.io.FileInputStream) LandAirMech(megamek.common.LandAirMech) JOptionPane(javax.swing.JOptionPane) InfantryWeapon(megamek.common.weapons.infantry.InfantryWeapon) ACWeapon(megamek.common.weapons.autocannons.ACWeapon) MMLogger(megamek.common.logging.MMLogger) DefaultCaret(javax.swing.text.DefaultCaret) QuadMech(megamek.common.QuadMech) InputStream(java.io.InputStream) AmmoType(megamek.common.AmmoType) HashMap(java.util.HashMap) Mounted(megamek.common.Mounted) WeaponType(megamek.common.WeaponType) MiscType(megamek.common.MiscType) ArrayList(java.util.ArrayList) List(java.util.List) Aero(megamek.common.Aero) TestAero(megamek.common.verifier.TestAero) BattleArmor(megamek.common.BattleArmor) TestBattleArmor(megamek.common.verifier.TestBattleArmor)

Aggregations

Entity (megamek.common.Entity)33 File (java.io.File)10 JFileChooser (javax.swing.JFileChooser)10 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)10 UnitLoadingDialog (megamek.client.ui.swing.UnitLoadingDialog)10 UnitSelectorDialog (megamek.client.ui.swing.UnitSelectorDialog)10 MechFileParser (megamek.common.MechFileParser)10 BattleArmor (megamek.common.BattleArmor)7 Vector (com.sun.java.util.collections.Vector)6 Aero (megamek.common.Aero)6 Infantry (megamek.common.Infantry)6 Mech (megamek.common.Mech)6 Tank (megamek.common.Tank)6 BLKFile (megamek.common.loaders.BLKFile)6 Iterator (com.sun.java.util.collections.Iterator)5 Enumeration (java.util.Enumeration)4 Vector (java.util.Vector)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 List (java.util.List)3