Search in sources :

Example 1 with CDOMChooserFacadeImpl

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

the class SubClassApplication method checkForSubClass.

public static void checkForSubClass(PlayerCharacter aPC, PCClass cl) {
    List<SubClass> subClassList = cl.getListFor(ListKey.SUB_CLASS);
    if (subClassList == null || subClassList.isEmpty()) {
        return;
    }
    List<PCClass> availableList = new ArrayList<>();
    String subClassKey = aPC.getSubClassName(cl);
    boolean subClassSelected = subClassKey != null && !subClassKey.equals(Constants.NONE) && !subClassKey.equals("");
    for (SubClass sc : subClassList) {
        if (!PrereqHandler.passesAll(sc.getPrerequisiteList(), aPC, cl)) {
            continue;
        }
        // If a subclass has already been selected, only add that one
        if (!subClassSelected || sc.getKeyName().equals(aPC.getSubClassName(cl))) {
            availableList.add(sc);
        }
    }
    // add base class to the chooser
    if (cl.getSafe(ObjectKey.ALLOWBASECLASS) && (!subClassSelected || cl.getKeyName().equals(aPC.getSubClassName(cl)))) {
        availableList.add(0, cl);
    }
    /*
		 * REFACTOR This makes an assumption that SubClasses are ONLY Schools, which may
		 * not be a fabulous assumption
		 */
    List<PCClass> selectedSubClasses;
    CDOMChooserFacadeImpl<PCClass> chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
    LanguageBundle.getString("in_schoolSpecChoice"), //$NON-NLS-1$
    availableList, new ArrayList<>(), 1);
    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
    chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
    if (availableList.size() == 1) {
        selectedSubClasses = availableList;
    } else if (availableList.isEmpty()) {
        if (Logging.isLoggable(Logging.WARNING)) {
            Logging.log(Logging.WARNING, "No subclass choices avaialble for " + cl);
        }
        return;
    } else {
        ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
        selectedSubClasses = chooserFacade.getFinalSelected();
    }
    if (!cl.getSafe(ObjectKey.ALLOWBASECLASS)) {
        while (selectedSubClasses.isEmpty()) {
            ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
            selectedSubClasses = chooserFacade.getFinalSelected();
        }
    }
    if (selectedSubClasses.isEmpty()) {
        return;
    }
    PCClass subselected = selectedSubClasses.get(0);
    if (subselected instanceof SubClass) {
        aPC.removeProhibitedSchools(cl);
        /*
			 * CONSIDER What happens to this reset during PCClass/PCClassLevel split
			 */
        aPC.removeAssoc(cl, AssociationKey.SPECIALTY);
        SubClass sc = (SubClass) subselected;
        availableList.clear();
        for (SubClass sub : subClassList) {
            if (sub.equals(sc)) {
                //Skip the selected specialist school
                continue;
            }
            if (!PrereqHandler.passesAll(sub.getPrerequisiteList(), aPC, cl)) {
                continue;
            }
            int displayedCost = sub.getProhibitCost();
            if (displayedCost == 0) {
                continue;
            }
            availableList.add(sub);
        }
        setSubClassKey(aPC, cl, sc.getKeyName());
        if (sc.get(ObjectKey.CHOICE) != null) {
            aPC.setAssoc(cl, AssociationKey.SPECIALTY, sc.getChoice());
        }
        if (sc.getSafe(IntegerKey.COST) != 0) {
            chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
            LanguageBundle.getString("in_schoolProhibitChoice"), availableList, new ArrayList<>(), sc.getSafe(IntegerKey.COST));
            chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
            chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
            chooserFacade.setRequireCompleteSelection(true);
            ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
            selectedSubClasses = chooserFacade.getFinalSelected();
            for (PCClass choice : chooserFacade.getFinalSelected()) {
                sc = (SubClass) choice;
                SpellProhibitor prohibSchool = new SpellProhibitor();
                prohibSchool.setType(ProhibitedSpellType.SCHOOL);
                prohibSchool.addValue(sc.getChoice());
                SpellProhibitor prohibSubSchool = new SpellProhibitor();
                prohibSubSchool.setType(ProhibitedSpellType.SUBSCHOOL);
                prohibSubSchool.addValue(sc.getChoice());
                aPC.addProhibitedSchool(prohibSchool, cl);
                aPC.addProhibitedSchool(prohibSubSchool, cl);
            }
        }
    }
}
Also used : SubClass(pcgen.core.SubClass) CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) SpellProhibitor(pcgen.core.SpellProhibitor) Gui2InfoFactory(pcgen.gui2.facade.Gui2InfoFactory)

