Search in sources :

Example 1 with Entity

use of megamek.common.Entity in project megameklab by MegaMek.

the class MenuBarCreator method jMenuInsertImageFile_actionPerformed.

private void jMenuInsertImageFile_actionPerformed() {
    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("Load Mech");
    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 {
        Entity tempEntity = new MechFileParser(unitFile).getEntity();
        if (UnitUtil.validateUnit(parentFrame.getEntity()).trim().length() > 0) {
            JOptionPane.showMessageDialog(parentFrame, "Warning:Invalid unit, it might load incorrectly!");
        }
        FileDialog fDialog = new FileDialog(parentFrame, "Image Path", FileDialog.LOAD);
        if (parentFrame.getEntity().getFluff().getMMLImagePath().trim().length() > 0) {
            String fullPath = new File(parentFrame.getEntity().getFluff().getMMLImagePath()).getAbsolutePath();
            String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
            fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
            fDialog.setDirectory(fullPath);
            fDialog.setFile(imageName);
        } else {
            fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + "mech" + File.separatorChar);
            fDialog.setFile(parentFrame.getEntity().getChassis() + " " + parentFrame.getEntity().getModel() + ".png");
        }
        fDialog.setLocationRelativeTo(parentFrame);
        fDialog.setVisible(true);
        if (fDialog.getFile() != null) {
            String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath();
            relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir").toString()).getAbsolutePath().length() + 1);
            parentFrame.getEntity().getFluff().setMMLImagePath(relativeFilePath);
            BLKFile.encode(unitFile.getAbsolutePath(), tempEntity);
        }
    } catch (Exception ex) {
    }
    return;
}
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) FileDialog(java.awt.FileDialog)

Example 2 with Entity

use of megamek.common.Entity in project megameklab by MegaMek.

the class MenuBarCreator method jMenuGetUnitBVFromCache_actionPerformed.

private void jMenuGetUnitBVFromCache_actionPerformed() {
    UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(parentFrame);
    unitLoadingDialog.setVisible(true);
    UnitSelectorDialog viewer = new UnitSelectorDialog(parentFrame, unitLoadingDialog, true);
    Entity tempEntity = viewer.getChosenEntity();
    if (null == tempEntity) {
        return;
    }
    tempEntity.calculateBattleValue(true, true);
    UnitUtil.showBVCalculations(tempEntity.getBVText(), parentFrame);
}
Also used : Entity(megamek.common.Entity) UnitLoadingDialog(megamek.client.ui.swing.UnitLoadingDialog) UnitSelectorDialog(megamek.client.ui.swing.UnitSelectorDialog)

Example 3 with Entity

use of megamek.common.Entity in project megameklab by MegaMek.

the class MenuBarCreator method jMenuGetUnitBreakdownFromCache_actionPerformed.

private void jMenuGetUnitBreakdownFromCache_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.showUnitCostBreakDown(tempEntity, parentFrame);
}
Also used : Entity(megamek.common.Entity) UnitLoadingDialog(megamek.client.ui.swing.UnitLoadingDialog) UnitSelectorDialog(megamek.client.ui.swing.UnitSelectorDialog)

Example 4 with Entity

use of megamek.common.Entity in project megameklab by MegaMek.

the class MenuBarCreator method jMenuGetUnitWeightBreakdownFromCache_actionPerformed.

private void jMenuGetUnitWeightBreakdownFromCache_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.showUnitWeightBreakDown(tempEntity, parentFrame);
}
Also used : Entity(megamek.common.Entity) UnitLoadingDialog(megamek.client.ui.swing.UnitLoadingDialog) UnitSelectorDialog(megamek.client.ui.swing.UnitSelectorDialog)

Example 5 with Entity

use of megamek.common.Entity in project megameklab by MegaMek.

the class MenuBarCreator method loadUnit.

private void loadUnit() {
    UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(parentFrame);
    unitLoadingDialog.setVisible(true);
    UnitSelectorDialog viewer = new UnitSelectorDialog(parentFrame, unitLoadingDialog, true);
    Entity newUnit = viewer.getChosenEntity();
    viewer.setVisible(false);
    viewer.dispose();
    if (null == newUnit) {
        return;
    }
    if (UnitUtil.validateUnit(newUnit).trim().length() > 0) {
        JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", UnitUtil.validateUnit(newUnit)));
    }
    if (newUnit.getEntityType() != parentFrame.getEntity().getEntityType()) {
        MegaMekLabMainUI newUI = null;
        if (newUnit.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
            newUI = new megameklab.com.ui.Dropship.MainUI(((Aero) newUnit).isPrimitive());
        } else if (newUnit.hasETypeFlag(Entity.ETYPE_AERO) && !(newUnit.hasETypeFlag(Entity.ETYPE_JUMPSHIP) || newUnit.hasETypeFlag(Entity.ETYPE_FIXED_WING_SUPPORT))) {
            newUI = new megameklab.com.ui.Aero.MainUI(((Aero) newUnit).isPrimitive());
        } else if (newUnit.hasETypeFlag(Entity.ETYPE_BATTLEARMOR)) {
            newUI = new megameklab.com.ui.BattleArmor.MainUI();
        } else if (newUnit.hasETypeFlag(Entity.ETYPE_INFANTRY)) {
            newUI = new megameklab.com.ui.Infantry.MainUI();
        } else if (newUnit.hasETypeFlag(Entity.ETYPE_MECH)) {
            newUI = new megameklab.com.ui.Mek.MainUI();
        } else if (newUnit.hasETypeFlag(Entity.ETYPE_TANK) && !newUnit.hasETypeFlag(Entity.ETYPE_GUN_EMPLACEMENT)) {
            newUI = new megameklab.com.ui.Vehicle.MainUI();
        }
        if (null == newUI) {
            JOptionPane.showMessageDialog(parentFrame, "Warning: Could not create new UI, aborting unit load!" + System.lineSeparator() + "Probable cause: Unsupported unit type.");
            return;
        }
        parentFrame.dispose();
        UnitUtil.updateLoadedUnit(newUnit);
        newUI.setEntity(newUnit);
        newUI.reloadTabs();
        newUI.repaint();
        newUI.refreshAll();
        return;
    }
    CConfig.updateSaveFiles("");
    UnitUtil.updateLoadedUnit(newUnit);
    if (viewer.getChosenMechSummary().getSourceFile().getName().endsWith(".zip")) {
        String fileName = viewer.getChosenMechSummary().getSourceFile().getAbsolutePath();
        fileName = fileName.substring(0, fileName.lastIndexOf(File.separatorChar) + 1);
        fileName = fileName + viewer.getChosenMechSummary().getName() + ".mtf";
        CConfig.updateSaveFiles(fileName);
    } else {
        CConfig.updateSaveFiles(viewer.getChosenMechSummary().getSourceFile().getAbsolutePath());
    }
    parentFrame.setEntity(newUnit);
    reload();
    refresh();
    parentFrame.setVisible(true);
}
Also used : MegaMekLabMainUI(megameklab.com.ui.MegaMekLabMainUI) Entity(megamek.common.Entity) UnitLoadingDialog(megamek.client.ui.swing.UnitLoadingDialog) UnitSelectorDialog(megamek.client.ui.swing.UnitSelectorDialog) MegaMek(megamek.MegaMek) MegaMekLabMainUI(megameklab.com.ui.MegaMekLabMainUI) Aero(megamek.common.Aero) BattleArmor(megamek.common.BattleArmor)

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