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);
}
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);
}
}
Aggregations