use of pcgen.gui2.facade.Gui2InfoFactory 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);
}
}
}
}
use of pcgen.gui2.facade.Gui2InfoFactory in project pcgen by PCGen.
the class CDOMChoiceManager method doChooser.
/**
* Display a chooser to the user.
*
* @param aPc The character the choice is for.
* @param availableList The list of possible choices.
* @param selectedList The list of existing selections.
* @return list The list of the new selections made by the user (unchanged if the dialog was cancelled)
*/
@Override
public List<T> doChooser(PlayerCharacter aPc, final List<T> availableList, final List<T> selectedList, final List<String> reservedList) {
int effectiveChoices = getNumEffectiveChoices(selectedList, reservedList, aPc);
boolean dupsAllowed = controller.isMultYes() && controller.isStackYes();
/*
* TODO This is temporarily commented out until the correct behavior of
* the "available" list is established. This is done to make
* CDOMChoiceManager not remove items when selected, which is consistent
* with the (buggy?) old Choose system
*/
if (!dupsAllowed) {
// availableList.removeAll(reservedList);
availableList.removeAll(selectedList);
}
Globals.sortChooserLists(availableList, selectedList);
String title = //$NON-NLS-1$
StringUtils.isBlank(info.getTitle()) ? //$NON-NLS-1$
"in_chooser" : info.getTitle();
if (//$NON-NLS-1$
title.startsWith("in_")) {
title = LanguageBundle.getString(title);
}
CDOMChooserFacadeImpl<T> chooserFacade = new CDOMChooserFacadeImpl<>(title, availableList, selectedList, effectiveChoices);
chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
chooserFacade.setAllowsDups(dupsAllowed);
chooserFacade.setInfoFactory(new Gui2InfoFactory(aPc));
ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
return chooserFacade.getFinalSelected();
}
use of pcgen.gui2.facade.Gui2InfoFactory 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();
}
use of pcgen.gui2.facade.Gui2InfoFactory in project pcgen by PCGen.
the class UserInputManager method doChooser.
/**
* Display a chooser to the user.
*
* @param aPc The character the choice is for.
* @param availableList The list of possible choices.
* @param selectedList The list of existing selections.
* @return list The list of the new selections made by the user (unchanged if the dialog was cancelled)
*/
@Override
public List<String> doChooser(PlayerCharacter aPc, final List<String> availableList, final List<String> selectedList, final List<String> reservedList) {
int effectiveChoices = getNumEffectiveChoices(selectedList, reservedList, aPc);
boolean dupsAllowed = controller.isMultYes() && controller.isStackYes();
Globals.sortChooserLists(availableList, selectedList);
String title = StringUtils.isBlank(info.getTitle()) ? "in_chooser" : info.getTitle();
if (title.startsWith("in_")) {
title = LanguageBundle.getString(title);
}
CDOMChooserFacadeImpl<String> chooserFacade = new CDOMChooserFacadeImpl<>(title, availableList, selectedList, effectiveChoices);
chooserFacade.setAllowsDups(dupsAllowed);
chooserFacade.setInfoFactory(new Gui2InfoFactory(aPc));
chooserFacade.setUserInput(true);
ChooserFactory.getDelegate().showGeneralChooser(chooserFacade);
return chooserFacade.getFinalSelected();
}
use of pcgen.gui2.facade.Gui2InfoFactory 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;
}
Aggregations