Ejemplo n.º 1
0
  /** Closes all resources. */
  public static void close() {
    // close databases
    DBController.closeConnections();

    // cancel all downloads
    DownloadList.get().cancelAllDownloads();

    // close server socket
    if (SERVER_SOCKET != null) {
      try {
        SERVER_SOCKET.close();
      } catch (IOException e) {
        ErrorHandler.error("Failed to close server socket.", e, false);
      }
    }
  }
Ejemplo n.º 2
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;
  }