|
|
@@ -6,6 +6,7 @@ import org.jdesktop.swingx.VerticalLayout;
|
|
|
import org.leumasjaffe.charsheet.model.magic.DDSpell;
|
|
|
import org.leumasjaffe.charsheet.view.level.UpdateClassWithLevelPanel.BoolArray;
|
|
|
import org.leumasjaffe.charsheet.view.magic.SelectSpellsPanel;
|
|
|
+import org.leumasjaffe.charsheet.view.magic.SelectSpellsPanel.Info;
|
|
|
import org.leumasjaffe.observer.ObserverDispatch;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
@@ -26,21 +27,50 @@ import java.awt.GridBagConstraints;
|
|
|
@FieldDefaults(level=AccessLevel.PUBLIC, makeFinal=true)
|
|
|
class LevelUpSpellPanel extends JPanel {
|
|
|
|
|
|
+ public static enum SpellPickType {
|
|
|
+ LEARN {
|
|
|
+ @Override
|
|
|
+ public List<List<Integer>> getSpellCounts(SelectSpellsPanel.Info info) {
|
|
|
+ return info.dclass.getProto().getSpells().get().getKnown();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Collection<DDSpell> getAvailableSpells(Info info, int i) {
|
|
|
+ Collection<DDSpell> spells = new ArrayList<>(info.dclass.getBase().getSpellList(i));
|
|
|
+ spells.removeAll(info.dclass.getSpellBook().get().spellsKnownAtLevel(i));
|
|
|
+ return spells;
|
|
|
+ }
|
|
|
+
|
|
|
+ }, PREPARE {
|
|
|
+ @Override
|
|
|
+ public List<List<Integer>> getSpellCounts(SelectSpellsPanel.Info info) {
|
|
|
+ // TODO: Bonus spells for high ability scores
|
|
|
+ return info.dclass.getProto().getSpells().get().getPerDay();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Collection<DDSpell> getAvailableSpells(Info info, int i) {
|
|
|
+ return info.dclass.getSpellBook().get().spellsKnownAtLevel(i);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ public abstract List<List<Integer>> getSpellCounts(SelectSpellsPanel.Info info);
|
|
|
+ public abstract Collection<DDSpell> getAvailableSpells(SelectSpellsPanel.Info info, int i);
|
|
|
+ }
|
|
|
+
|
|
|
int[] ready = {0};
|
|
|
@NonFinal int spellLevelsGrown = 0;
|
|
|
int oldHighestSpellLevel, newHighestSpellLevel;
|
|
|
|
|
|
- public LevelUpSpellPanel(SelectSpellsPanel.Info info, int toLevel, BoolArray readyCount) {
|
|
|
+ public LevelUpSpellPanel(SpellPickType pick, SelectSpellsPanel.Info info, int toLevel, BoolArray readyCount) {
|
|
|
newHighestSpellLevel = info.dclass.getHighestSpellLevel(toLevel);
|
|
|
oldHighestSpellLevel = info.dclass.getHighestSpellLevel();
|
|
|
-
|
|
|
+
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
|
gridBagLayout.rowHeights = new int[]{0, 0};
|
|
|
gridBagLayout.columnWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
|
gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
|
|
|
setLayout(gridBagLayout);
|
|
|
-
|
|
|
+
|
|
|
JScrollPane scrollPane = new JScrollPane();
|
|
|
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
|
|
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
|
|
@@ -50,9 +80,9 @@ class LevelUpSpellPanel extends JPanel {
|
|
|
|
|
|
JPanel panel = new JPanel(new VerticalLayout(5));
|
|
|
scrollPane.setViewportView(panel);
|
|
|
-
|
|
|
+
|
|
|
final List<SelectSpellsPanel> panels = new ArrayList<>();
|
|
|
- final List<List<Integer>> spellList = info.dclass.getProto().getSpells().get().getKnown();
|
|
|
+ final List<List<Integer>> spellList = pick.getSpellCounts(info);
|
|
|
final List<Integer> spellsAtPreviousLevel = toLevel == 1 ? Collections.emptyList() :
|
|
|
spellList.get(toLevel-2);
|
|
|
final List<Integer> spellsAtCurrentLevel = spellList.get(toLevel-1);
|
|
|
@@ -61,7 +91,8 @@ class LevelUpSpellPanel extends JPanel {
|
|
|
final int newSpells = diff(spellsAtCurrentLevel, spellsAtPreviousLevel, i,
|
|
|
isNewSpellCircle(i));
|
|
|
SelectSpellsPanel lvl = new SelectSpellsPanel(info, i,
|
|
|
- new LinkedHashSet<>(), newSpells, getAvailableSpells(info, i), false);
|
|
|
+ new LinkedHashSet<>(), newSpells, pick.getAvailableSpells(info, i),
|
|
|
+ pick != SpellPickType.LEARN);
|
|
|
panels.add(lvl);
|
|
|
lvl.addPropertyChangeListener(SelectSpellsPanel.READY, e -> {
|
|
|
if ((Boolean) e.getNewValue()) ++ready[0];
|
|
|
@@ -78,13 +109,7 @@ class LevelUpSpellPanel extends JPanel {
|
|
|
}
|
|
|
|
|
|
private int diff(List<Integer> current, List<Integer> previous, int level, boolean newSpellLevel) {
|
|
|
- return current.get(level) - (newSpellLevel ? 0 : previous.get(level));
|
|
|
- }
|
|
|
-
|
|
|
- private Collection<DDSpell> getAvailableSpells(SelectSpellsPanel.Info info, int i) {
|
|
|
- Collection<DDSpell> spells = new ArrayList<>(info.dclass.getBase().getSpellList(i));
|
|
|
- spells.removeAll(info.dclass.getSpellBook().get().spellsKnownAtLevel(i));
|
|
|
- return spells;
|
|
|
+ return current.get(level) - (newSpellLevel || previous.size() <= level ? 0 : previous.get(level));
|
|
|
}
|
|
|
|
|
|
}
|