Exemplo n.º 1
0
  @Override
  public void render(GameContainer container, StateBasedGame game, Graphics g)
      throws SlickException {
    int width = container.getWidth();
    int height = container.getHeight();

    // draw background
    Beatmap beatmap = MusicController.getBeatmap();
    if (Options.isDynamicBackgroundEnabled()
        && beatmap != null
        && beatmap.drawBG(width, height, bgAlpha, true)) ;
    else {
      Image bg = GameImage.MENU_BG.getImage();
      bg.setAlpha(bgAlpha);
      bg.draw();
    }

    // top/bottom horizontal bars
    float oldAlpha = Utils.COLOR_BLACK_ALPHA.a;
    Utils.COLOR_BLACK_ALPHA.a = 0.2f;
    g.setColor(Utils.COLOR_BLACK_ALPHA);
    g.fillRect(0, 0, width, height / 9f);
    g.fillRect(0, height * 8 / 9f, width, height / 9f);
    Utils.COLOR_BLACK_ALPHA.a = oldAlpha;

    // draw downloads button
    downloadsButton.draw();

    // draw buttons
    if (logoTimer > 0) {
      playButton.draw();
      exitButton.draw();
      optionsButton.draw();
    }
    logo.draw();

    // draw music buttons
    if (MusicController.isPlaying()) musicPause.draw();
    else musicPlay.draw();
    musicNext.draw();
    musicPrevious.draw();

    // draw music position bar
    int mouseX = input.getMouseX(), mouseY = input.getMouseY();
    g.setColor((musicPositionBarContains(mouseX, mouseY)) ? BG_HOVER : BG_NORMAL);
    g.fillRoundRect(musicBarX, musicBarY, musicBarWidth, musicBarHeight, 4);
    g.setColor(Color.white);
    if (!MusicController.isTrackLoading() && beatmap != null) {
      float musicBarPosition =
          Math.min((float) MusicController.getPosition() / MusicController.getDuration(), 1f);
      g.fillRoundRect(musicBarX, musicBarY, musicBarWidth * musicBarPosition, musicBarHeight, 4);
    }

    // draw repository button
    if (repoButton != null) repoButton.draw();

    // draw update button
    if (Updater.get().showButton()) {
      Color updateColor = null;
      switch (Updater.get().getStatus()) {
        case UPDATE_AVAILABLE:
          updateColor = Color.red;
          break;
        case UPDATE_DOWNLOADED:
          updateColor = Color.green;
          break;
        case UPDATE_DOWNLOADING:
          updateColor = Color.yellow;
          break;
        default:
          updateColor = Color.white;
          break;
      }
      updateButton.draw(updateColor);
    }

    // draw text
    float marginX = width * 0.015f, topMarginY = height * 0.01f, bottomMarginY = height * 0.015f;
    g.setFont(Utils.FONT_MEDIUM);
    float lineHeight = Utils.FONT_MEDIUM.getLineHeight() * 0.925f;
    g.drawString(
        String.format(
            "Loaded %d songs and %d beatmaps.",
            BeatmapSetList.get().getMapSetCount(), BeatmapSetList.get().getMapCount()),
        marginX,
        topMarginY);
    if (MusicController.isTrackLoading())
      g.drawString("Track loading...", marginX, topMarginY + lineHeight);
    else if (MusicController.trackExists()) {
      if (Options.useUnicodeMetadata()) // load glyphs
      Utils.loadGlyphs(Utils.FONT_MEDIUM, beatmap.titleUnicode, beatmap.artistUnicode);
      g.drawString(
          (MusicController.isPlaying()) ? "Now Playing:" : "Paused:",
          marginX,
          topMarginY + lineHeight);
      g.drawString(
          String.format("%s: %s", beatmap.getArtist(), beatmap.getTitle()),
          marginX + 25,
          topMarginY + (lineHeight * 2));
    }
    g.drawString(
        String.format(
            "opsu! has been running for %s.",
            Utils.getTimeString((int) (System.currentTimeMillis() - programStartTime) / 1000)),
        marginX,
        height - bottomMarginY - (lineHeight * 2));
    g.drawString(
        String.format("It is currently %s.", new SimpleDateFormat("h:mm a").format(new Date())),
        marginX,
        height - bottomMarginY - lineHeight);

    UI.draw(g);
  }