Exemplo n.º 1
0
/**
 * Class which keeps set of all areas required to represent Capital Fighter unit in
 * MechDsiplay.ArmorPanel class.
 */
public class CapitalFighterMapSet implements DisplayMapSet {

  private JComponent comp;
  //  Images that shows how much armor left.
  private Image armorImage;
  // Set of areas to show fighter armor left
  private PMPicArea armorArea;
  // Set of labels to show fighter armor left
  // images and areas for each crit tally
  private Image avCritImage;
  private PMPicArea avCritArea;
  private Image engineCritImage;
  private PMPicArea engineCritArea;
  private Image fcsCritImage;
  private PMPicArea fcsCritArea;
  private Image sensorCritImage;
  private PMPicArea sensorCritArea;
  private Image pilotCritImage;
  private PMPicArea pilotCritArea;
  private PMSimpleLabel armorLabel;
  private PMValueLabel armorVLabel;
  private PMSimpleLabel avCritLabel;
  private PMSimpleLabel engineCritLabel;
  private PMSimpleLabel fcsCritLabel;
  private PMSimpleLabel sensorCritLabel;
  private PMSimpleLabel pilotCritLabel;
  private Vector<BackGroundDrawer> bgDrawers = new Vector<BackGroundDrawer>();
  private PMAreasGroup content = new PMAreasGroup();

  private int stepY = 14;
  private int squareSize = 7;
  private int armorRows = 8;
  private int armorCols = 6;

  private static final Font FONT_LABEL =
      new Font(
          "SansSerif",
          Font.PLAIN,
          GUIPreferences.getInstance()
              .getInt("AdvancedMechDisplayArmorSmallFontSize")); // $NON-NLS-1$

  public CapitalFighterMapSet(JComponent c) {
    comp = c;
    setAreas();
    setLabels();
    setBackGround();
    translateAreas();
    setContent();
  }

  public void setRest() {}

  public PMAreasGroup getContentGroup() {
    return content;
  }

  public Vector<BackGroundDrawer> getBackgroundDrawers() {
    return bgDrawers;
  }

  public void setEntity(Entity e) {
    Aero t = (Aero) e;

    int armor = t.getCapArmor();
    int armorO = t.getCap0Armor();
    armorVLabel.setValue(Integer.toString(armor));

    if (t.getGame().getOptions().booleanOption("aero_sanity")) {
      armor = (int) Math.ceil(armor / 10.0);
      armorO = (int) Math.ceil(armorO / 10.0);
    }

    drawArmorImage(armorImage, armor, armorO);
    drawCrits(avCritImage, t.getAvionicsHits());
    drawCrits(engineCritImage, t.getEngineHits());
    drawCrits(fcsCritImage, t.getFCSHits());
    drawCrits(sensorCritImage, t.getSensorHits());
    drawCrits(pilotCritImage, t.getCrew().getHits());
  }

  private void setContent() {
    content.addArea(armorLabel);
    content.addArea(armorArea);
    content.addArea(armorVLabel);
    content.addArea(avCritLabel);
    content.addArea(engineCritLabel);
    content.addArea(fcsCritLabel);
    content.addArea(sensorCritLabel);
    content.addArea(pilotCritLabel);
    content.addArea(avCritArea);
    content.addArea(engineCritArea);
    content.addArea(fcsCritArea);
    content.addArea(sensorCritArea);
    content.addArea(pilotCritArea);
  }

  private void setAreas() {
    armorImage = comp.createImage(armorCols * (squareSize + 1), armorRows * (squareSize + 1));
    armorArea = new PMPicArea(armorImage);

    avCritImage = comp.createImage(3 * (squareSize + 1), squareSize + 1);
    avCritArea = new PMPicArea(avCritImage);
    engineCritImage = comp.createImage(3 * (squareSize + 1), squareSize + 1);
    engineCritArea = new PMPicArea(engineCritImage);
    fcsCritImage = comp.createImage(3 * (squareSize + 1), squareSize + 1);
    fcsCritArea = new PMPicArea(fcsCritImage);
    sensorCritImage = comp.createImage(3 * (squareSize + 1), squareSize + 1);
    sensorCritArea = new PMPicArea(sensorCritImage);
    pilotCritImage = comp.createImage(6 * (squareSize + 1), squareSize + 1);
    pilotCritArea = new PMPicArea(pilotCritImage);
  }

  private void setLabels() {
    FontMetrics fm = comp.getFontMetrics(FONT_LABEL);
    armorLabel = new PMSimpleLabel("Armor:", fm, Color.white);
    armorVLabel = new PMValueLabel(fm, Color.red.brighter());

    avCritLabel = new PMSimpleLabel("Avionics:", fm, Color.white); // $NON-NLS-1$
    engineCritLabel = new PMSimpleLabel("Engine:", fm, Color.white); // $NON-NLS-1$
    fcsCritLabel = new PMSimpleLabel("FCS:", fm, Color.white); // $NON-NLS-1$
    sensorCritLabel = new PMSimpleLabel("Sensors:", fm, Color.white); // $NON-NLS-1$
    pilotCritLabel = new PMSimpleLabel("Pilot hits:", fm, Color.white); // $NON-NLS-1$
  }

