Skip to content

Commit

Permalink
Merge pull request #1344 from SJuliez/user-dir
Browse files Browse the repository at this point in the history
User files directory setting in MML
  • Loading branch information
neoancient authored Dec 26, 2023
2 parents 8f61bbf + deef5ef commit c7a712d
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
39 changes: 39 additions & 0 deletions megameklab/docs/UserDirHelp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<HTML><H2>How to Use the User Data Directory</H2>

<P>Use this directory for resources you want to share between different installs or versions of MegaMek, MegaMekLab and MekHQ. Fonts, units, camos, portraits and unit fluff images will also be loaded from this directory (in addition to what is loaded from MegaMek's own data). The directory should be an absolute path such as D:/MyBTStuff (in other words, not relative to your MegaMek directory).</P>

<P>How to place files within the user data directory:
<UL>
<LI><B>Fonts</B> can be placed anywhere in the user data directory (i.e., in the directory itself or in any subfolder)

<LI><B>Units</B> (.mtf and .blk files) can be placed anywhere in the user data directory

<LI><B>Camo</B> images must be placed in &lt;user data directory&gt;/data/images/camo/. In this subfolder, further subfolders can be used (optional).

<LI><B>Portrait</B> images must be placed in &lt;user data directory&gt;/data/images/portraits/. In this subfolder, further subfolders can be used (optional).

<LI><B>Unit fluff</B> images must be placed in &lt;user data directory&gt;/data/images/fluff/&lt;unit type&gt;/. To find the exact subfolders to use, go to your megamek folder and open /data/images/fluff/.
</UL>

<P>This is an example of a suitable directory structure with a few example files:
<BR><BR>
D:/myBTStuff<BR>
&nbsp;&nbsp;&nbsp;&nbsp;Oxanium.ttf<BR>
&nbsp;&nbsp;&nbsp;&nbsp;Exo.ttf<BR>
&nbsp;&nbsp;&nbsp;&nbsp;/campaign_units<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Atlas AS8-XT.mtf<BR>
&nbsp;&nbsp;&nbsp;&nbsp;/data<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jura.ttf<BR>
&nbsp;&nbsp;&nbs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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Atlas.png<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/DropShip<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Colossus.png<BR>
3 changes: 3 additions & 0 deletions megameklab/resources/megameklab/resources/Dialogs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ ConfigurationDialog.chkShowExtinct.text=Show extinct equipment
ConfigurationDialog.chkShowExtinct.tooltip=Show equipment that has already gone out of production in the selected year
ConfigurationDialog.chkUnofficialIgnoreYear.text=Ignore intro/extinct years on Unofficial Tech Level units
ConfigurationDialog.chkUnofficialIgnoreYear.tooltip=If the tech level is set to unofficial, the intro/extinct year will be ignored.
ConfigurationDialog.userDir.text=User Files Directory:
ConfigurationDialog.userDir.tooltip=<html>Use this directory for resources you want to share between different installs or versions of MegaMek, MegaMekLab and MekHQ. Fonts, units, camos, portraits and fluff images will also be loaded from this directory.<BR>Note: Inside the user directory, use the directory structure of MM/MML/MHQ for camos, portraits and fluff images, i.e. data/images/camo, data/images/portraits and data/images/fluff/. <BR>Fonts and units can be placed anywhere in the user directory.
ConfigurationDialog.userDir.chooser.title=Choose User Data Folder
ConfigurationDialog.cbPaper.text=Paper Size:
ConfigurationDialog.cbPaper.tooltip=<html>The dimensions of the page to use when exporting to PDF.<br/>When printing, this can be changed in the print dialog.</html>
ConfigurationDialog.chkColor.text=Use color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
*/
package megameklab.ui.dialog.settings;

import megamek.MMConstants;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.CommonSettingsDialog;
import megamek.client.ui.swing.HelpDialog;
import megamek.common.preference.PreferenceManager;
import megameklab.ui.util.SpringUtilities;
import megameklab.util.CConfig;
import org.apache.logging.log4j.LogManager;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
Expand All @@ -35,10 +44,36 @@ public class MiscSettingsPanel extends JPanel {

private final JCheckBox chkSummaryFormatTRO = new JCheckBox();
private final JCheckBox chkSkipSavePrompts = new JCheckBox();
private final JTextField txtUserDir = new JTextField(20);

MiscSettingsPanel() {
MiscSettingsPanel(JFrame parent) {
ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Dialogs");

JLabel userDirLabel = new JLabel(resourceMap.getString("ConfigurationDialog.userDir.text"));
userDirLabel.setToolTipText(resourceMap.getString("ConfigurationDialog.userDir.tooltip"));
txtUserDir.setToolTipText(resourceMap.getString("ConfigurationDialog.userDir.tooltip"));
txtUserDir.setText(PreferenceManager.getClientPreferences().getUserDir());
JButton userDirChooser = new JButton("...");
userDirChooser.addActionListener(e -> CommonSettingsDialog.fileChooseUserDir(txtUserDir, parent));
userDirChooser.setToolTipText(resourceMap.getString("ConfigurationDialog.userDir.chooser.title"));
JButton userDirHelp = new JButton("Help");
try {
String helpTitle = Messages.getString("UserDirHelpDialog.title");
URL helpFile = new File(MMConstants.USER_DIR_README_FILE).toURI().toURL();
userDirHelp.addActionListener(e -> new HelpDialog(helpTitle, helpFile, parent).setVisible(true));
} catch (MalformedURLException e) {
LogManager.getLogger().error("Could not find the user data directory readme file at "
+ MMConstants.USER_DIR_README_FILE);
}
JPanel userDirLine = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
userDirLine.add(userDirLabel);
userDirLine.add(Box.createHorizontalStrut(25));
userDirLine.add(txtUserDir);
userDirLine.add(Box.createHorizontalStrut(10));
userDirLine.add(userDirChooser);
userDirLine.add(Box.createHorizontalStrut(10));
userDirLine.add(userDirHelp);

chkSummaryFormatTRO.setText(resourceMap.getString("ConfigurationDialog.chkSummaryFormatTRO.text"));
chkSummaryFormatTRO.setToolTipText(resourceMap.getString("ConfigurationDialog.chkSummaryFormatTRO.tooltip"));
chkSummaryFormatTRO.setSelected(CConfig.getBooleanParam(CConfig.MISC_SUMMARY_FORMAT_TRO));
Expand All @@ -48,10 +83,11 @@ public class MiscSettingsPanel extends JPanel {
chkSkipSavePrompts.setSelected(CConfig.getBooleanParam(CConfig.MISC_SKIP_SAFETY_PROMPTS));

JPanel gridPanel = new JPanel(new SpringLayout());
gridPanel.add(userDirLine);
gridPanel.add(chkSummaryFormatTRO);
gridPanel.add(chkSkipSavePrompts);

SpringUtilities.makeCompactGrid(gridPanel, 2, 1, 0, 0, 15, 10);
SpringUtilities.makeCompactGrid(gridPanel, 3, 1, 0, 0, 15, 10);
gridPanel.setBorder(new EmptyBorder(20, 30, 20, 30));
setLayout(new FlowLayout(FlowLayout.LEFT));
add(gridPanel);
Expand All @@ -63,4 +99,8 @@ Map<String, String> getMiscSettings() {
miscSettings.put(CConfig.MISC_SKIP_SAFETY_PROMPTS, String.valueOf(chkSkipSavePrompts.isSelected()));
return miscSettings;
}

String getUserDir() {
return txtUserDir.getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package megameklab.ui.dialog.settings;

import megamek.client.ui.baseComponents.MMButton;
import megamek.common.preference.PreferenceManager;
import megameklab.ui.dialog.AbstractMMLButtonDialog;
import megameklab.util.CConfig;

Expand All @@ -33,10 +34,11 @@ public class SettingsDialog extends AbstractMMLButtonDialog {
private final ColorSettingsPanel colorPreferences = new ColorSettingsPanel();
private final TechSettingsPanel techSettings = new TechSettingsPanel();
private final ExportSettingsPanel exportSettingsPanel = new ExportSettingsPanel();
private final MiscSettingsPanel miscSettingsPanel = new MiscSettingsPanel();
private final MiscSettingsPanel miscSettingsPanel;

public SettingsDialog(JFrame frame) {
super(frame, true, "ConfigurationDialog", "ConfigurationDialog.windowName.text");
miscSettingsPanel = new MiscSettingsPanel(frame);
initialize();
}

Expand Down Expand Up @@ -69,6 +71,7 @@ protected void okAction() {
exportSettingsPanel.getRecordSheetSettings().forEach(CConfig::setParam);
miscSettingsPanel.getMiscSettings().forEach(CConfig::setParam);
CConfig.saveConfig();
PreferenceManager.getClientPreferences().setUserDir(miscSettingsPanel.getUserDir());
}

@Override
Expand Down

0 comments on commit c7a712d

Please sign in to comment.