diff --git a/megameklab/src/megameklab/ui/MegaMekLabMainUI.java b/megameklab/src/megameklab/ui/MegaMekLabMainUI.java index c71d6ecb3..95f960aaf 100644 --- a/megameklab/src/megameklab/ui/MegaMekLabMainUI.java +++ b/megameklab/src/megameklab/ui/MegaMekLabMainUI.java @@ -184,4 +184,6 @@ private void performRefresh() { refreshAll(); } } + + public abstract JDialog getFloatingEquipmentDatabase(); } \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/battleArmor/BAStatusBar.java b/megameklab/src/megameklab/ui/battleArmor/BAStatusBar.java index 317a9dc64..5b3a5e059 100644 --- a/megameklab/src/megameklab/ui/battleArmor/BAStatusBar.java +++ b/megameklab/src/megameklab/ui/battleArmor/BAStatusBar.java @@ -16,153 +16,51 @@ package megameklab.ui.battleArmor; -import megamek.client.ui.WrapLayout; import megamek.common.BattleArmor; -import megamek.common.verifier.EntityVerifier; import megamek.common.verifier.TestBattleArmor; -import megameklab.ui.util.ITab; -import megameklab.ui.util.RefreshListener; -import megameklab.util.ImageHelper; +import megameklab.ui.generalUnit.StatusBar; import megameklab.util.UnitUtil; import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; -public class BAStatusBar extends ITab { +public class BAStatusBar extends StatusBar { + + private static final String MOVE_LABEL = "Movement: %d / %d"; + private static final String WEIGHT_LABEL_SUIT = "Suit Weight: %,.0f kg/%,.0f kg"; + private static final String REMAINDER = " (%,.0f kg Remaining)"; - private final JPanel tonnagePanel = new JPanel(); - private final JPanel movementPanel = new JPanel(); - private final JPanel bvPanel = new JPanel(); - private final JLabel move = new JLabel(); - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final EntityVerifier entityVerifier = EntityVerifier.getInstance(new File( - "data/mechfiles/UnitVerifierOptions.xml")); - private final DecimalFormat formatter; - private final JFrame parentFrame; + private final JLabel suitWeight = new JLabel(); - private RefreshListener refresh; public BAStatusBar(final BAMainUI parent) { super(parent); - parentFrame = parent; - formatter = new DecimalFormat(); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(evt -> UnitUtil.showValidation(getBattleArmor(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(evt -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(movementPanel()); - add(bvPanel()); - add(tonnagePanel()); - add(invalid); - add(cost); - refresh(); - } - - public JPanel movementPanel() { - final int walk = getBattleArmor().getOriginalWalkMP(); - final int jump = getBattleArmor().getOriginalJumpMP(); - - move.setText("Movement: " + walk + "/" + jump); - movementPanel.add(move); - return movementPanel; + add(move); + add(suitWeight); } - public JPanel bvPanel() { - final int bv = getBattleArmor().calculateBattleValue(); - bvLabel.setText("BV: " + bv); - bvPanel.add(bvLabel); - - return bvPanel; + @Override + protected void additionalRefresh() { + refreshMovement(); + refreshSuitWeight(); } - public JPanel tonnagePanel() { - tonnagePanel.add(tons); - - return tonnagePanel; + public void refreshMovement() { + int walk = getBattleArmor().getOriginalWalkMP(); + int jump = getBattleArmor().getOriginalJumpMP(); + move.setText(String.format(MOVE_LABEL, walk, jump)); } - public void refresh() { - - final int walk = getBattleArmor().getOriginalWalkMP(); - final int jump = getBattleArmor().getOriginalJumpMP(); + private void refreshSuitWeight() { final double maxKilos = getBattleArmor().getTrooperWeight() * 1000; - double currentKilos; - final int bv = getBattleArmor().calculateBattleValue(); - - TestBattleArmor testBA = new TestBattleArmor(getBattleArmor(), entityVerifier.baOption, - null); - currentKilos = testBA.calculateWeight(BattleArmor.LOC_SQUAD); + double currentKilos = ((TestBattleArmor) getTestEntity()).calculateWeight(BattleArmor.LOC_SQUAD); currentKilos += UnitUtil.getUnallocatedAmmoTonnage(getBattleArmor()); currentKilos *= 1000; - - tons.setText(String.format("Suit Weight: %,.0f/%,.0f (%,.0f Remaining)", currentKilos, maxKilos, maxKilos - currentKilos)); - tons.setToolTipText("This represents the weight of all squad-level " + - "equipment, it does not count individual equipment"); - if (currentKilos > maxKilos) { - tons.setForeground(Color.red); - } else { - tons.setForeground(UIManager.getColor("Label.foreground")); - } - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - move.setText("Movement: " + walk + "/" + jump); - move.setToolTipText("Walk/Jump MP"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testBA.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); - } - - private void getFluffImage() { - // copied from structureTab - final FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", - FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() - + File.separatorChar + ImageHelper.imageMech - + File.separatorChar); - fDialog.setLocationRelativeTo(this); - - fDialog.setVisible(true); - - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() - + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." - + File.separatorChar - + relativeFilePath - .substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getBattleArmor().getFluff().setMMLImagePath(relativeFilePath); + String remaining = ""; + if (maxKilos - currentKilos > 0) { + remaining = String.format(REMAINDER, maxKilos - currentKilos); } - refresh.refreshPreview(); - } - - private JFrame getParentFrame() { - return parentFrame; - } - - public void addRefreshedListener(final RefreshListener l) { - refresh = l; + suitWeight.setText(String.format(WEIGHT_LABEL_SUIT, currentKilos, maxKilos) + remaining); + suitWeight.setToolTipText("This represents the weight of all squad-level " + + "equipment, it does not count individual equipment"); } - } \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/combatVehicle/CVMainUI.java b/megameklab/src/megameklab/ui/combatVehicle/CVMainUI.java index 7ebef8b41..777263be1 100644 --- a/megameklab/src/megameklab/ui/combatVehicle/CVMainUI.java +++ b/megameklab/src/megameklab/ui/combatVehicle/CVMainUI.java @@ -63,7 +63,7 @@ public void reloadTabs() { equipmentTab.addRefreshedListener(this); buildTab.addRefreshedListener(this); fluffTab.setRefreshedListener(this); - statusbar.setRefreshListener(this); + statusbar.addRefreshedListener(this); previewTab = new PreviewTab(this); diff --git a/megameklab/src/megameklab/ui/combatVehicle/CVStatusBar.java b/megameklab/src/megameklab/ui/combatVehicle/CVStatusBar.java index c3987a608..cc2b2b3fc 100644 --- a/megameklab/src/megameklab/ui/combatVehicle/CVStatusBar.java +++ b/megameklab/src/megameklab/ui/combatVehicle/CVStatusBar.java @@ -15,173 +15,46 @@ */ package megameklab.ui.combatVehicle; +import megamek.client.ui.swing.GUIPreferences; import megamek.common.Tank; -import megamek.common.verifier.EntityVerifier; -import megamek.common.verifier.TestTank; -import megameklab.ui.util.ITab; -import megameklab.ui.util.RefreshListener; -import megamek.client.ui.WrapLayout; -import megameklab.util.ImageHelper; -import megameklab.util.UnitUtil; +import megameklab.ui.generalUnit.StatusBar; import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; /** * The Status Bar for Combat Vehicles */ -public class CVStatusBar extends ITab { +public class CVStatusBar extends StatusBar { + + private static final String MOVE_LABEL = "Movement: %d / %d / %d"; + private static final String SLOTS_LABEL = "Free Slots: %d / %d"; - private final JPanel slotsPanel = new JPanel(); private final JLabel move = new JLabel(); - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); private final JLabel slots = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final EntityVerifier entityVerifier = EntityVerifier.getInstance(new File( - "data/mechfiles/UnitVerifierOptions.xml")); - private TestTank testEntity; - private final DecimalFormat formatter; - private final JFrame parentFrame; - - private RefreshListener refresh; public CVStatusBar(CVMainUI parent) { super(parent); - parentFrame = parent; - - formatter = new DecimalFormat(); - testEntity = new TestTank((Tank) parent.getEntity(), entityVerifier.tankOption, - null); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(evt -> UnitUtil.showValidation(getTank(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(evt -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(tons); - add(movementLabel()); - add(bvLabel()); - add(bvLabel); - add(tonnageLabel()); - add(slotsPanel()); - add(invalid); - add(cost); - refresh(); + add(move); + add(slots); } - public void setRefreshListener(RefreshListener refresh) { - this.refresh = refresh; + @Override + protected void additionalRefresh() { + refreshMovement(); + refreshSlots(); } - public JLabel movementLabel() { + public void refreshMovement() { int walk = getTank().getOriginalWalkMP(); int run = getTank().getOriginalRunMP(); int jump = getTank().getOriginalJumpMP(); - - move.setText("Movement: " + walk + "/" + run + "/" + jump); - return move; - } - - public JLabel bvLabel() { - int bv = getTank().calculateBattleValue(); - bvLabel.setText("BV: " + bv); - - return bvLabel; + move.setText(String.format(MOVE_LABEL, walk, run, jump)); } - public JLabel tonnageLabel() { - double tonnage = getTank().getWeight(); - double currentTonnage; - - currentTonnage = testEntity.calculateWeight(); - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getTank()); - - tons.setText("Tonnage: " + currentTonnage + "/" + tonnage); - return tons; - } - - public JPanel slotsPanel() { + public void refreshSlots() { Tank tank = getTank(); int currentSlots = tank.getTotalSlots() - tank.getFreeSlots(); - slots.setText("Slots: "+currentSlots+"/"+tank.getTotalSlots()); - slotsPanel.add(slots); - return slotsPanel; - } - - public void refresh() { - int walk = getTank().getOriginalWalkMP(); - int run = getTank().getRunMP(); - int jump = getTank().getOriginalJumpMP(); - double tonnage = getTank().getWeight(); - double currentTonnage; - int bv = getTank().calculateBattleValue(); - - testEntity = new TestTank(getTank(), entityVerifier.tankOption, - null); - - currentTonnage = testEntity.calculateWeight(); - - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getTank()); - - tons.setText(String.format("Tonnage: %.1f/%.1f (%.1f Remaining)", currentTonnage, tonnage, tonnage - currentTonnage)); - tons.setToolTipText("Current Tonnage/Max Tonnage"); - if (currentTonnage > tonnage) { - tons.setForeground(Color.red); - } else { - tons.setForeground(UIManager.getColor("Label.foreground")); - } - Tank tank = getTank(); - int currentSlots = tank.getTotalSlots() - tank.getFreeSlots(); - slots.setText("Slots: "+currentSlots+"/"+tank.getTotalSlots()); - if (currentSlots > tank.getTotalSlots()) { - slots.setForeground(Color.red); - } else { - slots.setForeground(UIManager.getColor("Label.foreground")); - } - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - move.setText("Movement: " + walk + "/" + run + "/" + jump); - move.setToolTipText("Walk/Run/Jump MP"); - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testEntity.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); - } - - private void getFluffImage() { - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); - fDialog.setLocationRelativeTo(this); - fDialog.setVisible(true); - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." + File.separatorChar + relativeFilePath - .substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getTank().getFluff().setMMLImagePath(relativeFilePath); - } - if (refresh != null) { - refresh.refreshPreview(); - } - } - - private JFrame getParentFrame() { - return parentFrame; + slots.setText(String.format(SLOTS_LABEL, currentSlots, tank.getTotalSlots())); + slots.setForeground(currentSlots > tank.getTotalSlots() ? GUIPreferences.getInstance().getWarningColor() : null); } } \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/fighterAero/ASStatusBar.java b/megameklab/src/megameklab/ui/fighterAero/ASStatusBar.java index 477603a23..696a634fb 100644 --- a/megameklab/src/megameklab/ui/fighterAero/ASStatusBar.java +++ b/megameklab/src/megameklab/ui/fighterAero/ASStatusBar.java @@ -15,178 +15,31 @@ */ package megameklab.ui.fighterAero; -import megamek.client.ui.WrapLayout; -import megamek.common.AmmoType; -import megamek.common.Entity; -import megamek.common.Mounted; -import megamek.common.WeaponType; -import megamek.common.verifier.EntityVerifier; -import megamek.common.verifier.TestAero; -import megameklab.ui.util.ITab; -import megameklab.ui.util.RefreshListener; -import megameklab.util.ImageHelper; -import megameklab.util.UnitUtil; +import megameklab.ui.generalUnit.StatusBar; import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; -public class ASStatusBar extends ITab { +public class ASStatusBar extends StatusBar { - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); - private final JLabel heatSink = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final EntityVerifier entityVerifier = EntityVerifier.getInstance(new File( - "data/mechfiles/UnitVerifierOptions.xml")); - private final DecimalFormat formatter; - private final JFrame parentFrame; + private static final String HEAT_LABEL = "Heat: %d / %d"; - private RefreshListener refresh; + private final JLabel heat = new JLabel(); public ASStatusBar(ASMainUI parent) { super(parent); - parentFrame = parent; - - formatter = new DecimalFormat(); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(evt -> UnitUtil.showValidation(getAero(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(evt -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(tons); - add(heatSink); - add(bvLabel); - add(invalid); - add(cost); - refresh(); + add(heat); } - public void refresh() { - int heat = getAero().getHeatCapacity(); - double tonnage = getAero().getWeight(); - double currentTonnage; - int bv = getAero().calculateBattleValue(); - - TestAero testAero = new TestAero(getAero(), entityVerifier.aeroOption, null); - - currentTonnage = testAero.calculateWeight(); - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getAero()); - - double totalHeat = calculateTotalHeat(); - - heatSink.setText("Heat: " + totalHeat + "/" + heat); - heatSink.setToolTipText("Total Heat Generated/Total Heat Dissipated"); - if (totalHeat > heat) { - heatSink.setForeground(Color.red); - } else { - heatSink.setForeground(UIManager.getColor("Label.foreground")); - } - heatSink.setVisible(getAero().getEntityType() == Entity.ETYPE_AERO); - - tons.setText(String.format("Tonnage: %.1f/%.1f (%.1f Remaining)", currentTonnage, tonnage, tonnage - currentTonnage)); - tons.setToolTipText("Current Tonnage/Max Tonnage"); - if (currentTonnage > tonnage) { - tons.setForeground(Color.red); - } else { - tons.setForeground(UIManager.getColor("Label.foreground")); - } - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testAero.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); + @Override + protected void additionalRefresh() { + refreshHeat(); } - public double calculateTotalHeat() { - double heat = 0; - - for (Mounted mounted : getAero().getWeaponList()) { - WeaponType wtype = (WeaponType) mounted.getType(); - double weaponHeat = wtype.getHeat(); - - // only count non-damaged equipment - if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() - || mounted.isBreached()) { - continue; - } - - // one shot weapons count 1/4 - if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) - || wtype.hasFlag(WeaponType.F_ONESHOT)) { - weaponHeat *= 0.25; - } - - // double heat for ultras - if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) - || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) { - weaponHeat *= 2; - } - - // Six times heat for RAC - if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) { - weaponHeat *= 6; - } - - // half heat for streaks - if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) - || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) { - weaponHeat *= 0.5; - } - heat += weaponHeat; - } - if (getAero().hasStealth()) { - heat += 10; - } - for (Mounted m : getAero().getMisc()) { - heat += m.getType().getHeat(); - } - return heat; - } - - private void getFluffImage() { - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", - FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() - + File.separatorChar + ImageHelper.imageMech - + File.separatorChar); - fDialog.setLocationRelativeTo(this); - fDialog.setVisible(true); - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() - + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." - + File.separatorChar - + relativeFilePath - .substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getAero().getFluff().setMMLImagePath(relativeFilePath); - } - refresh.refreshPreview(); + public void refreshHeat() { + int heatCapacity = getAero().getHeatCapacity(); + long totalHeat = estimatedHeatGeneration(); + heat.setText(String.format(HEAT_LABEL, totalHeat, heatCapacity)); + heat.setToolTipText("Estimated Total Heat Generated / Total Heat Dissipated"); + heat.setVisible(getEntity().tracksHeat()); } - - private JFrame getParentFrame() { - return parentFrame; - } - - public void addRefreshedListener(RefreshListener l) { - refresh = l; - } - } \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/generalUnit/StatusBar.java b/megameklab/src/megameklab/ui/generalUnit/StatusBar.java new file mode 100644 index 000000000..a721f4b2b --- /dev/null +++ b/megameklab/src/megameklab/ui/generalUnit/StatusBar.java @@ -0,0 +1,242 @@ +/* + * Copyright (c) 2023 - 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.ui.generalUnit; + +import megamek.client.ui.WrapLayout; +import megamek.client.ui.swing.GUIPreferences; +import megamek.client.ui.swing.calculationReport.CalculationReport; +import megamek.common.*; +import megamek.common.verifier.EntityVerifier; +import megamek.common.verifier.TestEntity; +import megameklab.ui.MegaMekLabMainUI; +import megameklab.ui.util.ITab; +import megameklab.ui.util.RefreshListener; +import megameklab.util.ImageHelper; +import megameklab.util.UnitUtil; + +import javax.swing.*; +import javax.swing.border.MatteBorder; +import java.awt.*; +import java.io.File; +import java.text.DecimalFormat; + +public class StatusBar extends ITab { + + private static final String WEIGHT_LABEL = "Weight: %s %s / %s %s %s"; + + private final MegaMekLabMainUI parentFrame; + private final JLabel bvLabel = new JLabel(); + protected final JLabel tons = new JLabel(); + private final JLabel cost = new JLabel(); + private final JLabel invalid = new JLabel("Invalid"); + private final DecimalFormat formatter; + + protected final EntityVerifier entityVerifier = EntityVerifier.getInstance( + new File("data/mechfiles/UnitVerifierOptions.xml")); + private TestEntity testEntity; + + private RefreshListener refresh; + + public StatusBar(MegaMekLabMainUI parent) { + super(parent); + setBorder(new MatteBorder(1, 0, 0, 0, UIManager.getColor("Separator.foreground"))); + setLayout(new WrapLayout(FlowLayout.LEFT, 22, 8)); + parentFrame = parent; + formatter = new DecimalFormat(); + + JButton btnValidate = new JButton("Validate Unit"); + btnValidate.addActionListener(evt -> UnitUtil.showValidation(getEntity(), getParentFrame())); + + JButton btnFluffImage = new JButton("Set Fluff Image"); + btnFluffImage.addActionListener(evt -> getFluffImage()); + + invalid.setForeground(GUIPreferences.getInstance().getWarningColor()); + invalid.setVisible(false); + + if (!getEntity().isConventionalInfantry()) { + JButton showEquipmentDatabase = new JButton("Show Equipment Database"); + showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); + add(showEquipmentDatabase); + } + + add(btnValidate); + add(btnFluffImage); + add(tons); + add(bvLabel); + add(invalid); + add(cost); + } + + public final void refresh() { + testEntity = UnitUtil.getEntityVerifier(getEntity()); + refreshWeight(); + refreshBV(); + refreshCost(); + refreshInvalid(); + additionalRefresh(); + } + + /** + * Subclasses must override this to provide the correct type of TestEntity subclass. + */ + protected TestEntity getTestEntity() { + return testEntity; + }; + + /** + * This method is called whenever the status bar is refreshed. When additional type-specific information + * is shown in a subclassed status bar, this method should be overridden to refresh that information. + */ + protected void additionalRefresh() { } + + /** + * Refreshes the weight display. This may be overridden; when doing so, the + * {@link #tons} JLabel should be updated to reflect the weight. + */ + protected void refreshWeight() { + double tonnage = getEntity().getWeight(); + double currentTonnage = testEntity.calculateWeight(); + currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getEntity()); + String current = CalculationReport.formatForReport(currentTonnage); + String full = CalculationReport.formatForReport(tonnage); + String remaining = CalculationReport.formatForReport(tonnage - currentTonnage); + String unit = "t"; + if (TestEntity.usesKgStandard(getEntity())) { + unit = "kg"; + current = Math.round(currentTonnage * 1000) + ""; + full = Math.round(tonnage * 1000) + ""; + remaining = Math.round((tonnage - currentTonnage) * 1000) + ""; + } + String remainingText = ((currentTonnage < tonnage) ? " (" + remaining + " " + unit + " Remaining)" : ""); + tons.setText(String.format(WEIGHT_LABEL, current, unit, full, unit, remainingText)); + tons.setToolTipText("Current Weight / Max Weight (Remaining Weight, if any)"); + tons.setForeground((currentTonnage > tonnage) ? GUIPreferences.getInstance().getWarningColor() : null); + } + + private void refreshBV() { + int bv = getEntity().calculateBattleValue(); + bvLabel.setText("BV: " + bv); + bvLabel.setToolTipText("Battle Value 2.0"); + } + + private void refreshCost() { + cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); + cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " + + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); + } + + private void refreshInvalid() { + StringBuffer sb = new StringBuffer(); + invalid.setVisible(!testEntity.correctEntity(sb)); + invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); + } + + private void getFluffImage() { + FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); + fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); + fDialog.setLocationRelativeTo(this); + fDialog.setVisible(true); + if (fDialog.getFile() != null) { + String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath(); + relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); + getEntity().getFluff().setMMLImagePath(relativeFilePath); + } + refresh.refreshPreview(); + } + + private JFrame getParentFrame() { + return parentFrame; + } + + public void addRefreshedListener(RefreshListener refreshListener) { + refresh = refreshListener; + } + + /** + * Returns an estimated value of the total heat generation for Meks and Aeros (0 for other types). + * This method is very specific to this use and cannot be generalized. It shouldn't be used elsewhere. It is + * here in StatusBar to avoid duplication in BMStatusBar and ASStatusBar. + * + * @return An estimated value of the total heat generation. + */ + protected long estimatedHeatGeneration() { + if (!(getEntity() instanceof Mech) && !(getEntity() instanceof Aero)) { + return 0; + } + double heat = 0; + + if (getEntity() instanceof Mech) { + if (getEntity().getOriginalJumpMP() > 0) { + if (getEntity().getJumpType() == Mech.JUMP_IMPROVED) { + heat += Math.max(3, Math.ceil(getMech().getOriginalJumpMP() / 2.0f)); + } else if (getEntity().getJumpType() != Mech.JUMP_BOOSTER) { + heat += Math.max(3, getEntity().getOriginalJumpMP()); + } + if (getEntity().getEngineType() == Engine.XXL_ENGINE) { + heat *= 2; + } + } else if (getEntity().getEngineType() == Engine.XXL_ENGINE) { + heat += 6; + } else { + heat += 2; + } + } + + for (Mounted mounted : getEntity().getTotalWeaponList()) { + WeaponType wtype = (WeaponType) mounted.getType(); + double weaponHeat = wtype.getHeat(); + + if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() || mounted.isBreached()) { + continue; + } + + if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) || wtype.hasFlag(WeaponType.F_ONESHOT)) { + weaponHeat *= 0.25; + } + + if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) { + weaponHeat *= 2; + } + + if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) { + weaponHeat *= 6; + } + + if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) { + weaponHeat *= 0.5; + } + heat += weaponHeat; + } + + if (getEntity().hasWorkingMisc(MiscType.F_STEALTH, -1) + || getEntity().hasWorkingMisc(MiscType.F_VOIDSIG, -1) + || getEntity().hasWorkingMisc(MiscType.F_NULLSIG, -1)) { + heat += 10; + } + + if (getEntity().hasWorkingMisc(MiscType.F_CHAMELEON_SHIELD, -1)) { + heat += 6; + } + + for (Mounted m : getEntity().getMisc()) { + heat += m.getType().getHeat(); + } + return Math.round(heat); + } +} \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/infantry/CIMainUI.java b/megameklab/src/megameklab/ui/infantry/CIMainUI.java index 0b69a9de2..aea71935e 100644 --- a/megameklab/src/megameklab/ui/infantry/CIMainUI.java +++ b/megameklab/src/megameklab/ui/infantry/CIMainUI.java @@ -18,8 +18,7 @@ import java.awt.BorderLayout; -import javax.swing.JTabbedPane; -import javax.swing.SwingConstants; +import javax.swing.*; import megamek.common.*; import megamek.common.weapons.infantry.InfantryWeapon; @@ -143,6 +142,11 @@ public void refreshPreview() { previewTab.refresh(); } + @Override + public JDialog getFloatingEquipmentDatabase() { + return null; + } + @Override public void refreshSummary() { } diff --git a/megameklab/src/megameklab/ui/infantry/CIStatusBar.java b/megameklab/src/megameklab/ui/infantry/CIStatusBar.java index 701636298..a4a49cb20 100644 --- a/megameklab/src/megameklab/ui/infantry/CIStatusBar.java +++ b/megameklab/src/megameklab/ui/infantry/CIStatusBar.java @@ -15,115 +15,49 @@ */ package megameklab.ui.infantry; -import java.awt.*; -import java.io.File; +import megamek.client.ui.swing.calculationReport.CalculationReport; +import megameklab.ui.MegaMekLabMainUI; +import megameklab.ui.generalUnit.StatusBar; + +import javax.swing.*; import java.text.DecimalFormat; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; +public class CIStatusBar extends StatusBar { -import megameklab.ui.MegaMekLabMainUI; -import megameklab.ui.util.ITab; -import megameklab.util.ImageHelper; -import megameklab.ui.util.RefreshListener; -import megameklab.util.UnitUtil; + private static final String MOVE_LABEL = "Movement: %d / %d"; + private static final String DAMAGE_LABEL = "Damage per Trooper: "; + private static final String INF_WEIGHT_LABEL = "Weight: %s t"; + private static final DecimalFormat roundFormat = new DecimalFormat("#.##"); -public class CIStatusBar extends ITab { private final JLabel move = new JLabel(); private final JLabel damage = new JLabel(); - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final DecimalFormat formatter; - private final JFrame parentFrame; - - private RefreshListener refresh; public CIStatusBar(MegaMekLabMainUI parent) { super(parent); - this.parentFrame = parent; - - formatter = new DecimalFormat(); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(evt -> UnitUtil.showValidation(getInfantry(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(evt -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - setLayout(new GridBagLayout()); - GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridx = 0; - gbc.gridy = 0; - gbc.insets = new Insets(5,2,2,20); - gbc.anchor = GridBagConstraints.WEST; - this.add(btnValidate, gbc); - gbc.gridx = 1; - this.add(btnFluffImage, gbc); - gbc.gridx = 2; - this.add(move, gbc); - gbc.gridx = 3; - this.add(damage, gbc); - gbc.gridx = 4; - this.add(tons, gbc); - gbc.gridx = 5; - this.add(bvLabel, gbc); - gbc.gridx = 6; - this.add(invalid, gbc); - gbc.gridx = 7; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.weightx = 1.0; - this.add(cost, gbc); - refresh(); + add(move); + add(damage); } - public void refresh() { - DecimalFormat roundFormat = new DecimalFormat("#.##"); - int bv = getInfantry().calculateBattleValue(); - - double currentTonnage = getInfantry().getWeight(); - - move.setText("Movement: " + getInfantry().getWalkMP() + "/" + getInfantry().getJumpMP()); - - damage.setText("Damage/Trooper: " + roundFormat.format(getInfantry().getDamagePerTrooper())); - - tons.setText("Tons: " + currentTonnage); - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - String str = UnitUtil.validateUnit(getInfantry()); - invalid.setVisible(!str.isEmpty()); - invalid.setToolTipText("" + str.replaceAll("\n", "
") + ""); + @Override + protected void additionalRefresh() { + refreshMovement(); + refreshDamage(); } - private void getFluffImage() { - // copied from structureTab - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); - fDialog.setLocationRelativeTo(this); - - fDialog.setVisible(true); - - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getInfantry().getFluff().setMMLImagePath(relativeFilePath); - } - refresh.refreshPreview(); + public void refreshMovement() { + int walk = getInfantry().getWalkMP(); + int jump = getInfantry().getJumpMP(); + move.setText(String.format(MOVE_LABEL, walk, jump)); } - private JFrame getParentFrame() { - return parentFrame; + public void refreshDamage() { + damage.setText(DAMAGE_LABEL + roundFormat.format(getInfantry().getDamagePerTrooper())); } - public void addRefreshedListener(RefreshListener l) { - refresh = l; + @Override + protected void refreshWeight() { + double tonnage = getEntity().getWeight(); + String full = CalculationReport.formatForReport(tonnage); + tons.setText(String.format(INF_WEIGHT_LABEL, full)); } -} +} \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/largeAero/DSMainUI.java b/megameklab/src/megameklab/ui/largeAero/DSMainUI.java index ac677ddd6..3499c03bc 100644 --- a/megameklab/src/megameklab/ui/largeAero/DSMainUI.java +++ b/megameklab/src/megameklab/ui/largeAero/DSMainUI.java @@ -36,7 +36,7 @@ public class DSMainUI extends MegaMekLabMainUI { private PreviewTab previewTab; private LABuildTab buildTab; private TransportTab transportTab; - private DSStatusBar statusbar; + private StatusBar statusbar; private QuirksTab quirksTab; private FloatingEquipmentDatabaseDialog floatingEquipmentDatabase; @@ -144,7 +144,7 @@ public void reloadTabs() { previewTab = new PreviewTab(this); - statusbar = new DSStatusBar(this); + statusbar = new StatusBar(this); equipmentTab = new LAEquipmentTab(this); buildTab = new LABuildTab(this); transportTab = new TransportTab(this); diff --git a/megameklab/src/megameklab/ui/largeAero/DSStatusBar.java b/megameklab/src/megameklab/ui/largeAero/DSStatusBar.java deleted file mode 100644 index 04d36423d..000000000 --- a/megameklab/src/megameklab/ui/largeAero/DSStatusBar.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * MegaMekLab - Copyright (C) 2017 - The MegaMek Team - * - * This program 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 2 of the License, or (at your option) any later - * version. - * - * This program 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. - */ -package megameklab.ui.largeAero; - -import megamek.common.AmmoType; -import megamek.common.Entity; -import megamek.common.Mounted; -import megamek.common.WeaponType; -import megamek.common.verifier.EntityVerifier; -import megamek.common.verifier.TestSmallCraft; -import megameklab.ui.util.ITab; -import megameklab.ui.util.RefreshListener; -import megamek.client.ui.WrapLayout; -import megameklab.util.ImageHelper; -import megameklab.util.UnitUtil; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; - -/** - * Status bar for SmallCraft and Dropships - * - * @author Neoancient - * - */ -public class DSStatusBar extends ITab { - - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); - private final JLabel heatSink = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final EntityVerifier entityVerifier = EntityVerifier.getInstance(new File( - "data/mechfiles/UnitVerifierOptions.xml")); - private final DecimalFormat formatter; - private final JFrame parentFrame; - - private RefreshListener refresh; - - public DSStatusBar(DSMainUI parent) { - super(parent); - parentFrame = parent; - - formatter = new DecimalFormat(); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(e -> UnitUtil.showValidation(getSmallCraft(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(e -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(tons); - add(heatSink); - add(bvLabel); - add(invalid); - add(cost); - refresh(); - } - - public void refresh() { - int heat = getSmallCraft().getHeatCapacity(); - double tonnage = getSmallCraft().getWeight(); - double currentTonnage; - int bv = getSmallCraft().calculateBattleValue(); - - TestSmallCraft testSmallCraft = new TestSmallCraft(getSmallCraft(), entityVerifier.aeroOption, null); - - currentTonnage = testSmallCraft.calculateWeight(); - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getSmallCraft()); - - double totalHeat = calculateTotalHeat(); - - heatSink.setText("Heat: " + totalHeat + "/" + heat); - heatSink.setToolTipText("Total Heat Generated/Total Heat Dissipated"); - if (totalHeat > heat) { - heatSink.setForeground(Color.red); - } else { - heatSink.setForeground(UIManager.getColor("Label.foreground")); - } - heatSink.setVisible(getSmallCraft().getEntityType() == Entity.ETYPE_AERO); - - tons.setText(String.format("Tonnage: %,.1f/%,.1f (%,.1f Remaining)", currentTonnage, tonnage, tonnage - currentTonnage)); - tons.setToolTipText("Current Tonnage/Max Tonnage"); - if (currentTonnage > tonnage) { - tons.setForeground(Color.red); - } else { - tons.setForeground(UIManager.getColor("Label.foreground")); - } - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testSmallCraft.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); - } - - public double calculateTotalHeat() { - double heat = 0; - - for (Mounted mounted : getSmallCraft().getWeaponList()) { - WeaponType wtype = (WeaponType) mounted.getType(); - double weaponHeat = wtype.getHeat(); - - // only count non-damaged equipment - if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() - || mounted.isBreached()) { - continue; - } - - // one shot weapons count 1/4 - if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) - || wtype.hasFlag(WeaponType.F_ONESHOT)) { - weaponHeat *= 0.25; - } - - // double heat for ultras - if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) - || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) { - weaponHeat *= 2; - } - - // Six times heat for RAC - if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) { - weaponHeat *= 6; - } - - // half heat for streaks - if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) - || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) { - weaponHeat *= 0.5; - } - heat += weaponHeat; - } - for (Mounted m : getSmallCraft().getMisc()) { - heat += m.getType().getHeat(); - } - return heat; - } - - private void getFluffImage() { - //copied from structureTab - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", - FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() - + File.separatorChar + ImageHelper.imageMech - + File.separatorChar); - fDialog.setLocationRelativeTo(this); - - fDialog.setVisible(true); - - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() - + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." - + File.separatorChar - + relativeFilePath - .substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getSmallCraft().getFluff().setMMLImagePath(relativeFilePath); - } - refresh.refreshPreview(); - } - - private JFrame getParentFrame() { - return parentFrame; - } - - public void addRefreshedListener(RefreshListener l) { - refresh = l; - } - - -} diff --git a/megameklab/src/megameklab/ui/largeAero/WSMainUI.java b/megameklab/src/megameklab/ui/largeAero/WSMainUI.java index 5571821e3..2d050c89c 100644 --- a/megameklab/src/megameklab/ui/largeAero/WSMainUI.java +++ b/megameklab/src/megameklab/ui/largeAero/WSMainUI.java @@ -38,7 +38,7 @@ public class WSMainUI extends MegaMekLabMainUI { private TransportTab transportTab; private FluffTab fluffTab; private QuirksTab quirksTab; - private WSStatusBar statusbar; + private StatusBar statusbar; private FloatingEquipmentDatabaseDialog floatingEquipmentDatabase; public WSMainUI(boolean primitive) { @@ -160,7 +160,7 @@ public void reloadTabs() { structureTab = new WSStructureTab(this); previewTab = new PreviewTab(this); - statusbar = new WSStatusBar(this); + statusbar = new StatusBar(this); equipmentTab = new LAEquipmentTab(this); buildTab = new LABuildTab(this); fluffTab = new FluffTab(this); diff --git a/megameklab/src/megameklab/ui/largeAero/WSStatusBar.java b/megameklab/src/megameklab/ui/largeAero/WSStatusBar.java deleted file mode 100644 index 964ae5d5e..000000000 --- a/megameklab/src/megameklab/ui/largeAero/WSStatusBar.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * MegaMekLab - Copyright (C) 2018 - The MegaMek Team - * - * This program 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 2 of the License, or (at your option) any later - * version. - * - * This program 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. - */ -package megameklab.ui.largeAero; - -import megamek.common.AmmoType; -import megamek.common.Entity; -import megamek.common.Mounted; -import megamek.common.WeaponType; -import megamek.common.verifier.EntityVerifier; -import megamek.common.verifier.TestAdvancedAerospace; -import megameklab.ui.util.ITab; -import megameklab.ui.util.RefreshListener; -import megamek.client.ui.WrapLayout; -import megameklab.util.ImageHelper; -import megameklab.util.UnitUtil; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; - -/** - * Status bar for Jumpships/Warships/Space Stations - * - * @author Neoancient - * - */ -public class WSStatusBar extends ITab { - - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); - private final JLabel remainingTons = new JLabel(); - private final JLabel heatSink = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final EntityVerifier entityVerifier = EntityVerifier.getInstance(new File( - "data/mechfiles/UnitVerifierOptions.xml")); - private final DecimalFormat formatter; - private final JFrame parentFrame; - - private RefreshListener refresh; - - public WSStatusBar(WSMainUI parent) { - super(parent); - parentFrame = parent; - - formatter = new DecimalFormat(); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(e -> UnitUtil.showValidation(getJumpship(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(e -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(tons); - add(remainingTons); - add(heatSink); - add(bvLabel); - add(invalid); - add(cost); - refresh(); - } - - public void refresh() { - int heat = getJumpship().getHeatCapacity(); - double tonnage = getJumpship().getWeight(); - double currentTonnage; - int bv = getJumpship().calculateBattleValue(); - - TestAdvancedAerospace testAdvAero = new TestAdvancedAerospace(getJumpship(), entityVerifier.aeroOption, null); - currentTonnage = testAdvAero.calculateWeight(); - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getJumpship()); - - double totalHeat = calculateTotalHeat(); - - heatSink.setText("Heat: " + totalHeat + "/" + heat); - heatSink.setToolTipText("Total Heat Generated/Total Heat Dissipated"); - if (totalHeat > heat) { - heatSink.setForeground(Color.red); - } else { - heatSink.setForeground(UIManager.getColor("Label.foreground")); - } - heatSink.setVisible(getJumpship().getEntityType() == Entity.ETYPE_AERO); - - tons.setText(String.format("Tonnage: %,.1f/%,.1f (%,.1f Remaining)", currentTonnage, tonnage, tonnage - currentTonnage)); - tons.setToolTipText("Current Tonnage/Max Tonnage"); - remainingTons.setText("Remaining: " + (tonnage - currentTonnage)); - if (currentTonnage > tonnage) { - tons.setForeground(Color.red); - remainingTons.setForeground(Color.red); - } else { - tons.setForeground(UIManager.getColor("Label.foreground")); - remainingTons.setForeground(UIManager.getColor("Label.foreground")); - } - - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testAdvAero.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); - } - - public double calculateTotalHeat() { - double heat = 0; - - for (Mounted mounted : getJumpship().getWeaponList()) { - WeaponType wtype = (WeaponType) mounted.getType(); - double weaponHeat = wtype.getHeat(); - - // only count non-damaged equipment - if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() - || mounted.isBreached()) { - continue; - } - - // one shot weapons count 1/4 - if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) - || wtype.hasFlag(WeaponType.F_ONESHOT)) { - weaponHeat *= 0.25; - } - - // double heat for ultras - if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) - || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) { - weaponHeat *= 2; - } - - // Six times heat for RAC - if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) { - weaponHeat *= 6; - } - - // half heat for streaks - if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) - || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) { - weaponHeat *= 0.5; - } - heat += weaponHeat; - } - for (Mounted m : getJumpship().getMisc()) { - heat += m.getType().getHeat(); - } - return heat; - } - - private void getFluffImage() { - //copied from structureTab - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", - FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() - + File.separatorChar + ImageHelper.imageMech - + File.separatorChar); - fDialog.setLocationRelativeTo(this); - - fDialog.setVisible(true); - - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() - + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." - + File.separatorChar - + relativeFilePath - .substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getJumpship().getFluff().setMMLImagePath(relativeFilePath); - } - refresh.refreshPreview(); - } - - private JFrame getParentFrame() { - return parentFrame; - } - - public void addRefreshedListener(RefreshListener l) { - refresh = l; - } -} diff --git a/megameklab/src/megameklab/ui/mek/BMMainUI.java b/megameklab/src/megameklab/ui/mek/BMMainUI.java index 95f452ecf..c4dd2e6ec 100644 --- a/megameklab/src/megameklab/ui/mek/BMMainUI.java +++ b/megameklab/src/megameklab/ui/mek/BMMainUI.java @@ -243,6 +243,7 @@ public ITechManager getTechManager() { return structureTab.getTechManager(); } + @Override public JDialog getFloatingEquipmentDatabase() { return floatingEquipmentDatabase; } diff --git a/megameklab/src/megameklab/ui/mek/BMStatusBar.java b/megameklab/src/megameklab/ui/mek/BMStatusBar.java index 57e82dcd7..10f2acf64 100644 --- a/megameklab/src/megameklab/ui/mek/BMStatusBar.java +++ b/megameklab/src/megameklab/ui/mek/BMStatusBar.java @@ -16,183 +16,42 @@ package megameklab.ui.mek; import megamek.client.ui.swing.GUIPreferences; -import megamek.common.*; -import megamek.common.verifier.EntityVerifier; -import megamek.common.verifier.TestMech; -import megameklab.ui.util.ITab; -import megameklab.ui.util.RefreshListener; -import megamek.client.ui.WrapLayout; -import megameklab.util.ImageHelper; +import megameklab.ui.generalUnit.StatusBar; import megameklab.util.UnitUtil; import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; -public class BMStatusBar extends ITab { +public class BMStatusBar extends StatusBar { - private final JLabel crits = new JLabel(); - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); - private final JLabel heatSink = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml")); - private TestMech testEntity; - private final DecimalFormat formatter; - private final JFrame parentFrame; + private static final String HEAT_LABEL = "Heat: %d / %d"; + private static final String SLOTS_LABEL = "Free Slots: %d / %d"; - private RefreshListener refresh; + private final JLabel slots = new JLabel(); + private final JLabel heat = new JLabel(); public BMStatusBar(BMMainUI parent) { super(parent); - parentFrame = parent; - - formatter = new DecimalFormat(); - testEntity = new TestMech(getMech(), entityVerifier.mechOption, null); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(evt -> UnitUtil.showValidation(getMech(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(evt -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(tons); - add(crits); - add(heatSink); - add(bvLabel); - add(invalid); - add(cost); - refresh(); - } - - public void refresh() { - int heat = getMech().getHeatCapacity(); - double tonnage = getMech().getWeight(); - double currentTonnage; - int bv = getMech().calculateBattleValue(); - int maxCrits; - if (getMech() instanceof TripodMech) { - maxCrits = 84; - } else if (getMech() instanceof QuadMech) { - maxCrits = 66; - } else { - maxCrits = 78; - } - int currentCrits = UnitUtil.countUsedCriticals(getMech()); - - testEntity = new TestMech(getMech(), entityVerifier.mechOption, null); - - currentTonnage = testEntity.calculateWeight(); - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(getMech()); - - double totalHeat = calculateTotalHeat(); - heatSink.setText("Heat: " + totalHeat + " / " + heat); - heatSink.setToolTipText("Total Heat Generated / Total Heat Dissipated"); - - tons.setText(String.format("Tonnage: %.1f / %.0f (%.1f Remaining)", currentTonnage, tonnage, tonnage - currentTonnage)); - tons.setToolTipText("Current Tonnage/Max Tonnage"); - tons.setForeground(currentTonnage > tonnage ? GUIPreferences.getInstance().getWarningColor() : null); - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - crits.setText("Criticals: " + currentCrits + " / " + maxCrits); - crits.setForeground(currentCrits > maxCrits ? GUIPreferences.getInstance().getWarningColor() : null); - - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testEntity.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); + add(slots); + add(heat); } - public double calculateTotalHeat() { - double heat = 0; - - if (getMech().getOriginalJumpMP() > 0) { - if (getMech().getJumpType() == Mech.JUMP_IMPROVED) { - heat += Math.max(3, Math.ceil(getMech().getOriginalJumpMP() / 2.0f)); - } else if (getMech().getJumpType() != Mech.JUMP_BOOSTER) { - heat += Math.max(3, getMech().getOriginalJumpMP()); - } - if (getMech().getEngine().getEngineType() == Engine.XXL_ENGINE) { - heat *= 2; - } - } else if (getMech().getEngine().getEngineType() == Engine.XXL_ENGINE) { - heat += 6; - } else { - heat += 2; - } - - for (Mounted mounted : getMech().getWeaponList()) { - WeaponType wtype = (WeaponType) mounted.getType(); - double weaponHeat = wtype.getHeat(); - - // only count non-damaged equipment - if (mounted.isMissing() || mounted.isHit() || mounted.isDestroyed() || mounted.isBreached()) { - continue; - } - - // one shot weapons count 1/4 - if ((wtype.getAmmoType() == AmmoType.T_ROCKET_LAUNCHER) || wtype.hasFlag(WeaponType.F_ONESHOT)) { - weaponHeat *= 0.25; - } - - // double heat for ultras - if ((wtype.getAmmoType() == AmmoType.T_AC_ULTRA) || (wtype.getAmmoType() == AmmoType.T_AC_ULTRA_THB)) { - weaponHeat *= 2; - } - - // Six times heat for RAC - if (wtype.getAmmoType() == AmmoType.T_AC_ROTARY) { - weaponHeat *= 6; - } - - // half heat for streaks - if ((wtype.getAmmoType() == AmmoType.T_SRM_STREAK) || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) { - weaponHeat *= 0.5; - } - heat += weaponHeat; - } - if (getMech().hasStealth()) { - heat += 10; - } - for (Mounted m : getMech().getMisc()) { - heat += m.getType().getHeat(); - } - return heat; + @Override + protected void additionalRefresh() { + refreshSlots(); + refreshHeat(); } - private void getFluffImage() { - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); - fDialog.setLocationRelativeTo(this); - fDialog.setVisible(true); - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getMech().getFluff().setMMLImagePath(relativeFilePath); - } - refresh.refreshPreview(); + public void refreshSlots() { + int maxCrits = getTestEntity().totalCritSlotCount(); + int currentSlots = UnitUtil.countUsedCriticals(getMech()); + slots.setText(String.format(SLOTS_LABEL, currentSlots, maxCrits)); + slots.setForeground(currentSlots > maxCrits ? GUIPreferences.getInstance().getWarningColor() : null); } - private JFrame getParentFrame() { - return parentFrame; + public void refreshHeat() { + int heatCapacity = getMech().getHeatCapacity(); + long totalHeat = estimatedHeatGeneration(); + heat.setText(String.format(HEAT_LABEL, totalHeat, heatCapacity)); + heat.setToolTipText("Estimated Total Heat Generated / Total Heat Dissipated"); } - - public void addRefreshedListener(RefreshListener refreshListener) { - refresh = refreshListener; - } - } \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/protoMek/PMStatusBar.java b/megameklab/src/megameklab/ui/protoMek/PMStatusBar.java index d9ed056a9..14ab90f24 100644 --- a/megameklab/src/megameklab/ui/protoMek/PMStatusBar.java +++ b/megameklab/src/megameklab/ui/protoMek/PMStatusBar.java @@ -13,124 +13,42 @@ */ package megameklab.ui.protoMek; -import megamek.common.verifier.EntityVerifier; +import megamek.client.ui.swing.GUIPreferences; import megamek.common.verifier.TestProtomech; -import megameklab.ui.util.ITab; -import megameklab.ui.util.RefreshListener; -import megamek.client.ui.WrapLayout; -import megameklab.util.ImageHelper; -import megameklab.util.UnitUtil; +import megameklab.ui.generalUnit.StatusBar; import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; /** * Status bar for ProtoMek construction * * @author Neoancient */ -public class PMStatusBar extends ITab { - private final JLabel crits = new JLabel(); - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final TestProtomech testEntity; - private final DecimalFormat formatter; - private final JFrame parentFrame; +public class PMStatusBar extends StatusBar { - private RefreshListener refresh; + private static final String SLOTS_LABEL = "Free Slots: %d / %d"; + + private final JLabel slots = new JLabel(); public PMStatusBar(PMMainUI parent) { super(parent); - parentFrame = parent; - - formatter = new DecimalFormat(); - EntityVerifier entityVerifier = EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml")); - testEntity = new TestProtomech(getProtomech(), entityVerifier.mechOption, null); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(ev -> UnitUtil.showValidation(getProtomech(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(ev -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); + add(slots); + } - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(tons); - add(crits); - add(bvLabel); - add(invalid); - add(cost); - refresh(); + @Override + protected void additionalRefresh() { + refreshSlots(); } - public void refresh() { - double tonnage = getProtomech().getWeight() * 1000; - int bv = getProtomech().calculateBattleValue(); + public void refreshSlots() { int maxCrits = 0; for (int l = 0; l < getProtomech().locations(); l++) { maxCrits += TestProtomech.maxSlotsByLocation(l, getProtomech()); } - long currentCrits = getProtomech().getEquipment().stream() + long currentSlots = getProtomech().getEquipment().stream() .filter(m -> TestProtomech.requiresSlot(m.getType())).count(); - double currentTonnage = testEntity.calculateWeight() * 1000; - - tons.setText(String.format("Tonnage: %,.0f/%,.0f (%,.0f Remaining)", currentTonnage, tonnage, tonnage - currentTonnage)); - tons.setToolTipText("Current Tonnage/Max Tonnage"); - if (currentTonnage > tonnage) { - tons.setForeground(Color.red); - } else { - tons.setForeground(UIManager.getColor("Label.foreground")); - } - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - crits.setText("Criticals: " + currentCrits + "/" + maxCrits); - if (currentCrits > maxCrits) { - crits.setForeground(Color.red); - } else { - crits.setForeground(UIManager.getColor("Label.foreground")); - } - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testEntity.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); - } - - private void getFluffImage() { - // copied from mech StatusBar - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); - fDialog.setLocationRelativeTo(this); - - fDialog.setVisible(true); - - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - getProtomech().getFluff().setMMLImagePath(relativeFilePath); - } - refresh.refreshPreview(); - } - - private JFrame getParentFrame() { - return parentFrame; - } - - public void addRefreshedListener(RefreshListener l) { - refresh = l; + slots.setText(String.format(SLOTS_LABEL, currentSlots, maxCrits)); + slots.setForeground(currentSlots > maxCrits ? GUIPreferences.getInstance().getWarningColor() : null); } -} +} \ No newline at end of file diff --git a/megameklab/src/megameklab/ui/supportVehicle/SVStatusBar.java b/megameklab/src/megameklab/ui/supportVehicle/SVStatusBar.java index 9581f6fc3..9548dd678 100644 --- a/megameklab/src/megameklab/ui/supportVehicle/SVStatusBar.java +++ b/megameklab/src/megameklab/ui/supportVehicle/SVStatusBar.java @@ -18,173 +18,47 @@ */ package megameklab.ui.supportVehicle; -import megamek.client.ui.WrapLayout; -import megamek.common.EntityWeightClass; -import megamek.common.verifier.EntityVerifier; +import megamek.client.ui.swing.GUIPreferences; import megamek.common.verifier.TestSupportVehicle; -import megameklab.ui.MegaMekLabMainUI; -import megameklab.ui.util.ITab; -import megameklab.util.ImageHelper; -import megameklab.util.UnitUtil; +import megameklab.ui.generalUnit.StatusBar; import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.text.DecimalFormat; /** * The Status Bar for Support Vehicles */ -class SVStatusBar extends ITab { +class SVStatusBar extends StatusBar { + + private static final String MOVE_LABEL = "Movement: %d / %d / %d"; + private static final String SLOTS_LABEL = "Free Slots: %d / %d"; - private final JPanel slotsPanel = new JPanel(); private final JLabel move = new JLabel(); - private final JLabel bvLabel = new JLabel(); - private final JLabel tons = new JLabel(); private final JLabel slots = new JLabel(); - private final JLabel cost = new JLabel(); - private final JLabel invalid = new JLabel(); - private final EntityVerifier entityVerifier = EntityVerifier.getInstance(new File( - "data/mechfiles/UnitVerifierOptions.xml")); - private TestSupportVehicle testEntity; - private final DecimalFormat formatter; - private final MegaMekLabMainUI mainUI; SVStatusBar(SVMainUI parent) { super(parent); - mainUI = parent; - - formatter = new DecimalFormat(); - testEntity = new TestSupportVehicle(parent.getEntity(), entityVerifier.tankOption, - null); - JButton showEquipmentDatabase = new JButton("Show Equipment Database"); - showEquipmentDatabase.addActionListener(evt -> parent.getFloatingEquipmentDatabase().setVisible(true)); - JButton btnValidate = new JButton("Validate Unit"); - btnValidate.addActionListener(evt -> UnitUtil.showValidation(parent.getEntity(), getParentFrame())); - JButton btnFluffImage = new JButton("Set Fluff Image"); - btnFluffImage.addActionListener(evt -> getFluffImage()); - invalid.setText("Invalid"); - invalid.setForeground(Color.RED); - invalid.setVisible(false); - - setLayout(new WrapLayout(FlowLayout.LEFT, 22, 5)); - add(showEquipmentDatabase); - add(btnValidate); - add(btnFluffImage); - add(tons); - add(movementLabel()); - add(bvLabel()); - add(bvLabel); - add(tonnageLabel()); - add(slotsPanel()); - add(invalid); - add(cost); - refresh(); + add(move); + add(slots); } - private JLabel movementLabel() { - int walk = eSource.getEntity().getOriginalWalkMP(); - int run = eSource.getEntity().getOriginalRunMP(); - int jump = eSource.getEntity().getOriginalJumpMP(); - - move.setText("Movement: " + walk + "/" + run + "/" + jump); - return move; - } - - private JLabel bvLabel() { - int bv = eSource.getEntity().calculateBattleValue(); - bvLabel.setText("BV: " + bv); - - return bvLabel; + @Override + protected void additionalRefresh() { + refreshMovement(); + refreshSlots(); } - private JLabel tonnageLabel() { - double tonnage = eSource.getEntity().getWeight(); - double currentTonnage; - - currentTonnage = testEntity.calculateWeight(); - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(eSource.getEntity()); - - tons.setText("Tonnage: " + currentTonnage + "/" + tonnage); - return tons; + public void refreshMovement() { + int walk = getEntity().getOriginalWalkMP(); + int run = getEntity().getOriginalRunMP(); + int jump = getEntity().getOriginalJumpMP(); + move.setText(String.format(MOVE_LABEL, walk, run, jump)); } - private JPanel slotsPanel() { + public void refreshSlots() { + TestSupportVehicle testEntity = (TestSupportVehicle) getTestEntity(); final int totalSlots = testEntity.totalSlotCount(); final int currentSlots = testEntity.occupiedSlotCount(); - slots.setText("Slots: " + currentSlots + "/" + totalSlots); - slotsPanel.add(slots); - return slotsPanel; - } - - public void refresh() { - int walk = eSource.getEntity().getOriginalWalkMP(); - int run = eSource.getEntity().getOriginalRunMP(); - int jump = eSource.getEntity().getOriginalJumpMP(); - double tonnage = eSource.getEntity().getWeight(); - double currentTonnage; - int bv = eSource.getEntity().calculateBattleValue(); - - testEntity = new TestSupportVehicle(eSource.getEntity(), entityVerifier.tankOption, - null); - - currentTonnage = testEntity.calculateWeight(); - - currentTonnage += UnitUtil.getUnallocatedAmmoTonnage(eSource.getEntity()); - - if (eSource.getEntity().getWeightClass() == EntityWeightClass.WEIGHT_SMALL_SUPPORT) { - tons.setText(String.format("Tonnage: %.0f/%.0f (%.0f Remaining)", - currentTonnage * 1000, tonnage * 1000, (tonnage - currentTonnage) * 1000)); - } else { - tons.setText(String.format("Tonnage: %.1f/%.1f (%.1f Remaining)", currentTonnage, tonnage, tonnage - currentTonnage)); - } - tons.setToolTipText("Current Tonnage/Max Tonnage"); - if (currentTonnage > tonnage) { - tons.setForeground(Color.red); - } else { - tons.setForeground(UIManager.getColor("Label.foreground")); - } - - final int totalSlots = testEntity.totalSlotCount(); - final int currentSlots = testEntity.occupiedSlotCount(); - slots.setText("Slots: " + currentSlots + "/" + totalSlots); - if (currentSlots > totalSlots) { - slots.setForeground(Color.red); - } else { - slots.setForeground(UIManager.getColor("Label.foreground")); - } - - bvLabel.setText("BV: " + bv); - bvLabel.setToolTipText("BV 2.0"); - - cost.setText("Dry Cost: " + formatter.format(Math.round(getEntity().getCost(true))) + " C-bills"); - cost.setToolTipText("The dry cost of the unit (without ammo). The unit's full cost is " - + formatter.format(Math.round(getEntity().getCost(false))) + " C-bills."); - - move.setText("Movement: " + walk + "/" + run + "/" + jump); - move.setToolTipText("Walk/Run/Jump MP"); - StringBuffer sb = new StringBuffer(); - invalid.setVisible(!testEntity.correctEntity(sb)); - invalid.setToolTipText("" + sb.toString().replaceAll("\n", "
") + ""); - } - - private void getFluffImage() { - //copied from structureTab - FileDialog fDialog = new FileDialog(getParentFrame(), "Image Path", FileDialog.LOAD); - fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar); - fDialog.setLocationRelativeTo(this); - - fDialog.setVisible(true); - - if (fDialog.getFile() != null) { - String relativeFilePath = new File(fDialog.getDirectory() + fDialog.getFile()).getAbsolutePath(); - relativeFilePath = "." + File.separatorChar + relativeFilePath.substring(new File(System.getProperty("user.dir")).getAbsolutePath().length() + 1); - eSource.getEntity().getFluff().setMMLImagePath(relativeFilePath); - } - mainUI.refreshPreview(); - } - - private JFrame getParentFrame() { - return mainUI; + slots.setText(String.format(SLOTS_LABEL, currentSlots, totalSlots)); + slots.setForeground(currentSlots > totalSlots ? GUIPreferences.getInstance().getWarningColor() : null); } -} +} \ No newline at end of file