  private void setBackGround() {
    Image tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "tile.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    int b = BackGroundDrawer.TILING_BOTH;
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_HORIZONTAL | BackGroundDrawer.VALIGN_TOP;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "h_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_HORIZONTAL | BackGroundDrawer.VALIGN_BOTTOM;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "h_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_VERTICAL | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "v_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_VERTICAL | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "v_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_TOP | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "tl_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_BOTTOM | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "bl_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_TOP | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "tr_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_BOTTOM | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "br_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));
  }

  private void translateAreas() {
    armorLabel.translate(0, 0);
    armorArea.translate(0, squareSize);
    armorVLabel.translate(
        (armorCols * (squareSize + 1)) / 2, squareSize + (armorRows * (squareSize + 1)) / 2);

    avCritLabel.translate(5 + armorCols * (squareSize + 1), stepY);
    engineCritLabel.translate(5 + armorCols * (squareSize + 1), 2 * stepY);
    fcsCritLabel.translate(5 + armorCols * (squareSize + 1), 3 * stepY);
    sensorCritLabel.translate(5 + armorCols * (squareSize + 1), 4 * stepY);
    pilotCritLabel.translate(5 + armorCols * (squareSize + 1), 5 * stepY);

    avCritArea.translate(
        10 + pilotCritLabel.width + armorCols * (squareSize + 1), stepY - (squareSize + 1));
    engineCritArea.translate(
        10 + pilotCritLabel.width + armorCols * (squareSize + 1), 2 * stepY - (squareSize + 1));
    fcsCritArea.translate(
        10 + pilotCritLabel.width + armorCols * (squareSize + 1), 3 * stepY - (squareSize + 1));
    sensorCritArea.translate(
        10 + pilotCritLabel.width + armorCols * (squareSize + 1), 4 * stepY - (squareSize + 1));
    pilotCritArea.translate(
        10 + pilotCritLabel.width + armorCols * (squareSize + 1), 5 * stepY - (squareSize + 1));
  }

  private void drawCrits(Image im, int crits) {
    int w = im.getWidth(null);
    int h = im.getHeight(null);
    Graphics g = im.getGraphics();
    g.setColor(Color.black);
    g.fillRect(0, 0, w, h);
    for (int i = 0; i < crits; i++) {
      g.setColor(Color.red.darker());
      g.fillRect(i * (squareSize + 1), 0, squareSize, squareSize);
    }
  }

  //  Redraws armor images
  private void drawArmorImage(Image im, int a, int initial) {
    int w = im.getWidth(null);
    int h = im.getHeight(null);
    Graphics g = im.getGraphics();
    g.setColor(Color.gray);
    g.fillRect(0, 0, w, h);
    // first fill up the initial armor area with black
    for (int i = 0; i < initial; i++) {
      // 6 across and 8 down
      int row = i / armorRows;
      int column = i - row * armorRows;
      g.setColor(Color.black);
      g.fillRect(
          row * (squareSize + 1), column * (squareSize + 1), (squareSize + 1), (squareSize + 1));
    }
    for (int i = 0; i < a; i++) {
      int row = i / armorRows;
      int column = i - row * armorRows;
      g.setColor(Color.green.darker());
      g.fillRect(row * (squareSize + 1), column * (squareSize + 1), squareSize, squareSize);
    }
  }
}
Exemplo n.º 2
0
  @Override
  public StringBuffer getTooltip() {

    // Tooltip info for a sensor blip
    if (onlyDetectedBySensors())
      return new StringBuffer(Messages.getString("BoardView1.sensorReturn"));

    // No sensor blip...
    Infantry thisInfantry = null;
    if (entity instanceof Infantry) thisInfantry = (Infantry) entity;
    GunEmplacement thisGunEmp = null;
    if (entity instanceof GunEmplacement) thisGunEmp = (GunEmplacement) entity;
    Aero thisAero = null;
    if (entity instanceof Aero) thisAero = (Aero) entity;

    tooltipString = new StringBuffer();

    // Unit Chassis and Player
    addToTT(
        "Unit",
        NOBR,
        Integer.toHexString(PlayerColors.getColorRGB(entity.getOwner().getColorIndex())),
        entity.getChassis(),
        entity.getOwner().getName());

    // Pilot Info
    // Nickname > Name > "Pilot"
    String pnameStr = "Pilot";

    if ((entity.getCrew().getName() != null) && !entity.getCrew().getName().equals(""))
      pnameStr = entity.getCrew().getName();

    if ((entity.getCrew().getNickname() != null) && !entity.getCrew().getNickname().equals(""))
      pnameStr = "'" + entity.getCrew().getNickname() + "'";

    addToTT("Pilot", BR, pnameStr, entity.getCrew().getGunnery(), entity.getCrew().getPiloting());

    // Pilot Status
    if (!entity.getCrew().getStatusDesc().equals(""))
      addToTT("PilotStatus", NOBR, entity.getCrew().getStatusDesc());

    // Pilot Advantages
    int numAdv = entity.getCrew().countOptions(PilotOptions.LVL3_ADVANTAGES);
    if (numAdv == 1) addToTT("Adv1", NOBR, numAdv);
    else if (numAdv > 1) addToTT("Advs", NOBR, numAdv);

    // Pilot Manei Domini
    if ((entity.getCrew().countOptions(PilotOptions.MD_ADVANTAGES) > 0)) addToTT("MD", NOBR);

    // Unit movement ability
    if (thisGunEmp == null) {
      addToTT("Movement", BR, entity.getWalkMP(), entity.getRunMPasString());
      if (entity.getJumpMP() > 0) tooltipString.append("/" + entity.getJumpMP());
    }

    // Armor and Internals
    addToTT("ArmorInternals", BR, entity.getTotalArmor(), entity.getTotalInternal());

    // Heat, not shown for units with 999 heat sinks (vehicles)
    if (entity.getHeatCapacity() != 999) {
      if (entity.heat == 0) addToTT("Heat0", BR);
      else addToTT("Heat", BR, entity.heat);
    }

    // Actual Movement
    if (thisGunEmp == null) {
      // In the Movement Phase, unit not done
      if (!entity.isDone() && this.bv.game.getPhase() == Phase.PHASE_MOVEMENT) {
        // "Has not yet moved" only during movement phase
        addToTT("NotYetMoved", BR);

        // In the Movement Phase, unit is done - or in the Firing Phase
      } else if ((entity.isDone() && this.bv.game.getPhase() == Phase.PHASE_MOVEMENT)
          || this.bv.game.getPhase() == Phase.PHASE_FIRING) {
        int tmm = Compute.getTargetMovementModifier(bv.game, entity.getId()).getValue();
        // Unit didn't move
        if (entity.moved == EntityMovementType.MOVE_NONE) {
          addToTT("NoMove", BR, tmm);

          // Unit did move
        } else {
          // Colored arrow
          // get the color resource
          String guipName = "AdvancedMoveDefaultColor";
          if ((entity.moved == EntityMovementType.MOVE_RUN)
              || (entity.moved == EntityMovementType.MOVE_VTOL_RUN)
              || (entity.moved == EntityMovementType.MOVE_OVER_THRUST))
            guipName = "AdvancedMoveRunColor";
          else if (entity.moved == EntityMovementType.MOVE_SPRINT)
            guipName = "AdvancedMoveSprintColor";
          else if (entity.moved == EntityMovementType.MOVE_JUMP) guipName = "AdvancedMoveJumpColor";

          // HTML color String from Preferences
          String moveTypeColor =
              Integer.toHexString(
                  GUIPreferences.getInstance().getColor(guipName).getRGB() & 0xFFFFFF);

          // Arrow
          addToTT("Arrow", BR, moveTypeColor);

          // Actual movement and modifier
          addToTT(
              "MovementF",
              NOBR,
              entity.getMovementString(entity.moved),
              entity.delta_distance,
              tmm);
        }
        // Special Moves
        if (entity.isEvading()) addToTT("Evade", NOBR);

        if ((thisInfantry != null) && (thisInfantry.isTakingCover())) addToTT("TakingCover", NOBR);

        if (entity.isCharging()) addToTT("Charging", NOBR);

        if (entity.isMakingDfa()) addToTT("DFA", NOBR);
      }
    }

    // ASF Velocity
    if (thisAero != null) {
      addToTT("AeroVelocity", BR, thisAero.getCurrentVelocity());
    }

    // Gun Emplacement Status
    if (thisGunEmp != null) {
      if (thisGunEmp.isTurret() && thisGunEmp.isTurretLocked(thisGunEmp.getLocTurret()))
        addToTT("TurretLocked", BR);
    }

    // Unit Immobile
    if ((thisGunEmp == null) && (entity.isImmobile())) addToTT("Immobile", BR);

    if (entity.isHiddenActivating()) {
      addToTT(
          "HiddenActivating",
          BR,
          IGame.Phase.getDisplayableName(entity.getHiddenActivationPhase()));
    } else if (entity.isHidden()) {
      addToTT("Hidden", BR);
    }

    // Jammed by ECM
    if (isAffectedByECM()) {
      addToTT("Jammed", BR);
    }

    // If DB, add information about who sees this Entity
    if (bv.game.getOptions().booleanOption("double_blind")) {
      StringBuffer playerList = new StringBuffer();
      boolean teamVision = bv.game.getOptions().booleanOption("team_vision");
      for (IPlayer player : entity.getWhoCanSee()) {
        if (player.isEnemyOf(entity.getOwner()) || !teamVision) {
          playerList.append(player.getName());
          playerList.append(", ");
        }
      }
      if (playerList.length() > 1) {
        playerList.delete(playerList.length() - 2, playerList.length());
        addToTT("SeenBy", BR, playerList.toString());
      }
    }

    // If sensors, display what sensors this unit is using
    if (bv.game.getOptions().booleanOption("tacops_sensors")) {
      addToTT("Sensors", BR, entity.getSensorDesc());
    }

    // Weapon List
    if (GUIPreferences.getInstance().getBoolean(GUIPreferences.SHOW_WPS_IN_TT)) {

      ArrayList<Mounted> weapons = entity.getWeaponList();
      HashMap<String, Integer> wpNames = new HashMap<String, Integer>();

      // Gather names, counts, Clan/IS
      // When clan then the number will be stored as negative
      for (Mounted curWp : weapons) {
        String weapDesc = curWp.getDesc();
        // Append ranges
        WeaponType wtype = (WeaponType) curWp.getType();
        int ranges[];
        if (entity instanceof Aero) {
          ranges = wtype.getATRanges();
        } else {
          ranges = wtype.getRanges(curWp);
        }
        String rangeString = "(";
        if ((ranges[RangeType.RANGE_MINIMUM] != WeaponType.WEAPON_NA)
            && (ranges[RangeType.RANGE_MINIMUM] != 0)) {
          rangeString += ranges[RangeType.RANGE_MINIMUM] + "/";
        } else {
          rangeString += "-/";
        }
        int maxRange = RangeType.RANGE_LONG;
        if (bv.game.getOptions().booleanOption(OptionsConstants.AC_TAC_OPS_RANGE)) {
          maxRange = RangeType.RANGE_EXTREME;
        }
        for (int i = RangeType.RANGE_SHORT; i <= maxRange; i++) {
          rangeString += ranges[i];
          if (i != maxRange) {
            rangeString += "/";
          }
        }

        weapDesc += rangeString + ")";
        if (wpNames.containsKey(weapDesc)) {
          int number = wpNames.get(weapDesc);
          if (number > 0) wpNames.put(weapDesc, number + 1);
          else wpNames.put(weapDesc, number - 1);
        } else {
          WeaponType wpT = ((WeaponType) curWp.getType());

          if (entity.isClan() && TechConstants.isClan(wpT.getTechLevel(entity.getYear())))
            wpNames.put(weapDesc, -1);
          else wpNames.put(weapDesc, 1);
        }
      }

      // Print to Tooltip
      tooltipString.append("<FONT SIZE=\"-2\">");

      for (Entry<String, Integer> entry : wpNames.entrySet()) {
        // Check if weapon is destroyed, text gray and strikethrough if so, remove the "x "/"*"
        // Also remove "+", means currently selected for firing
        boolean wpDest = false;
        String nameStr = entry.getKey();
        if (entry.getKey().startsWith("x ")) {
          nameStr = entry.getKey().substring(2, entry.getKey().length());
          wpDest = true;
        }

        if (entry.getKey().startsWith("*")) {
          nameStr = entry.getKey().substring(1, entry.getKey().length());
          wpDest = true;
        }

        if (entry.getKey().startsWith("+")) {
          nameStr = entry.getKey().substring(1, entry.getKey().length());
          nameStr = nameStr.concat(" <I>(Firing)</I>");
        }

        // normal coloring
        tooltipString.append("<FONT COLOR=#8080FF>");
        // but: color gray and strikethrough when weapon destroyed
        if (wpDest) tooltipString.append("<FONT COLOR=#a0a0a0><S>");

        String clanStr = "";
        if (entry.getValue() < 0) clanStr = Messages.getString("BoardView1.Tooltip.Clan");

        // when more than 5 weapons are present, they will be grouped
        // and listed with a multiplier
        if (weapons.size() > 5) {
          addToTT("WeaponN", BR, Math.abs(entry.getValue()), clanStr, nameStr);

        } else { // few weapons: list each weapon separately
          for (int i = 0; i < Math.abs(entry.getValue()); i++) {
            addToTT("Weapon", BR, Math.abs(entry.getValue()), clanStr, nameStr);
          }
        }
        // Weapon destroyed? End strikethrough
        if (wpDest) tooltipString.append("</S>");
        tooltipString.append("</FONT>");
      }
      tooltipString.append("</FONT>");
    }
    return tooltipString;
  }