Example 2 with CDOMChooserFacadeImpl

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

the class EquipmentChoiceDriver method setChoice.

private static void setChoice(Equipment parent, EquipmentModifier eqMod, final List<Object> selectedList, final EquipmentChoice equipChoice) {
    parent.removeAllAssociations(eqMod);
    for (int i = 0; i < selectedList.size(); i++) {
        String aString = String.valueOf(selectedList.get(i));
        if (equipChoice.getMinValue() < equipChoice.getMaxValue()) {
            final int idx = aString.indexOf('|');
            if (idx < 0) {
                final List<SignedInteger> secondaryChoice = new ArrayList<>();
                for (int j = equipChoice.getMinValue(); j <= equipChoice.getMaxValue(); j += equipChoice.getIncValue()) {
                    if (j != 0) {
                        secondaryChoice.add(new SignedInteger(j));
                    }
                }
                String title = LanguageBundle.getFormattedString("in_equipChoiceSelectMod", //$NON-NLS-1$
                aString);
                CDOMChooserFacadeImpl<SignedInteger> chooserFacade = new CDOMChooserFacadeImpl<>(title, secondaryChoice, new ArrayList<>(), 1);
                chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
                chooserFacade.setAllowsDups(equipChoice.isAllowDuplicates());
                ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
                List<SignedInteger> chosenList = chooserFacade.getFinalSelected();
                if (chosenList.isEmpty()) {
                    continue;
                }
                aString += ('|' + chosenList.get(0).toString());
            }
        }
        if (equipChoice.isAllowDuplicates() || !parent.containsAssociated(eqMod, aString)) {
            parent.addAssociation(eqMod, aString);
        }
    }
}
Also used : CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) SignedInteger(pcgen.util.SignedInteger)

Example 3 with CDOMChooserFacadeImpl

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

the class Globals method getChoiceFromList.

/**
	 * Ask the user for a choice from a list.
	 * @param title The title of the chooser dialog.
	 * @param choiceList The list of possible choices.
	 * @param selectedList The values already selected (none of which should be in the available list).
	 * @param pool The number of choices the user can make.
	 * @param forceChoice true if the user will be forced to make all choices.
	 * @param preferRadioSelection true if this would be better presented as a radio button list
	 * @param pc The character the choice is being made for.
	 * @return The list of choices made by the user.
	 */
public static <T> List<T> getChoiceFromList(final String title, final List<T> choiceList, final List<T> selectedList, final int pool, final boolean forceChoice, final boolean preferRadioSelection, final PlayerCharacter pc) {
    List<T> startingSelectedList = new ArrayList<>();
    if (selectedList != null) {
        startingSelectedList = selectedList;
    }
    final CDOMChooserFacadeImpl<T> chooserFacade = new CDOMChooserFacadeImpl<>(title, choiceList, startingSelectedList, pool);
    chooserFacade.setAllowsDups(false);
    chooserFacade.setRequireCompleteSelection(forceChoice);
    chooserFacade.setInfoFactory(new Gui2InfoFactory(pc));
    chooserFacade.setDefaultView(ChooserFacade.ChooserTreeViewType.NAME);
    chooserFacade.setPreferRadioSelection(preferRadioSelection);
    ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
    return chooserFacade.getFinalSelected();
}
Also used : Gui2InfoFactory(pcgen.gui2.facade.Gui2InfoFactory) CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList)

Example 4 with CDOMChooserFacadeImpl

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

the class StatApplication method askForStatIncrease.

