Skip to content

Commit

Permalink
Open with MML
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbraginskiy committed Oct 30, 2024
1 parent 9bd2a47 commit 4254353
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 20 deletions.
4 changes: 2 additions & 2 deletions megameklab/resources/megameklab/resources/Dialogs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ ConfigurationDialog.startup.text=MML Startup:
ConfigurationDialog.startup.tooltip=Depending on the startup type selected, MML will start in the main menu or, alternatively, directly load the most recent unit or start with a new unit instead of the main menu.
ConfigurationDialog.mekChassis.text=Mek Chassis Arrangement:
ConfigurationDialog.mekChassis.tooltip=Meks with a Clan and an IS chassis name will print their chassis in the selected arrangement. Meks with no clan chassis name will always just print their chassis.
ConfigurationDialog.cbMulDndBehaviour.text=MUL file drag and drop behaviour:
ConfigurationDialog.cbMulDndBehaviour.tooltip=What should be done when a MUL file is dragged onto the MML window?
ConfigurationDialog.cbMulOpenBehaviour.text=MUL file open behaviour:
ConfigurationDialog.cbMulOpenBehaviour.tooltip=What should be done when a MUL file is dragged onto the MML window or opened with MML by the operating system?
RecordSheetTask.printing=Printing
RecordSheetTask.exporting=Exporting
Expand Down
27 changes: 25 additions & 2 deletions megameklab/src/megameklab/MegaMekLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import megameklab.ui.StartupGUI;
import megameklab.ui.dialog.UiLoader;
import megameklab.util.CConfig;
import megameklab.util.UnitPrintManager;
import megameklab.util.UnitUtil;

