Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to show total heat and dissipation on record sheet #634

Merged
merged 4 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion resources/megameklab/resources/Dialogs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ ConfigurationDialog.chkShowEraIcon.text=Era Icon
ConfigurationDialog.chkShowEraIcon.tooltip=Shows the icon associated with the era the unit was constructed.
ConfigurationDialog.chkShowRole.text=Unit Role
ConfigurationDialog.chkShowRole.tooltip=Shows the unit's primary role.
ConfigurationDialog.lblFeatureLimitation.text=<html><i>These options are only fully supported on Mek sheets currently.</i></html>
ConfigurationDialog.chkHeatProfile.text=Heat Profile
ConfigurationDialog.chkHeatProfile.tooltip=Show total weapon heat and dissipation in the inventory panel for units that track heat.
ConfigurationDialog.chkSummaryFormatTRO.text=Use TRO format for summary
ConfigurationDialog.chkSummaryFormatTRO.tooltip=Whether to format the export text as a technical readout or as a traditional MegaMek unit summary.

7 changes: 7 additions & 0 deletions src/megameklab/com/printing/InventoryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ public void writeEquipment() {
if (sheet.getEntity() instanceof SmallCraft && !transportBays.isEmpty()) {
printBayInfo(metrics[0], metrics[1], ypos);
}
if (sheet.showHeatProfile()) {
sheet.addTextElement(canvas, viewX + viewWidth * 0.025, ypos, sheet.heatProfileText(),
FONT_SIZE_MEDIUM, SVGConstants.SVG_START_VALUE, SVGConstants.SVG_NORMAL_VALUE);
}
writeFooterBlock(metrics[0], metrics[1]);
}

Expand Down Expand Up @@ -567,6 +571,9 @@ private int calcLineCount(float fontSize) {
lines += transportBays.size() + 1; // add extra for header
}
lines += footerLines(fontSize);
if (sheet.showHeatProfile()) {
lines++;
}
return lines;
}

Expand Down
15 changes: 15 additions & 0 deletions src/megameklab/com/printing/PrintEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ protected boolean showPilotInfo() {
return options.showPilotData() && !getEntity().getCrew().getName().equalsIgnoreCase("unnamed");
}

/**
* @return Whether the total weapon heat and dissipation should be shown on the record sheet
*/
protected boolean showHeatProfile() {
return getEntity().tracksHeat() && options.showHeatProfile();
}

/**
* @return A String showing the total weapon heat and dissipation.
*/
protected String heatProfileText() {
int heat = getEntity().getEquipment().stream().mapToInt(m -> m.getType().getHeat()).sum();
return "Total Heat (Dissipation): " + heat + " (" + getEntity().getHeatCapacity() + ")";
}