Exemplo n.º 3
0
/**
 * Class which keeps set of all areas required to represent Protomech unit in MechDisplay.ArmorPanel
 * class.
 */
public class ProtomechMapSet implements DisplayMapSet {

  // Boring list of labels.
  private PMValueLabel[] sectionLabels = new PMValueLabel[Protomech.NUM_PMECH_LOCATIONS];
  private PMValueLabel[] armorLabels = new PMValueLabel[Protomech.NUM_PMECH_LOCATIONS];
  private PMValueLabel[] internalLabels = new PMValueLabel[Protomech.NUM_PMECH_LOCATIONS];
  private PMSimplePolygonArea[] areas = new PMSimplePolygonArea[Protomech.NUM_PMECH_LOCATIONS];

  private Polygon head =
      new Polygon(
          new int[] {50, 50, 60, 80, 90, 90, 80, 60},
          new int[] {40, 20, 10, 10, 20, 40, 50, 50},
          8);
  private Polygon mainGun = new Polygon(new int[] {20, 20, 50, 50}, new int[] {30, 0, 0, 30}, 4);
  private Polygon leftArm =
      new Polygon(
          new int[] {0, 0, 20, 30, 40, 30, 20, 20, 10},
          new int[] {100, 40, 30, 30, 60, 60, 70, 110, 110},
          9);
  private Polygon rightArm =
      new Polygon(
          new int[] {120, 120, 110, 100, 110, 120, 140, 140, 130},
          new int[] {110, 70, 60, 60, 30, 30, 40, 100, 110, 110},
          9);
  private Polygon torso =
      new Polygon(
          new int[] {40, 40, 30, 50, 50, 60, 80, 90, 90, 110, 100, 100},
          new int[] {130, 60, 30, 30, 40, 50, 50, 40, 30, 30, 60, 130},
          12);
  private Polygon legs =
      new Polygon(
          new int[] {
            0, 0, 10, 30, 30, 40, 100, 110, 110, 130, 140, 140, 100, 90, 90, 80, 60, 50, 50, 40
          },
          new int[] {
            240, 230, 220, 220, 160, 130, 130, 160, 220, 220, 230, 240, 240, 230, 190, 170, 170,
            190, 230, 240
          },
          20);

