Search in sources :

Example 6 with AbilityCategoryFacade

use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.

the class AbilityChooserTab method adviseTodo.

@Override
public void adviseTodo(String fieldName) {
    CategoryTableModel model = (CategoryTableModel) categoryTable.getModel();
    model.refilter();
    for (int i = 0; i < model.getRowCount(); i++) {
        AbilityCategoryFacade category = model.getCategory(i);
        if (category.getName().equals(fieldName)) {
            categoryTable.getSelectionModel().setSelectionInterval(i, i);
            return;
        }
    }
}
Also used : CategoryTableModel(pcgen.gui2.tabs.ability.CategoryTableModel) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade)

Example 7 with AbilityCategoryFacade

use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.

the class CharacterAbilities method rebuildAbilityLists.

/**
	 * Rebuild the ability lists for the character to include the character's 
	 * current abilities.
	 */
synchronized void rebuildAbilityLists() {
    Map<AbilityCategoryFacade, DefaultListFacade<AbilityFacade>> workingAbilityListMap = new LinkedHashMap<>();
    DefaultListFacade<AbilityCategoryFacade> workingActiveCategories = new DefaultListFacade<>();
    for (AbilityCategoryFacade category : dataSetFacade.getAbilities().getKeys()) {
        AbilityCategory cat = (AbilityCategory) category;
        for (CNAbility cna : theCharacter.getPoolAbilities(cat)) {
            addCategorisedAbility(cna, workingAbilityListMap);
        }
        // deal with visibility
        boolean visible = cat.isVisibleTo(theCharacter, View.VISIBLE_DISPLAY);
        if (visible && !workingActiveCategories.containsElement(cat)) {
            int index = getCatIndex(cat, workingActiveCategories);
            workingActiveCategories.addElement(index, cat);
        }
        if (!visible && workingActiveCategories.containsElement(cat)) {
            workingActiveCategories.removeElement(cat);
        //				updateAbilityCategoryTodo(cat);
        }
        if (visible) {
            adviseSelectionChangeLater(cat);
        }
    }
    // Update map contents
    for (AbilityCategoryFacade category : workingAbilityListMap.keySet()) {
        DefaultListFacade<AbilityFacade> workingListFacade = workingAbilityListMap.get(category);
        DefaultListFacade<AbilityFacade> masterListFacade = abilityListMap.get(category);
        if (masterListFacade == null) {
            abilityListMap.put(category, workingListFacade);
        } else {
            masterListFacade.updateContentsNoOrder(workingListFacade.getContents());
        }
        updateAbilityCategoryTodo((AbilityCategory) category);
    }
    Set<AbilityCategoryFacade> origCats = new HashSet<>(abilityListMap.keySet());
    for (AbilityCategoryFacade category : origCats) {
        if (!workingAbilityListMap.containsKey(category)) {
            if (workingActiveCategories.containsElement(category)) {
                abilityListMap.get(category).clearContents();
            } else {
                abilityListMap.remove(category);
            }
            updateAbilityCategoryTodo((AbilityCategory) category);
        }
    }
    activeCategories.updateContents(workingActiveCategories.getContents());
}
Also used : AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) LinkedHashMap(java.util.LinkedHashMap) CNAbility(pcgen.cdom.content.CNAbility) AbilityFacade(pcgen.facade.core.AbilityFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade) AbilityCategory(pcgen.core.AbilityCategory) HashSet(java.util.HashSet)

Example 8 with AbilityCategoryFacade

use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.

the class CharacterAbilities method removeElement.

private void removeElement(CNAbilitySelection cnas) {
    CNAbility cas = cnas.getCNAbility();
    Ability ability = cas.getAbility();
    AbilityCategoryFacade cat = (AbilityCategoryFacade) cas.getAbilityCategory();
    DefaultListFacade<AbilityFacade> listFacade = abilityListMap.get(cat);
    if (listFacade != null) {
        listFacade.removeElement(ability);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) AbilityFacade(pcgen.facade.core.AbilityFacade)

Example 9 with AbilityCategoryFacade

use of pcgen.facade.core.AbilityCategoryFacade in project pcgen by PCGen.

the class CharacterAbilitiesTest method testRebuildAbilityListsNoMult.

/**
	 * Test method for {@link pcgen.gui2.facade.CharacterAbilities#rebuildAbilityLists()}.
	 */
@Test
public final void testRebuildAbilityListsNoMult() {
    PlayerCharacter pc = getCharacter();
    CharacterAbilities ca = new CharacterAbilities(pc, uiDelegate, dataset, todoManager);
    ca.rebuildAbilityLists();
    ListFacade<AbilityCategoryFacade> categories = ca.getActiveAbilityCategories();
    assertNotNull("Categories should not be null", categories);
    assertTrue("Feat should be active", categories.containsElement(AbilityCategory.FEAT));
    ListFacade<AbilityFacade> abilities = ca.getAbilities(AbilityCategory.FEAT);
    assertNotNull("Feat list should not be null", abilities);
    assertTrue("Feat list should be empty", abilities.isEmpty());
    // Add an entry - note rebuild is implicit
    Ability fencing = TestHelper.makeAbility("fencing", AbilityCategory.FEAT, "sport");
    addAbility(AbilityCategory.FEAT, fencing);
    abilities = ca.getAbilities(AbilityCategory.FEAT);
    assertEquals("Feat list should have one entry", 1, abilities.getSize());
    Ability abilityFromList = (Ability) abilities.getElementAt(0);
    assertEquals("Should have found fencing", fencing, abilityFromList);
}
Also used : Ability(pcgen.core.Ability) PlayerCharacter(pcgen.core.PlayerCharacter) AbilityCategoryFacade(pcgen.facade.core.AbilityCategoryFacade) AbilityFacade(pcgen.facade.core.AbilityFacade) Test(org.junit.Test)

Aggregations

AbilityCategoryFacade (pcgen.facade.core.AbilityCategoryFacade)9 AbilityFacade (pcgen.facade.core.AbilityFacade)6 Ability (pcgen.core.Ability)4 CNAbility (pcgen.cdom.content.CNAbility)3 Test (org.junit.Test)2 PlayerCharacter (pcgen.core.PlayerCharacter)2 BorderLayout (java.awt.BorderLayout)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Box (javax.swing.Box)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 EmptyBorder (javax.swing.border.EmptyBorder)1 AbilityCategory (pcgen.core.AbilityCategory)1 CharacterFacade (pcgen.facade.core.CharacterFacade)1 DefaultListFacade (pcgen.facade.util.DefaultListFacade)1 FilterBar (pcgen.gui2.filter.FilterBar)1 FilterButton (pcgen.gui2.filter.FilterButton)1 SearchFilterPanel (pcgen.gui2.filter.SearchFilterPanel)1 CategoryTableModel (pcgen.gui2.tabs.ability.CategoryTableModel)1