|
|
@@ -12,12 +12,13 @@ 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.magic.DDSpellbook;
|
|
|
import org.leumasjaffe.charsheet.model.observable.IntValue;
|
|
|
-import org.leumasjaffe.function.VoidVoidFunction;
|
|
|
+import org.leumasjaffe.observer.IndirectObservableListener;
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
+import lombok.Value;
|
|
|
import lombok.experimental.FieldDefaults;
|
|
|
+import lombok.experimental.NonFinal;
|
|
|
|
|
|
import java.awt.GridBagConstraints;
|
|
|
|
|
|
@@ -28,11 +29,22 @@ public class SpellPanel extends JPanel {
|
|
|
*/
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
DDCharacterClass dclass;
|
|
|
- VoidVoidFunction _reload;
|
|
|
+ @NonFinal int previousHighestSpellLevel = 0;
|
|
|
+ IndirectObservableListener<Fields, Packet> listener;
|
|
|
+
|
|
|
+ @Value
|
|
|
+ private static final class Fields {
|
|
|
+ JPanel prepared, known;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Value
|
|
|
+ private static final class Packet {
|
|
|
+ DDCharacterClass dclass;
|
|
|
+ IntValue ability;
|
|
|
+ }
|
|
|
|
|
|
public SpellPanel(DDCharacter chara, final DDCharacterClass cclass) {
|
|
|
dclass = cclass;
|
|
|
- final DDSpellbook model = cclass.getSpellBook().get();
|
|
|
|
|
|
GridBagLayout gridBagLayout = new GridBagLayout();
|
|
|
gridBagLayout.columnWidths = new int[]{0, 0};
|
|
|
@@ -54,30 +66,27 @@ public class SpellPanel extends JPanel {
|
|
|
JScrollPane knownPane = new JScrollPane();
|
|
|
spellsPane.addTab("Known", null, knownPane, "Spells the player knows for this class");
|
|
|
|
|
|
- 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();
|
|
|
+ final IntValue ability = Ability.fields.get(dclass.getProto().getSpells().get().getAbility()).apply(chara.getAbilities().getBase());
|
|
|
+ final JPanel prepared = new JPanel(new VerticalLayout());
|
|
|
+ preparedPane.setViewportView(prepared);
|
|
|
+ final JPanel known = new JPanel(new VerticalLayout());
|
|
|
+ knownPane.setViewportView(known);
|
|
|
+
|
|
|
+ listener = new IndirectObservableListener<>(
|
|
|
+ new Fields(prepared, known),
|
|
|
+ (c, p) -> {
|
|
|
+ generateSpellTree(c.prepared, (l) -> new SpellLevelPerDayPanel(p.dclass, l, p.ability));
|
|
|
+ generateSpellTree(c.known, (l) -> new SpellLevelPanel(p.dclass, l, p.ability));
|
|
|
+ previousHighestSpellLevel = dclass.getHighestSpellLevel();
|
|
|
+ });
|
|
|
+ listener.setObserved(new Packet(dclass, ability), ability, dclass.getLevel(), dclass.getSpellBook().get());
|
|
|
}
|
|
|
|
|
|
- public void reload() {
|
|
|
- _reload.apply();
|
|
|
- }
|
|
|
-
|
|
|
- private void generateSpellTree(final Function<Integer, JPanel> getPanel, final JScrollPane preparedPane) {
|
|
|
- JPanel root = new JPanel();
|
|
|
- root.setLayout(new VerticalLayout());
|
|
|
-
|
|
|
- for (int i = 0; i < dclass.getHighestSpellLevel(); ++i) {
|
|
|
- if (dclass.getSpellBook().get().numSpellsKnownAtLevel(i) == 0) continue;
|
|
|
+ private void generateSpellTree(final JPanel root, final Function<Integer, JPanel> getPanel) {
|
|
|
+ for (int i = previousHighestSpellLevel; i < dclass.getHighestSpellLevel(); ++i) {
|
|
|
+ if (dclass.getSpellBook().get().numSpellsKnownAtLevel(i) == 0) break;
|
|
|
root.add(getPanel.apply(i));
|
|
|
}
|
|
|
-
|
|
|
- preparedPane.setViewportView(root);
|
|
|
}
|
|
|
|
|
|
}
|