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

Add RISC Heat Sink Override Kit #1643

Merged
merged 3 commits into from
Oct 27, 2024
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: 3 additions & 0 deletions megameklab/resources/megameklab/resources/Views.properties
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ HeatSinkView.lblCritFree.text=Engine Free:
HeatSinkView.lblCritFree.tooltip=<html>These heat sinks are an integral part of the engine and do not have to be assigned critical space.<br/>Omni units must assign critical space to any pod-mounted heat sinks even if they would be part of the engine in standard Meks.</html>
HeatSinkView.lblWeightFree.text=Weight Free:
HeatSinkView.lblWeightFree.tooltip=<html>These heat sinks are included in the weight of the engine.</html>
HeatSinkView.lblRiscHeatSinkKit.text=RISC Heat Sink Override Kit:
HeatSinkView.lblRiscHeatSinkKit.tooltip=<html>Reduces chance of heat-induced shutdown. IO:AE p86.<br/>\
Construction only, not implemented for gameplay in MegaMek.</html>

ArmorView.cbArmorType.text=Armor Type:
ArmorView.cbArmorType.tooltip=The type of armor determines the amount of protection per ton and the amount of space required. Some armors provide additional special abilities.
Expand Down
16 changes: 13 additions & 3 deletions megameklab/src/megameklab/printing/InventoryWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import megamek.common.equipment.MiscMounted;
import org.apache.batik.util.SVGConstants;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGRectElement;
Expand Down Expand Up @@ -260,6 +261,15 @@ private void parseEquipment() {
same.incrementQty();
}
}
if (sheet.getEntity() instanceof Mek mek && mek.hasRiscHeatSinkOverrideKit()) {
var mounted = new MiscMounted(sheet.getEntity(), new MiscType() {{
name = "RISC Heat Sink Override Kit";
shortName = "RISC HS Override Kit";
internalName = "RISC Heat Sink Override Kit";
}});
mounted.setLocation(Mek.LOC_NONE);
equipment.add(new StandardInventoryEntry(mounted));
}
}

