From b228b8df976a3f82209b86f981500af0530df004 Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 31 Jan 2024 14:21:52 +0100 Subject: [PATCH] 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, "");