@Override
  public void scaleView() {
    // Slot sizes
    skillBoxSize = (int) (((double) getScreenWidth() / 15));
    imgSize = (int) ((double) skillBoxSize * .40);
    levelUpBoxSize = (int) ((double) skillBoxSize * .60);
    plusIconSize = (int) ((double) skillBoxSize * .45);

    // Rect size
    skillRectWidth = skillCount * skillBoxSize;
    skillRectHeight = skillBoxSize;

    // Coordinates for skill box
    skillBoxStartX = (getScreenWidth() - skillRectWidth) / 2;
    skillBoxStartY = getScreenHeight() - skillRectHeight - 25;

    // Coordinates for level up boxes
    levelUpBoxLeftX = skillBoxStartX + (skillBoxSize - levelUpBoxSize) / 2;
    int skillBoxRight = skillBoxStartX + skillBoxSize;
    levelUpBoxLeftXDistanceGap =
        skillBoxRight + (skillBoxSize - levelUpBoxSize) / 2 - levelUpBoxLeftX;
    levelUpBoxRightX =
        levelUpBoxLeftX + ((skillCount - 1) * levelUpBoxLeftXDistanceGap) + levelUpBoxSize;
    levelUpBoxBottomY = skillBoxStartY;
    levelUpBoxTopY = levelUpBoxBottomY - levelUpBoxSize;

    // Font
    keyBindFontSize = getScreenWidth() / 100;
    skillLabelFontSize = keyBindFontSize;
    CDFontSize = getScreenWidth() / 50;

    skillLabelFont = new Font("Courier New", Font.PLAIN, skillLabelFontSize);

    // Setup keybind font
    keyBindFont = new Font("Courier New", Font.BOLD, keyBindFontSize);
    Map<TextAttribute, Object> attributes = new HashMap<>();
    attributes.put(TextAttribute.FAMILY, keyBindFont.getFamily());
    attributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_EXTRABOLD);
    attributes.put(TextAttribute.SIZE, (int) (keyBindFont.getSize() * 1.5));
    keyBindFont = Font.getFont(attributes);

    CDFont = new Font("Courier New", Font.PLAIN, CDFontSize);
  }
Ejemplo n.º 2
0
  private void draw() {
    Renderer renderer = ui.getRenderer();
    Graphics g = renderer.getGraphics();
    int fsize = g.getFont().getSize();
    JPanel target = ui.getDrawTarget();

    g.setColor(Color.GRAY);
    g.fillRect(0, 0, target.getWidth(), target.getHeight());

    Map<CabinType, Integer> xmap =
        new HashMap<CabinType, Integer>() {
          {
            this.put(CabinType.LEFT, Floor.PIXEL_WIDTH + 10);
            this.put(CabinType.RIGHT, Floor.PIXEL_WIDTH + 10 + Cabin.PIXEL_WIDTH + 30);
          }
        };

    for (CabinType type : cabins.keySet()) {
      Integer x = xmap.get(type);
      Cabin cabin = cabins.get(type);

      int passengers = cabin.getPassengers().size();
      double cabinY = cabin.getPosition() * REAL_TO_PIXEL_RATIO,
          cabinH = (double) cabin.PIXEL_HEIGHT,
          cabinW = (double) cabin.PIXEL_WIDTH;

      g.setColor(Color.WHITE);
      g.fillRect(x, (int) cabinY, (int) cabinW, (int) cabinH);
      g.setColor(Color.BLACK);
      g.drawRect(x, (int) cabinY, (int) cabinW, (int) cabinH);
      // cabin fullness
      g.drawString(
          passengers >= cabinLimitPeople ? passengers > cabinLimitPeople ? "초과" : "만원" : "",
          (int) (x + cabinW / 2.0 - fsize),
          (int) (cabinY + cabinH / 2.0 - fsize));
      // passengers on cabin
      g.drawString(
          String.format("%d명", passengers),
          (int) (x + cabinW / 2.0 - fsize * 2.0 / 2.0),
          (int) (cabinY + cabinH / 2.0));
      // cabin weight
      g.drawString(String.format("%.0fkg", mass(cabin)), x, (int) (cabinY + cabinH / 2.0 + fsize));
      // cabin speed
      g.drawString(
          String.format("%.1fm/s", Math.abs(cabin.getVelocity())),
          x,
          (int) (cabinY + cabinH / 2.0 + fsize * 2.0));
    }

    for (Floor floor : floors.values()) {
      int passengers = floor.getPassengers().size();
      double floorY = floor.getPosition() * REAL_TO_PIXEL_RATIO;
      g.setFont(Font.getFont(Font.SANS_SERIF));
      g.setColor(Color.WHITE);
      g.fillRect(1, (int) floorY, Floor.PIXEL_WIDTH, Floor.PIXEL_HEIGHT);
      g.setColor(Color.BLACK);
      g.drawRect(1, (int) floorY, Floor.PIXEL_WIDTH, Floor.PIXEL_HEIGHT);
      g.drawString(floor.getNum() + "층", 1, (int) floorY + 15);
      g.drawString(
          Integer.toString(passengers),
          (int) (1 + (double) (Floor.PIXEL_WIDTH) / 2.0 - (double) fsize / 2.0),
          (int) (floorY + (double) Floor.PIXEL_HEIGHT / 2.0));
    }
    if (state >> 1 == CircumstanceType.FIRE.state()) {
      Floor firedFloor = (Floor) Circumstance.get(CircumstanceType.FIRE).getParameter("floor");
      if (null != firedFloor)
        g.drawString(
            "화재",
            Floor.PIXEL_WIDTH / 2 - fsize,
            (int)
                (firedFloor.getPosition() * REAL_TO_PIXEL_RATIO
                    + (double) Floor.PIXEL_HEIGHT / 2.0
                    + fsize * 2.0));
    }
    renderer.flush();
  }