Пример #1
0
 private void showOptions() {
   final PreferencesDialog dialog = new PreferencesDialog(this);
   dialog.setVisible(true);
   if (dialog.okClicked()) {
     setRenderOptions();
     nes.setParameters();
   }
 }
Пример #2
0
 public GeneralPanel(PreferencesDialog preferencesDialog) {
   this.preferencesDialog = preferencesDialog;
   applicationPreferences = preferencesDialog.getApplicationPreferences();
   createUI();
 }
Пример #3
0
  @Override
  public void run() {
    if (EditorResourceManager.getUFODirectory() == null) {
      JOptionPane.showMessageDialog(
          null,
          "No UFO directory has been set.  The preferences window will now be opened so that you can select one.  Saved game and image data will be loaded from this directory.",
          "Unknown UFO Directory - XCOMSGE",
          JOptionPane.PLAIN_MESSAGE);
      PreferencesDialog prefsDialog = new PreferencesDialog(null, true);
      prefsDialog.setVisible(true);

      if (EditorResourceManager.getUFODirectory() == null
          || prefsDialog.getResult() == PreferencesDialog.PREFERENCES_CANCELLED) {
        System.exit(0);
      }
    }

    final LoadingDialog loadingDialog = new LoadingDialog(null, true);
    /*
    loadingDialog.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowDeactivated(java.awt.event.WindowEvent e) {
            System.out.println("Detected lost focus, exiting.");
            // System.exit(0);
            loadingDialog.setVisible(false);
        }
    });
    */
    loadingDialog.setVisible(true);

    String ufodir = EditorResourceManager.getUFODirectory();
    ArrayList<ShortSaveInfo> info = new ArrayList<>();

    try {
      for (int i = 1; i <= 10; i++) {
        File savedir = new File(ufodir, "GAME_" + i);
        System.out.println("Loading save " + i + "...");
        ShortSaveInfo ssi = ShortSaveInfo.loadShortSaveInfo(savedir);
        info.add(ssi);

        if (ssi == null) {
          System.out.println("  No save in slot " + i + ".");
        } else {
          ssi.slot = i;
          System.out.println("  " + ssi);
        }
      }
    } catch (IOException ioe) {
      System.out.println("IO exception: " + ioe.getMessage());
    }

    System.out.println("Num saved games loaded: " + info.size());

    final JDialog selectDialog = new JDialog((JFrame) null, true);
    final SaveSelectionPanel ssp = new SaveSelectionPanel(info);
    ssp.addTableMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            System.out.println("Table clicked.");
            if (e.getClickCount() == 2) {
              loadSavedGame(ssp, selectDialog);
            }
          }
        });
    ssp.addLoadListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.out.println("Load button clicked.");

            loadSavedGame(ssp, selectDialog);
          }
        });
    ssp.addQuitListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            System.out.println("Quit button clicked.");
            selectDialog.dispose();
          }
        });

    /*
    JFrame letterFrame = new JFrame("Test");
    BoxLayout box = new BoxLayout(letterFrame.getContentPane(), BoxLayout.Y_AXIS);
    letterFrame.getContentPane().setLayout(box);
    letterFrame.getContentPane().add(new JLabel(new ImageIcon(XCOMImageResources.yellowBigLetters.get(32))));
    letterFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    letterFrame.pack();
    letterFrame.setVisible(true);
    */

    // Note that valid radii taken from OpenXCOM appear to be (in a 320x200 display):
    // 90, 120, 180, 280, 250, 720

    /*
     * Testing code
    double ww = 640.0;
    double wh = 400.0;
    double radius = 180.0;
    double cenlon = Math.PI / 4.0;
    double cenlat = 0.0;

    JFrame bufferTestFrame = new JFrame("World");
    BufferedImage worldImage = new BufferedImage(640, 400, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = worldImage.createGraphics();

    g.setBackground(Color.WHITE);
    g.clearRect(0, 0, (int)ww, (int)wh);

    g.setColor(XCOMImageResources.palettes.get("GEOSCAPE").colors[12*16]);
    g.fillOval((int)(ww / 2.0 - radius), (int)(wh / 2.0 - radius), (int)(radius * 2.0), (int)(radius * 2.0));

    Rectangle2D texRect = new Rectangle2D.Double(0.0, 0.0, WorldTextureFile.WORLD_TEXTURE_WIDTH, WorldTextureFile.WORLD_TEXTURE_HEIGHT);

    for (WorldPolygon p : XCOMImageResources.worldPolygons) {
        p.backface = true;
        for (Vertex v : p.vertices) {
            // Orthographic projection code and backface detection taken from OpenXCOM project (Globe.cpp)
            v.x = (int)(ww / 2.0) + (int)Math.floor(radius * Math.cos(v.latitude) * Math.sin(v.longitude - cenlon));
            v.y = (int)(wh / 2.0) + (int)Math.floor(radius * (Math.cos(cenlat) * Math.sin(v.latitude) - Math.sin(cenlat) * Math.cos(v.latitude) * Math.cos(v.longitude - cenlon)));
            p.backface = p.backface && (Math.cos(cenlat) * Math.cos(v.latitude) * Math.cos(v.longitude - cenlon) + Math.sin(cenlat) * Math.sin(v.latitude)) < 0;

            if (v.x > worldImage.getWidth() || v.y > worldImage.getHeight()) {
                // p.backface = true;
                // break;
                // System.out.println("Coordinate " + v.x + ", " + v.y + " is out of bounds.");
                // System.exit(1);
            }

            // worldImage.setRGB(v.x, v.y, Color.BLACK.getRGB());
        }

        if (!p.backface) {
            g.setColor(Color.GREEN);
            g.setPaint(new TexturePaint(XCOMImageResources.smallWorldTextures.get(p.terrainType), texRect));
            g.fillPolygon(p.getAWTPolygon());
        }
    }

    JLabel worldLabel = new JLabel(new ImageIcon(worldImage));
    worldLabel.setMinimumSize(new Dimension(640, 400));
    bufferTestFrame.getContentPane().add(worldLabel);
    bufferTestFrame.pack();
    bufferTestFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    bufferTestFrame.setVisible(true);
    */

    /*
     * Background image load verification test
    JFrame frame = new JFrame("Background Test");
    JLabel background = new JLabel(new ImageIcon(XCOMImageResources.geoscapeBackground));
    background.setMinimumSize(new Dimension(XCOMImageResources.geoscapeBackground.getWidth(), XCOMImageResources.geoscapeBackground.getHeight()));
    background.setPreferredSize(new Dimension(XCOMImageResources.geoscapeBackground.getWidth(), XCOMImageResources.geoscapeBackground.getHeight()));
    frame.getContentPane().add(background);
    frame.pack();
    frame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
    */

    /*
     * World view verification test
     */

    JFrame frame = new JFrame("Background Test");
    frame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    frame.getContentPane().setLayout(new FlowLayout());
    // frame.getContentPane().add(new JLabel(new
    // ImageIcon(XCOMImageResources.geoscapeBackground.getSubimage(0, 0, 256,
    // XCOMImageResources.geoscapeBackground.getHeight()))));
    final WorldView wv = new WorldView(3);
    wv.setZoom(zooms[zoomIndex]);
    wv.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            System.out.println(
                "Mouse clicked: " + e.getX() + ", " + e.getY() + " (" + e.getButton() + ")");
            if (e.getButton() == e.BUTTON1) {
              wv.recenter(e.getX(), e.getY());
            } else if (e.getButton() == e.BUTTON3) {
              zoomIndex = (zoomIndex + 1) % zooms.length;
              wv.setZoom(zooms[zoomIndex]);
            }
          }
        });
    frame.getContentPane().add(wv);
    frame.pack();
    frame.setVisible(true);

    selectDialog.setTitle("Select Saved Game - XCOMSGE");
    selectDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    selectDialog.add(ssp);
    selectDialog.pack();
    selectDialog.dispose();
    // selectDialog.setVisible(true);

    System.out.println("Initial thread closed.");
  }
  public void DoCommand(ActionEvent e) {
    String currAction = e.getActionCommand();

    if (currAction.equals(ArcadeTheme.UP_BUTTON_ACTION)) {
      if (lstGames.ScrollDown()) {
        bLoadScreenshot = true; // Position is important!
        this.repaint();
      }
    } else if (currAction.equals(ArcadeTheme.DOWN_BUTTON_ACTION)) {
      if (lstGames.ScrollUp()) {
        bLoadScreenshot = true; // Position is important!
        this.repaint();
      }
    } else if (currAction.equals(ArcadeTheme.LOAD_GAME_BUTTON_ACTION)) {
      if (lstGames.hasNoGames())
        JOptionPane.showMessageDialog(
            this,
            "You need to install at least " + "one game before trying to load.",
            "No Game Installed",
            JOptionPane.WARNING_MESSAGE);
      else
        parentFrame.BurnUsingProgrammer(
            lstGames.getSelectedGameId(), lstGames.getSelectedGameName());
    } else if (currAction.equals(ArcadeTheme.HOW_TO_PLAY_BUTTON_ACTION)) {
      if (lstGames.hasNoGames())
        JOptionPane.showMessageDialog(
            this, "No games are installed", "No Game Installed", JOptionPane.WARNING_MESSAGE);
      else {
        if (dlgHowtoPlay == null) dlgHowtoPlay = new HowtoPlayDialog(parentFrame);

        dlgHowtoPlay.PopulateNShow(
            lstGames.getSelectedGameId(), lstGames.getSelectedGameName(), selJoystickId);
      }
    } else if (currAction.equals(ArcadeTheme.INSTALL_GAME_BUTTON_ACTION)) {
      File romZipFile =
          UIHelpers.ShowFileOpen(
              "Open Zip file containing game rom files", zipFileFilter, ".zip", null, null);
      if (romZipFile != null) {
        if (InstallGame(romZipFile)) {
          if (!bReinstalledGame) {
            File logoImageFile;
            BufferedImage biLogo = null;
            logoImageFile = new File(monogramsPath, installedGameId + ".png");
            if (logoImageFile.isFile()) biLogo = UIHelpers.LoadBufferedImage(logoImageFile);
            else biLogo = UIHelpers.LoadBufferedImage(new File(monogramsPath, "nologo.png"));
            lstGames.AddInstalledGame(
                installedGameIndex,
                new GamesListbox.GameStruct(installedGameId, installedGameName, biLogo));

            bLoadScreenshot = true; // Position is important!
            this.repaint();
          }
        }
      }

    } else if (currAction.equals(ArcadeTheme.PREFERENCES_BUTTON_ACTION)) {
      // Always instantiate dlgPreferences
      dlgPreferences = new PreferencesDialog(parentFrame, docPlatformXML);
      dlgPreferences.PopulateForm();
      if (dlgPreferences.isOKClicked()) {
        // Propogate changed application settings to required settings variables.
        selJoystickId = programSettings.getStringProperty("JoystickId");
        parentFrame.setSelectedPlatformId(programSettings.getStringProperty("PlatformId"));
        parentFrame.setWrite2Target(programSettings.getStringProperty("Writeto"));
      }
      /* User is not likely to invoke Preferences dialogbox many times, so it makes no
        sense to cache it in memory. Further, the dialogbox does not have to free any
        external resources such as files, etc. Hence, it is best to dispose it when user
        dismisses it.
      */
      dlgPreferences.dispose();
    } else if (currAction.equals(ArcadeTheme.UPDATE_BUTTON_ACTION)) {
      parentFrame.PlaceGlassPane("Checking for Updates");

      new SwingWorker<List<Boolean>, Void>() {
        /* It is tempting to declare List<Boolean> alPossibleErrors here - as class
          level variable. This way, it will be available to doInBackground() as well
          as done(). But bear in mind that said procedures are being executed on 2
          different threads. Thus, accessing alPossibleErrors becomes a cross-thread
          issue. Even though it is possible that no issue will arise, it is better
          to let Java handle it. So, return alPossibleErrors in doInBackground()
          and retrieve it using get() in done().
        */

        // Executed on a worker (background) thread
        // Should never touch any Swing component
        @Override
        protected List<Boolean> doInBackground() {
          List<Boolean> alPossibleErrors = new ArrayList<Boolean>(3);
          if (UpdateDialog.CheckForUpdates(alPossibleErrors)) {
            return alPossibleErrors;
          } else return null;
        }

        // Executed on EDT
        @Override
        protected void done() {
          try {
            parentFrame.RemoveGlassPane();

            List<Boolean> alPossibleErrors = get();
            if (alPossibleErrors == null)
              JOptionPane.showMessageDialog(
                  parentFrame,
                  "There was an error connecting Gadgetfactory website",
                  "Update Error",
                  JOptionPane.ERROR_MESSAGE);
            else if (alPossibleErrors.get(0).equals(Boolean.TRUE))
              JOptionPane.showMessageDialog(
                  parentFrame,
                  "You are not connected to Internet. " + "Please connect before updating",
                  "Update Error",
                  JOptionPane.ERROR_MESSAGE);
            else if (alPossibleErrors.get(1).equals(Boolean.TRUE))
              JOptionPane.showMessageDialog(
                  parentFrame,
                  "It is taking too long to connect to Gadgetfactory " + "website, aborting update",
                  "Update Error",
                  JOptionPane.ERROR_MESSAGE);
            else {
              /* User is not likely to invoke Update dialogbox many times, so it makes
                sense to use it on "on-demand" basis - so that unnecessary memory will
                not be allocated. Hence, it is best to instantiate it and dispose it
                when user dismisses it.
              */
              dlgUpdate =
                  new UpdateDialog(
                      parentFrame, docGameXML, docHardwareXML, romsFolder, imagesFolder);
              dlgUpdate.PopulateForm();
              //							if (dlgPreferences.isOKClicked()) {
              //							}
              dlgUpdate.dispose();
            }
          } catch (InterruptedException e) {
            System.err.println("(Anonymous).done\t" + e.getMessage());
          } catch (ExecutionException e) {
            System.err.println("(Anonymous).done\t" + e.getMessage());
          }
        }
      }.execute();
    } else if (currAction.equals(ArcadeTheme.HELP_BUTTON_ACTION)) {
      File helpFile = new File(AppPath, "help/index.html");
      HelperFunctions.BrowseURL(helpFile.toURI().toString(), runningonWindows);
    } else if (currAction.equals(ArcadeTheme.EXIT_BUTTON_ACTION)) {
      parentFrame.CleanupAndExit();
    }
  }
 private void jMenuItemShowPreferencesActionPerformed(
     java.awt.event.ActionEvent evt) // GEN-FIRST:event_jMenuItemShowPreferencesActionPerformed
     { // GEN-HEADEREND:event_jMenuItemShowPreferencesActionPerformed
   PreferencesDialog.showPreferencesDialog(this, this.thePrefs);
 } // GEN-LAST:event_jMenuItemShowPreferencesActionPerformed