public class MegaMekLab {
Expand Down Expand Up @@ -74,7 +75,7 @@ public static void main(String... args) {
MegaMek.initializeSuiteGraphicalSetups(MMLConstants.PROJECT_NAME);
ToolTipManager.sharedInstance().setDismissDelay(1000000);
ToolTipManager.sharedInstance().setReshowDelay(50);
startup();
startup(args);
}

public static void initializeLogging(final String originProject) {
Expand All @@ -89,7 +90,7 @@ public static String getUnderlyingInformation(final String originProject) {
return MegaMek.getUnderlyingInformation(originProject, MMLConstants.PROJECT_NAME);
}

private static void startup() {
private static void startup(String[] args) {
EquipmentType.initializeTypes();
MekSummaryCache.getInstance();
CConfig.load();
Expand All @@ -103,6 +104,28 @@ private static void startup() {

updateGuiScaling(); // also sets the look-and-feel

if (args.length == 1) {
try {
var name = args[0];
logger.info("Trying to open file {}", name);
if (name.toLowerCase().endsWith(".blk") || name.endsWith(".mtf")) {
var file = new File(name);
Entity e = new MekFileParser(file).getEntity();
if (!UnitUtil.validateUnit(e).isBlank()) {
PopupMessages.showUnitInvalidWarning(null, UnitUtil.validateUnit(e));
}
UiLoader.loadUi(e, file.toString());
return;
} else if (name.toLowerCase().endsWith(".mul")) {
UnitPrintManager.printMUL(new JFrame(), CConfig.getBooleanParam(CConfig.MISC_MUL_OPEN_BEHAVIOUR), new File(name));
System.exit(0);
return;
}
} catch (Exception e) {
logger.warn(e);
}
}

// Create a startup frame and display it
switch (CConfig.getStartUpType()) {
case NEW_MEK -> UiLoader.loadUi(Entity.ETYPE_MEK, false, false);
Expand Down
24 changes: 12 additions & 12 deletions megameklab/src/megameklab/ui/dialog/settings/MiscSettingsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class MiscSettingsPanel extends JPanel {
private final JCheckBox chkSkipSavePrompts = new JCheckBox();
private final JTextField txtUserDir = new JTextField(20);
private final JSlider guiScale = new JSlider();
private final MMComboBox<MulDndBehaviour> cbMulDndBehaviour = new MMComboBox<>("MUL Drag and Drop behaviour", MulDndBehaviour.values());
private final MMComboBox<MulDndBehaviour> cbMulOpenBehaviour = new MMComboBox<>("MUL Drag and Drop behaviour", MulDndBehaviour.values());

MiscSettingsPanel(JFrame parent) {
startUpMMComboBox.setRenderer(miscComboBoxRenderer);
Expand All @@ -73,16 +73,16 @@ public class MiscSettingsPanel extends JPanel {
startUpLine.add(Box.createHorizontalStrut(5));
startUpLine.add(startUpMMComboBox);

cbMulDndBehaviour.setRenderer(miscComboBoxRenderer);
cbMulDndBehaviour.setToolTipText(resources.getString("ConfigurationDialog.cbMulDndBehaviour.tooltip"));
cbMulDndBehaviour.setSelectedItem(CConfig.getBooleanParam(CConfig.MISC_MUL_DND_BEHAVIOUR) ? MulDndBehaviour.EXPORT : MulDndBehaviour.PRINT);
JLabel mulDndLabel = new JLabel(resources.getString("ConfigurationDialog.cbMulDndBehaviour.text"));
mulDndLabel.setToolTipText(resources.getString("ConfigurationDialog.cbMulDndBehaviour.tooltip"));
cbMulOpenBehaviour.setRenderer(miscComboBoxRenderer);
cbMulOpenBehaviour.setToolTipText(resources.getString("ConfigurationDialog.cbMulOpenBehaviour.tooltip"));
cbMulOpenBehaviour.setSelectedItem(CConfig.getBooleanParam(CConfig.MISC_MUL_OPEN_BEHAVIOUR) ? MulDndBehaviour.EXPORT : MulDndBehaviour.PRINT);
JLabel mulOpenLabel = new JLabel(resources.getString("ConfigurationDialog.cbMulOpenBehaviour.text"));
mulOpenLabel.setToolTipText(resources.getString("ConfigurationDialog.cbMulOpenBehaviour.tooltip"));

JPanel mulDndLine = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
mulDndLine.add(mulDndLabel);
mulDndLine.add(Box.createHorizontalStrut(5));
mulDndLine.add(cbMulDndBehaviour);
JPanel mulOpenLine = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
mulOpenLine.add(mulOpenLabel);
mulOpenLine.add(Box.createHorizontalStrut(5));
mulOpenLine.add(cbMulOpenBehaviour);

chkSummaryFormatTRO.setText(resources.getString("ConfigurationDialog.chkSummaryFormatTRO.text"));
chkSummaryFormatTRO.setToolTipText(resources.getString("ConfigurationDialog.chkSummaryFormatTRO.tooltip"));
Expand Down Expand Up @@ -142,7 +142,7 @@ public class MiscSettingsPanel extends JPanel {
JPanel gridPanel = new JPanel(new SpringLayout());
gridPanel.add(startUpLine);
gridPanel.add(userDirLine);
gridPanel.add(mulDndLine);
gridPanel.add(mulOpenLine);
gridPanel.add(chkSummaryFormatTRO);
gridPanel.add(chkSkipSavePrompts);
gridPanel.add(scaleLine);
Expand All @@ -161,7 +161,7 @@ Map<String, String> getMiscSettings() {
? MMLStartUp.SPLASH_SCREEN
: startUpMMComboBox.getSelectedItem();
miscSettings.put(CConfig.MISC_STARTUP, startUp.name());
miscSettings.put(CConfig.MISC_MUL_DND_BEHAVIOUR, String.valueOf(cbMulDndBehaviour.getSelectedItem() == MulDndBehaviour.EXPORT));
miscSettings.put(CConfig.MISC_MUL_OPEN_BEHAVIOUR, String.valueOf(cbMulOpenBehaviour.getSelectedItem() == MulDndBehaviour.EXPORT));
// User directory and gui scale are stored in MM's client settings, not in CConfig, therefore not added here
return miscSettings;
}
Expand Down
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/util/CConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public final class CConfig {
public static final String MISC_STARTUP = "StartupGui";
public static final String MISC_SUMMARY_FORMAT_TRO = "useTROFormat";
public static final String MISC_SKIP_SAFETY_PROMPTS = "skipSafetyPrompts";
public static final String MISC_MUL_DND_BEHAVIOUR = "mulDndBehaviour";
public static final String MISC_MUL_OPEN_BEHAVIOUR = "mulDndBehaviour";

public static final String GUI_PLAF = "lookAndFeel";
public static final String GUI_COLOR_WEAPONS = "Weapons";
Expand Down
6 changes: 3 additions & 3 deletions megameklab/src/megameklab/util/MMLFileDropTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public synchronized void drop(DropTargetDropEvent event) {
var file = files.get(0);
var name = file.getName();

if (name.endsWith(".mtf") || name.endsWith(".blk")) {
if (name.toLowerCase().endsWith(".mtf") || name.toLowerCase().endsWith(".blk")) {
owner.getMMLMenuBar().loadFile(file);
event.dropComplete(true);
} else if (name.endsWith(".mul")) {
UnitPrintManager.printMUL(owner.getFrame(), CConfig.getBooleanParam(CConfig.MISC_MUL_DND_BEHAVIOUR), file);
} else if (name.toLowerCase().endsWith(".mul")) {
UnitPrintManager.printMUL(owner.getFrame(), CConfig.getBooleanParam(CConfig.MISC_MUL_OPEN_BEHAVIOUR), file);
event.dropComplete(true);
} else {
event.dropComplete(false);
Expand Down

0 comments on commit 4254353

Please sign in to comment.