  // Reference to Component (required for Image handling)
  private JComponent comp;
  // Content group which will be sent to PicMap component
  private PMAreasGroup content = new PMAreasGroup();
  // Set of Backgrpund drawers which will be sent to PicMap component
  private Vector<BackGroundDrawer> bgDrawers = new Vector<BackGroundDrawer>();

  private static final Font FONT_VALUE =
      new Font(
          "SansSerif",
          Font.PLAIN,
          GUIPreferences.getInstance()
              .getInt("AdvancedMechDisplayArmorLargeFontSize")); // $NON-NLS-1$

  /** This constructor have to be called anly from addNotify() method */
  public ProtomechMapSet(JComponent c) {
    comp = c;
    setAreas();
    setBackGround();
  }

  /*
   * * Set the armor diagram on the mapset.
   */
  private void setAreas() {
    areas[Protomech.LOC_HEAD] = new PMSimplePolygonArea(head);
    areas[Protomech.LOC_LEG] = new PMSimplePolygonArea(legs);
    areas[Protomech.LOC_LARM] = new PMSimplePolygonArea(leftArm);
    areas[Protomech.LOC_RARM] = new PMSimplePolygonArea(rightArm);
    areas[Protomech.LOC_TORSO] = new PMSimplePolygonArea(torso);
    areas[Protomech.LOC_MAINGUN] = new PMSimplePolygonArea(mainGun);

    for (int i = 0; i <= 5; i++) {
      content.addArea(areas[i]);
    }

    FontMetrics fm = comp.getFontMetrics(FONT_VALUE);

    for (int i = 0; i < Protomech.NUM_PMECH_LOCATIONS; i++) {
      sectionLabels[i] = new PMValueLabel(fm, Color.black);
      content.addArea(sectionLabels[i]);
      armorLabels[i] = new PMValueLabel(fm, Color.yellow.brighter());
      content.addArea(armorLabels[i]);
      internalLabels[i] = new PMValueLabel(fm, Color.red.brighter());
      content.addArea(internalLabels[i]);
    }
    sectionLabels[0].moveTo(70, 30);
    armorLabels[0].moveTo(60, 45);
    internalLabels[0].moveTo(80, 45);
    sectionLabels[1].moveTo(70, 70);
    armorLabels[1].moveTo(70, 85);
    internalLabels[1].moveTo(70, 100);
    sectionLabels[2].moveTo(125, 55);
    armorLabels[2].moveTo(125, 70);
    internalLabels[2].moveTo(125, 85);
    sectionLabels[3].moveTo(15, 55);
    armorLabels[3].moveTo(15, 70);
    internalLabels[3].moveTo(15, 85);
    sectionLabels[4].moveTo(70, 150);
    armorLabels[4].moveTo(60, 165);
    internalLabels[4].moveTo(80, 165);
    sectionLabels[5].moveTo(35, 15);
    armorLabels[5].moveTo(25, 30);
    internalLabels[5].moveTo(45, 30);
  }

  public PMAreasGroup getContentGroup() {
    return content;
  }

  public Vector<BackGroundDrawer> getBackgroundDrawers() {
    return bgDrawers;
  }

