Пример #1
0
      @Override
      public void draw(GameContainer container, StateBasedGame game, Graphics g) {
        int width = container.getWidth();
        int height = container.getHeight();

        // score multiplier (TODO: fade in color changes)
        float mult = GameMod.getScoreMultiplier();
        String multString = String.format("Score Multiplier: %.2fx", mult);
        Color multColor = (mult == 1f) ? Color.white : (mult > 1f) ? Color.green : Color.red;
        float multY = Utils.FONT_LARGE.getLineHeight() * 2 + height * 0.06f;
        Utils.FONT_LARGE.drawString(
            (width - Utils.FONT_LARGE.getWidth(multString)) / 2f, multY, multString, multColor);

        // category text
        for (GameMod.Category category : GameMod.Category.values()) {
          Utils.FONT_LARGE.drawString(
              category.getX(),
              category.getY() - Utils.FONT_LARGE.getLineHeight() / 2f,
              category.getName(),
              category.getColor());
        }

        // buttons
        for (GameMod mod : GameMod.values()) mod.draw();

        super.draw(container, game, g);
      }
Пример #2
0
    /**
     * Draws the title and buttons to the graphics context.
     *
     * @param container the game container
     * @param game the game
     * @param g the graphics context
     */
    public void draw(GameContainer container, StateBasedGame game, Graphics g) {
      // draw title
      if (actualTitle != null) {
        float marginX = container.getWidth() * 0.015f, marginY = container.getHeight() * 0.01f;
        int lineHeight = Utils.FONT_LARGE.getLineHeight();
        for (int i = 0, size = actualTitle.size(); i < size; i++)
          Utils.FONT_LARGE.drawString(
              marginX, marginY + (i * lineHeight), actualTitle.get(i), Color.white);
      }

      // draw buttons
      for (int i = 0; i < buttons.length; i++) menuButtons[i].draw(buttons[i].getColor());

      UI.draw(g);
    }
Пример #3
0
    /**
     * Processes a state enter request.
     *
     * @param container the game container
     * @param game the game
     */
    public void enter(GameContainer container, StateBasedGame game) {
      float center = container.getWidth() / 2f;
      float centerOffsetX = container.getWidth() * OFFSET_WIDTH_RATIO;
      centerOffset = new AnimatedValue(700, centerOffsetX, 0, AnimationEquation.OUT_BOUNCE);
      for (int i = 0; i < buttons.length; i++) {
        menuButtons[i].setX(center + ((i % 2 == 0) ? centerOffsetX : centerOffsetX * -1));
        menuButtons[i].resetHover();
      }

      // create title string list
      actualTitle = new ArrayList<String>();
      String[] title = getTitle(container, game);
      int maxLineWidth = (int) (container.getWidth() * 0.96f);
      for (int i = 0; i < title.length; i++) {
        // wrap text if too long
        if (Utils.FONT_LARGE.getWidth(title[i]) > maxLineWidth) {
          List<String> list = Utils.wrap(title[i], Utils.FONT_LARGE, maxLineWidth);
          actualTitle.addAll(list);
        } else actualTitle.add(title[i]);
      }
    }
Пример #4
0
 /**
  * Returns the base Y coordinate for the buttons.
  *
  * @param container the game container
  * @param game the game
  */
 protected float getBaseY(GameContainer container, StateBasedGame game) {
   float baseY = container.getHeight() * 0.2f;
   baseY += ((getTitle(container, game).length - 1) * Utils.FONT_LARGE.getLineHeight());
   return baseY;
 }