|
|
@@ -16,10 +16,10 @@ import org.jdesktop.swingx.VerticalLayout;
|
|
|
import org.leumasjaffe.charsheet.model.Ability;
|
|
|
import org.leumasjaffe.charsheet.model.DDCharacter;
|
|
|
import org.leumasjaffe.charsheet.model.DDCharacterClass;
|
|
|
+import org.leumasjaffe.charsheet.model.DDCharacterClass.DDSpellbookWrapper;
|
|
|
import org.leumasjaffe.charsheet.model.magic.DDSpell;
|
|
|
import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
|
|
|
import org.leumasjaffe.observer.IndirectObservableListener;
|
|
|
-import org.leumasjaffe.observer.Observable;
|
|
|
import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
@@ -35,10 +35,7 @@ class SpellLevelPanel extends JPanel {
|
|
|
IndirectObservableListener<JPanel, DDCharacterClass> listener;
|
|
|
|
|
|
protected SpellLevelPanel(JPanel header, DDCharacter chara, DDCharacterClass dclass, int level,
|
|
|
- BiFunction<DDSpellbook, Integer, Collection<DDSpell>> getSpells) {
|
|
|
-// final Map<DDSpellbook, Collection<DDSpell>> spells = new HashMap<>();
|
|
|
-// dclass.getSpellBook().forEach(sb -> spells.put(sb, getSpells.apply(sb, level)));
|
|
|
-
|
|
|
+ BiFunction<DDSpellbook, Integer, Collection<DDSpell>> getSpells) {
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0, 0};
|
|
|
gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
|
|
|
@@ -69,23 +66,31 @@ class SpellLevelPanel extends JPanel {
|
|
|
gbc_horizontalStrut.gridy = 2;
|
|
|
add(horizontalStrut, gbc_horizontalStrut);
|
|
|
|
|
|
+ final DDSpellbookWrapper wrap = dclass.getSpellBook().get();
|
|
|
listener = new IndirectObservableListener<>(panel, (c, v) -> {
|
|
|
c.removeAll();
|
|
|
- for (int i = 0; i < dclass.getSpellBook().size(); ++i) {
|
|
|
- final DDSpellbook sb = dclass.getSpellBook().get(i);
|
|
|
+ {
|
|
|
+ final DDSpellbook sb = wrap.getMain();
|
|
|
final Collection<DDSpell> spells = getSpells.apply(sb, level);
|
|
|
- if (spells.isEmpty()) continue;
|
|
|
- if (i != 0) c.add(new JSeparator(SwingConstants.HORIZONTAL));
|
|
|
spells.forEach(spell -> c.add(new SpellLine(chara, v, sb, spell, isCastableFromHere())));
|
|
|
}
|
|
|
+ wrap.getSecondary().ifPresent(sb -> {
|
|
|
+ final Collection<DDSpell> spells = getSpells.apply(sb, level);
|
|
|
+ if (!spells.isEmpty()) c.add(new JSeparator(SwingConstants.HORIZONTAL));
|
|
|
+ spells.forEach(spell -> c.add(new SpellLine(chara, v, sb, spell, isCastableFromHere())));
|
|
|
+ });
|
|
|
c.repaint();
|
|
|
+ c.validate();
|
|
|
});
|
|
|
- listener.setObserved(dclass, dclass.getSpellBook().toArray(new Observable[0]));
|
|
|
+ if (wrap.getSecondary().isPresent()) {
|
|
|
+ listener.setObserved(dclass, wrap.getMain(), wrap.getSecondary().get());
|
|
|
+ } else {
|
|
|
+ listener.setObserved(dclass, wrap.getMain());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public SpellLevelPanel(DDCharacter chara, DDCharacterClass dclass, int level, Ability.Scores ability) {
|
|
|
- // TODO figure out what to do about that get(0)
|
|
|
- this(new SpellsKnownHeader(level, dclass.getSpellBook().get(0), ability),
|
|
|
+ this(new SpellsKnownHeader(level, dclass.getSpellBook().get().getMain(), ability),
|
|
|
chara, dclass, level, DDSpellbook::spellsKnownAtLevel);
|
|
|
}
|
|
|
|