// called when the load script button is pressed.
 private void scriptPressed() {
   int returnVal = fileChooser.showDialog(this, "Load Script");
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     notifyControllerListeners(
         ControllerEvent.SCRIPT_CHANGE, fileChooser.getSelectedFile().getAbsoluteFile());
     scriptComponent.setContents(fileChooser.getSelectedFile().getAbsolutePath());
   }
 }
  /**
   * Display a file chooser dialog box.
   *
   * @param owner <code>Component</code> which 'owns' the dialog
   * @param mode Can be either <code>OPEN</code>, <code>SCRIPT</code> or <code>SAVE</code>
   * @return The path to selected file, null otherwise
   */
  public static String chooseFile(Component owner, int mode) {
    JFileChooser chooser = getFileChooser(owner, mode);
    chooser.setMultiSelectionEnabled(false);

    if (chooser.showDialog(owner, null) == JFileChooser.APPROVE_OPTION) {
      /*Jext*/ AbstractEditorPanel.setProperty(
          "lastdir." + mode, chooser.getSelectedFile().getParent());
      return chooser.getSelectedFile().getAbsolutePath();
    } else owner.repaint();

    return null;
  }
Exemple #3
0
  // ask user for script file and name of new profile
  // return false if user cancelled operation
  private boolean getNewWkldInput(
      JFileChooser chooser, Object[] optionDlgMsg, StringBuffer name, StringBuffer scriptFile) {
    // let user select script file with queries
    boolean fileOk = false;
    int retval;
    File file = null;
    FileReader reader = null;
    while (!fileOk) {
      if ((retval = chooser.showDialog(this, "Ok")) != 0) {
        return false;
      }
      file = chooser.getSelectedFile();
      try {
        reader = new FileReader(file.getPath());
        fileOk = true;
        scriptFile.append(file.getPath());
      } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(
            this,
            "Selected script file does not exist",
            "Error: New Profile",
            JOptionPane.ERROR_MESSAGE);
      }
    }

    // let user select filename for profile
    int response =
        JOptionPane.showOptionDialog(
            this,
            optionDlgMsg,
            "New Profile",
            JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            null);
    if (response != JOptionPane.OK_OPTION) {
      return false;
    }
    JTextField textFld = (JTextField) optionDlgMsg[1];
    name.append(file.getParent() + "/" + textFld.getText());
    return true;
  }
  // saves the destination file
  private void saveDest() {
    int returnVal = destFileChooser.showDialog(this, "Save Destination File");
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      if (destFileChooser.getSelectedFile().exists()) {
        Object[] options = {"Yes", "No", "Cancel"};
        int pressedButtonValue =
            JOptionPane.showOptionDialog(
                (JFrame) this,
                "File exists. Replace it ?",
                "Question",
                JOptionPane.YES_NO_CANCEL_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[2]);

        if (pressedButtonValue != JOptionPane.YES_OPTION) return;
      }

      String fileName = destFileChooser.getSelectedFile().getAbsolutePath();
      notifyHackTranslatorListeners(HackTranslatorEvent.SAVE_DEST, fileName);
    }
  }
 // loads a source file
 private void loadSource() {
   int returnVal = sourceFileChooser.showDialog(this, "Load Source File");
   if (returnVal == JFileChooser.APPROVE_OPTION)
     notifyHackTranslatorListeners(
         HackTranslatorEvent.SOURCE_LOAD, sourceFileChooser.getSelectedFile().getAbsolutePath());
 }
  /** devSetupGameState. */
  public static void devSetupGameState() {
    String t_humanLife = "-1";
    String t_computerLife = "-1";
    String t_humanSetupCardsInPlay = "NONE";
    String t_computerSetupCardsInPlay = "NONE";
    String t_humanSetupCardsInHand = "NONE";
    String t_computerSetupCardsInHand = "NONE";
    String t_humanSetupGraveyard = "NONE";
    String t_computerSetupGraveyard = "NONE";
    String t_humanSetupLibrary = "NONE";
    String t_computerSetupLibrary = "NONE";
    String t_humanSetupExile = "NONE";
    String t_computerSetupExile = "NONE";
    String t_changePlayer = "NONE";
    String t_changePhase = "NONE";

    String wd = ".";
    JFileChooser fc = new JFileChooser(wd);
    int rc = fc.showDialog(null, "Select Game State File");
    if (rc != JFileChooser.APPROVE_OPTION) return;

    try {
      FileInputStream fstream = new FileInputStream(fc.getSelectedFile().getAbsolutePath());
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));

      String temp = "";

      while ((temp = br.readLine()) != null) {
        String[] temp_data = temp.split("=");

        if (temp_data.length < 2) continue;
        if (temp_data[0].toCharArray()[0] == '#') continue;

        String categoryName = temp_data[0];
        String categoryValue = temp_data[1];

        if (categoryName.toLowerCase().equals("humanlife")) t_humanLife = categoryValue;
        else if (categoryName.toLowerCase().equals("ailife")) t_computerLife = categoryValue;
        else if (categoryName.toLowerCase().equals("humancardsinplay"))
          t_humanSetupCardsInPlay = categoryValue;
        else if (categoryName.toLowerCase().equals("aicardsinplay"))
          t_computerSetupCardsInPlay = categoryValue;
        else if (categoryName.toLowerCase().equals("humancardsinhand"))
          t_humanSetupCardsInHand = categoryValue;
        else if (categoryName.toLowerCase().equals("aicardsinhand"))
          t_computerSetupCardsInHand = categoryValue;
        else if (categoryName.toLowerCase().equals("humancardsingraveyard"))
          t_humanSetupGraveyard = categoryValue;
        else if (categoryName.toLowerCase().equals("aicardsingraveyard"))
          t_computerSetupGraveyard = categoryValue;
        else if (categoryName.toLowerCase().equals("humancardsinlibrary"))
          t_humanSetupLibrary = categoryValue;
        else if (categoryName.toLowerCase().equals("aicardsinlibrary"))
          t_computerSetupLibrary = categoryValue;
        else if (categoryName.toLowerCase().equals("humancardsinexile"))
          t_humanSetupExile = categoryValue;
        else if (categoryName.toLowerCase().equals("aicardsinexile"))
          t_computerSetupExile = categoryValue;
        else if (categoryName.toLowerCase().equals("activeplayer")) t_changePlayer = categoryValue;
        else if (categoryName.toLowerCase().equals("activephase")) t_changePhase = categoryValue;
      }

      in.close();
    } catch (FileNotFoundException fnfe) {
      JOptionPane.showMessageDialog(
          null, "File not found: " + fc.getSelectedFile().getAbsolutePath());
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, "Error loading battle setup file!");
      return;
    }

    int setHumanLife = Integer.parseInt(t_humanLife);
    int setComputerLife = Integer.parseInt(t_computerLife);

    String humanSetupCardsInPlay[] = t_humanSetupCardsInPlay.split(";");
    String computerSetupCardsInPlay[] = t_computerSetupCardsInPlay.split(";");
    String humanSetupCardsInHand[] = t_humanSetupCardsInHand.split(";");
    String computerSetupCardsInHand[] = t_computerSetupCardsInHand.split(";");
    String humanSetupGraveyard[] = t_humanSetupGraveyard.split(";");
    String computerSetupGraveyard[] = t_computerSetupGraveyard.split(";");
    String humanSetupLibrary[] = t_humanSetupLibrary.split(";");
    String computerSetupLibrary[] = t_computerSetupLibrary.split(";");
    String humanSetupExile[] = t_humanSetupExile.split(";");
    String computerSetupExile[] = t_computerSetupExile.split(";");

    CardList humanDevSetup = new CardList();
    CardList computerDevSetup = new CardList();
    CardList humanDevHandSetup = new CardList();
    CardList computerDevHandSetup = new CardList();
    CardList humanDevGraveyardSetup = new CardList();
    CardList computerDevGraveyardSetup = new CardList();
    CardList humanDevLibrarySetup = new CardList();
    CardList computerDevLibrarySetup = new CardList();
    CardList humanDevExileSetup = new CardList();
    CardList computerDevExileSetup = new CardList();

    if (!t_changePlayer.trim().toLowerCase().equals("none")) {
      if (t_changePlayer.trim().toLowerCase().equals("human")) {
        AllZone.getPhase().setPlayerTurn(AllZone.getHumanPlayer());
      }
      if (t_changePlayer.trim().toLowerCase().equals("ai")) {
        AllZone.getPhase().setPlayerTurn(AllZone.getComputerPlayer());
      }
    }

    if (!t_changePhase.trim().toLowerCase().equals("none")) {
      AllZone.getPhase().setDevPhaseState(t_changePhase);
    }

    if (!t_humanSetupCardsInPlay.trim().toLowerCase().equals("none"))
      humanDevSetup = devProcessCardsForZone(humanSetupCardsInPlay, AllZone.getHumanPlayer());

    if (!t_humanSetupCardsInHand.trim().toLowerCase().equals("none"))
      humanDevHandSetup = devProcessCardsForZone(humanSetupCardsInHand, AllZone.getHumanPlayer());

    if (!t_computerSetupCardsInPlay.trim().toLowerCase().equals("none"))
      computerDevSetup =
          devProcessCardsForZone(computerSetupCardsInPlay, AllZone.getComputerPlayer());

    if (!t_computerSetupCardsInHand.trim().toLowerCase().equals("none"))
      computerDevHandSetup =
          devProcessCardsForZone(computerSetupCardsInHand, AllZone.getComputerPlayer());

    if (!t_computerSetupGraveyard.trim().toLowerCase().equals("none"))
      computerDevGraveyardSetup =
          devProcessCardsForZone(computerSetupGraveyard, AllZone.getComputerPlayer());

    if (!t_humanSetupGraveyard.trim().toLowerCase().equals("none"))
      humanDevGraveyardSetup =
          devProcessCardsForZone(humanSetupGraveyard, AllZone.getHumanPlayer());

    if (!t_humanSetupLibrary.trim().toLowerCase().equals("none"))
      humanDevLibrarySetup = devProcessCardsForZone(humanSetupLibrary, AllZone.getHumanPlayer());

    if (!t_computerSetupLibrary.trim().toLowerCase().equals("none"))
      computerDevLibrarySetup =
          devProcessCardsForZone(computerSetupLibrary, AllZone.getComputerPlayer());

    if (!t_humanSetupExile.trim().toLowerCase().equals("none"))
      humanDevExileSetup = devProcessCardsForZone(humanSetupExile, AllZone.getHumanPlayer());

    if (!t_computerSetupExile.trim().toLowerCase().equals("none"))
      computerDevExileSetup =
          devProcessCardsForZone(computerSetupExile, AllZone.getComputerPlayer());

    AllZone.getTriggerHandler().suppressMode("ChangesZone");

    for (Card c : humanDevSetup) {
      AllZone.getHumanHand().add(c);
      AllZone.getGameAction().moveToPlay(c);
      c.setSickness(false);
    }

    for (Card c : computerDevSetup) {
      AllZone.getComputerHand().add(c);
      AllZone.getGameAction().moveToPlay(c);
      c.setSickness(false);
    }

    if (computerDevGraveyardSetup.size() > 0)
      AllZone.getComputerGraveyard().setCards(computerDevGraveyardSetup.toArray());
    if (humanDevGraveyardSetup.size() > 0)
      AllZone.getHumanGraveyard().setCards(humanDevGraveyardSetup.toArray());

    if (computerDevHandSetup.size() > 0)
      AllZone.getComputerHand().setCards(computerDevHandSetup.toArray());
    if (humanDevHandSetup.size() > 0) AllZone.getHumanHand().setCards(humanDevHandSetup.toArray());

    if (humanDevLibrarySetup.size() > 0)
      AllZone.getHumanLibrary().setCards(humanDevLibrarySetup.toArray());
    if (computerDevLibrarySetup.size() > 0)
      AllZone.getComputerLibrary().setCards(computerDevLibrarySetup.toArray());

    if (humanDevExileSetup.size() > 0)
      AllZone.getHumanExile().setCards(humanDevExileSetup.toArray());
    if (computerDevExileSetup.size() > 0)
      AllZone.getComputerExile().setCards(computerDevExileSetup.toArray());

    AllZone.getTriggerHandler().clearSuppression("ChangesZone");

    if (setComputerLife > 0) AllZone.getComputerPlayer().setLife(setComputerLife, null);
    if (setHumanLife > 0) AllZone.getHumanPlayer().setLife(setHumanLife, null);

    AllZone.getGameAction().checkStateEffects();
    AllZone.getPhase().updateObservers();
    AllZone.getHumanExile().updateObservers();
    AllZone.getComputerExile().updateObservers();
    AllZone.getHumanHand().updateObservers();
    AllZone.getComputerHand().updateObservers();
    AllZone.getHumanGraveyard().updateObservers();
    AllZone.getComputerGraveyard().updateObservers();
    AllZone.getHumanBattlefield().updateObservers();
    AllZone.getComputerBattlefield().updateObservers();
    AllZone.getHumanLibrary().updateObservers();
    AllZone.getComputerLibrary().updateObservers();
  }