소스 검색

Add ability to prepare newly obtained spells on level up.
Fixing some edge checks

Sam Jaffe 8 년 전
부모
커밋
a5ca4a4cab

+ 1 - 0
src/main/lombok/org/leumasjaffe/charsheet/model/DDCharacterClass.java

@@ -99,6 +99,7 @@ public class DDCharacterClass extends Observable implements Comparable<DDCharact
 	public int getHighestSpellLevel(int level) {
 		// TODO: Bonus levels to spellsKnown/spellsPerDay?
 		// TODO: Bonus spellsPerDay for high ability scores
+		if (level == 0) { return -1; }
 		final List<Integer> list = getProto().getSpells().get().getPerDay().get(level-1);
 		level = list.size() - 1;
 		return list.get(level) == 0 ? level : level + 1;

+ 38 - 13
src/main/lombok/org/leumasjaffe/charsheet/view/level/LevelUpSpellPanel.java

@@ -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));
 	}
 
 }

+ 12 - 4
src/main/lombok/org/leumasjaffe/charsheet/view/level/UpdateClassWithLevelPanel.java

@@ -67,10 +67,18 @@ class UpdateClassWithLevelPanel extends JPanel {
 		tabbedPane.addTab("Skills", null, skills, null);
 		
 		info.ddClass.getSpellBook().ifPresent(sb -> {
-			if (!sb.learnsSpells()) return;
-			JPanel spells = new LevelUpSpellPanel(new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
-					info.toLevel, readyCount);
-			tabbedPane.addTab("Spells", null, spells, null);
+			if (sb.learnsSpells()) {
+				JPanel spells = new LevelUpSpellPanel(LevelUpSpellPanel.SpellPickType.LEARN,
+						new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
+						info.toLevel, readyCount);
+				tabbedPane.addTab("Learn Spells", null, spells, null);
+			}
+			if (sb.preparesSpells()) {
+				JPanel spells = new LevelUpSpellPanel(LevelUpSpellPanel.SpellPickType.PREPARE,
+						new SelectSpellsPanel.Info(info.ddCharacter, info.ddClass),
+						info.toLevel, readyCount);
+				tabbedPane.addTab("Prepare Spells", null, spells, null);
+			}
 		});
 		
 		JPanel panel = new JPanel();