private void parseBays() {
Expand Down Expand Up @@ -933,12 +943,12 @@ public double printBayInfo(float fontSize, double lineHeight, double currY) {
}
bayCapacityString.append(NumberFormat.getInstance().format(capacity));
if ((i + 1) < bays.size()) {
bayTypeString.append("/");
bayCapacityString.append("/");
bayTypeString.append('/');
bayCapacityString.append('/');
}
doors = Math.max(doors, b.getDoors());
}
bayCapacityString.append(")");
bayCapacityString.append(')');
String bayString = "Bay " + bayNum + ": " + bayTypeString
+ bayCapacityString + " (" + doors + (doors == 1 ? " Door)" : " Doors)");
sheet.addTextElement(canvas, bayColX[0], currY, bayString, fontSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ private boolean showTechBase() {
}

private String formatLocation() {
if (mount.getLocation() == Entity.LOC_NONE) {
return DASH;
}
if ((mount.getEntity() instanceof Tank)
&& mount.getLocation() == Tank.LOC_TURRET
&& !((Tank) mount.getEntity()).hasNoDualTurret()) {
Expand Down
41 changes: 38 additions & 3 deletions megameklab/src/megameklab/ui/generalUnit/HeatSinkView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import java.util.ResourceBundle;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

Expand Down Expand Up @@ -94,6 +92,9 @@ public void removeListener(BuildListener l) {
private final JLabel lblCritFreeCount = new JLabel();
private final JLabel lblWeightFreeText = new JLabel();
private final JLabel lblWeightFreeCount = new JLabel();
private final JLabel lblRiscHeatSinkKit = new JLabel();
private final JCheckBox chkRiscHeatSinkKit = new JCheckBox();


private final SpinnerNumberModel countModel = new SpinnerNumberModel(0, 0, null, 1);
private final SpinnerNumberModel baseCountModel = new SpinnerNumberModel(0, 0, null, 1);
Expand Down Expand Up @@ -142,6 +143,8 @@ private void initUI() {
add(spnCount, gbc);
spnCount.addChangeListener(this);

gbc.gridx = 2;
add(new JLabel("<html>&nbsp;</html>"), gbc);
gbc.gridx = 3;
lblCritFreeText.setText(resourceMap.getString("HeatSinkView.lblCritFree.text"));
add(lblCritFreeText, gbc);
Expand Down Expand Up @@ -177,12 +180,33 @@ private void initUI() {
lblWeightFreeCount.setToolTipText(resourceMap.getString("HeatSinkView.lblWeightFree.tooltip"));
add(lblWeightFreeCount, gbc);


lblRiscHeatSinkKit.setText(resourceMap.getString("HeatSinkView.lblRiscHeatSinkKit.text"));
lblRiscHeatSinkKit.setToolTipText(resourceMap.getString("HeatSinkView.lblRiscHeatSinkKit.tooltip"));
chkRiscHeatSinkKit.setToolTipText(resourceMap.getString("HeatSinkView.lblRiscHeatSinkKit.tooltip"));
lblRiscHeatSinkKit.setVisible(false);
chkRiscHeatSinkKit.setVisible(false);
gbc.gridx = 0;
gbc.gridy++;
add(lblRiscHeatSinkKit, gbc);
gbc.gridx = GridBagConstraints.RELATIVE;
add(chkRiscHeatSinkKit, gbc);
chkRiscHeatSinkKit.addActionListener(this);

}

private String getDisplayName(int index) {
return isAero ? aeroDisplayNames[index] : MekDisplayNames[index];
}

private void showRiscKit(boolean show) {
chkRiscHeatSinkKit.setVisible(show);
lblRiscHeatSinkKit.setVisible(show);
if (!show) {
chkRiscHeatSinkKit.setSelected(false);
}
}

public void setFromMek(Mek mek) {
isAero = false;
isPrimitive = mek.isPrimitive();
Expand Down Expand Up @@ -224,6 +248,11 @@ public void setFromMek(Mek mek) {
spnPrototypeCount.addChangeListener(this);
lblCritFreeCount.setText(String.valueOf(UnitUtil.getCriticalFreeHeatSinks(mek, isCompact)));
lblWeightFreeCount.setText(String.valueOf(mek.getEngine().getWeightFreeEngineHeatSinks()));

showRiscKit(techManager.isLegal(Mek.getRiscHeatSinkOverrideKitAdvancement()));
if (mek.hasRiscHeatSinkOverrideKit()) {
chkRiscHeatSinkKit.setSelected(true);
}
}

public void setFromAero(Aero aero) {
Expand Down Expand Up @@ -258,6 +287,8 @@ public void setFromAero(Aero aero) {
spnPrototypeCount.setVisible(false);
lblCritFreeText.setVisible(false);
lblCritFreeCount.setVisible(false);

showRiscKit(false);
}

public void refresh() {
Expand Down Expand Up @@ -287,6 +318,8 @@ public void refresh() {
if (cbHSType.getSelectedIndex() < 0) {
cbHSType.setSelectedIndex(0);
}

showRiscKit(techManager.isLegal(Mek.getRiscHeatSinkOverrideKitAdvancement()) && !isAero);
}

public int getHeatSinkIndex() {
Expand Down Expand Up @@ -333,6 +366,8 @@ public int getPrototypeCount() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == cbHSType) {
reportChange();
} else if (e.getSource() == chkRiscHeatSinkKit) {
listeners.forEach(l -> l.riscHeatSinkOverrideKitChanged(chkRiscHeatSinkKit.isSelected()));
}
}

Expand Down
17 changes: 12 additions & 5 deletions megameklab/src/megameklab/ui/listeners/BuildListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default void clanNameChanged(String clanName) {
* Notifies of a change of the manually entered BV. When manualBV is 0 or less,
* the unit
* should be set to not use a manual BV value and the manual BV set to -1.
*
*
* @param manualBV The entered manual BV; may be invalid (0 or less)
*/
void manualBVChanged(int manualBV);
Expand All @@ -75,7 +75,7 @@ default void clanNameChanged(String clanName) {

/**
* Notifies of a change in heat sink type or count for aerospace units
*
*
* @param index Either
* {@link megameklab.ui.generalUnit.HeatSinkView#TYPE_SINGLE} or
* {@link megameklab.ui.generalUnit.HeatSinkView#TYPE_DOUBLE_AERO}
Expand All @@ -86,7 +86,7 @@ default void heatSinksChanged(int index, int count) {

/**
* Notifies of a change in heat sink type or count for meks
*
*
* @param hsType The type of heat sink
* @param count The total number of heat sinks
*/
Expand All @@ -97,7 +97,7 @@ default void heatSinksChanged(EquipmentType hsType, int count) {
* Notifies of a change in the distribution between single and double heat sinks
* on a unit with
* prototype double heat sinks.
*
*
* @param prototype The number of prototype double heat sinks
*/
default void redistributePrototypeHS(int prototype) {
Expand All @@ -106,12 +106,19 @@ default void redistributePrototypeHS(int prototype) {
/**
* Notifies of a change in the number of heat sinks that are part of the base
* chassis of an omni unit
*
*
* @param count The number of fixed heat sinks
*/
default void heatSinkBaseCountChanged(int count) {
}

/**
* Notifies of a change in the presence of a RISC Heat Sink Override Kit
* @param hasKit True if the unit now has the kit
*/
default void riscHeatSinkOverrideKitChanged(boolean hasKit) {
}

// For aerospace units and support vehicles
default void fuelTonnageChanged(double tonnage) {
}
Expand Down
2 changes: 2 additions & 0 deletions megameklab/src/megameklab/ui/mek/BMChassisView.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ private void refreshFullHeadEject() {
chkFullHeadEject.addActionListener(this);
}



public List<Engine> getAvailableEngines() {
List<Engine> retVal = new ArrayList<>();
boolean isMixed = techManager.useMixedTech();
Expand Down
11 changes: 11 additions & 0 deletions megameklab/src/megameklab/ui/mek/BMStructureTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ public void updateTechLevel() {
} else {
refresh.refreshEquipmentTable();
}
if (!getTechManager().isLegal(Mek.getRiscHeatSinkOverrideKitAdvancement())) {
getMek().setRiscHeatSinkOverrideKit(false);
}
panChassis.refresh();
panHeat.refresh();
panArmor.refresh();
Expand Down Expand Up @@ -978,6 +981,14 @@ public void heatSinkBaseCountChanged(int count) {
refresh.refreshPreview();
}

@Override
public void riscHeatSinkOverrideKitChanged(boolean hasKit) {
getMek().setRiscHeatSinkOverrideKit(hasKit);
refresh.refreshBuild();
refresh.refreshStatus();
refresh.refreshPreview();
}

@Override
public void redistributePrototypeHS(int prototype) {
int netChange = prototype - getMek().countWorkingMisc(MiscType.F_IS_DOUBLE_HEAT_SINK_PROTOTYPE);
Expand Down