  /**
   * Show the diagram for the given Protomech.
   *
   * @param entity - the <code>Entity</code> to be displayed. This should be a <code>Protomech
   *     </code> unit.
   */
  public void setEntity(Entity entity) {
    Protomech proto = (Protomech) entity;

    int loc = proto.locations();
    if (loc != Protomech.NUM_PMECH_LOCATIONS) {
      armorLabels[5].setVisible(false);
      internalLabels[5].setVisible(false);
      sectionLabels[5].setVisible(false);
    } else {
      armorLabels[5].setVisible(true);
      internalLabels[5].setVisible(true);
      sectionLabels[5].setVisible(true);
    }
    for (int i = 0; i < loc; i++) {
      // armor = proto.getArmor(i);
      // internal = proto.getInternal(i);
      armorLabels[i].setValue(proto.getArmorString(i));
      internalLabels[i].setValue(proto.getInternalString(i));
      sectionLabels[i].setValue(proto.getLocationAbbr(i));
    }
  }

  /*
   * * Sets the background on the mapset.
   */
  private void setBackGround() {
    Image tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "tile.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    int b = BackGroundDrawer.TILING_BOTH;
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_HORIZONTAL | BackGroundDrawer.VALIGN_TOP;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "h_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_HORIZONTAL | BackGroundDrawer.VALIGN_BOTTOM;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "h_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_VERTICAL | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "v_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_VERTICAL | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "v_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_TOP | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "tl_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_BOTTOM | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "bl_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_TOP | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "tr_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_BOTTOM | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "br_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));
  }
}
Exemplo n.º 4
0
  /**
   * Creates the sprite for this entity. Fortunately it is no longer an extra pain to create
   * transparent images in AWT.
   */
  @Override
  public void prepare() {
    final IBoard board = bv.game.getBoard();

    // recalculate bounds & label
    getBounds();

    // create image for buffer
    GraphicsConfiguration config =
        GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice()
            .getDefaultConfiguration();
    image = config.createCompatibleImage(bounds.width, bounds.height, Transparency.TRANSLUCENT);
    Graphics2D graph = (Graphics2D) image.getGraphics();
    GUIPreferences.AntiAliasifSet(graph);

    // translate everything (=correction for label placement)
    graph.translate(-hexOrigin.x, -hexOrigin.y);

    if (!bv.useIsometric()) {
      // The entity sprite is drawn when the hexes are rendered.
      // So do not include the sprite info here.
      if (onlyDetectedBySensors()) {
        graph.drawImage(bv.getScaledImage(radarBlipImage, true), 0, 0, this);
      } else {
        // draw the unit icon translucent if:
        // hidden from the enemy (and activated graphics setting); or
        // submerged
        boolean translucentHiddenUnits =
            GUIPreferences.getInstance()
                .getBoolean(GUIPreferences.ADVANCED_TRANSLUCENT_HIDDEN_UNITS);
        boolean shouldBeTranslucent =
            (trackThisEntitiesVisibilityInfo(entity) && !entity.isVisibleToEnemy())
                || entity.isHidden();
        if ((shouldBeTranslucent && translucentHiddenUnits) || (entity.relHeight() < 0)) {
          graph.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        }
        graph.drawImage(
            bv.getScaledImage(bv.tileManager.imageFor(entity, secondaryPos), true), 0, 0, this);
        graph.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
      }
    }

    // scale the following draws according to board zoom
    graph.scale(bv.scale, bv.scale);

    boolean isInfantry = (entity instanceof Infantry);
    boolean isAero = (entity instanceof Aero);

    if ((isAero && ((Aero) entity).isSpheroid() && !board.inSpace()) && (secondaryPos == 1)) {
      graph.setColor(Color.WHITE);
      graph.draw(bv.facingPolys[entity.getFacing()]);
    }

    if ((secondaryPos == -1) || (secondaryPos == 6)) {

      // Gather unit conditions
      ArrayList<Status> stStr = new ArrayList<Status>();
      criticalStatus = false;

      // Determine if the entity has a locked turret,
      // and if it is a gun emplacement
      boolean turretLocked = false;
      int crewStunned = 0;
      boolean ge = false;
      if (entity instanceof Tank) {
        turretLocked = !((Tank) entity).hasNoTurret() && !entity.canChangeSecondaryFacing();
        crewStunned = ((Tank) entity).getStunnedTurns();
        ge = entity instanceof GunEmplacement;
      }

      // draw elevation/altitude if non-zero
      if (entity.isAirborne()) {
        if (!board.inSpace()) {
          stStr.add(new Status(Color.CYAN, "A", SMALL));
          stStr.add(new Status(Color.CYAN, Integer.toString(entity.getAltitude()), SMALL));
        }
      } else if (entity.getElevation() != 0) {
        stStr.add(new Status(Color.CYAN, Integer.toString(entity.getElevation()), SMALL));
      }

      // Shutdown
      if (entity.isManualShutdown()) {
        stStr.add(new Status(Color.YELLOW, "SHUTDOWN"));
      } else if (entity.isShutDown()) {
        stStr.add(new Status(Color.RED, "SHUTDOWN"));
      }

      // Prone, Hulldown, Stuck, Immobile, Jammed
      if (entity.isProne()) stStr.add(new Status(Color.RED, "PRONE"));
      if (entity.isHiddenActivating()) stStr.add(new Status(Color.RED, "ACTIVATING"));
      if (entity.isHidden()) stStr.add(new Status(Color.RED, "HIDDEN"));
      if (entity.isHullDown()) stStr.add(new Status(Color.ORANGE, "HULLDOWN"));
      if ((entity.isStuck())) stStr.add(new Status(Color.ORANGE, "STUCK"));
      if (!ge && entity.isImmobile()) stStr.add(new Status(Color.RED, "IMMOBILE"));
      if (isAffectedByECM()) stStr.add(new Status(Color.YELLOW, "Jammed"));

      // Turret Lock
      if (turretLocked) stStr.add(new Status(Color.YELLOW, "LOCKED"));

      // Grappling & Swarming
      if (entity.getGrappled() != Entity.NONE) {
        if (entity.isGrappleAttacker()) {
          stStr.add(new Status(Color.YELLOW, "GRAPPLER"));
        } else {
          stStr.add(new Status(Color.RED, "GRAPPLED"));
        }
      }
      if (entity.getSwarmAttackerId() != Entity.NONE) {
        stStr.add(new Status(Color.RED, "SWARMED"));
      }

      // Transporting
      if ((entity.getLoadedUnits()).size() > 0) {
        stStr.add(new Status(Color.YELLOW, "T", SMALL));
      }

      // Hidden, Unseen Unit
      if (trackThisEntitiesVisibilityInfo(entity)) {
        if (!entity.isEverSeenByEnemy()) {
          stStr.add(new Status(Color.GREEN, "U", SMALL));
        } else if (!entity.isVisibleToEnemy()) {
          stStr.add(new Status(Color.GREEN, "H", SMALL));
        }
      }

      // Crew
      if (entity.getCrew().isDead()) stStr.add(new Status(Color.RED, "CrewDead"));
      if (crewStunned > 0) {
        stStr.add(new Status(Color.YELLOW, "STUNNED", new Object[] {crewStunned}));
      }

      // Infantry
      if (isInfantry) {
        int dig = ((Infantry) entity).getDugIn();
        if (dig == Infantry.DUG_IN_COMPLETE) {
          stStr.add(new Status(Color.PINK, "D", SMALL));
        } else if (dig != Infantry.DUG_IN_NONE) {
          stStr.add(new Status(Color.YELLOW, "Working", DIRECT));
          stStr.add(new Status(Color.PINK, "D", SMALL));
        } else if (((Infantry) entity).isTakingCover()) {
          stStr.add(new Status(Color.YELLOW, "TakingCover"));
        }
      }

      // Aero
      if (isAero) {
        Aero a = (Aero) entity;
        if (a.isRolled()) stStr.add(new Status(Color.YELLOW, "ROLLED"));
        if (a.getFuel() <= 0) stStr.add(new Status(Color.RED, "FUEL"));
        if (a.isEvading()) stStr.add(new Status(Color.GREEN, "EVADE"));

        if (a.isOutControlTotal() & a.isRandomMove()) {
          stStr.add(new Status(Color.RED, "RANDOM"));
        } else if (a.isOutControlTotal()) {
          stStr.add(new Status(Color.RED, "CONTROL"));
        }
      }

      if (GUIPreferences.getInstance().getShowDamageLevel()) {
        Color damageColor = getDamageColor();
        if (damageColor != null) {
          stStr.add(new Status(damageColor, 0, SMALL));
        }
      }

      // Unit Label
      // no scaling for the label, its size is changed by varying
      // the font size directly => better control
      graph.scale(1 / bv.scale, 1 / bv.scale);

      // Label background
      if (criticalStatus) {
        graph.setColor(LABEL_CRITICAL_BACK);
      } else {
        graph.setColor(LABEL_BACK);
      }
      graph.fillRoundRect(labelRect.x, labelRect.y, labelRect.width, labelRect.height, 5, 10);

      // Label text
      graph.setFont(labelFont);
      Color textColor = LABEL_TEXT_COLOR;
      if (!entity.isDone() && !onlyDetectedBySensors()) {
        textColor =
            GUIPreferences.getInstance().getColor(GUIPreferences.ADVANCED_UNITOVERVIEW_VALID_COLOR);
      }
      if (isSelected) {
        textColor =
            GUIPreferences.getInstance()
                .getColor(GUIPreferences.ADVANCED_UNITOVERVIEW_SELECTED_COLOR);
      }
      bv.drawCenteredText(
          graph,
          getAdjShortName(),
          labelRect.x + labelRect.width / 2,
          labelRect.y + labelRect.height / 2 - 1,
          textColor,
          (entity.isDone() && !onlyDetectedBySensors()));

      // Past here, everything is drawing status that shouldn't be seen
      // on a sensor return, so we'll just quit here
      if (onlyDetectedBySensors()) {
        graph.dispose();
        return;
      }

      // Draw all the status information now
      drawStatusStrings(graph, stStr);

      // from here, scale the following draws according to board zoom
      graph.scale(bv.scale, bv.scale);

      // draw facing
      graph.setColor(Color.white);
      if ((entity.getFacing() != -1)
          && !(isInfantry
              && !((Infantry) entity).hasFieldGun()
              && !((Infantry) entity).isTakingCover())
          && !(isAero && ((Aero) entity).isSpheroid() && !board.inSpace())) {
        graph.draw(bv.facingPolys[entity.getFacing()]);
      }

      // determine secondary facing for non-mechs & flipped arms
      int secFacing = entity.getFacing();
      if (!((entity instanceof Mech) || (entity instanceof Protomech))) {
        secFacing = entity.getSecondaryFacing();
      } else if (entity.getArmsFlipped()) {
        secFacing = (entity.getFacing() + 3) % 6;
      }
      // draw red secondary facing arrow if necessary
      if ((secFacing != -1) && (secFacing != entity.getFacing())) {
        graph.setColor(Color.red);
        graph.draw(bv.facingPolys[secFacing]);
      }
      if ((entity instanceof Aero) && this.bv.game.useVectorMove()) {
        for (int head : entity.getHeading()) {
          graph.setColor(Color.red);
          graph.draw(bv.facingPolys[head]);
        }
      }

      // armor and internal status bars
      int baseBarLength = 23;
      int barLength = 0;
      double percentRemaining = 0.00;

      percentRemaining = entity.getArmorRemainingPercent();
      barLength = (int) (baseBarLength * percentRemaining);

      graph.setColor(Color.darkGray);
      graph.fillRect(56, 7, 23, 3);
      graph.setColor(Color.lightGray);
      graph.fillRect(55, 6, 23, 3);
      graph.setColor(getStatusBarColor(percentRemaining));
      graph.fillRect(55, 6, barLength, 3);

      if (!ge) {
        // Gun emplacements don't have internal structure
        percentRemaining = entity.getInternalRemainingPercent();
        barLength = (int) (baseBarLength * percentRemaining);

        graph.setColor(Color.darkGray);
        graph.fillRect(56, 11, 23, 3);
        graph.setColor(Color.lightGray);
        graph.fillRect(55, 10, 23, 3);
        graph.setColor(getStatusBarColor(percentRemaining));
        graph.fillRect(55, 10, barLength, 3);
      }
    }

    graph.dispose();
  }
