Example #1
0
  /**
   * Gets current locale's resource bundle (UTF-8)
   *
   * @param baseName base name of the bundle
   * @return the resource bundle
   */
  public static ResourceBundle getResourceBundle(String baseName) {
    File file = new File(AssetsConverter.getAssetsFolder());
    try {
      URL[] urls = {file.toURI().toURL()};
      ClassLoader loader = new URLClassLoader(urls);
      return ResourceBundle.getBundle(baseName, Locale.getDefault(), loader, new UTF8Control());
    } catch (Exception e) {
      logger.log(
          Level.SEVERE,
          "Failed to locate the resource bundle " + baseName + " in " + file + "!",
          e);
    }

    // Works only from the IDE
    return ResourceBundle.getBundle(baseName, new UTF8Control());
  }
Example #2
0
  @Override
  public void simpleInitApp() {

    // Distribution locator
    getAssetManager().registerLocator(AssetsConverter.getAssetsFolder(), FileLocator.class);

    // Initiate the title screen
    TitleScreenState gameLoader =
        new TitleScreenState() {
          @Override
          public Void onLoad() {
            try {
              long startTime = System.currentTimeMillis();

              // Asset loaders
              // Sound
              getAssetManager().registerLoader(MP2Loader.class, "mp2");
              // Camera sweep files
              getAssetManager()
                  .registerLoader(
                      CameraSweepDataLoader.class,
                      CameraSweepDataLoader.CAMERA_SWEEP_DATA_FILE_EXTENSION);

              // Set the anisotropy asset listener
              setAnisotropy();

              // Allow people to take screenshots
              ScreenshotAppState screenShotState = new ScreenshotAppState(SCREENSHOTS_FOLDER);
              stateManager.attach(screenShotState);

              // Recording video
              if (params.containsKey("record")) {
                float quality =
                    (getUserSettings().getSettingFloat(Settings.Setting.RECORDER_QUALITY));
                int frameRate =
                    (getUserSettings().getSettingInteger(Settings.Setting.RECORDER_FPS));
                getSettings().setFrameRate(frameRate);
                VideoRecorderAppState recorder = new VideoRecorderAppState(quality, frameRate);
                String folder = params.get("record");
                if (folder == null) {
                  folder = SCREENSHOTS_FOLDER;
                }
                if (!folder.endsWith(File.separator)) {
                  folder = folder.concat(File.separator);
                }
                folder =
                    folder
                        .concat(getSettings().getTitle())
                        .concat("-")
                        .concat(String.valueOf(System.currentTimeMillis() / 1000))
                        .concat(".avi");
                recorder.setFile(new File(folder));

                stateManager.attach(recorder);
              }

              // Nifty
              NiftyJmeDisplay niftyDisplay = getNifty();

              // Validate the XML, great for debuging purposes
              List<String> guiXMLs =
                  Arrays.asList("Interface/MainMenu.xml", "Interface/GameHUD.xml");
              for (String xml : guiXMLs) {
                try {
                  //                            niftyDisplay.getNifty().validateXml(xml); <--
                  // Amazingly buggy?
                } catch (Exception e) {
                  throw new RuntimeException("GUI file " + xml + " failed to validate!", e);
                }
              }

              // Initialize persistent app states
              MainMenuState mainMenuState =
                  new MainMenuState(!params.containsKey("level"), assetManager);
              mainMenuState.setEnabled(false);
              PlayerState playerState = new PlayerState();
              playerState.setEnabled(false);
              stateManager.attach(mainMenuState);
              stateManager.attach(playerState);

              // Eventually we are going to use Nifty, the XML files take some time to parse
              niftyDisplay.getNifty().registerScreenController(mainMenuState, playerState);
              for (String xml : guiXMLs) {
                niftyDisplay.getNifty().addXml(xml);
              }

              // It is all a clever ruge, we don't actually load much here
              if (!params.containsKey("nomovies") && !params.containsKey("level")) {
                Thread.sleep(5000 - (System.currentTimeMillis() - startTime));
              }
            } catch (InterruptedException ex) {
              // Doesn't matter
            } catch (Exception e) {
              logger.log(Level.SEVERE, "Failed to load the game!", e);
              app.stop();
            }
            return null;
          }

          @Override
          public void onLoadComplete() {

            // FIXME: We need ambient light, but it may be different for different states. There
            // just seems to be a bug in BatchNodes concerning the removal of the light. So this is
            // temporary perhaps
            AmbientLight al = new AmbientLight();
            al.setColor(ColorRGBA.White.multLocal(5f));
            rootNode.addLight(al);

            if (params.containsKey("nomovies") || params.containsKey("level")) {
              startGame();
            } else {

              // The fireworks!
              playIntro();
            }
          }
        };
    this.stateManager.attach(gameLoader);
  }
Example #3
0
  /**
   * Check that we have all we need to run this app
   *
   * @param app the app (we need asset managers etc.)
   * @return true if the app is ok for running!
   * @throws InterruptedException lots of threads waiting
   */
  private static boolean checkSetup(final Main app) throws InterruptedException {

    boolean saveSetup = false;

    // First and foremost, the folder
    if (!checkDkFolder(dkIIFolder)) {
      logger.info("Dungeon Keeper II folder not found or valid! Prompting user!");
      saveSetup = true;

      // Let the user select
      setLookNFeel();
      DKFolderSelector frame =
          new DKFolderSelector() {
            @Override
            protected void continueOk(String path) {
              if (!path.endsWith(File.separator)) {
                dkIIFolder = path.concat(File.separator);
              }
              app.getSettings().putString(DKII_FOLDER_KEY, dkIIFolder);
              folderOk = true;
            }
          };
      openFrameAndWait(frame);
    } else {
      folderOk = true;
    }

    // If the folder is ok, check the conversion
    if (folderOk && (AssetsConverter.conversionNeeded(app.getSettings()))) {
      logger.info("Need to convert the assets!");
      saveSetup = true;

      // Convert
      setLookNFeel();
      AssetManager assetManager =
          JmeSystem.newAssetManager(
              Thread.currentThread()
                  .getContextClassLoader()
                  .getResource(
                      "com/jme3/asset/Desktop.cfg")); // Get temporary asset manager instance since
      // we not yet have one ourselves
      assetManager.registerLocator(AssetsConverter.getAssetsFolder(), FileLocator.class);
      DKConverter frame =
          new DKConverter(dkIIFolder, assetManager) {
            @Override
            protected void continueOk() {
              AssetsConverter.setConversionSettings(app.getSettings());
              conversionOk = true;
            }
          };
      openFrameAndWait(frame);
    } else if (folderOk) {
      conversionOk = true;
    }

    // If everything is ok, we might need to save the setup
    boolean result = (folderOk && conversionOk);
    if (result && saveSetup) {
      try {
        app.getSettings().save(new FileOutputStream(new File(SETTINGS_FILE)));
      } catch (IOException ex) {
        Logger.getLogger(Main.class.getName())
            .log(Level.WARNING, "Settings file failed to save!", ex);
      }
    }

    return result;
  }