Search in sources :

Example 1 with CompanionFacade

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());
    }
}
Also used : FollowerOption(pcgen.core.FollowerOption) CompanionList(pcgen.cdom.list.CompanionList) ArrayList(java.util.ArrayList) Follower(pcgen.core.character.Follower) CompanionFacade(pcgen.facade.core.CompanionFacade) CDOMObject(pcgen.cdom.base.CDOMObject) File(java.io.File)

Example 2 with CompanionFacade

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);
    }
}
Also used : AbstractTreeTableModel(pcgen.gui2.util.treetable.AbstractTreeTableModel) TreeTableModel(pcgen.gui2.util.treetable.TreeTableModel) CompanionFacade(pcgen.facade.core.CompanionFacade) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath)

Example 3 with CompanionFacade

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();
        }
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) CompanionFacade(pcgen.facade.core.CompanionFacade)

Example 4 with CompanionFacade

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;
        }
    }
}
Also used : File(java.io.File) CompanionFacade(pcgen.facade.core.CompanionFacade)

Example 5 with CompanionFacade

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CharacterStubFacade(pcgen.facade.core.CharacterStubFacade) CharacterFacade(pcgen.facade.core.CharacterFacade) CompanionFacade(pcgen.facade.core.CompanionFacade)

Aggregations

CompanionFacade (pcgen.facade.core.CompanionFacade)5 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 CompanionList (pcgen.cdom.list.CompanionList)1 FollowerOption (pcgen.core.FollowerOption)1 PlayerCharacter (pcgen.core.PlayerCharacter)1 Follower (pcgen.core.character.Follower)1 CharacterFacade (pcgen.facade.core.CharacterFacade)1 CharacterStubFacade (pcgen.facade.core.CharacterStubFacade)1 AbstractTreeTableModel (pcgen.gui2.util.treetable.AbstractTreeTableModel)1 TreeTableModel (pcgen.gui2.util.treetable.TreeTableModel)1