Exemplo n.º 5
0
/** Set of elements to reperesent pilot information in MechDisplay */
public class PilotMapSet implements DisplayMapSet {

  private static String STAR3 = "***"; // $NON-NLS-1$
  private static int N_ADV = 35;
  private JComponent comp;
  private PMAreasGroup content = new PMAreasGroup();
  private PMPicArea portraitArea;
  private PMSimpleLabel nameL,
      nickL,
      pilotL,
      gunneryL,
      gunneryLL,
      gunneryML,
      gunneryBL,
      toughBL,
      initBL,
      commandBL;
  private PMSimpleLabel pilotR,
      gunneryR,
      gunneryLR,
      gunneryMR,
      gunneryBR,
      toughBR,
      initBR,
      commandBR,
      hitsR;
  private PMSimpleLabel[] advantagesR;
  private Vector<BackGroundDrawer> bgDrawers = new Vector<BackGroundDrawer>();
  private static final Font FONT_VALUE =
      new Font(
          "SansSerif",
          Font.PLAIN,
          GUIPreferences.getInstance().getInt("AdvancedMechDisplayLargeFontSize")); // $NON-NLS-1$
  private static final Font FONT_TITLE =
      new Font(
          "SansSerif",
          Font.ITALIC,
          GUIPreferences.getInstance().getInt("AdvancedMechDisplayLargeFontSize")); // $NON-NLS-1$
  private int yCoord = 1;

