Ejemplo n.º 1
0
  @Override
  public void previewSpells() {
    boolean aBool = SettingsHandler.getPrintSpellsWithPC();
    SettingsHandler.setPrintSpellsWithPC(true);

    String templateFileName =
        PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
    if (StringUtils.isEmpty(templateFileName)) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME, LanguageBundle.getString("in_spellNoSheet")); // $NON-NLS-1$
      return;
    }
    File templateFile = new File(templateFileName);

    File outputFile = BatchExporter.getTempOutputFilename(templateFile);

    boolean success;
    if (ExportUtilities.isPdfTemplate(templateFile)) {
      success = BatchExporter.exportCharacterToPDF(pcFacade, outputFile, templateFile);
    } else {
      success = BatchExporter.exportCharacterToNonPDF(pcFacade, outputFile, templateFile);
    }
    if (success) {
      try {
        Utility.viewInBrowser(outputFile);
      } catch (IOException e) {
        Logging.errorPrint("SpellSupportFacadeImpl.previewSpells failed", e);
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getString("in_spellPreviewFail")); // $NON-NLS-1$
      }
    }
    SettingsHandler.setPrintSpellsWithPC(aBool);
  }
Ejemplo n.º 2
0
  /**
   * Request the metamagic feats to be applied to a spell from the user via a chooser.
   *
   * @param spellNode The spell to have metamagic applied
   * @return The list of metamagic feats to be applied.
   */
  private List<Ability> queryUserForMetamagic(SpellNode spellNode) {
    // get the list of metamagic feats for the PC
    List<InfoFacade> availableList = buildAvailableMetamagicFeatList(spellNode);
    if (availableList.isEmpty()) {
      return Collections.emptyList();
    }

    String label = dataSet.getGameMode().getAddWithMetamagicMessage();
    if (StringUtils.isEmpty(label)) {
      label = LanguageBundle.getString("InfoSpells.add.with.metamagic");
    }

    final ArrayList<Ability> selectedList = new ArrayList<>();
    GeneralChooserFacadeBase chooserFacade =
        new GeneralChooserFacadeBase(label, availableList, new ArrayList<>(), 99, infoFactory) {
          @Override
          public void commit() {
            for (InfoFacade item : getSelectedList()) {
              selectedList.add((Ability) item);
            }
          }
        };

    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
    boolean result = delegate.showGeneralChooser(chooserFacade);
    return result ? selectedList : null;
  }
Ejemplo n.º 3
0
  /**
   * Add a spell to the named book for the character. The request will be validated and any errors
   * shown to the user by the UIDelegate.
   *
   * @param spell The spell to be added.
   * @param bookName The book to add the spell to.
   * @param metamagicFeats List of the metamagic feats that should be applied to this spell.
   * @return The new SpellNode, or null if the selection was invalid.
   */
  private SpellNode addSpellToCharacter(
      SpellNode spell, String bookName, List<Ability> metamagicFeats) {
    if (!(spell.getSpell() instanceof SpellFacadeImplem)) {
      return null;
    }
    if (spell.getSpellcastingClass() == null) {
      return null;
    }
    CharacterSpell charSpell = ((SpellFacadeImplem) spell.getSpell()).getCharSpell();
    if (charSpell == null) {
      return null;
    }
    int level = Integer.parseInt(spell.getSpellLevel());
    for (Ability ability : metamagicFeats) {
      level += ability.getSafe(IntegerKey.ADD_SPELL_LEVEL);
    }

    String errorMsg =
        pc.addSpell(
            charSpell,
            metamagicFeats,
            spell.getSpellcastingClass().getKeyName(),
            bookName,
            level,
            level);
    if (!StringUtils.isEmpty(errorMsg)) {
      delegate.showErrorMessage(Constants.APPLICATION_NAME, errorMsg);
      return null;
    }

    SpellInfo spellInfo = charSpell.getSpellInfoFor(bookName, level, metamagicFeats);
    boolean isKnown = Globals.getDefaultSpellBook().equals(bookName);
    SpellFacadeImplem spellImplem =
        new SpellFacadeImplem(pc, charSpell.getSpell(), charSpell, spellInfo);
    SpellNodeImpl node =
        new SpellNodeImpl(
            spellImplem,
            spell.getSpellcastingClass(),
            String.valueOf(spellInfo.getActualLevel()),
            getRootNode(bookName));
    return node;
  }