//
// Ask user to select a stat to increment. This can happen before skill
// points
// are calculated, so an increase to the appropriate stat can give more
// skill points
//
public static int askForStatIncrease(final PlayerCharacter aPC, final int statsToChoose, final boolean isPre) {
    //
    if (isPre) {
        if (!Globals.checkRule(RuleConstants.INTBEFORE)) {
            return statsToChoose;
        }
    }
    String titleKey = "in_statTitle";
    if (isPre && !Globals.checkRule(RuleConstants.RETROSKILL)) {
        titleKey = "in_statTitleWithSkill";
    }
    int iCount = 0;
    Set<PCStat> statsAlreadyBonused = new HashSet<>();
    boolean allowStacks = SettingsHandler.getGame().isBonusStatAllowsStack();
    DecimalFormat formatter = PrettyIntegerFormat.getFormat();
    for (int ix = 0; ix < statsToChoose; ++ix) {
        final List<String> selectableStats = new ArrayList<>();
        for (PCStat aStat : aPC.getDisplay().getStatSet()) {
            final StringBuilder sStats = new StringBuilder(100);
            final int iAdjStat = aPC.getTotalStatFor(aStat);
            final int iCurStat = aPC.getBaseStatFor(aStat);
            sStats.append(aStat.getDisplayName()).append(":  ").append(iCurStat);
            if (iCurStat != iAdjStat) {
                sStats.append(" adjusted: ").append(iAdjStat);
            }
            sStats.append(" (").append(formatter.format(aPC.getStatModFor(aStat))).append(")");
            if (allowStacks || !statsAlreadyBonused.contains(aStat)) {
                selectableStats.add(sStats.toString());
            } else {
                sStats.append(" * Already incremented.");
                selectableStats.add(sStats.toString());
            }
        }
        CDOMChooserFacadeImpl<String> chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
        LanguageBundle.getString(titleKey), //$NON-NLS-1$
        selectableStats, new ArrayList<>(), 1);
        chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
        chooserFacade.setPreferRadioSelection(true);
        chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
        ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
        final List<String> selectedValues = chooserFacade.getFinalSelected();
        final String selectedValue = selectedValues.isEmpty() ? null : selectedValues.get(0);
        if (selectedValue != null) {
            for (PCStat aStat : aPC.getStatSet()) {
                if (selectedValue.startsWith(aStat.getDisplayName())) {
                    aPC.saveStatIncrease(aStat, 1, isPre);
                    aPC.setStat(aStat, aPC.getStat(aStat) + 1);
                    aPC.setPoolAmount(aPC.getPoolAmount() - 1);
                    statsAlreadyBonused.add(aStat);
                    ++iCount;
                    break;
                }
            }
        }
    }
    return statsToChoose - iCount;
}
Also used : CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Gui2InfoFactory(pcgen.gui2.facade.Gui2InfoFactory) PCStat(pcgen.core.PCStat) HashSet(java.util.HashSet)

Example 5 with CDOMChooserFacadeImpl

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

the class SubstitutionClassApplication method checkForSubstitutionClass.

public static void checkForSubstitutionClass(PCClass cl, final int aLevel, final PlayerCharacter aPC) {
    List<SubstitutionClass> substitutionClassList = cl.getListFor(ListKey.SUBSTITUTION_CLASS);
    if (substitutionClassList == null || substitutionClassList.isEmpty()) {
        return;
    }
    List<PCClass> choiceList = new ArrayList<>();
    buildSubstitutionClassChoiceList(cl, choiceList, aPC.getLevel(cl), aPC);
    if (choiceList.size() <= 1) {
        // This means the there are no classes for which
        return;
    // the pc meets the prerequisitions and thus the
    // base class is chosen.
    }
    CDOMChooserFacadeImpl<PCClass> chooserFacade = new CDOMChooserFacadeImpl<>(//$NON-NLS-1$
    LanguageBundle.getString("in_SubstLvlChoice"), //$NON-NLS-1$
    choiceList, new ArrayList<>(), 1);
    chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
    chooserFacade.setInfoFactory(new Gui2InfoFactory(aPC));
    ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
    List<PCClass> selectedList = chooserFacade.getFinalSelected();
    PCClass selected = null;
    if (!selectedList.isEmpty()) {
        selected = selectedList.get(0);
    }
    if ((!selectedList.isEmpty()) && selected instanceof SubstitutionClass) {
        SubstitutionClass sc = (SubstitutionClass) selected;
        SubstitutionLevelSupport.applyLevelArrayModsToLevel(sc, cl, aLevel, aPC);
        aPC.setSubstitutionClassName(aPC.getActiveClassLevel(cl, aLevel), sc.getKeyName());
        return;
    } else {
        /*
			 * the original code has the below line.. however, it appears to not
			 * be needed. I say this because if the original
			 * buildSubstitutionClassChoiceList method returned an empty list,
			 * it returned right away without calling this method.
			 */
        aPC.removeSubstitutionClassName(aPC.getActiveClassLevel(cl, aLevel));
        return;
    }
}
Also used : Gui2InfoFactory(pcgen.gui2.facade.Gui2InfoFactory) CDOMChooserFacadeImpl(pcgen.core.chooser.CDOMChooserFacadeImpl) ArrayList(java.util.ArrayList) PCClass(pcgen.core.PCClass) SubstitutionClass(pcgen.core.SubstitutionClass)

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