Ejemplo n.º 1
0
 /** Plays the next track, and adds the previous one to the stack. */
 private void nextTrack() {
   boolean isTheme = MusicController.isThemePlaying();
   SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
   BeatmapSetNode node = menu.setFocus(BeatmapSetList.get().getRandomNode(), -1, true, false);
   boolean sameAudio = false;
   if (node != null) {
     sameAudio =
         MusicController.getBeatmap()
             .audioFilename
             .equals(node.getBeatmapSet().get(0).audioFilename);
     if (!isTheme && !sameAudio) previous.add(node.index);
   }
   if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying())
     bgAlpha = 0f;
 }
Ejemplo n.º 2
0
  @Override
  public void mousePressed(int button, int x, int y) {
    // check mouse button
    if (button == Input.MOUSE_MIDDLE_BUTTON) return;

    // music position bar
    if (MusicController.isPlaying()) {
      if (musicPositionBarContains(x, y)) {
        float pos = (x - musicBarX) / musicBarWidth;
        MusicController.setPosition((int) (pos * MusicController.getDuration()));
        return;
      }
    }

    // music button actions
    if (musicPlay.contains(x, y)) {
      if (MusicController.isPlaying()) {
        MusicController.pause();
        UI.sendBarNotification("Pause");
      } else if (!MusicController.isTrackLoading()) {
        MusicController.resume();
        UI.sendBarNotification("Play");
      }
    } else if (musicNext.contains(x, y)) {
      nextTrack();
      UI.sendBarNotification(">> Next");
    } else if (musicPrevious.contains(x, y)) {
      if (!previous.isEmpty()) {
        SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
        menu.setFocus(BeatmapSetList.get().getBaseNode(previous.pop()), -1, true, false);
        if (Options.isDynamicBackgroundEnabled()) bgAlpha = 0f;
      } else MusicController.setPosition(0);
      UI.sendBarNotification("<< Previous");
    }

    // downloads button actions
    else if (downloadsButton.contains(x, y)) {
      SoundController.playSound(SoundEffect.MENUHIT);
      game.enterState(
          Opsu.STATE_DOWNLOADSMENU,
          new FadeOutTransition(Color.black),
          new FadeInTransition(Color.black));
    }

    // repository button actions
    else if (repoButton != null && repoButton.contains(x, y)) {
      try {
        Desktop.getDesktop().browse(Options.REPOSITORY_URI);
      } catch (IOException e) {
        ErrorHandler.error("Could not browse to repository URI.", e, false);
      }
    }

    // update button actions
    else if (Updater.get().showButton() && updateButton.contains(x, y)) {
      switch (Updater.get().getStatus()) {
        case UPDATE_AVAILABLE:
          SoundController.playSound(SoundEffect.MENUHIT);
          Updater.get().startDownload();
          break;
        case UPDATE_DOWNLOADED:
          SoundController.playSound(SoundEffect.MENUHIT);
          Updater.get().prepareUpdate();
          container.setForceExit(false);
          container.exit();
          break;
        default:
          break;
      }
    }

    // start moving logo (if clicked)
    else if (!logoClicked) {
      if (logo.contains(x, y, 0.25f)) {
        logoClicked = true;
        logoTimer = 0;
        playButton.getImage().setAlpha(0f);
        exitButton.getImage().setAlpha(0f);
        SoundController.playSound(SoundEffect.MENUHIT);
      }
    }

    // other button actions (if visible)
    else if (logoClicked) {
      if (logo.contains(x, y, 0.25f) || playButton.contains(x, y, 0.25f)) {
        SoundController.playSound(SoundEffect.MENUHIT);
        enterSongMenu();
      } else if (exitButton.contains(x, y, 0.25f)) {
        container.exit();
      } else if (optionsButton.contains(x, y, 0.25f)) {
        enterOptionsMenu();
      }
    }
  }
Ejemplo n.º 3
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);
  }