Search in sources :

Example 6 with CDOMChooserFacadeImpl

use of pcgen.core.chooser.CDOMChooserFacadeImpl in project pcgen by PCGen.

the class EquipmentChoiceDriver method getChoice.

/**
	 * @param pool
	 * @param parent
	 * @param bAdd being added
	 * @return an integer where apparently (from how it's used) only 0 is significant
	 */
public static boolean getChoice(final int pool, final Equipment parent, EquipmentModifier eqMod, final boolean bAdd, PlayerCharacter pc) {
    String choiceString = eqMod.getSafe(StringKey.CHOICE_STRING);
    if (choiceString.isEmpty()) {
        return true;
    }
    final boolean forEqBuilder = choiceString.startsWith("EQBUILDER.");
    if (bAdd && forEqBuilder) {
        return true;
    }
    List<Object> selectedList = new ArrayList<>(parent.getAssociationList(eqMod));
    final EquipmentChoice equipChoice = buildEquipmentChoice(pool, parent, eqMod, bAdd, forEqBuilder, selectedList.size(), pc);
    int effectiveChoices;
    if (equipChoice.isBAdd()) {
        effectiveChoices = selectedList.size() + equipChoice.getMaxSelect();
    } else {
        effectiveChoices = selectedList.size();
    }
    String title = //$NON-NLS-1$
    LanguageBundle.getFormattedString(//$NON-NLS-1$
    "in_equipChoiceMod", equipChoice.getTitle(), eqMod.getDisplayName(), "|");
    CDOMChooserFacadeImpl<Object> chooserFacade = new CDOMChooserFacadeImpl<>(title, equipChoice.getAvailableList(), selectedList, effectiveChoices);
    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
    chooserFacade.setAllowsDups(equipChoice.isAllowDuplicates());
    ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
    selectedList = chooserFacade.getFinalSelected();
    setChoice(parent, eqMod, selectedList, equipChoice);
    return parent.hasAssociations(eqMod);
}
Also used : CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) EquipmentChoice(pcgen.core.EquipmentChoice)

Example 7 with CDOMChooserFacadeImpl

use of pcgen.core.chooser.CDOMChooserFacadeImpl in project pcgen by PCGen.

the class ExchangeLevelApplication method exchangeLevels.

public static void exchangeLevels(final PlayerCharacter aPC, PCClass newcl) {
    LevelExchange le = newcl.get(ObjectKey.EXCHANGE_LEVEL);
    try {
        PCClass cl = le.getExchangeClass().get();
        int iMinLevel = le.getMinDonatingLevel();
        int iMaxDonation = le.getMaxDonatedLevels();
        int iLowest = le.getDonatingLowerLevelBound();
        final PCClass aClass = aPC.getClassKeyed(cl.getKeyName());
        if (aClass != null) {
            final int iNumOrigClassLevel = aPC.getLevel(aClass);
            if (iNumOrigClassLevel >= iMinLevel) {
                iMaxDonation = Math.min(iMaxDonation, iNumOrigClassLevel - iLowest + 1);
                if (newcl.hasMaxLevel()) {
                    iMaxDonation = Math.min(iMaxDonation, newcl.getSafe(IntegerKey.LEVEL_LIMIT) - aPC.getLevel(newcl));
                }
                if (iMaxDonation > 0) {
                    //
                    // Build the choice list
                    //
                    final List<Integer> choiceNames = new ArrayList<>();
                    for (int i = 0; i <= iMaxDonation; ++i) {
                        choiceNames.add(i);
                    }
                    //
                    // Get number of levels to exchange for this class
                    //
                    String title = LanguageBundle.getFormattedString("in_exchangeLevelsChoice", aClass.getDisplayName(), newcl.getDisplayName());
                    CDOMChooserFacadeImpl<Integer> chooserFacade = new CDOMChooserFacadeImpl<>(title, choiceNames, new ArrayList<>(), 1);
                    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
                    ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
                    final List<Integer> selectedList = chooserFacade.getFinalSelected();
                    int iLevels = 0;
                    if (!selectedList.isEmpty()) {
                        iLevels = selectedList.get(0);
                    }
                    if (iLevels > 0) {
                        aPC.giveClassesAway(newcl, aClass, iLevels);
                    }
                }
            }
        }
    } catch (NumberFormatException exc) {
        ShowMessageDelegate.showMessageDialog("levelExchange:" + Constants.LINE_SEPARATOR + exc.getMessage(), Constants.APPLICATION_NAME, MessageType.ERROR);
    }
}
Also used : LevelExchange(pcgen.cdom.content.LevelExchange) CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass)

Aggregations

ArrayList (java.util.ArrayList)7 CDOMChooserFacadeImpl (pcgen.core.chooser.CDOMChooserFacadeImpl)7 Gui2InfoFactory (pcgen.gui2.facade.Gui2InfoFactory)4 PCClass (pcgen.core.PCClass)3 DecimalFormat (java.text.DecimalFormat)1 HashSet (java.util.HashSet)1 LevelExchange (pcgen.cdom.content.LevelExchange)1 EquipmentChoice (pcgen.core.EquipmentChoice)1 PCStat (pcgen.core.PCStat)1 SpellProhibitor (pcgen.core.SpellProhibitor)1 SubClass (pcgen.core.SubClass)1 SubstitutionClass (pcgen.core.SubstitutionClass)1 SignedInteger (pcgen.util.SignedInteger)1