Browse Source

Allow SpellPanel to be regenerated.

Sam Jaffe 8 years ago
parent
commit
95507bf35a
1 changed files with 16 additions and 9 deletions
  1. 16 9
      src/org/leumasjaffe/charsheet/view/magic/SpellPanel.java

+ 16 - 9
src/org/leumasjaffe/charsheet/view/magic/SpellPanel.java

@@ -13,10 +13,9 @@ 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.DDClass;
-import org.leumasjaffe.charsheet.model.magic.DDSpellList;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 import org.leumasjaffe.charsheet.model.observable.IntValue;
+import org.leumasjaffe.function.VoidVoidFunction;
 
 import lombok.AccessLevel;
 import lombok.experimental.FieldDefaults;
@@ -30,6 +29,7 @@ public class SpellPanel extends JPanel {
 	 */
 	private static final long serialVersionUID = 1L;
 	DDCharacterClass dclass;
+	VoidVoidFunction _reload;
 	int highestSpellLevel;
 
 	public SpellPanel(DDCharacter chara, final DDCharacterClass cclass) {
@@ -54,14 +54,21 @@ public class SpellPanel extends JPanel {
 		JScrollPane preparedPane = new JScrollPane();
 		spellsPane.addTab("Prepared", null, preparedPane, "Spells the character can use today");
 
-		final IntValue value = Ability.fields.get(cclass.getProto().getSpells().get().getAbility()).apply(chara.getAbilities().getBase());
-		generateSpellTree((l) -> new SpellLevelPerDayPanel(new SpellsPerDayHeader(l, model, value), dclass, l),
-				preparedPane);
-
 		JScrollPane knownPane = new JScrollPane();
 		spellsPane.addTab("Known", null, knownPane, "Spells the player knows for this class");
-		generateSpellTree((l) -> new SpellLevelPanel(new SpellsKnownHeader(l, model, value), dclass, l), 
-				knownPane);
+		
+		final IntValue value = Ability.fields.get(dclass.getProto().getSpells().get().getAbility()).apply(chara.getAbilities().getBase());
+		_reload = () -> {
+			generateSpellTree((l) -> new SpellLevelPerDayPanel(new SpellsPerDayHeader(l, model, value), dclass, l),
+					preparedPane);
+			generateSpellTree((l) -> new SpellLevelPanel(new SpellsKnownHeader(l, model, value), dclass, l), 
+					knownPane);
+		};
+		reload();
+	}
+	
+	public void reload() {
+		_reload.apply();
 	}
 
 	private static int calcHighestSpellLevel(final DDCharacterClass cclass) {
@@ -75,8 +82,8 @@ public class SpellPanel extends JPanel {
 		JPanel root = new JPanel();
 		root.setLayout(new VerticalLayout());
 		
-		// TODO some classes don't get 0-th level spells
 		for (int i = 0; i < highestSpellLevel; ++i) {
+			if (dclass.getSpellBook().get().numSpellsKnownAtLevel(i) == 0) continue;
 			root.add(getPanel.apply(i));
 		}