Exemplo n.º 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();
  }
Exemplo n.º 2
0
 @Override
 public void update(GameContainer container, StateBasedGame game, int delta)
     throws SlickException {
   UI.update(delta);
   MusicController.loopTrackIfEnded(false);
   if (menuState != null) menuState.update(container, delta, input.getMouseX(), input.getMouseY());
 }
Exemplo n.º 3
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;
  }
Exemplo n.º 4
0
 @Override
 public void keyPressed(int key, char c) {
   switch (key) {
     case Input.KEY_ESCAPE:
     case Input.KEY_Q:
       ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.EXIT);
       game.enterState(Opsu.STATE_BUTTONMENU);
       break;
     case Input.KEY_P:
       SoundController.playSound(SoundEffect.MENUHIT);
       if (!logoClicked) {
         logoClicked = true;
         logoTimer = 0;
         playButton.getImage().setAlpha(0f);
         exitButton.getImage().setAlpha(0f);
       } else enterSongMenu();
       break;
     case Input.KEY_D:
       SoundController.playSound(SoundEffect.MENUHIT);
       game.enterState(
           Opsu.STATE_DOWNLOADSMENU,
           new FadeOutTransition(Color.black),
           new FadeInTransition(Color.black));
       break;
     case Input.KEY_R:
       nextTrack();
       break;
     case Input.KEY_UP:
       UI.changeVolume(1);
       break;
     case Input.KEY_DOWN:
       UI.changeVolume(-1);
       break;
     case Input.KEY_F7:
       Options.setNextFPS(container);
       break;
     case Input.KEY_F10:
       Options.toggleMouseDisabled();
       break;
     case Input.KEY_F12:
       Utils.takeScreenShot();
       break;
   }
 }
Exemplo n.º 5
0
      @Override
      public void update(GameContainer container, int delta, int mouseX, int mouseY) {
        super.update(container, delta, mouseX, mouseY);
        GameMod hoverMod = null;
        for (GameMod mod : GameMod.values()) {
          mod.hoverUpdate(delta, mod.isActive());
          if (hoverMod == null && mod.contains(mouseX, mouseY)) hoverMod = mod;
        }

        // tooltips
        if (hoverMod != null && hoverMod.isImplemented())
          UI.updateTooltip(delta, hoverMod.getDescription(), true);
      }
Exemplo n.º 6
0
  @Override
  public boolean closeRequested() {
    int id = this.getCurrentStateID();

    // intercept close requests in game-related states and return to song menu
    if (id == STATE_GAME || id == STATE_GAMEPAUSEMENU || id == STATE_GAMERANKING) {
      // start playing track at preview position
      SongMenu songMenu = (SongMenu) this.getState(Opsu.STATE_SONGMENU);
      if (id == STATE_GAMERANKING) {
        GameData data = ((GameRanking) this.getState(Opsu.STATE_GAMERANKING)).getGameData();
        if (data != null && data.isGameplay()) {
          songMenu.resetGameDataOnLoad();
          songMenu.resetTrackOnLoad();
        }
      } else {
        songMenu.resetGameDataOnLoad();
        if (id == STATE_GAME) {
          MusicController.pause();
          MusicController.resume();
        } else songMenu.resetTrackOnLoad();
      }
      if (UI.getCursor().isSkinned()) UI.getCursor().reset();
      this.enterState(
          Opsu.STATE_SONGMENU,
          new FadeOutTransition(Color.black),
          new FadeInTransition(Color.black));
      return false;
    }

    // show confirmation dialog if any downloads are active
    if (DownloadList.get().hasActiveDownloads()
        && UI.showExitConfirmation(DownloadList.EXIT_CONFIRMATION)) return false;
    if (Updater.get().getStatus() == Updater.Status.UPDATE_DOWNLOADING
        && UI.showExitConfirmation(Updater.EXIT_CONFIRMATION)) return false;

    return true;
  }
Exemplo n.º 7
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);
    }
Exemplo n.º 8
0
 @Override
 public void enter(GameContainer container, StateBasedGame game) throws SlickException {
   UI.enter();
   if (menuState != null) menuState.enter(container, game);
 }
Exemplo n.º 9
0
 /**
  * Processes a mouse wheel movement.
  *
  * @param container the game container
  * @param game the game
  * @param newValue the amount that the mouse wheel moved
  */
 public void scroll(GameContainer container, StateBasedGame game, int newValue) {
   UI.changeVolume((newValue < 0) ? -1 : 1);
 }
