use of megameklab.com.ui.MegaMekLabMainUI 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);
}
use of megameklab.com.ui.MegaMekLabMainUI in project megameklab by MegaMek.
the class MenuBarCreator method loadUnitFromFile.
private void loadUnitFromFile(File unitFile) {
try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
if (null == tempEntity) {
return;
}
if (UnitUtil.validateUnit(tempEntity).trim().length() > 0) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", UnitUtil.validateUnit(tempEntity)));
}
if (tempEntity.getEntityType() != parentFrame.getEntity().getEntityType()) {
MegaMekLabMainUI newUI = null;
if (tempEntity.hasETypeFlag(Entity.ETYPE_SMALL_CRAFT)) {
newUI = new megameklab.com.ui.Dropship.MainUI(((Aero) tempEntity).isPrimitive());
} else if ((tempEntity instanceof Aero) && !((tempEntity instanceof Jumpship) || (tempEntity instanceof FixedWingSupport))) {
newUI = new megameklab.com.ui.Aero.MainUI(((Aero) tempEntity).isPrimitive());
} else if (tempEntity instanceof BattleArmor) {
newUI = new megameklab.com.ui.BattleArmor.MainUI();
} else if (tempEntity instanceof Infantry) {
newUI = new megameklab.com.ui.Infantry.MainUI();
} else if (tempEntity instanceof Mech) {
newUI = new megameklab.com.ui.Mek.MainUI();
} else if ((tempEntity instanceof Tank) && !(tempEntity instanceof GunEmplacement)) {
newUI = new megameklab.com.ui.Vehicle.MainUI();
}
if (null == newUI) {
JOptionPane.showMessageDialog(parentFrame, "Warning: Could not create new UI, aborting unit load!");
return;
}
parentFrame.dispose();
UnitUtil.updateLoadedUnit(tempEntity);
newUI.setEntity(tempEntity);
newUI.reloadTabs();
newUI.repaint();
newUI.refreshAll();
return;
}
parentFrame.setEntity(tempEntity);
UnitUtil.updateLoadedUnit(parentFrame.getEntity());
CConfig.updateSaveFiles(unitFile.getAbsolutePath());
} catch (Exception ex) {
JOptionPane.showMessageDialog(parentFrame, String.format("Warning:Invalid unit, it might load incorrectly!\n%1$s", ex.getMessage()));
}
reload();
refresh();
parentFrame.setVisible(true);
}
Aggregations