/**
* Space for misc equipment such as cargo space and SV chassis mods.
*
Expand Down
13 changes: 13 additions & 0 deletions src/megameklab/com/printing/RecordSheetOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ public class RecordSheetOptions {
private boolean pilotData;
private boolean eraIcon;
private boolean role;
private boolean heatProfile;

public RecordSheetOptions() {
this.quirks = CConfig.getBooleanParam(CConfig.RS_SHOW_QUIRKS);
this.pilotData = CConfig.getBooleanParam(CConfig.RS_SHOW_PILOT_DATA);
this.eraIcon = CConfig.getBooleanParam(CConfig.RS_SHOW_ERA);
this.role = CConfig.getBooleanParam(CConfig.RS_SHOW_ROLE);
this.heatProfile = CConfig.getBooleanParam(CConfig.RS_HEAT_PROFILE);
}

public boolean showQuirks() {
Expand All @@ -47,6 +49,9 @@ public boolean showPilotData() {
public boolean showRole() {
return role;
}
public boolean showHeatProfile() {
return heatProfile;
}

public void setPilotData(boolean pilotData) {
this.pilotData = pilotData;
Expand All @@ -60,4 +65,12 @@ public void setEraIcon(boolean eraIcon) {
this.eraIcon = eraIcon;
}

public void setRole(boolean role) {
this.role = role;
}

public void setHeatProfile(boolean heatProfile) {
this.heatProfile = heatProfile;
}

}
28 changes: 7 additions & 21 deletions src/megameklab/com/util/CConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class CConfig {
public static final String RS_SHOW_PILOT_DATA = "rs_show_pilot_data";
public static final String RS_SHOW_ERA = "rs_show_era";
public static final String RS_SHOW_ROLE = "rs_show_role";
public static final String RS_HEAT_PROFILE = "rs_heat_profile";

private static Properties config;// config. player values.

Expand Down Expand Up @@ -112,7 +113,7 @@ private Properties setDefaults() {
defaults.setProperty("WINDOWLEFT", "0");
defaults.setProperty("WINDOWTOP", "0");
defaults.setProperty(CONFIG_SAVE_LOC,
new File(System.getProperty("user.dir").toString()
new File(System.getProperty("user.dir")
+ "/data/mechfiles/").getAbsolutePath());
defaults.setProperty(SUMMARY_FORMAT_TRO, Boolean.toString(true));
defaults.setProperty(RS_SHOW_QUIRKS, Boolean.toString(true));
Expand Down Expand Up @@ -183,12 +184,10 @@ public void createConfig() {
* @return The value associated with the key
*/
public static String getParam(String param, String defaultVal) {
String tparam = null;

if (param.endsWith(":")) {
param = param.substring(0, param.lastIndexOf(":"));
}
tparam = config.getProperty(param);
String tparam = config.getProperty(param);
if (tparam == null) {
tparam = defaultVal;
}
Expand All @@ -212,17 +211,6 @@ public static void setParam(String param, String value) {
config.setProperty(param, value);
}

/**
* See if a paramater is enabled (YES, TRUE or ON).
*/
public static boolean isParam(String param) {
String tparam = CConfig.getParam(param);
if (tparam.equalsIgnoreCase("YES") || tparam.equalsIgnoreCase("TRUE") || tparam.equalsIgnoreCase("ON")) {
return true;
}
return false;
}

/**
* Return the int value of a given config property. Return a 0 if the
* property is a non-number. Used mostly by the misc. mail tab checks.
Expand Down Expand Up @@ -263,7 +251,7 @@ public static void saveConfig() {
config.store(ps, "Client Config Backup");
fos.close();
ps.close();
} catch (FileNotFoundException fnfe) {
} catch (FileNotFoundException ignored) {

} catch (Exception ex) {
ex.printStackTrace();
Expand All @@ -275,7 +263,7 @@ public static void saveConfig() {
config.store(ps, "Client Config");
fos.close();
ps.close();
} catch (FileNotFoundException fnfe) {
} catch (FileNotFoundException ignored) {

} catch (Exception ex) {
ex.printStackTrace();
Expand All @@ -284,11 +272,9 @@ public static void saveConfig() {

public static Color getForegroundColor(String fieldName) {
Color masterColor = Color.black;

try {
masterColor = Color.getColor("", Integer.parseInt(CConfig.getParam(fieldName + CConfig.CONFIG_FOREGROUND)));
} catch (Exception ex) {

} catch (Exception ignored) {
}
return masterColor;
}
Expand All @@ -298,7 +284,7 @@ public static Color getBackgroundColor(String fieldName) {

try {
masterColor = Color.getColor("", Integer.parseInt(CConfig.getParam(fieldName + CConfig.CONFIG_BACKGROUND)));
} catch (Exception ex) {
} catch (Exception ignored) {

}
return masterColor;
Expand Down
53 changes: 24 additions & 29 deletions src/megameklab/com/util/ConfigurationDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,11 @@

public final class ConfigurationDialog extends JDialog implements ActionListener {

/**
*
*/
private static final long serialVersionUID = -6504846822457360057L;

private final static String saveCommand = "Save"; //$NON-NLS-1$
private final static String cancelCommand = "Cancel"; //$NON-NLS-1$

// BUTTONS
private final JButton btnSave = new JButton(saveCommand);
private final JButton btnCancel = new JButton(cancelCommand);
private JButton baseButton;

private final JTabbedPane panMain = new JTabbedPane();
private final JPanel panColors = new JPanel(new SpringLayout());
private final JPanel panTech = new JPanel(new GridBagLayout());
private final JPanel panPrinting = new JPanel(new GridBagLayout());
Expand All @@ -74,8 +65,8 @@ public final class ConfigurationDialog extends JDialog implements ActionListener
private final JCheckBox chkShowPilotData = new JCheckBox();
private final JCheckBox chkShowEraIcon = new JCheckBox();
private final JCheckBox chkShowRole = new JCheckBox();
private final JLabel lblFeatureLimitation = new JLabel();
private final JCheckBox chkHeatProfile = new JCheckBox();

private final JCheckBox chkSummaryFormatTRO = new JCheckBox();

//Store changes in the color configuration to write only if the user clicks save
Expand All @@ -88,19 +79,23 @@ public ConfigurationDialog(JFrame frame) {
setTitle(resourceMap.getString("ConfigurationDialog.windowName.text")); //$NON-NLS-1$

getContentPane().setLayout(new BorderLayout());
JTabbedPane panMain = new JTabbedPane();
add(panMain, BorderLayout.CENTER);
JPanel panButtons = new JPanel();
btnSave.setText(resourceMap.getString("ConfigurationDialog.btnSave.text")); //$NON-NLS-1$
btnSave.setToolTipText(resourceMap.getString("ConfigurationDialog.btnSave.tooltip")); //$NON-NLS-1$
btnSave.setActionCommand(saveCommand);
btnSave.addActionListener(this);
panButtons.add(btnSave);
// BUTTONS
JButton button = new JButton(saveCommand);
button.setText(resourceMap.getString("ConfigurationDialog.btnSave.text")); //$NON-NLS-1$
button.setToolTipText(resourceMap.getString("ConfigurationDialog.btnSave.tooltip")); //$NON-NLS-1$
button.setActionCommand(saveCommand);
button.addActionListener(this);
panButtons.add(button);

btnCancel.setText(resourceMap.getString("ConfigurationDialog.btnCancel.text")); //$NON-NLS-1$
btnCancel.setToolTipText(resourceMap.getString("ConfigurationDialog.btnCancel.tooltip")); //$NON-NLS-1$
btnCancel.setActionCommand(cancelCommand);
btnCancel.addActionListener(this);
panButtons.add(btnCancel);
button = new JButton(cancelCommand);
button.setText(resourceMap.getString("ConfigurationDialog.btnCancel.text")); //$NON-NLS-1$
button.setToolTipText(resourceMap.getString("ConfigurationDialog.btnCancel.tooltip")); //$NON-NLS-1$
button.setActionCommand(cancelCommand);
button.addActionListener(this);
panButtons.add(button);
add(panButtons, BorderLayout.SOUTH);

panMain.addTab(resourceMap.getString("ConfigurationDialog.colorCodes.title"), panColors); //$NON-NLS-1$
Expand Down Expand Up @@ -133,7 +128,7 @@ private void addFields(String fieldName) {
baseLabel.setForeground(CConfig.getForegroundColor(fieldName));

panColors.add(baseLabel);
baseButton = new JButton("Foreground");
JButton baseButton = new JButton("Foreground");
baseButton.setName(fieldName + CConfig.CONFIG_FOREGROUND);
baseButton.addActionListener(this);
panColors.add(baseButton);
Expand All @@ -160,9 +155,7 @@ private void loadTechPanel(ResourceBundle resourceMap) {

gbc.gridy++;
gbc.gridwidth = 1;
chkTechUseYear.addActionListener(e -> {
txtTechYear.setEnabled(chkTechUseYear.isSelected());
});
chkTechUseYear.addActionListener(e -> txtTechYear.setEnabled(chkTechUseYear.isSelected()));
chkTechUseYear.setText(resourceMap.getString("ConfigurationDialog.chkTechYear.text")); //$NON-NLS-1$
chkTechUseYear.setToolTipText(resourceMap.getString("ConfigurationDialog.chkTechYear.tooltip")); //$NON-NLS-1$
chkTechUseYear.setSelected(CConfig.getBooleanParam(CConfig.TECH_USE_YEAR));
Expand Down Expand Up @@ -247,9 +240,10 @@ private void loadPrintingPanel(ResourceBundle resourceMap) {
panPrinting.add(chkShowRole, gbc);
gbc.gridy++;

// Inform user that these options are not yet limited for all units
lblFeatureLimitation.setText(resourceMap.getString("ConfigurationDialog.lblFeatureLimitation.text"));
panPrinting.add(lblFeatureLimitation, gbc);
chkHeatProfile.setText(resourceMap.getString("ConfigurationDialog.chkHeatProfile.text"));
chkHeatProfile.setToolTipText(resourceMap.getString("ConfigurationDialog.chkHeatProfile.tooltip"));
chkHeatProfile.setSelected(CConfig.getBooleanParam(CConfig.RS_HEAT_PROFILE));
panPrinting.add(chkHeatProfile, gbc);
}

private void loadExportPanel(ResourceBundle resourceMap) {
Expand Down Expand Up @@ -306,7 +300,7 @@ public void actionPerformed(ActionEvent e) {
}

private void saveConfig() {
colorMap.forEach((k,v) -> CConfig.setParam(k, v));
colorMap.forEach(CConfig::setParam);
CConfig.setParam(CConfig.TECH_PROGRESSION, String.valueOf(chkTechProgression.isSelected()));
CConfig.setParam(CConfig.TECH_USE_YEAR, String.valueOf(chkTechUseYear.isSelected()));
CConfig.setParam(CConfig.TECH_YEAR, String.valueOf(txtTechYear.getIntVal()));
Expand All @@ -319,6 +313,7 @@ private void saveConfig() {
CConfig.setParam(CConfig.RS_SHOW_PILOT_DATA, Boolean.toString(chkShowPilotData.isSelected()));
CConfig.setParam(CConfig.RS_SHOW_ERA, Boolean.toString(chkShowEraIcon.isSelected()));
CConfig.setParam(CConfig.RS_SHOW_ROLE, Boolean.toString(chkShowRole.isSelected()));
CConfig.setParam(CConfig.RS_HEAT_PROFILE, Boolean.toString(chkHeatProfile.isSelected()));
CConfig.setParam(CConfig.SUMMARY_FORMAT_TRO, Boolean.toString(chkSummaryFormatTRO.isSelected()));
CConfig.saveConfig();
}
Expand Down