예제 #1
0
  @Override
  public void enter(GameContainer container, StateBasedGame game) throws SlickException {
    UI.enter();
    if (!enterNotification) {
      if (Updater.get().getStatus() == Updater.Status.UPDATE_AVAILABLE) {
        UI.sendBarNotification("An opsu! update is available.");
        enterNotification = true;
      } else if (Updater.get().justUpdated()) {
        UI.sendBarNotification("opsu! is now up to date!");
        enterNotification = true;
      }
    }

    // reset button hover states if mouse is not currently hovering over the button
    int mouseX = input.getMouseX(), mouseY = input.getMouseY();
    if (!logo.contains(mouseX, mouseY, 0.25f)) logo.resetHover();
    if (!playButton.contains(mouseX, mouseY, 0.25f)) playButton.resetHover();
    if (!optionsButton.contains(mouseX, mouseY, 0.25f)) optionsButton.resetHover();
    if (!exitButton.contains(mouseX, mouseY, 0.25f)) exitButton.resetHover();
    if (!musicPlay.contains(mouseX, mouseY)) musicPlay.resetHover();
    if (!musicPause.contains(mouseX, mouseY)) musicPause.resetHover();
    if (!musicNext.contains(mouseX, mouseY)) musicNext.resetHover();
    if (!musicPrevious.contains(mouseX, mouseY)) musicPrevious.resetHover();
    if (repoButton != null && !repoButton.contains(mouseX, mouseY)) repoButton.resetHover();
    if (!updateButton.contains(mouseX, mouseY)) updateButton.resetHover();
    if (!downloadsButton.contains(mouseX, mouseY)) downloadsButton.resetHover();
  }
예제 #2
0
  /**
   * Plays an audio file at the preview position. If the audio file is already playing, then nothing
   * will happen.
   *
   * @param beatmap the beatmap to play
   * @param loop whether or not to loop the track
   * @param preview whether to start at the preview time (true) or beginning (false)
   */
  public static void play(final Beatmap beatmap, final boolean loop, final boolean preview) {
    // new track: load and play
    if (lastBeatmap == null || !beatmap.audioFilename.equals(lastBeatmap.audioFilename)) {
      final File audioFile = beatmap.audioFilename;
      if (!audioFile.isFile() && !ResourceLoader.resourceExists(audioFile.getPath())) {
        UI.sendBarNotification(String.format("Could not find track '%s'.", audioFile.getName()));
        System.out.println(beatmap);
        return;
      }

      reset();
      System.gc();

      switch (BeatmapParser.getExtension(beatmap.audioFilename.getName())) {
        case "ogg":
        case "mp3":
          trackLoader =
              new Thread() {
                @Override
                public void run() {
                  loadTrack(audioFile, (preview) ? beatmap.previewTime : 0, loop);
                }
              };
          trackLoader.start();
          break;
        default:
          break;
      }
    }

    // new track position: play at position
    else if (beatmap.previewTime != lastBeatmap.previewTime) playAt(beatmap.previewTime, loop);

    lastBeatmap = beatmap;
  }
예제 #3
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();
      }
    }
  }