Ejemplo n.º 1
0
  protected void loadSavedGame(SaveSelectionPanel ssp, Window windowToClose) {
    ShortSaveInfo ssi = ssp.getSelectedSaveGame();
    if (ssi == null) {
      JOptionPane.showMessageDialog(
          windowToClose, "Select a non-empty slot.", "Error", JOptionPane.ERROR_MESSAGE);
      return;
    }

    try {
      System.out.println("Loading game with slot " + ssi.slot + "...");
      SavedGame sg = SavedGame.loadSavedGame(EditorResourceManager.getUFODirectory(), ssi.slot);
      System.out.println("Successfully loaded saved game.");
      windowToClose.dispose();
      MainMenuFrame mainMenu = new MainMenuFrame(sg);
      mainMenu.setVisible(true);
    } catch (IOException ioe) {
      System.out.println("Error loading saved game: " + ioe.getMessage());
      ioe.printStackTrace(System.out);
    }
  }
Ejemplo n.º 2
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.");
  }