From 5b9b0c02869eeee4a90f0e96bd0d7a5d843726f5 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 28 Jan 2024 11:05:11 +0100 Subject: [PATCH 1/4] fluff image handling in MML, remove unused code --- .../src/megameklab/printing/PrintAero.java | 8 +- .../megameklab/printing/PrintCapitalShip.java | 10 +- .../megameklab/printing/PrintDropship.java | 3 +- .../src/megameklab/printing/PrintMech.java | 2 +- .../printing/PrintSmallUnitSheet.java | 6 +- .../src/megameklab/printing/PrintTank.java | 6 +- megameklab/src/megameklab/ui/MenuBar.java | 2 +- .../megameklab/ui/generalUnit/StatusBar.java | 2 +- .../src/megameklab/util/ImageHelper.java | 192 +++--------------- 9 files changed, 44 insertions(+), 187 deletions(-) diff --git a/megameklab/src/megameklab/printing/PrintAero.java b/megameklab/src/megameklab/printing/PrintAero.java index d7ade351f..1020bfcd5 100644 --- a/megameklab/src/megameklab/printing/PrintAero.java +++ b/megameklab/src/megameklab/printing/PrintAero.java @@ -201,13 +201,7 @@ public String formatFeatures() { @Override protected void drawFluffImage() { - String dir = ImageHelper.imageAero; - if (aero instanceof ConvFighter) { - dir = ImageHelper.imageConvFighter; - } else if (aero instanceof SmallCraft) { - dir = ImageHelper.imageSmallcraft; - } - File f = ImageHelper.getFluffFile(aero, dir); + File f = ImageHelper.getFluffFile(aero); if (null != f) { Element rect = getSVGDocument().getElementById(FLUFF_IMAGE); if (rect instanceof SVGRectElement) { diff --git a/megameklab/src/megameklab/printing/PrintCapitalShip.java b/megameklab/src/megameklab/printing/PrintCapitalShip.java index e8f616f96..0bf96ee47 100644 --- a/megameklab/src/megameklab/printing/PrintCapitalShip.java +++ b/megameklab/src/megameklab/printing/PrintCapitalShip.java @@ -369,17 +369,9 @@ private Element createPip(double pipWidth, double pipHeight, String fillColor, @Override protected void drawFluffImage() { - String dir; - if (getEntity() instanceof Warship) { - dir = ImageHelper.imageWarship; - } else if (getEntity() instanceof SpaceStation) { - dir = ImageHelper.imageSpaceStation; - } else { - dir = ImageHelper.imageJumpship; - } Element rect = getSVGDocument().getElementById(FLUFF_IMAGE); if (rect instanceof SVGRectElement) { - embedImage(ImageHelper.getFluffFile(ship, dir), + embedImage(ImageHelper.getFluffFile(ship), (Element) rect.getParentNode(), getRectBBox((SVGRectElement) rect), true); } hideElement(getSVGDocument().getElementById(NOTES)); diff --git a/megameklab/src/megameklab/printing/PrintDropship.java b/megameklab/src/megameklab/printing/PrintDropship.java index 66cf25c32..4acbc2ac3 100644 --- a/megameklab/src/megameklab/printing/PrintDropship.java +++ b/megameklab/src/megameklab/printing/PrintDropship.java @@ -349,10 +349,9 @@ public String formatFeatures() { @Override protected void drawFluffImage() { - String dir = ImageHelper.imageDropship; Element rect = getSVGDocument().getElementById("fluffImage"); if (rect instanceof SVGRectElement) { - embedImage(ImageHelper.getFluffFile(ship, dir), + embedImage(ImageHelper.getFluffFile(ship), (Element) rect.getParentNode(), getRectBBox((SVGRectElement) rect), true); } hideElement(getSVGDocument().getElementById(NOTES)); diff --git a/megameklab/src/megameklab/printing/PrintMech.java b/megameklab/src/megameklab/printing/PrintMech.java index aa7c142fa..6a3856278 100644 --- a/megameklab/src/megameklab/printing/PrintMech.java +++ b/megameklab/src/megameklab/printing/PrintMech.java @@ -540,7 +540,7 @@ protected void drawFluffImage() { placeReferenceCharts(tables, rect.getParentNode(), bbox.getX(), bbox.getY(), bbox.getWidth() + 6.0, bbox.getHeight() + 6.0); } else { - embedImage(ImageHelper.getFluffFile(mech, ImageHelper.imageMech), + embedImage(ImageHelper.getFluffFile(mech), (Element) rect.getParentNode(), getRectBBox((SVGRectElement) rect), true); } } diff --git a/megameklab/src/megameklab/printing/PrintSmallUnitSheet.java b/megameklab/src/megameklab/printing/PrintSmallUnitSheet.java index 56ac1649a..5613a2f08 100644 --- a/megameklab/src/megameklab/printing/PrintSmallUnitSheet.java +++ b/megameklab/src/megameklab/printing/PrintSmallUnitSheet.java @@ -129,11 +129,11 @@ private void drawFluffImage() { } File f = null; if (entities.get(0) instanceof BattleArmor) { - f = ImageHelper.getFluffFile(entities.get(0), ImageHelper.imageBattleArmor); + f = ImageHelper.getFluffFile(entities.get(0)); } else if (entities.get(0) instanceof Infantry) { - f = ImageHelper.getFluffFile(entities.get(0), ImageHelper.imageInfantry); + f = ImageHelper.getFluffFile(entities.get(0)); } else if (entities.get(0) instanceof Protomech) { - f = ImageHelper.getFluffFile(entities.get(0), ImageHelper.imageProto); + f = ImageHelper.getFluffFile(entities.get(0)); } if (f != null) { Element rect = getSVGDocument().getElementById(FLUFF_IMAGE); diff --git a/megameklab/src/megameklab/printing/PrintTank.java b/megameklab/src/megameklab/printing/PrintTank.java index d6def265b..8e04ca5a9 100644 --- a/megameklab/src/megameklab/printing/PrintTank.java +++ b/megameklab/src/megameklab/printing/PrintTank.java @@ -193,11 +193,11 @@ public String formatFeatures() { protected void drawFluffImage() { File f; if (tank.getMovementMode().isMarine()) { - f = ImageHelper.getFluffFile(tank, ImageHelper.imageNaval); + f = ImageHelper.getFluffFile(tank); } else if (tank instanceof LargeSupportTank) { - f = ImageHelper.getFluffFile(tank, ImageHelper.imageLargeSupportVehicle); + f = ImageHelper.getFluffFile(tank); } else { - f = ImageHelper.getFluffFile(tank, ImageHelper.imageVehicle); + f = ImageHelper.getFluffFile(tank); } if (null != f) { Element rect = getSVGDocument().getElementById(FLUFF_IMAGE); diff --git a/megameklab/src/megameklab/ui/MenuBar.java b/megameklab/src/megameklab/ui/MenuBar.java index 204c3377f..832cd34b9 100644 --- a/megameklab/src/megameklab/ui/MenuBar.java +++ b/megameklab/src/megameklab/ui/MenuBar.java @@ -943,7 +943,7 @@ private void importFluffImageAction() { loadImageFileChooser.setCurrentDirectory(new File(fullPath)); loadImageFileChooser.setSelectedFile(new File(imageName)); } else { - loadImageFileChooser.setCurrentDirectory(new File(ImageHelper.fluffPath)); + loadImageFileChooser.setCurrentDirectory(Configuration.fluffImagesDir()); loadImageFileChooser.setSelectedFile(new File(getUnitMainUi().getEntity().getChassis() + ' ' + getUnitMainUi().getEntity().getModel() + ".png")); } diff --git a/megameklab/src/megameklab/ui/generalUnit/StatusBar.java b/megameklab/src/megameklab/ui/generalUnit/StatusBar.java index 6d08a87d3..69c79eae6 100644 --- a/megameklab/src/megameklab/ui/generalUnit/StatusBar.java +++ b/megameklab/src/megameklab/ui/generalUnit/StatusBar.java @@ -144,7 +144,7 @@ private void refreshInvalid() { private void getFluffImage() { FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); + fDialog.setDirectory(Configuration.fluffImagesDir().toString()); fDialog.setLocationRelativeTo(this); fDialog.setVisible(true); if (fDialog.getFile() != null) { diff --git a/megameklab/src/megameklab/util/ImageHelper.java b/megameklab/src/megameklab/util/ImageHelper.java index 17412565c..d637b91a1 100644 --- a/megameklab/src/megameklab/util/ImageHelper.java +++ b/megameklab/src/megameklab/util/ImageHelper.java @@ -15,31 +15,17 @@ */ package megameklab.util; +import megamek.client.ui.swing.util.FluffImageHelper; +import megamek.common.Configuration; import megamek.common.Entity; import megamek.common.annotations.Nullable; +import megamek.common.preference.PreferenceManager; -import javax.swing.*; -import java.awt.*; import java.io.File; +import java.util.ArrayList; +import java.util.List; -public class ImageHelper { - public static String fluffPath = "./data/images/fluff/"; // TODO : Remove inline file path - public static String imagePath = "./data/images/"; // TODO : Remove inline file path - - public static String imageMech = "Mech"; - public static String imageAero = "Fighter"; - public static String imageBattleArmor = "BattleArmor"; - public static String imageConvFighter = "ConvFighter"; - public static String imageInfantry = "Infantry"; - public static String imageVehicle = "Vehicle"; - public static String imageNaval = "Naval"; - public static String imageLargeSupportVehicle = "LargeSupportVehicle"; - public static String imageProto = "ProtoMek"; - public static String imageSmallcraft = "Small Craft"; - public static String imageDropship = "DropShip"; - public static String imageJumpship = "JumpShip"; - public static String imageWarship = "WarShip"; - public static String imageSpaceStation = "Space Station"; +public final class ImageHelper { /** * Checks for a fluff image for the unit starting with any file explicitly associated with the @@ -47,159 +33,45 @@ public class ImageHelper { * unit with an image format extension. * * @param unit The unit to find a fluff image for - * @param dir The directory to check for a default image based on unit name * @return A file to use for the fluff image, or null if no file is found. */ - public static @Nullable File getFluffFile(Entity unit, String dir) { - String path = new File(fluffPath).getAbsolutePath(); - File f; - - if (!unit.getFluff().getMMLImagePath().isBlank()) { - f = new File(unit.getFluff().getMMLImagePath()); - if (f.exists()) { - return f; - } - f = new File(path, unit.getFluff().getMMLImagePath()); - if (f.exists()) { - return f; - } - } - - path = new File(path, dir).getAbsolutePath(); - final String [] EXTENSIONS = { ".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".gif", ".GIF" }; - for (String ext : EXTENSIONS) { - f = new File(path, unit.getShortNameRaw() + ext); - if (f.exists()) { - return f; - } - } - for (String ext : EXTENSIONS) { - f = new File(path, unit.getChassis() + ext); - if (f.exists()) { - return f; - } - } - f = new File(path, "hud.png"); - if (f.exists()) { - return f; - } - return null; - } + public static @Nullable File getFluffFile(Entity unit) { + List fileCandidates = new ArrayList<>(); + var fluffDir = new File(Configuration.fluffImagesDir(), FluffImageHelper.getImagePath(unit)); - public static @Nullable Image getFluffImage(String image) { - if ((image == null) || image.isBlank()) { - return null; - } - - String path = new File(fluffPath).getAbsolutePath() + File.separatorChar + image; - - if (!(new File(path).exists())) { - path = new File(image).getAbsolutePath(); - if (!(new File(path).exists())) { - return null; - } - } - return new ImageIcon(path).getImage(); - } - - public static Image getFluffImage(Entity unit, String dir) { - String path = new File(fluffPath).getAbsolutePath() - + File.separatorChar + dir + File.separatorChar; - - Image fluff = ImageHelper.getFluffImage(unit.getFluff().getMMLImagePath()); - - if (fluff == null) { - fluff = ImageHelper.getFluffPNG(unit, path); - } - - if (fluff == null) { - fluff = ImageHelper.getFluffJPG(unit, path); - } - - if (fluff == null) { - fluff = ImageHelper.getFluffGIF(unit, path); - } - - if (fluff == null) { - fluff = new ImageIcon(path + "hud.png").getImage(); - } - - return fluff; - } - - public static Image getFluffPNG(Entity unit, String path) { - Image fluff = null; - - String fluffFile = path + unit.getChassis() + " " + unit.getModel() + ".png"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); - } - - if (fluff == null) { - fluffFile = path + unit.getModel() + ".png"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); - } - } - - if (fluff == null) { - fluffFile = path + unit.getChassis() + ".png"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); - } - } - - return fluff; - } - - public static Image getFluffJPG(Entity unit, String path) { - Image fluff = null; - - String fluffFile = path + unit.getChassis() + " " + unit.getModel() + ".jpg"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); + // MML Path matches (??) + if (!unit.getFluff().getMMLImagePath().isBlank()) { + fileCandidates.add(new File(unit.getFluff().getMMLImagePath())); + fileCandidates.add(new File(fluffDir, unit.getFluff().getMMLImagePath())); } - if (fluff == null) { - fluffFile = path + unit.getModel() + ".jpg"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); - } + // Internal fluff path matches + for (String ext : FluffImageHelper.EXTENSIONS_FLUFF_IMAGE_FORMATS) { + fileCandidates.add(new File(fluffDir, unit.getShortNameRaw() + ext)); } - if (fluff == null) { - fluffFile = path + unit.getChassis() + ".jpg"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); + // UserDir matches + String userDir = PreferenceManager.getClientPreferences().getUserDir(); + if (!userDir.isBlank() && new File(userDir).isDirectory()) { + var fluffPath = new File(userDir, fluffDir.toString()); + for (String ext : FluffImageHelper.EXTENSIONS_FLUFF_IMAGE_FORMATS) { + fileCandidates.add(new File(fluffPath, unit.getFullChassis() + ext)); } } - return fluff; - } - - public static Image getFluffGIF(Entity unit, String path) { - Image fluff = null; - - String fluffFile = path + unit.getChassis() + " " + unit.getModel() - + ".gif"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); + // Chassis matches + for (String ext : FluffImageHelper.EXTENSIONS_FLUFF_IMAGE_FORMATS) { + fileCandidates.add(new File(fluffDir, unit.getFullChassis() + ext)); } - if (fluff == null) { - fluffFile = path + unit.getModel() + ".gif"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); - } - } + // Fallback + fileCandidates.add(new File(fluffDir, "hud.png")); - if (fluff == null) { - fluffFile = path + unit.getChassis() + ".gif"; - if (new File(fluffFile.toLowerCase()).exists()) { - fluff = new ImageIcon(fluffFile).getImage(); + for (File possibleFile : fileCandidates) { + if (possibleFile.exists() && !possibleFile.isDirectory()) { + return possibleFile; } } - - return fluff; + return null; } -} +} \ No newline at end of file From fc0540fffeba487cf4667e9605a5dbafc5410bca Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 28 Jan 2024 14:55:44 +0100 Subject: [PATCH 2/4] small corrections --- megameklab/src/megameklab/util/ImageHelper.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/megameklab/src/megameklab/util/ImageHelper.java b/megameklab/src/megameklab/util/ImageHelper.java index d637b91a1..ebe417e1c 100644 --- a/megameklab/src/megameklab/util/ImageHelper.java +++ b/megameklab/src/megameklab/util/ImageHelper.java @@ -53,14 +53,16 @@ public final class ImageHelper { // UserDir matches String userDir = PreferenceManager.getClientPreferences().getUserDir(); if (!userDir.isBlank() && new File(userDir).isDirectory()) { - var fluffPath = new File(userDir, fluffDir.toString()); + var fluffUserDir = new File(userDir, fluffDir.toString()); for (String ext : FluffImageHelper.EXTENSIONS_FLUFF_IMAGE_FORMATS) { - fileCandidates.add(new File(fluffPath, unit.getFullChassis() + ext)); + fileCandidates.add(new File(fluffUserDir, unit.getChassis() + ext)); + fileCandidates.add(new File(fluffUserDir, unit.getFullChassis() + ext)); } } // Chassis matches for (String ext : FluffImageHelper.EXTENSIONS_FLUFF_IMAGE_FORMATS) { + fileCandidates.add(new File(fluffDir, unit.getChassis() + ext)); fileCandidates.add(new File(fluffDir, unit.getFullChassis() + ext)); } From 8f6596225d4a861a00a3f5d9e09b3a6c8da7189b Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 28 Jan 2024 23:08:42 +0100 Subject: [PATCH 3/4] add clan name editing for MML, corrections --- .../megameklab/resources/Views.properties | 2 ++ .../src/megameklab/ui/MegaMekLabMainUI.java | 2 +- .../ui/generalUnit/BasicInfoView.java | 20 ++++++++++++++++++- .../ui/listeners/BuildListener.java | 3 +++ .../src/megameklab/ui/mek/BMStructureTab.java | 7 +++++++ 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/megameklab/resources/megameklab/resources/Views.properties b/megameklab/resources/megameklab/resources/Views.properties index 791d0e752..a8ba93200 100644 --- a/megameklab/resources/megameklab/resources/Views.properties +++ b/megameklab/resources/megameklab/resources/Views.properties @@ -1,5 +1,7 @@ BasicInfoView.txtChassis.text=Chassis: BasicInfoView.txtChassis.tooltip=Units with the same chassis name are usually considered variants +BasicInfoView.txtClanName.text=Clan Name: +BasicInfoView.txtClanName.tooltip=The clan name of the Mek, such as Timber Wolf BasicInfoView.txtModel.text=Model: BasicInfoView.txtModel.tooltip=The name of this variant BasicInfoView.txtMulId.text=MUL ID: diff --git a/megameklab/src/megameklab/ui/MegaMekLabMainUI.java b/megameklab/src/megameklab/ui/MegaMekLabMainUI.java index 0d17221cc..087d5069e 100644 --- a/megameklab/src/megameklab/ui/MegaMekLabMainUI.java +++ b/megameklab/src/megameklab/ui/MegaMekLabMainUI.java @@ -124,7 +124,7 @@ public boolean exit() { @Override public void refreshHeader() { String fileInfo = fileName.isBlank() ? "" : " (" + fileName + ")"; - setTitle(getEntity().getChassis() + " " + getEntity().getModel() + fileInfo); + setTitle(getEntity().getFullChassis() + " " + getEntity().getModel() + fileInfo); } @Override diff --git a/megameklab/src/megameklab/ui/generalUnit/BasicInfoView.java b/megameklab/src/megameklab/ui/generalUnit/BasicInfoView.java index a0d7d7078..a2d3c2eeb 100644 --- a/megameklab/src/megameklab/ui/generalUnit/BasicInfoView.java +++ b/megameklab/src/megameklab/ui/generalUnit/BasicInfoView.java @@ -59,7 +59,11 @@ public class BasicInfoView extends BuildView implements ITechManager, ActionList private String[] techBaseNames; private TechAdvancement baseTA; + private final ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Views"); private final JTextField txtChassis = new JTextField(5); + private final JTextField txtClanName = new JTextField(5); + private final JLabel lblClanName = createLabel(resourceMap, "lblClanName", "BasicInfoView.txtClanName.text", + "BasicInfoView.txtClanName.tooltip", labelSize); private final JTextField txtModel = new JTextField(5); private final IntRangeTextField txtYear = new IntRangeTextField(3); private final FactionComboBox cbFaction = new FactionComboBox(); @@ -85,7 +89,6 @@ public BasicInfoView(TechAdvancement baseTA) { //endregion Constructors private void initUI() { - ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Views"); techBaseNames = resourceMap.getString("BasicInfoView.cbTechBase.values").split(","); setLayout(new GridBagLayout()); @@ -104,6 +107,15 @@ private void initUI() { setFieldSize(txtChassis, controlSize); txtChassis.addFocusListener(this); + gbc.gridx = 0; + gbc.gridy++; + add(lblClanName, gbc); + gbc.gridx = 1; + txtClanName.setToolTipText(resourceMap.getString("BasicInfoView.txtModel.tooltip")); + add(txtClanName, gbc); + setFieldSize(txtClanName, controlSize); + txtClanName.addFocusListener(this); + gbc.gridx = 0; gbc.gridy++; add(createLabel(resourceMap, "lblModel", "BasicInfoView.txtModel.text", @@ -228,6 +240,9 @@ public void setFromEntity(Entity en) { txtYear.setMinimum(Math.max(baseTA.getIntroductionDate(), ITechnology.DATE_PS)); refreshTechBase(); setChassis(en.getChassis()); + txtClanName.setText(en.getClanChassisName()); + txtClanName.setVisible(en instanceof Mech); + lblClanName.setVisible(en instanceof Mech); setModel(en.getModel()); txtMulId.setText(en.getMulId() + ""); browseMul.setVisible(en.hasMulId()); @@ -259,6 +274,7 @@ public void setFromEntity(Entity en) { public void setAsCustomization() { txtChassis.setEnabled(false); + txtClanName.setEnabled(false); txtYear.setEnabled(false); } @@ -495,6 +511,8 @@ public void focusGained(FocusEvent e) { public void focusLost(FocusEvent e) { if (e.getSource() == txtChassis) { listeners.forEach(l -> l.chassisChanged(getChassis())); + } else if (e.getSource() == txtClanName) { + listeners.forEach(l -> l.clanNameChanged(txtClanName.getText())); } else if (e.getSource() == txtModel) { listeners.forEach(l -> l.modelChanged(getModel())); } else if (e.getSource() == txtMulId) { diff --git a/megameklab/src/megameklab/ui/listeners/BuildListener.java b/megameklab/src/megameklab/ui/listeners/BuildListener.java index 9828e02e6..34dfa3b29 100644 --- a/megameklab/src/megameklab/ui/listeners/BuildListener.java +++ b/megameklab/src/megameklab/ui/listeners/BuildListener.java @@ -29,6 +29,9 @@ public interface BuildListener { void refreshSummary(); void chassisChanged(String chassis); + + default void clanNameChanged(String clanName) { } + void modelChanged(String model); void yearChanged(int year); void updateTechLevel(); diff --git a/megameklab/src/megameklab/ui/mek/BMStructureTab.java b/megameklab/src/megameklab/ui/mek/BMStructureTab.java index 718420e63..c9fd84464 100644 --- a/megameklab/src/megameklab/ui/mek/BMStructureTab.java +++ b/megameklab/src/megameklab/ui/mek/BMStructureTab.java @@ -550,6 +550,13 @@ public void chassisChanged(String chassis) { refresh.refreshPreview(); } + @Override + public void clanNameChanged(String clanName) { + getMech().setClanChassisName(clanName); + refresh.refreshHeader(); + refresh.refreshPreview(); + } + @Override public void modelChanged(String model) { getMech().setModel(model); From b228b8df976a3f82209b86f981500af0530df004 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 31 Jan 2024 14:21:52 +0100 Subject: [PATCH 4/4] Add record sheet setting for mek Clan/IS naming --- .../megameklab/resources/Dialogs.properties | 2 + .../megameklab/resources/Menu.properties | 8 +- .../printing/MekChassisArrangement.java | 76 +++++++++++++++++++ .../src/megameklab/printing/PrintEntity.java | 12 ++- .../dialog/settings/ExportSettingsPanel.java | 32 +++++++- .../ui/dialog/settings/SettingsDialog.java | 18 +++-- megameklab/src/megameklab/util/CConfig.java | 7 ++ 7 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 megameklab/src/megameklab/printing/MekChassisArrangement.java diff --git a/megameklab/resources/megameklab/resources/Dialogs.properties b/megameklab/resources/megameklab/resources/Dialogs.properties index 61948b8e1..1593b1b72 100644 --- a/megameklab/resources/megameklab/resources/Dialogs.properties +++ b/megameklab/resources/megameklab/resources/Dialogs.properties @@ -55,6 +55,8 @@ ConfigurationDialog.chkSkipSavePrompts.text=Disable save prompts. Use at your ow ConfigurationDialog.chkSkipSavePrompts.tooltip=When checked, no safety dialogs warning about losing changes when switching unit or unit type will be shown. 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. RecordSheetTask.printing=Printing RecordSheetTask.exporting=Exporting diff --git a/megameklab/resources/megameklab/resources/Menu.properties b/megameklab/resources/megameklab/resources/Menu.properties index 88a1e048d..6deae8127 100644 --- a/megameklab/resources/megameklab/resources/Menu.properties +++ b/megameklab/resources/megameklab/resources/Menu.properties @@ -113,4 +113,10 @@ MMLStartUp.NEW_FIGHTER=New Fighter MMLStartUp.NEW_DROPSHIP=New SmallCraft/DropShip MMLStartUp.NEW_JUMPSHIP=New Advanced Aerospace MMLStartUp.NEW_SUPPORTVEE=New Support Vehicle -MMLStartUp.NEW_PROTOMEK=New ProtoMek \ No newline at end of file +MMLStartUp.NEW_PROTOMEK=New ProtoMek + +# The following values are used programatically by ClanISMekNameOrdering +ClanISMekNameOrdering.CLAN_IS=Clan Name (IS Name) +ClanISMekNameOrdering.IS_CLAN=IS Name (Clan Name) +ClanISMekNameOrdering.CLAN_ONLY=Clan Name only +ClanISMekNameOrdering.IS_ONLY=IS Name only diff --git a/megameklab/src/megameklab/printing/MekChassisArrangement.java b/megameklab/src/megameklab/printing/MekChassisArrangement.java new file mode 100644 index 000000000..d1129d53e --- /dev/null +++ b/megameklab/src/megameklab/printing/MekChassisArrangement.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. + * + * This file is part of MegaMekLab. + * + * MegaMek is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MegaMek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MegaMek. If not, see . + */ +package megameklab.printing; + +import megamek.codeUtilities.StringUtility; +import megamek.common.Entity; + +import java.util.ResourceBundle; + +/** + * This class represents the different types of arrangement of the chassis names of those Meks that have a Clan + * and an IS name such as the Mad Cat a.k.a. Timber Wolf. This is used to determine how to print those names + * on record sheets (but not elsewhere as we might not want this to be dependent on how the record sheets + * might be at any moment). + * + * @author Simon (Juliez) + */ +public enum MekChassisArrangement { + + CLAN_IS, + IS_CLAN, + CLAN_ONLY, + IS_ONLY; + + private final ResourceBundle resources = ResourceBundle.getBundle("megameklab.resources.Menu"); + + /** @return A display name for this ClanIsMekNameArrangement taken from the resources (possibly localised). */ + public String getDisplayName() { + return resources.getString("ClanISMekNameOrdering." + name()); + } + + /** + * Parses the given String, returning the ClanIsMekNameArrangement fitting the String like the valueOf() method does, + * but returns CLAN_IS when it can't be parsed (instead of null). + * + * @param arrangementName A string giving one of the ClanIsMekNameArrangement values + * @return the MekChassisArrangement parsed from the string or CLAN_IS. Never returns null. + */ + public static MekChassisArrangement parse(String arrangementName) { + try { + return valueOf(arrangementName); + } catch (IllegalArgumentException e) { + return CLAN_IS; + } + } + + public String printChassis(Entity entity) { + if (StringUtility.isNullOrBlank(entity.getClanChassisName())) { + return entity.getChassis(); + } else if (this == IS_ONLY) { + return entity.getChassis(); + } else if (this == CLAN_ONLY) { + return entity.getClanChassisName(); + } else if (this == CLAN_IS) { + return entity.getClanChassisName() + " (" + entity.getChassis() + ")"; + } else { + return entity.getChassis() + " (" + entity.getClanChassisName() + ")"; + } + } +} \ No newline at end of file diff --git a/megameklab/src/megameklab/printing/PrintEntity.java b/megameklab/src/megameklab/printing/PrintEntity.java index 83d2faa43..53922fc0f 100644 --- a/megameklab/src/megameklab/printing/PrintEntity.java +++ b/megameklab/src/megameklab/printing/PrintEntity.java @@ -14,6 +14,7 @@ package megameklab.printing; import megamek.client.generator.RandomNameGenerator; +import megamek.codeUtilities.StringUtility; import megamek.common.*; import megamek.common.eras.Era; import megamek.common.eras.Eras; @@ -62,7 +63,7 @@ protected PrintEntity(int startPage, RecordSheetOptions options) { @Override public List getBookmarkNames() { - return Collections.singletonList(getEntity().getShortNameRaw()); + return Collections.singletonList(entityName()); } /** @@ -187,7 +188,7 @@ protected void processImage(int pageNum, PageFormat pageFormat) { protected void writeTextFields() { setTextField(TITLE, getRecordSheetTitle().toUpperCase()); - setTextField(TYPE, getEntity().getShortNameRaw()); + setTextField(TYPE, entityName()); setTextField(MP_WALK, formatWalk()); setTextField(MP_RUN, formatRun()); setTextField(MP_JUMP, formatJump()); @@ -596,5 +597,10 @@ protected String formatCost() { NumberFormat nf = NumberFormat.getNumberInstance(Locale.getDefault()); return nf.format(getEntity().getCost(true)) + " C-bills"; } - + + private String entityName() { + return CConfig.getMekNameArrangement().printChassis(getEntity()) + + (StringUtility.isNullOrBlank(getEntity().getModel()) ? "" : " " + getEntity().getModel()); + } + } diff --git a/megameklab/src/megameklab/ui/dialog/settings/ExportSettingsPanel.java b/megameklab/src/megameklab/ui/dialog/settings/ExportSettingsPanel.java index 7d62bda31..6b162d3a7 100644 --- a/megameklab/src/megameklab/ui/dialog/settings/ExportSettingsPanel.java +++ b/megameklab/src/megameklab/ui/dialog/settings/ExportSettingsPanel.java @@ -18,6 +18,8 @@ */ package megameklab.ui.dialog.settings; +import megamek.client.ui.baseComponents.MMComboBox; +import megameklab.printing.MekChassisArrangement; import megameklab.printing.PaperSize; import megameklab.ui.util.IntRangeTextField; import megameklab.ui.util.SpringUtilities; @@ -30,6 +32,7 @@ import java.awt.*; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.ResourceBundle; /** @@ -52,6 +55,8 @@ class ExportSettingsPanel extends JPanel { private final JCheckBox chkTacOpsHeat = new JCheckBox(); private final JComboBox cbRSScale = new JComboBox<>(); private final IntRangeTextField txtScale = new IntRangeTextField(3); + private final MMComboBox mekChassis = + new MMComboBox<>("Mek Names", MekChassisArrangement.values()); ExportSettingsPanel() { ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Dialogs"); @@ -129,6 +134,17 @@ class ExportSettingsPanel extends JPanel { chkTacOpsHeat.setToolTipText(resourceMap.getString("ConfigurationDialog.chkTacOpsHeat.tooltip")); chkTacOpsHeat.setSelected(CConfig.getBooleanParam(CConfig.RS_TAC_OPS_HEAT)); + mekChassis.setRenderer(mekNameArrangementRenderer); + mekChassis.setSelectedItem(CConfig.getMekNameArrangement()); + mekChassis.setToolTipText(resourceMap.getString("ConfigurationDialog.mekChassis.tooltip")); + JLabel startUpLabel = new JLabel(resourceMap.getString("ConfigurationDialog.mekChassis.text")); + startUpLabel.setToolTipText(resourceMap.getString("ConfigurationDialog.mekChassis.tooltip")); + + JPanel mekNameLine = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + mekNameLine.add(startUpLabel); + mekNameLine.add(Box.createHorizontalStrut(5)); + mekNameLine.add(mekChassis); + for (RSScale val : RSScale.values()) { cbRSScale.addItem(val.fullName); } @@ -161,8 +177,9 @@ class ExportSettingsPanel extends JPanel { gridPanel.add(chkShowRole); gridPanel.add(chkHeatProfile); gridPanel.add(chkTacOpsHeat); + gridPanel.add(mekNameLine); gridPanel.add(scalePanel); - SpringUtilities.makeCompactGrid(gridPanel, 13, 1, 0, 0, 15, 10); + SpringUtilities.makeCompactGrid(gridPanel, 14, 1, 0, 0, 15, 10); gridPanel.setBorder(new EmptyBorder(20, 30, 20, 30)); setLayout(new FlowLayout(FlowLayout.LEFT)); add(gridPanel); @@ -184,6 +201,8 @@ Map getRecordSheetSettings() { recordSheetSettings.put(CConfig.RS_TAC_OPS_HEAT, Boolean.toString(chkTacOpsHeat.isSelected())); recordSheetSettings.put(CConfig.RS_SCALE_UNITS, RSScale.values()[cbRSScale.getSelectedIndex()].toString()); recordSheetSettings.put(CConfig.RS_SCALE_FACTOR, Integer.toString(txtScale.getIntVal(getDefaultScale()))); + recordSheetSettings.put(CConfig.RS_MEK_NAMES, + Objects.requireNonNullElse(mekChassis.getSelectedItem(), MekChassisArrangement.CLAN_IS).name()); return recordSheetSettings; } @@ -201,4 +220,15 @@ private int getDefaultScale() { return 1; } } + + DefaultListCellRenderer mekNameArrangementRenderer = new DefaultListCellRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + return super.getListCellRendererComponent(list, displayName(value), index, isSelected, cellHasFocus); + } + }; + + private String displayName(Object value) { + return (value instanceof MekChassisArrangement) ? ((MekChassisArrangement) value).getDisplayName() : ""; + } } \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/dialog/settings/SettingsDialog.java b/megameklab/src/megameklab/ui/dialog/settings/SettingsDialog.java index cf25a3af9..9be6b5b57 100644 --- a/megameklab/src/megameklab/ui/dialog/settings/SettingsDialog.java +++ b/megameklab/src/megameklab/ui/dialog/settings/SettingsDialog.java @@ -45,10 +45,10 @@ public SettingsDialog(JFrame frame) { @Override protected Container createCenterPane() { JTabbedPane panMain = new JTabbedPane(); - panMain.addTab(resources.getString("ConfigurationDialog.misc.title"), miscSettingsPanel); - panMain.addTab(resources.getString("ConfigurationDialog.colorCodes.title"), colorPreferences); - panMain.addTab(resources.getString("ConfigurationDialog.techProgression.title"), techSettings); - panMain.addTab(resources.getString("ConfigurationDialog.printing.title"), exportSettingsPanel); + panMain.addTab(resources.getString("ConfigurationDialog.misc.title"), new SettingsScrollPane(miscSettingsPanel)); + panMain.addTab(resources.getString("ConfigurationDialog.colorCodes.title"), new SettingsScrollPane(colorPreferences)); + panMain.addTab(resources.getString("ConfigurationDialog.techProgression.title"), new SettingsScrollPane(techSettings)); + panMain.addTab(resources.getString("ConfigurationDialog.printing.title"), new SettingsScrollPane(exportSettingsPanel)); return panMain; } @@ -78,4 +78,12 @@ protected void okAction() { protected void cancelAction() { CConfig.loadConfigFile(); } -} + + private static class SettingsScrollPane extends JScrollPane { + SettingsScrollPane(Component view) { + super(view); + setBorder(null); + getVerticalScrollBar().setUnitIncrement(16); + } + } +} \ No newline at end of file diff --git a/megameklab/src/megameklab/util/CConfig.java b/megameklab/src/megameklab/util/CConfig.java index 51f41b70d..1d884480b 100644 --- a/megameklab/src/megameklab/util/CConfig.java +++ b/megameklab/src/megameklab/util/CConfig.java @@ -16,6 +16,7 @@ package megameklab.util; import megamek.common.Configuration; +import megameklab.printing.MekChassisArrangement; import megameklab.ui.MMLStartUp; import megameklab.ui.MegaMekLabMainUI; import megameklab.ui.MenuBarOwner; @@ -99,6 +100,7 @@ public final class CConfig { public static final String RS_CONDENSED_REFERENCE = "rs_condensed_reference"; public static final String RS_SCALE_FACTOR = "rs_scale_factor"; public static final String RS_SCALE_UNITS = "rs_scale_units"; + public static final String RS_MEK_NAMES = "rs_mek_names"; public static final String NAG_EQUIPMENT_CTRLCLICK = "nag_equipment_ctrlclick"; public static final String NAG_IMPORT_SETTINGS = "nag_import_settings"; @@ -127,6 +129,7 @@ private static Properties getDefaults() { defaults.setProperty(RS_SHOW_PILOT_DATA, Boolean.toString(true)); defaults.setProperty(RS_SCALE_FACTOR, "1"); defaults.setProperty(RS_SCALE_UNITS, RSScale.HEXES.toString()); + defaults.setProperty(RS_MEK_NAMES, MekChassisArrangement.IS_CLAN.name()); defaults.setProperty(NAG_EQUIPMENT_CTRLCLICK, Boolean.toString(true)); defaults.setProperty(MEK_AUTOFILL, Boolean.toString(true)); defaults.setProperty(MEK_AUTOSORT, Boolean.toString(true)); @@ -424,6 +427,10 @@ public static MMLStartUp getStartUpType() { return MMLStartUp.parse(CConfig.getParam(CConfig.MISC_STARTUP)); } + public static MekChassisArrangement getMekNameArrangement() { + return MekChassisArrangement.parse(CConfig.getParam(CConfig.RS_MEK_NAMES)); + } + public static void resetWindowPositions() { setParam(GUI_FULLSCREEN, Boolean.toString(false)); setParam(FILE_CHOOSER_WINDOW, "");