Exemplo n.º 10
0
 @Override
 public void mouseWheelMoved(int newValue) {
   UI.changeVolume((newValue < 0) ? -1 : 1);
 }
Exemplo n.º 11
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();
      }
    }
  }
Exemplo n.º 12
0
  @Override
  public void update(GameContainer container, StateBasedGame game, int delta)
      throws SlickException {
    UI.update(delta);
    if (MusicController.trackEnded()) nextTrack(); // end of track: go to next track
    int mouseX = input.getMouseX(), mouseY = input.getMouseY();
    logo.hoverUpdate(delta, mouseX, mouseY, 0.25f);
    playButton.hoverUpdate(delta, mouseX, mouseY, 0.25f);
    optionsButton.hoverUpdate(delta, mouseX, mouseY, 0.25f);
    exitButton.hoverUpdate(delta, mouseX, mouseY, 0.25f);
    if (repoButton != null) repoButton.hoverUpdate(delta, mouseX, mouseY);
    updateButton.hoverUpdate(delta, mouseX, mouseY);
    downloadsButton.hoverUpdate(delta, mouseX, mouseY);
    // ensure only one button is in hover state at once
    boolean noHoverUpdate = musicPositionBarContains(mouseX, mouseY);
    boolean contains = musicPlay.contains(mouseX, mouseY);
    musicPlay.hoverUpdate(delta, !noHoverUpdate && contains);
    musicPause.hoverUpdate(delta, !noHoverUpdate && contains);
    noHoverUpdate |= contains;
    musicNext.hoverUpdate(delta, !noHoverUpdate && musicNext.contains(mouseX, mouseY));
    musicPrevious.hoverUpdate(delta, !noHoverUpdate && musicPrevious.contains(mouseX, mouseY));

    // window focus change: increase/decrease theme song volume
    if (MusicController.isThemePlaying() && MusicController.isTrackDimmed() == container.hasFocus())
      MusicController.toggleTrackDimmed(0.33f);

    // fade in background
    if (bgAlpha < BG_MAX_ALPHA) {
      bgAlpha += delta / 1000f;
      if (bgAlpha > BG_MAX_ALPHA) bgAlpha = BG_MAX_ALPHA;
    }

    // buttons
    if (logoClicked) {
      if (logoTimer == 0) { // shifting to left
        if (logo.getX() > container.getWidth() / 3.3f) logo.setX(logo.getX() - delta);
        else logoTimer = 1;
      } else if (logoTimer >= MOVE_DELAY) // timer over: shift back to center
      logoClicked = false;
      else { // increment timer
        logoTimer += delta;
        if (logoTimer <= 500) {
          // fade in buttons
          playButton.getImage().setAlpha(logoTimer / 400f);
          optionsButton.getImage().setAlpha(logoTimer / 400f);
          exitButton.getImage().setAlpha(logoTimer / 400f);
        }
      }
    } else {
      // fade out buttons
      if (logoTimer > 0) {
        float alpha = playButton.getImage().getAlpha();
        if (alpha > 0f) {
          playButton.getImage().setAlpha(alpha - (delta / 200f));
          optionsButton.getImage().setAlpha(alpha - (delta / 200f));
          exitButton.getImage().setAlpha(alpha - (delta / 200f));
        } else logoTimer = 0;
      }

      // move back to original location
      if (logo.getX() < container.getWidth() / 2) {
        logo.setX(logo.getX() + (delta / 3f));
        if (logo.getX() > container.getWidth() / 2) logo.setX(container.getWidth() / 2);
      }
    }

    // tooltips
    if (musicPositionBarContains(mouseX, mouseY))
      UI.updateTooltip(delta, "Click to seek to a specific point in the song.", false);
    else if (musicPlay.contains(mouseX, mouseY))
      UI.updateTooltip(delta, (MusicController.isPlaying()) ? "Pause" : "Play", false);
    else if (musicNext.contains(mouseX, mouseY)) UI.updateTooltip(delta, "Next track", false);
    else if (musicPrevious.contains(mouseX, mouseY))
      UI.updateTooltip(delta, "Previous track", false);
    else if (Updater.get().showButton() && updateButton.contains(mouseX, mouseY))
      UI.updateTooltip(delta, Updater.get().getStatus().getDescription(), true);
  }
Exemplo n.º 13
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);
  }