use of pcgen.facade.core.InfoFacade in project pcgen by PCGen.
the class RadioChooserDialog method buildButtonPanel.
/**
* Create the panel of radio buttons.
*/
private void buildButtonPanel() {
ListFacade<InfoFacade> availableList = chooser.getAvailableList();
int row = 0;
avaRadioButton = new JRadioButton[availableList.getSize()];
avaGroup = new ButtonGroup();
// Create the buttons
for (InfoFacade infoFacade : availableList) {
avaRadioButton[row] = new JRadioButton(infoFacade.toString(), false);
avaGroup.add(avaRadioButton[row]);
avaRadioButton[row].addActionListener(this);
++row;
}
int numRows = row;
if (numRows > 0) {
avaRadioButton[0].setSelected(true);
selectedButton = avaRadioButton[0];
}
// Layout the buttons
GridBagLayout gridbag = new GridBagLayout();
buttonPanel = new JPanel();
TitledBorder title = BorderFactory.createTitledBorder(null, "");
buttonPanel.setBorder(title);
buttonPanel.setLayout(gridbag);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
if (numRows > 11) {
buildTwoColLayout(numRows, c, gridbag);
} else {
for (int i = 0; i < numRows; ++i) {
int cr = i;
c.anchor = GridBagConstraints.WEST;
Utility.buildConstraints(c, 0, cr, 2, 1, 1, 0);
gridbag.setConstraints(avaRadioButton[i], c);
buttonPanel.add(avaRadioButton[i]);
}
}
}
use of pcgen.facade.core.InfoFacade in project pcgen by PCGen.
the class SpellSupportFacadeImpl method queryUserForMetamagic.
/**
* 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;
}
use of pcgen.facade.core.InfoFacade in project pcgen by PCGen.
the class SpellSupportFacadeImpl method buildAvailableMetamagicFeatList.
/**
* Get the list of metatmagic feats that the character can use.
* @param spellNode The spell the feats would be applied to.
* @return The list of metamagic feats.
*/
private List<InfoFacade> buildAvailableMetamagicFeatList(SpellNode spellNode) {
List<Ability> characterMetaMagicFeats = new ArrayList<>();
List<CNAbility> feats = pc.getCNAbilities(AbilityCategory.FEAT);
for (CNAbility cna : feats) {
Ability aFeat = cna.getAbility();
if (//$NON-NLS-1$
aFeat.isType("Metamagic") && !aFeat.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.HIDDEN_EXPORT)) {
characterMetaMagicFeats.add(aFeat);
}
}
Globals.sortPObjectListByName(characterMetaMagicFeats);
if (!(spellNode.getSpell() instanceof SpellFacadeImplem)) {
return Collections.emptyList();
}
List<InfoFacade> availableList = new ArrayList<>();
availableList.addAll(characterMetaMagicFeats);
return availableList;
}
use of pcgen.facade.core.InfoFacade in project pcgen by PCGen.
the class TempBonusHelper method getTempBonusTarget.
/**
* Get the target of the temporary bonus. This may present a chooser to the
* user, if a choice of equipment is required. If the bonus is a character
* bonus only, then no chooser will be presented and the return value will
* be the character. If an equipment item is chosen, a new temporary item is
* created from the chosen equipment item, i.e. a copy that has no weight or
* cost.
*
* @param originObj The rules object providing the bonus.
* @param theCharacter The target character.
* @param delegate The user interface delegate which will provide the chooser.
* @param infoFactory An object to provide formatted information about an object.
* @return The temporary equipment item, the character or null if the request
* was cancelled.
*/
static Object getTempBonusTarget(CDOMObject originObj, PlayerCharacter theCharacter, UIDelegate delegate, InfoFactory infoFactory) {
List<InfoFacade> possibleTargets = getListOfApplicableEquipment(originObj, theCharacter);
boolean canApplyToPC = hasCharacterTempBonus(originObj);
if (possibleTargets.isEmpty()) {
if (canApplyToPC) {
return theCharacter;
}
delegate.showInfoMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_itmNoSuitableEquip"));
return null;
}
// Get the user's choice of item
//$NON-NLS-1$
String label = LanguageBundle.getString("im_itmSelectItem");
if (canApplyToPC) {
possibleTargets.add(new CharacterInfoFacade(theCharacter.getDisplay()));
}
final ArrayList<InfoFacade> selectedList = new ArrayList<>();
GeneralChooserFacadeBase chooserFacade = new GeneralChooserFacadeBase(label, possibleTargets, new ArrayList<>(), 1, infoFactory) {
@Override
public void commit() {
for (InfoFacade item : getSelectedList()) {
selectedList.add(item);
}
}
};
chooserFacade.setDefaultView(ChooserTreeViewType.NAME);
delegate.showGeneralChooser(chooserFacade);
if (!selectedList.isEmpty()) {
if (selectedList.get(0) instanceof CharacterInfoFacade) {
return theCharacter;
}
// Create temporary item
Equipment aEq = ((Equipment) selectedList.get(0)).clone();
aEq.makeVirtual();
String currAppName = aEq.getAppliedName();
if (currAppName != null && currAppName.length() > 2) {
if (theCharacter.hasTempApplied(originObj)) {
delegate.showInfoMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_itmAppBonButAlreadyApplied"));
return null;
}
// We need to remove the [] from the old name
aEq.setAppliedName(currAppName.substring(2, currAppName.length() - 1) + ", " + //$NON-NLS-1$
originObj.getKeyName());
} else {
aEq.setAppliedName(originObj.getKeyName());
}
return aEq;
}
return null;
}
use of pcgen.facade.core.InfoFacade in project pcgen by PCGen.
the class TempBonusHelper method getListOfApplicableEquipment.
/**
* Build a list of what equipment is possible to apply this bonus to.
* @param originObj The rules object providing the bonus.
* @param theCharacter The target character.
* @return The list of possible equipment.
*/
public static List<InfoFacade> getListOfApplicableEquipment(CDOMObject originObj, PlayerCharacter theCharacter) {
CharacterDisplay charDisplay = theCharacter.getDisplay();
List<InfoFacade> possibleEquipment = new ArrayList<>();
if (originObj == null) {
return possibleEquipment;
}
boolean found = false;
theCharacter.setCalcEquipmentList(theCharacter.getUseTempMods());
for (Equipment aEq : charDisplay.getEquipmentSet()) {
found = false;
for (EquipBonus eb : originObj.getSafeListFor(ListKey.BONUS_EQUIP)) {
String conditions = eb.conditions;
boolean passesConditions = passesConditions(aEq, conditions);
if (passesConditions && !found) {
possibleEquipment.add(aEq);
found = true;
}
}
}
return possibleEquipment;
}
Aggregations