Skip to content

Commit

Permalink
Add record sheet setting for mek Clan/IS naming
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Jan 31, 2024
1 parent 8f65962 commit b228b8d
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 10 deletions.
2 changes: 2 additions & 0 deletions megameklab/resources/megameklab/resources/Dialogs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion megameklab/resources/megameklab/resources/Menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
76 changes: 76 additions & 0 deletions megameklab/src/megameklab/printing/MekChassisArrangement.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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() + ")";
}
}
}
12 changes: 9 additions & 3 deletions megameklab/src/megameklab/printing/PrintEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,7 +63,7 @@ protected PrintEntity(int startPage, RecordSheetOptions options) {

@Override
public List<String> getBookmarkNames() {
return Collections.singletonList(getEntity().getShortNameRaw());
return Collections.singletonList(entityName());
}

/**
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +32,7 @@
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;

/**
Expand All @@ -52,6 +55,8 @@ class ExportSettingsPanel extends JPanel {
private final JCheckBox chkTacOpsHeat = new JCheckBox();
private final JComboBox<String> cbRSScale = new JComboBox<>();
private final IntRangeTextField txtScale = new IntRangeTextField(3);
private final MMComboBox<MekChassisArrangement> mekChassis =
new MMComboBox<>("Mek Names", MekChassisArrangement.values());

ExportSettingsPanel() {
ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Dialogs");
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -184,6 +201,8 @@ Map<String, String> 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;
}

Expand All @@ -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() : "";
}
}
18 changes: 13 additions & 5 deletions megameklab/src/megameklab/ui/dialog/settings/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
}
7 changes: 7 additions & 0 deletions megameklab/src/megameklab/util/CConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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, "");
Expand Down

0 comments on commit b228b8d

Please sign in to comment.