Exemplo n.º 1
0
  public static void loadPlayer(Registry registry) {
    Player p = (Player) getPlayers().get(player);
    if (p != null) {
      p.setTransient(registry);
    }

    GameController gc = registry.getGameController();
    registry.getPlayerManager().clearPlayers();
    registry.getPlayerManager().registerPlayer(p);
    BlockManager bm = (BlockManager) blockManagers.get(player);
    bm.name = "Saved";
    bm = (BlockManager) bm.clone();
    bm.name = "Clone";
    bm.setTransient(registry);
    gc.setBlockManager(bm);
    PlaceableManager pm = (PlaceableManager) placeableManagers.get(player).clone();
    gc.setPlaceableManager(pm);
    MonsterManager mm = (MonsterManager) monsterManagers.get(player).clone();
    mm.setTransient(registry);
    gc.setMonsterManager(mm);

    if (p != null) {
      p.resetPlayer();
    }

    // unloadUnused();
  }
Exemplo n.º 2
0
  private void processClose() {
    if (Registry.getInstance().isRestartNeeded()) {
      final ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication();
      final ApplicationInfo info = ApplicationInfo.getInstance();

      final int r =
          Messages.showOkCancelDialog(
              myContent,
              "You need to restart " + info.getVersionName() + " for the changes to take effect",
              "Restart Required",
              (app.isRestartCapable() ? "Restart Now" : "Shutdown Now"),
              (app.isRestartCapable() ? "Restart Later" : "Shutdown Later"),
              Messages.getQuestionIcon());

      if (r == 0) {
        LaterInvocator.invokeLater(
            new Runnable() {
              public void run() {
                if (app.isRestartCapable()) {
                  app.restart();
                } else {
                  app.exit(true);
                }
              }
            },
            ModalityState.NON_MODAL);
      }
    }
  }
Exemplo n.º 3
0
 private MyTableModel() {
   myAll = Registry.getAll();
   Collections.sort(
       myAll,
       new Comparator<RegistryValue>() {
         public int compare(RegistryValue o1, RegistryValue o2) {
           return o1.getKey().compareTo(o2.getKey());
         }
       });
 }
Exemplo n.º 4
0
 private void restoreDefaults() {
   final int r =
       Messages.showYesNoDialog(
           myContent,
           "Are you sure you want to revert registry settings to default values?",
           "Revert To Defaults",
           Messages.getQuestionIcon());
   if (r == 0) {
     Registry.getInstance().restoreDefaults();
     myModel.fireChanged();
     revaliateActions();
   }
 }
    private MyTableModel() {
      myAll = Registry.getAll();
      final List<String> recent = getRecent();

      Collections.sort(
          myAll,
          new Comparator<RegistryValue>() {
            @Override
            public int compare(@NotNull RegistryValue o1, @NotNull RegistryValue o2) {
              final String key1 = o1.getKey();
              final String key2 = o2.getKey();
              final int i1 = recent.indexOf(key1);
              final int i2 = recent.indexOf(key2);
              final boolean c1 = i1 != -1;
              final boolean c2 = i2 != -1;
              if (c1 && !c2) return -1;
              if (!c1 && c2) return 1;
              if (c1 && c2) return i1 - i2;
              return key1.compareToIgnoreCase(key2);
            }
          });
    }
Exemplo n.º 6
0
 private void revaliateActions() {
   myRestoreDefaultsAction.setEnabled(!Registry.getInstance().isInDefaultState());
 }
Exemplo n.º 7
0
  public static boolean save() {
    if (registry.isSaving) {
      return false;
    }

    boolean status = true;

    registry.isSaving = true;

    resolutions.add("800x600");
    resolutions.add("1024x768");
    resolutions.add("1152x864");
    resolutions.add("1280x720");
    resolutions.add("1280x768");
    resolutions.add("1280x800");
    resolutions.add("1280x960");
    resolutions.add("1280x1024");
    resolutions.add("1360x768");
    resolutions.add("1366x768");
    resolutions.add("1440x900");
    resolutions.add("1600x900");
    resolutions.add("1600x1024");
    resolutions.add("1680x1050");
    resolutions.add("1920x1080");
    resolutions.add("1920x1200");
    // resolutions.add("Full Screen");

    // try to save the settings file
    try {
      FileOutputStream settingsFile = new FileOutputStream("SettingsTemp.dat");
      ObjectOutputStream settings = new ObjectOutputStream(settingsFile);

      settings.writeObject(new Integer(1)); // settings file version
      settings.writeObject(new Integer(resolution));
      if (volumeMusic == 0) {
        settings.writeObject(new Integer(-1));
      } else {
        settings.writeObject(new Integer(volumeMusic));
      }
      if (volumeFX == 0) {
        settings.writeObject(new Integer(-1));
      } else {
        settings.writeObject(new Integer(volumeFX));
      }
      settings.writeObject(new Integer(buttonMoveRight));
      settings.writeObject(new Integer(buttonMoveLeft));
      settings.writeObject(new Integer(buttonJump));
      settings.writeObject(new Integer(buttonAction));
      settings.writeObject(new Integer(buttonRobot));
      settings.writeObject(new Integer(buttonInventory));
      settings.writeObject(new Integer(buttonPause));

      settings.close();

      moveFile("SettingsTemp.dat", "Settings.dat");
      EIError.debugMsg("Saved Settings", EIError.ErrorLevel.Notice);
    } catch (Exception e) {
      status = false;
      EIError.debugMsg("Couldn't save settings " + e.getMessage(), EIError.ErrorLevel.Error);
    }

    // try to save the players
    for (int i = 1; i <= NUMBER_OF_PLAYER_SLOTS; i++) {
      try {
        if (player == i - 1) {
          FileOutputStream playerFile = new FileOutputStream("PlayerTemp.dat");
          ObjectOutputStream playerInfo = new ObjectOutputStream(playerFile);

          playerInfo.writeObject(new Integer(2)); // settings file version
          playerInfo.writeObject(players.get(i - 1));
          if (registry.getGameController().multiplayerMode != GameController.MultiplayerMode.CLIENT
              && player == i - 1) {
            blockManagers.set(i - 1, registry.getBlockManager());
            placeableManagers.set(i - 1, registry.getPlaceableManager());
            monsterManagers.set(i - 1, registry.getMonsterManager());
          }
          playerInfo.writeObject(blockManagers.get(i - 1));
          playerInfo.writeObject(placeableManagers.get(i - 1));
          playerInfo.writeObject(monsterManagers.get(i - 1));

          playerInfo.close();

          moveFile("PlayerTemp.dat", "Player" + i + ".dat");
          EIError.debugMsg("Saved Player " + i, EIError.ErrorLevel.Notice);
        }
      } catch (Exception e) {
        status = false;
        EIError.debugMsg(
            "Couldn't save Player " + i + " " + e.getMessage(), EIError.ErrorLevel.Error);
      }
    }

    registry.isSaving = false;

    return status;
  }