Ejemplo n.º 4
0
  /**
   * Remove a spell from the named book for the character. The request will be validated and any
   * errors shown to the user by the UIDelegate.
   *
   * @param spell The spell to be removed.
   * @param bookName The book to remove the spell from.
   * @return True if the removal worked, false if the selection was invalid.
   */
  private boolean removeSpellFromCharacter(SpellNode spell, String bookName) {
    if (!(spell.getSpell() instanceof SpellFacadeImplem)) {
      return false;
    }
    SpellFacadeImplem sfi = (SpellFacadeImplem) spell.getSpell();
    CharacterSpell charSpell = sfi.getCharSpell();
    SpellInfo spellInfo = sfi.getSpellInfo();
    if (charSpell == null || spellInfo == null) {
      return false;
    }

    final String errorMsg =
        pc.delSpell(spellInfo, (PCClass) spell.getSpellcastingClass(), bookName);

    if (errorMsg.length() > 0) {
      delegate.showErrorMessage(Constants.APPLICATION_NAME, errorMsg);
      ShowMessageDelegate.showMessageDialog(
          errorMsg, Constants.APPLICATION_NAME, MessageType.ERROR);
      return false;
    }

    return true;
  }
Ejemplo n.º 5
0
  @Override
  public void exportSpells() {
    final String template =
        PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
    if (StringUtils.isEmpty(template)) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME, LanguageBundle.getString("in_spellNoSheet")); // $NON-NLS-1$
      return;
    }
    String ext = template.substring(template.lastIndexOf('.'));

    // Get the name of the file to output to.
    JFileChooser fcExport = new JFileChooser();
    fcExport.setCurrentDirectory(new File(PCGenSettings.getPcgDir()));
    fcExport.setDialogTitle(
        LanguageBundle.getString("InfoSpells.export.spells.for")
            + charDisplay.getDisplayName()); // $NON-NLS-1$

    if (fcExport.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) {
      return;
    }
    final String aFileName = fcExport.getSelectedFile().getAbsolutePath();
    if (aFileName.length() < 1) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME,
          LanguageBundle.getString("InfoSpells.must.set.filename")); // $NON-NLS-1$
      return;
    }

    try {
      final File outFile = new File(aFileName);

      if (outFile.isDirectory()) {
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getString("InfoSpells.can.not.overwrite.directory")); // $NON-NLS-1$
        return;
      }

      if (outFile.exists()) {
        int reallyClose =
            JOptionPane.showConfirmDialog(
                null,
                LanguageBundle.getFormattedString(
                    "InfoSpells.confirm.overwrite", outFile.getName()), // $NON-NLS-1$
                LanguageBundle.getFormattedString("InfoSpells.overwriting", outFile.getName()),
                JOptionPane.YES_NO_OPTION); // $NON-NLS-1$

        if (reallyClose != JOptionPane.YES_OPTION) {
          return;
        }
      }

      // Output the file
      File templateFile = new File(template);
      boolean success;
      if (ExportUtilities.isPdfTemplate(templateFile)) {
        success = BatchExporter.exportCharacterToPDF(pcFacade, outFile, templateFile);
      } else {
        success = BatchExporter.exportCharacterToNonPDF(pcFacade, outFile, templateFile);
      }

      if (!success) {
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getFormattedString(
                "InfoSpells.export.failed", charDisplay.getDisplayName())); // $NON-NLS-1$
      }
    } catch (Exception ex) {
      Logging.errorPrint(
          LanguageBundle.getFormattedString(
              "InfoSpells.export.failed", charDisplay.getDisplayName()),
          ex); //$NON-NLS-1$
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME,
          LanguageBundle.getFormattedString(
              "InfoSpells.export.failed.retry", charDisplay.getDisplayName())); // $NON-NLS-1$
    }
  }