use of pcgen.facade.core.CompanionFacade in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method initCompData.
/**
* Initialisation of the character's companion data.
* @param rebuildCompanionList Should the list of the character;s companions be rebuilt?
*/
private void initCompData(boolean rebuildCompanionList) {
List<CompanionStub> companions = new ArrayList<>();
for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
keyToCompanionListMap.put(compList.getKeyName(), compList);
Map<FollowerOption, CDOMObject> fMap = charDisplay.getAvailableFollowers(compList.getKeyName(), null);
for (FollowerOption followerOpt : fMap.keySet()) {
if (followerOpt.getRace() != Globals.s_EMPTYRACE && followerOpt.qualifies(theCharacter, null)) {
companions.add(new CompanionStub(followerOpt.getRace(), compList.getKeyName()));
}
}
int maxVal = theCharacter.getMaxFollowers(compList);
if (maxVal == 0) {
maxCompanionsMap.removeKey(compList.toString());
} else {
maxCompanionsMap.putValue(compList.toString(), maxVal);
}
}
availCompList.updateContents(companions);
if (rebuildCompanionList) {
for (Follower follower : charDisplay.getFollowerList()) {
CompanionFacade comp = new CompanionNotLoaded(follower.getName(), new File(follower.getFileName()), follower.getRace(), follower.getType().toString());
CompanionFacadeDelegate delegate = new CompanionFacadeDelegate();
delegate.setCompanionFacade(comp);
companionList.addElement(delegate);
}
}
//Logging.debugPrint("Companion list " + companionList);
for (CompanionList compList : Globals.getContext().getReferenceContext().getConstructedCDOMObjects(CompanionList.class)) {
updateCompanionTodo(compList.toString());
}
}
use of pcgen.facade.core.CompanionFacade in project pcgen by PCGen.
the class CompanionInfoTab method selectCompanion.
private void selectCompanion(CompanionFacade compFacade) {
TreeTableModel treeTableModel = companionsTable.getTreeTableModel();
treeTableModel.getRoot();
TreePath path = null;
JTree tree = companionsTable.getTree();
String companionType = compFacade.getCompanionType();
for (int i = 0; i < tree.getRowCount(); i++) {
TreePath pathForRow = tree.getPathForRow(i);
Object lastPathComponent = pathForRow.getLastPathComponent();
if (lastPathComponent.toString().startsWith(companionType)) {
tree.expandRow(i);
} else if (lastPathComponent instanceof pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) {
CompanionFacade rowComp = (CompanionFacade) ((pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) lastPathComponent).getValueAt(0);
if (rowComp != null && rowComp.getFileRef().get() == compFacade.getFileRef().get() && rowComp.getNameRef().get() == compFacade.getNameRef().get() && rowComp.getRaceRef().get() == compFacade.getRaceRef().get()) {
path = pathForRow;
}
}
}
if (path != null) {
companionsTable.getTree().setSelectionPath(path);
companionsTable.getTree().scrollPathToVisible(path);
}
}
use of pcgen.facade.core.CompanionFacade in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method refreshCompanionData.
/**
* Refresh the character's companion information, reflecting any changes in
* the character's qualification for companions.
*/
void refreshCompanionData() {
initCompData(false);
for (CompanionFacadeDelegate delegate : companionList) {
CompanionFacade compFacade = delegate.getDelegate();
if (compFacade instanceof CharacterFacadeImpl) {
CharacterFacadeImpl compFacadeImpl = (CharacterFacadeImpl) compFacade;
PlayerCharacter pc = compFacadeImpl.getTheCharacter();
pc.setMaster(pc.getDisplay().getMaster());
compFacadeImpl.refreshClassLevelModel();
compFacadeImpl.postLevellingUpdates();
}
}
}
use of pcgen.facade.core.CompanionFacade in project pcgen by PCGen.
the class CompanionSupportFacadeImpl method unlinkCompanion.
/**
* Removes a character from the companion framework.
* This will replace the specified character with a dummy
* CompanionFacade.
* This should be called after the specified character has been closed
* or is closing.
* If this method is not called after closing a companion character
* the underlying CharacterFacade would not be able to be garbage collected.
* @param character the character to unlink
*/
private void unlinkCompanion(CharacterFacade character) {
for (CompanionFacadeDelegate delegate : companionList) {
File file = delegate.getFileRef().get();
if (file.equals(character.getFileRef().get())) {
CompanionFacade comp = new CompanionNotLoaded(character.getNameRef().get(), character.getFileRef().get(), character.getRaceRef().get(), delegate.getCompanionType());
delegate.setCompanionFacade(comp);
return;
}
}
}
use of pcgen.facade.core.CompanionFacade in project pcgen by PCGen.
the class PCGenFrame method prepareForSave.
/**
* Prepare the character for a save. This is primarily concerned with
* ensuring all companions (or masters) have file names before the save is
* done.
* @param character The character being saved.
*/
private void prepareForSave(CharacterFacade character, boolean savingAll) {
List<CompanionFacade> tobeSaved = new ArrayList<>();
for (CompanionFacade comp : character.getCompanionSupport().getCompanions()) {
if (StringUtils.isEmpty(comp.getFileRef().get().getName()) && CharacterManager.getCharacterMatching(comp) != null) {
tobeSaved.add(comp);
}
}
if (!tobeSaved.isEmpty()) {
if (savingAll || showMessageConfirm(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_unsavedCompanions"))) {
for (CompanionFacade companionFacade : tobeSaved) {
CharacterFacade compChar = CharacterManager.getCharacterMatching(companionFacade);
showSaveCharacterChooser(compChar);
}
}
}
CharacterStubFacade master = character.getMaster();
if (master != null && (master.getFileRef().get() == null || StringUtils.isEmpty(master.getFileRef().get().getName()))) {
if (savingAll || showMessageConfirm(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_unsavedMaster"))) {
CharacterFacade masterChar = CharacterManager.getCharacterMatching(master);
showSaveCharacterChooser(masterChar);
}
}
}
Aggregations