Skip to content

Commit

Permalink
Merge branch 'master' into armor_rework
Browse files Browse the repository at this point in the history
  • Loading branch information
neoancient committed Feb 2, 2024
2 parents 63f2f99 + a718c04 commit 9a22d3e
Show file tree
Hide file tree
Showing 22 changed files with 224 additions and 199 deletions.
1 change: 1 addition & 0 deletions megameklab/docs/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ MEGAMEKLAB VERSION HISTORY:
+ Fix #1405: Fixed a bug with resetting system crits that lead to what seemed conflicts between XLFE, NullSig, and CLPS
+ Fix #1192: Fixed a bug with internal weapon and equipment linkage that lead to laser insulators sometimes affecting multiple lasers
+ PR #1402: Rework of the internal representation of Armor
+ PR #1410: Adaptation to Mek Clan name separation in MM; Adds a clan chassis name field for Meks; for units such as the Mad Cat, the IS name and clan name can be reordered on record sheets

0.49.17 (2023-12-31 1900 UTC)
+ PR #1352 MML interface changes
Expand Down
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
2 changes: 2 additions & 0 deletions megameklab/resources/megameklab/resources/Views.properties
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
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() + ")";
}
}
}
8 changes: 1 addition & 7 deletions megameklab/src/megameklab/printing/PrintAero.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 1 addition & 9 deletions megameklab/src/megameklab/printing/PrintCapitalShip.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions megameklab/src/megameklab/printing/PrintDropship.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
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 @@ -61,7 +62,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 @@ -186,7 +187,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());
}

}
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/printing/PrintMech.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions megameklab/src/megameklab/printing/PrintSmallUnitSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions megameklab/src/megameklab/printing/PrintTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/ui/MegaMekLabMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/ui/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
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);
}
}
}
Loading

0 comments on commit 9a22d3e

Please sign in to comment.