  // keep track of portrait images
  private DirectoryItems portraits;

  /** This constructor have to be called anly from addNotify() method */
  public PilotMapSet(JComponent c) {
    comp = c;
    try {
      portraits =
          new DirectoryItems(
              Configuration.portraitImagesDir(),
              "", //$NON-NLS-1$
              ImageFileFactory.getInstance());
    } catch (Exception e) {
      portraits = null;
    }
    setAreas();
    setBackGround();
  }

  // These two methods are used to vertically position new labels on the
  // display.
  private int getYCoord() {
    return (yCoord * 15) - 5;
  }

  private int getNewYCoord() {
    yCoord++;
    return getYCoord();
  }

  private void setAreas() {
    portraitArea = new PMPicArea(new BufferedImage(72, 72, BufferedImage.TYPE_BYTE_INDEXED));
    content.addArea(portraitArea);
    yCoord = 6;
    FontMetrics fm = comp.getFontMetrics(FONT_TITLE);
    nameL =
        createLabel(
            Messages.getString("GeneralInfoMapSet.LocOstLCT"), fm, 0, getYCoord()); // $NON-NLS-1$
    nameL.setColor(Color.yellow);
    content.addArea(nameL);

    fm = comp.getFontMetrics(FONT_VALUE);
    nickL =
        createLabel(
            Messages.getString("GeneralInfoMapSet.LocOstLCT"),
            fm,
            0,
            getNewYCoord()); //$NON-NLS-1$
    content.addArea(nickL);

    hitsR = createLabel(STAR3, fm, 0, getNewYCoord());
    hitsR.setColor(Color.RED);
    content.addArea(hitsR);
    getNewYCoord();

    pilotL =
        createLabel(
            Messages.getString("PilotMapSet.pilotLAntiMech"), fm, 0, getNewYCoord()); // $NON-NLS-1$
    content.addArea(pilotL);
    pilotR = createLabel(STAR3, fm, pilotL.getSize().width + 5, getYCoord());
    content.addArea(pilotR);

    initBL =
        createLabel(
            Messages.getString("PilotMapSet.initBL"),
            fm,
            pilotL.getSize().width + 50,
            getYCoord()); //$NON-NLS-1$
    content.addArea(initBL);
    initBR =
        createLabel(
            STAR3, fm, pilotL.getSize().width + 50 + initBL.getSize().width + 15, getYCoord());
    content.addArea(initBR);

    gunneryL =
        createLabel(
            Messages.getString("PilotMapSet.gunneryL"), fm, 0, getNewYCoord()); // $NON-NLS-1$
    content.addArea(gunneryL);
    gunneryR = createLabel(STAR3, fm, pilotL.getSize().width + 5, getYCoord());
    content.addArea(gunneryR);

    commandBL =
        createLabel(
            Messages.getString("PilotMapSet.commandBL"),
            fm,
            pilotL.getSize().width + 50,
            getYCoord()); //$NON-NLS-1$
    content.addArea(commandBL);
    commandBR =
        createLabel(
            STAR3, fm, pilotL.getSize().width + 50 + initBL.getSize().width + 15, getYCoord());
    content.addArea(commandBR);

    gunneryLL =
        createLabel(Messages.getString("PilotMapSet.gunneryLL"), fm, 0, getYCoord()); // $NON-NLS-1$
    content.addArea(gunneryLL);
    gunneryLR = createLabel(STAR3, fm, pilotL.getSize().width + 25, getYCoord());
    content.addArea(gunneryLR);

    gunneryML =
        createLabel(
            Messages.getString("PilotMapSet.gunneryML"), fm, 0, getNewYCoord()); // $NON-NLS-1$
    content.addArea(gunneryML);
    gunneryMR = createLabel(STAR3, fm, pilotL.getSize().width + 25, getYCoord());
    content.addArea(gunneryMR);

    toughBL =
        createLabel(
            Messages.getString("PilotMapSet.toughBL"),
            fm,
            pilotL.getSize().width + 50,
            getYCoord()); //$NON-NLS-1$
    content.addArea(toughBL);
    toughBR =
        createLabel(
            STAR3, fm, pilotL.getSize().width + 50 + initBL.getSize().width + 15, getYCoord());
    content.addArea(toughBR);

    gunneryBL =
        createLabel(
            Messages.getString("PilotMapSet.gunneryBL"), fm, 0, getNewYCoord()); // $NON-NLS-1$
    content.addArea(gunneryBL);
    gunneryBR = createLabel(STAR3, fm, pilotL.getSize().width + 25, getYCoord());
    content.addArea(gunneryBR);

    getNewYCoord();
    advantagesR = new PMSimpleLabel[N_ADV];
    for (int i = 0; i < advantagesR.length; i++) {
      advantagesR[i] = createLabel(new Integer(i).toString(), fm, 10, getNewYCoord());
      content.addArea(advantagesR[i]);
    }
    // DO NOT PLACE ANY MORE LABELS BELOW HERE. They will get
    // pushed off the bottom of the screen by the pilot advantage
    // labels. Why not just allocate the number of pilot advantage
    // labels required instead of a hard 24? Because we don't have
    // an entity at this point. Bleh.
  }

