Beispiel #1
0
public class StatusBar extends ITab {

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

  private JButton btnValidate = new JButton("Validate Unit");
  private JButton btnFluffImage = new JButton("Set Fluff Image");

  private JPanel tonnagePanel = new JPanel();
  private JPanel movementPanel = new JPanel();
  private JPanel bvPanel = new JPanel();

  private JLabel move = new JLabel();
  private JLabel bvLabel = new JLabel();
  private JLabel tons = new JLabel();
  private JLabel cost = new JLabel();

  private EntityVerifier entityVerifier =
      EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));

  private TestBattleArmor testBA = null;
  private DecimalFormat formatter;
  private JFrame parentFrame;

  private RefreshListener refresh;

  public StatusBar(MegaMekLabMainUI parent) {
    super(parent);

    formatter = new DecimalFormat();
    btnValidate.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            UnitUtil.showValidation(getBattleArmor(), getParentFrame());
          }
        });
    btnFluffImage.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            getFluffImage();
          }
        });

    setLayout(new GridBagLayout());
    this.add(movementPanel());
    this.add(bvPanel());
    this.add(tonnagePanel());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets = new Insets(5, 2, 2, 30);
    gbc.anchor = GridBagConstraints.WEST;
    this.add(btnValidate, gbc);
    gbc.gridx = 1;
    this.add(btnFluffImage, gbc);
    gbc.gridx = 2;
    this.add(movementPanel, gbc);
    gbc.gridx = 3;
    this.add(bvPanel, gbc);
    gbc.gridx = 4;
    this.add(tonnagePanel, gbc);
    gbc.gridx = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    this.add(cost, gbc);

    refresh();
  }

  public JPanel movementPanel() {
    int walk = getBattleArmor().getOriginalWalkMP();
    int jump = getBattleArmor().getOriginalJumpMP();

    move.setText("Movement: " + walk + "/" + jump);
    movementPanel.add(move);
    return movementPanel;
  }

  public JPanel bvPanel() {
    int bv = getBattleArmor().calculateBattleValue();
    bvLabel.setText("BV: " + bv);
    bvPanel.add(bvLabel);

    return bvPanel;
  }

  public JPanel tonnagePanel() {
    tonnagePanel.add(tons);

    return tonnagePanel;
  }

  public void refresh() {

    int walk = getBattleArmor().getOriginalWalkMP();
    int jump = getBattleArmor().getOriginalJumpMP();
    float maxKilos = getBattleArmor().getTrooperWeight();
    float currentKilos;
    int bv = getBattleArmor().calculateBattleValue();
    int currentCost = (int) Math.round(getBattleArmor().getCost(false));

    testBA = new TestBattleArmor(getBattleArmor(), entityVerifier.baOption, null);
    currentKilos = testBA.calculateWeight(BattleArmor.LOC_SQUAD);
    currentKilos += UnitUtil.getUnallocatedAmmoTonnage(getBattleArmor());

    tons.setText("Suit Weight: " + String.format("%1$.3f", currentKilos) + "/" + maxKilos);
    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(Color.black);
    }

    bvLabel.setText("BV: " + bv);
    bvLabel.setToolTipText("BV 2.0");

    move.setText("Movement: " + walk + "/" + jump);
    move.setToolTipText("Walk/Jump MP");

    cost.setText("Squad Cost: " + formatter.format(currentCost) + " C-bills");
  }

  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").toString()).getAbsolutePath().length()
                      + 1);
      getAero().getFluff().setMMLImagePath(relativeFilePath);
    }
    refresh.refreshPreview();
    return;
  }

  private JFrame getParentFrame() {
    return parentFrame;
  }

  public void addRefreshedListener(RefreshListener l) {
    refresh = l;
  }
}
Beispiel #2
0
public class StatusBar extends ITab {

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

  private JButton btnValidate = new JButton("Validate Unit");
  private JButton btnFluffImage = new JButton("Set Fluff Image");
  private JLabel crits = new JLabel();
  private JLabel bvLabel = new JLabel();
  private JLabel tons = new JLabel();
  private JLabel heatSink = new JLabel();
  private JLabel cost = new JLabel();
  private EntityVerifier entityVerifier =
      EntityVerifier.getInstance(new File("data/mechfiles/UnitVerifierOptions.xml"));
  private TestMech testEntity = null;
  private DecimalFormat formatter;
  private JFrame parentFrame;

  private RefreshListener refresh;

  public StatusBar(MegaMekLabMainUI parent) {
    super(parent);
    parentFrame = parent;

    formatter = new DecimalFormat();
    testEntity = new TestMech(getMech(), entityVerifier.mechOption, null);
    btnValidate.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            UnitUtil.showValidation(getMech(), getParentFrame());
          }
        });
    btnFluffImage.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            getFluffImage();
          }
        });
    // btnFluffImage.setEnabled(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(tons, gbc);
    gbc.gridx = 3;
    this.add(crits, gbc);
    gbc.gridx = 4;
    this.add(heatSink, gbc);
    gbc.gridx = 5;
    this.add(bvLabel, gbc);
    gbc.gridx = 6;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    this.add(cost, gbc);

    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());
    int currentCost = (int) Math.round(getMech().getCost(false));

    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");
    if (totalHeat > heat) {
      heatSink.setForeground(Color.red);
    } else {
      heatSink.setForeground(Color.black);
    }

    tons.setText("Tonnage: " + currentTonnage + "/" + tonnage);
    tons.setToolTipText("Current Tonnage/Max Tonnage");
    if (currentTonnage > tonnage) {
      tons.setForeground(Color.red);
    } else {
      tons.setForeground(Color.black);
    }

    bvLabel.setText("BV: " + bv);
    bvLabel.setToolTipText("BV 2.0");

    cost.setText("Cost: " + formatter.format(currentCost) + " C-bills");

    crits.setText("Criticals: " + currentCrits + "/" + maxCrits);
    if (currentCrits > maxCrits) {
      crits.setForeground(Color.red);
    } else {
      crits.setForeground(Color.BLACK);
    }
  }

  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;
    }

    if (getMech().hasNullSig()) {
      heat += 10;
    }

    if (getMech().hasChameleonShield()) {
      heat += 6;
    }

    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_MRM_STREAK)
          || (wtype.getAmmoType() == AmmoType.T_LRM_STREAK)) {
        weaponHeat *= 0.5;
      }
      heat += weaponHeat;
    }
    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);
    /*
     //This does not seem to be working
    if (getMech().getFluff().getMMLImagePath().trim().length() > 0) {
        String fullPath = new File(getMech().getFluff().getMMLImagePath()).getAbsolutePath();
        String imageName = fullPath.substring(fullPath.lastIndexOf(File.separatorChar) + 1);
        fullPath = fullPath.substring(0, fullPath.lastIndexOf(File.separatorChar) + 1);
        fDialog.setDirectory(fullPath);
        fDialog.setFile(imageName);
    } else {
        fDialog.setDirectory(new File(ImageHelper.fluffPath).getAbsolutePath() + File.separatorChar + ImageHelper.imageMech + File.separatorChar);
        fDialog.setFile(getMech().getChassis() + " " + getMech().getModel() + ".png");
    }
    */
    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").toString()).getAbsolutePath().length()
                      + 1);
      getMech().getFluff().setMMLImagePath(relativeFilePath);
    }
    refresh.refreshPreview();
    return;
  }

  private JFrame getParentFrame() {
    return parentFrame;
  }

  public void addRefreshedListener(RefreshListener l) {
    refresh = l;
  }
}