  /** updates fields for the unit */
  public void setEntity(Entity en) {

    if (en instanceof Infantry) {
      pilotL.setString(Messages.getString("PilotMapSet.pilotLAntiMech"));
    } else {
      pilotL.setString(Messages.getString("PilotMapSet.pilotL"));
    }
    nameL.setString(en.getCrew().getName());
    nickL.setString(en.getCrew().getNickname());
    pilotR.setString(Integer.toString(en.getCrew().getPiloting()));
    gunneryR.setString(Integer.toString(en.getCrew().getGunnery()));

    if (null != getPortrait(en.getCrew())) {
      portraitArea.setIdleImage(getPortrait(en.getCrew()));
    }

    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("rpg_gunnery")) {
      gunneryLR.setString(Integer.toString(en.getCrew().getGunneryL()));
      gunneryMR.setString(Integer.toString(en.getCrew().getGunneryM()));
      gunneryBR.setString(Integer.toString(en.getCrew().getGunneryB()));
      gunneryL.setVisible(false);
      gunneryR.setVisible(false);
      gunneryLL.setVisible(true);
      gunneryLR.setVisible(true);
      gunneryML.setVisible(true);
      gunneryMR.setVisible(true);
      gunneryBL.setVisible(true);
      gunneryBR.setVisible(true);
    } else {
      gunneryLL.setVisible(false);
      gunneryLR.setVisible(false);
      gunneryML.setVisible(false);
      gunneryMR.setVisible(false);
      gunneryBL.setVisible(false);
      gunneryBR.setVisible(false);
      gunneryL.setVisible(true);
      gunneryR.setVisible(true);
    }
    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("toughness")) {
      toughBR.setString(Integer.toString(en.getCrew().getToughness()));
    } else {
      toughBL.setVisible(false);
      toughBR.setVisible(false);
    }
    if ((en.getGame() != null)
        && en.getGame().getOptions().booleanOption("individual_initiative")) {
      initBR.setString(Integer.toString(en.getCrew().getInitBonus()));
    } else {
      initBL.setVisible(false);
      initBR.setVisible(false);
    }
    if ((en.getGame() != null) && en.getGame().getOptions().booleanOption("command_init")) {
      commandBR.setString(Integer.toString(en.getCrew().getCommandBonus()));
    } else {
      commandBL.setVisible(false);
      commandBR.setVisible(false);
    }
    hitsR.setString(en.getCrew().getStatusDesc());
    for (int i = 0; i < advantagesR.length; i++) {
      advantagesR[i].setString(""); // $NON-NLS-1$
    }
    int i = 0;
    for (Enumeration<IOptionGroup> advGroups = en.getCrew().getOptions().getGroups();
        advGroups.hasMoreElements(); ) {
      if (i >= (N_ADV - 1)) {
        advantagesR[i++].setString(Messages.getString("PilotMapSet.more"));
        break;
      }
      IOptionGroup advGroup = advGroups.nextElement();
      if (en.getCrew().countOptions(advGroup.getKey()) > 0) {
        advantagesR[i++].setString(advGroup.getDisplayableName());
        for (Enumeration<IOption> advs = advGroup.getOptions(); advs.hasMoreElements(); ) {
          if (i >= (N_ADV - 1)) {
            advantagesR[i++].setString("  " + Messages.getString("PilotMapSet.more"));
            break;
          }
          IOption adv = advs.nextElement();
          if (adv.booleanValue()) {
            advantagesR[i++].setString("  " + adv.getDisplayableNameWithValue());
          }
        }
      }
    }
  }

  public PMAreasGroup getContentGroup() {
    return content;
  }

  public Vector<BackGroundDrawer> getBackgroundDrawers() {
    return bgDrawers;
  }

  private void setBackGround() {
    Image tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "tile.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    int b = BackGroundDrawer.TILING_BOTH;
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_HORIZONTAL | BackGroundDrawer.VALIGN_TOP;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "h_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_HORIZONTAL | BackGroundDrawer.VALIGN_BOTTOM;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "h_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_VERTICAL | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "v_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.TILING_VERTICAL | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(new File(Configuration.widgetsDir(), "v_line.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_TOP | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "tl_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_BOTTOM | BackGroundDrawer.HALIGN_LEFT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "bl_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_TOP | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "tr_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));

    b = BackGroundDrawer.NO_TILING | BackGroundDrawer.VALIGN_BOTTOM | BackGroundDrawer.HALIGN_RIGHT;
    tile =
        comp.getToolkit()
            .getImage(
                new File(Configuration.widgetsDir(), "br_corner.gif").toString()); // $NON-NLS-1$
    PMUtil.setImage(tile, comp);
    bgDrawers.addElement(new BackGroundDrawer(tile, b));
  }

  private PMSimpleLabel createLabel(String s, FontMetrics fm, int x, int y) {
    PMSimpleLabel l = new PMSimpleLabel(s, fm, Color.white);
    l.moveTo(x, y);
    return l;
  }

  /**
   * Get the portrait for the given pilot.
   *
   * @return The <code>Image</code> of the pilot's portrait. This value will be <code>null</code> if
   *     no portrait was selected or if there was an error loading it.
   */
  public Image getPortrait(Crew pilot) {

    String category = pilot.getPortraitCategory();
    String file = pilot.getPortraitFileName();

    // Return a null if the player has selected no portrait file.
    if ((null == category) || (null == file) || (null == portraits)) {
      return null;
    }

    if (Crew.PORTRAIT_NONE.equals(file)) {
      file = "default.gif"; // $NON-NLS-1$
    }

    if (Crew.ROOT_PORTRAIT.equals(category)) {
      category = "";
    }

    // Try to get the player's portrait file.
    Image portrait = null;
    try {
      portrait = (Image) portraits.getItem(category, file);
      if (null == portrait) {
        // the image could not be found so switch to default one
        category = "";
        file = "default.gif";
        portrait = (Image) portraits.getItem(category, file);
      }
      // make sure no images are longer than 72 pixels
      if (null != portrait) {
        portrait = portrait.getScaledInstance(-1, 72, Image.SCALE_DEFAULT);
      }
    } catch (Exception err) {
      err.printStackTrace();
    }
    return portrait;
  }
}