Bläddra i källkod

Fetch spell match information into SpellInfoPanel

Sam Jaffe 8 år sedan
förälder
incheckning
f1d62adcac

+ 1 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/magic/PrepareSpellsDialog.java

@@ -83,7 +83,7 @@ public class PrepareSpellsDialog extends JPanel {
 		final Prepared spellBook = (Prepared) dclass.getSpellBook().get();
 		List<SelectPreparedSpellsPanel> panels = new ArrayList<>();
 		for (int i = 0; i < highestSpellLevel; ++i) {
-			SelectPreparedSpellsPanel lvl = new SelectPreparedSpellsPanel(i, dclass, score);
+			SelectPreparedSpellsPanel lvl = new SelectPreparedSpellsPanel(chara, i, dclass, score);
 			panels.add(lvl);
 			lvl.addPropertyChangeListener(SelectPreparedSpellsPanel.READY, e -> {
 				if ((Boolean) e.getNewValue()) ++ready[0];

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SelectPreparedSpellsPanel.java

@@ -10,6 +10,7 @@ import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
 
 import org.leumasjaffe.charsheet.model.Ability;
+import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.impl.Prepared;
@@ -80,7 +81,7 @@ class SelectPreparedSpellsPanel extends JPanel {
 	
 	SelectSpellModel modelPrepared, modelKnown;
 
-	public SelectPreparedSpellsPanel(int level, DDCharacterClass dclass, Ability.Scores score) {
+	public SelectPreparedSpellsPanel(DDCharacter chara, int level, DDCharacterClass dclass, Ability.Scores score) {
 		putClientProperty(READY, true);
 		final Prepared spellBook = (Prepared) dclass.getSpellBook().get();
 		this.prepared = new ArrayList<>(spellBook.getSpellsPreparedPreviouslyForLevel(level));
@@ -154,7 +155,7 @@ class SelectPreparedSpellsPanel extends JPanel {
 		mntmInfo.addActionListener( e -> {
 			DDSpell spell = known.get(tableKnown.getSelectedRow());
 			JFrame frame = new JFrame(spell.getName() +  " (" + dclass.getName() + " " + level + ")");
-			frame.add(new SpellInfoPanel(dclass, spell));
+			frame.add(new SpellInfoPanel(chara, dclass, spell));
 			frame.pack();
 			frame.setVisible(true);
 		});

+ 7 - 1
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellInfoPanel.java

@@ -4,12 +4,16 @@ import javax.swing.JPanel;
 import java.awt.GridBagLayout;
 import java.awt.GridBagConstraints;
 import java.awt.Insets;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.function.Function;
 
 import javax.swing.JTextArea;
 
+import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpell.Component;
@@ -32,8 +36,10 @@ class SpellInfoPanel extends JPanel {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	public SpellInfoPanel(DDCharacterClass dclass, final DDSpell spell) {
+	public SpellInfoPanel(DDCharacter chara, DDCharacterClass dclass, final DDSpell spell) {
 		final IntValue classLevel = dclass.getLevel();
+		Map<String, Object> props = new HashMap<>();
+		chara.getFeatureBonuses(spell).forEach(p -> p.accumulate(props));
 		
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0};

+ 5 - 4
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellLevelPanel.java

@@ -11,6 +11,7 @@ import java.util.function.BiFunction;
 
 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.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
@@ -29,7 +30,7 @@ class SpellLevelPanel extends JPanel {
 	
 	IndirectObservableListener<JPanel, DDCharacterClass> listener;
 
-	protected SpellLevelPanel(JPanel header, DDCharacterClass dclass, int level, 
+	protected SpellLevelPanel(JPanel header, DDCharacter chara, DDCharacterClass dclass, int level, 
 			BiFunction<DDSpellbook, Integer, Collection<DDSpell>> getSpells) {		
 		final Collection<DDSpell> spells = getSpells.apply(dclass.getSpellBook().get(), level);
 
@@ -65,14 +66,14 @@ class SpellLevelPanel extends JPanel {
 		
 		listener = new IndirectObservableListener<>(panel, (c, v) -> { 
 			c.removeAll();
-			spells.forEach(spell -> c.add(new SpellLine(v, spell, isCastableFromHere())));
+			spells.forEach(spell -> c.add(new SpellLine(chara, v, spell, isCastableFromHere())));
 			c.repaint();
 		});
 		listener.setObserved(dclass, dclass.getSpellBook().get());
 	}
 	
-	public SpellLevelPanel(DDCharacterClass dclass, int level, Ability.Scores ability) {
-		this(new SpellsKnownHeader(level, dclass.getSpellBook().get(), ability), dclass, level, DDSpellbook::spellsKnownAtLevel);
+	public SpellLevelPanel(DDCharacter chara, DDCharacterClass dclass, int level, Ability.Scores ability) {
+		this(new SpellsKnownHeader(level, dclass.getSpellBook().get(), ability), chara, dclass, level, DDSpellbook::spellsKnownAtLevel);
 	}
 	
 	public boolean isCastableFromHere() { return false; }

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellLevelPerDayPanel.java

@@ -1,6 +1,7 @@
 package org.leumasjaffe.charsheet.view.magic;
 
 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;
 
@@ -15,8 +16,8 @@ class SpellLevelPerDayPanel extends SpellLevelPanel {
 	 */
 	private static final long serialVersionUID = 1L;
 	
-	public SpellLevelPerDayPanel(DDCharacterClass dclass, int level, Ability.Scores ability) {
-		super(new SpellsPerDayHeader(level, dclass.getSpellBook().get(), ability), dclass, level, DDSpellbook::spellsPreparedAtLevel);
+	public SpellLevelPerDayPanel(DDCharacter chara, DDCharacterClass dclass, int level, Ability.Scores ability) {
+		super(new SpellsPerDayHeader(level, dclass.getSpellBook().get(), ability), chara, dclass, level, DDSpellbook::spellsPreparedAtLevel);
 	}
 	
 	public boolean isCastableFromHere() { return true; }

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellLine.java

@@ -2,6 +2,7 @@ package org.leumasjaffe.charsheet.view.magic;
 
 import javax.swing.JPanel;
 
+import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.event.PopClickListener;
@@ -20,7 +21,7 @@ class SpellLine extends JPanel {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	public SpellLine(final DDCharacterClass dclass, final DDSpell spell, boolean isPrepared) {
+	public SpellLine(DDCharacter chara, final DDCharacterClass dclass, final DDSpell spell, boolean isPrepared) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0};
@@ -101,7 +102,7 @@ class SpellLine extends JPanel {
 		gbc_lblAction_1.gridy = 0;
 		add(lblRange, gbc_lblAction_1);
 		
-		addMouseListener(new PopClickListener(new SpellMenu(dclass, spell, isPrepared)));
+		addMouseListener(new PopClickListener(new SpellMenu(chara, dclass, spell, isPrepared)));
 	}
 
 }

+ 3 - 2
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellMenu.java

@@ -2,6 +2,7 @@ package org.leumasjaffe.charsheet.view.magic;
 
 import javax.swing.JPopupMenu;
 
+import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
@@ -18,13 +19,13 @@ class SpellMenu extends JPopupMenu {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	public SpellMenu(final DDCharacterClass dclass, final DDSpell spell, boolean isPrepared) {
+	public SpellMenu(DDCharacter chara, final DDCharacterClass dclass, final DDSpell spell, boolean isPrepared) {
 		final int spellLevel = spell.getClassLevel(dclass.getName());
 		
 		JMenuItem mntmInfo = new JMenuItem("Info");
 		mntmInfo.addActionListener( e -> {
 			JFrame frame = new JFrame(spell.getName() +  " (" + dclass.getName() + " " + spellLevel + ")");
-			frame.add(new SpellInfoPanel(dclass, spell));
+			frame.add(new SpellInfoPanel(chara, dclass, spell));
 			frame.pack();
 			frame.setVisible(true);
 		});

+ 6 - 5
src/main/lombok/org/leumasjaffe/charsheet/view/magic/SpellPanel.java

@@ -13,7 +13,7 @@ import org.leumasjaffe.charsheet.model.Ability;
 import org.leumasjaffe.charsheet.model.DDCharacter;
 import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.util.AbilityHelper;
-import org.leumasjaffe.function.TriFunction;
+import org.leumasjaffe.function.QuadFunction;
 import org.leumasjaffe.observer.IndirectObservableListener;
 import org.leumasjaffe.observer.ObserverDispatch;
 
@@ -60,10 +60,10 @@ public class SpellPanel extends JPanel {
 		knownPane.setViewportView(known);
 				
 		listenerPerDay = new IndirectObservableListener<>(prepared, 
-				new AppendSpellLevelOperation(ability, SpellLevelPerDayPanel::new));
+				new AppendSpellLevelOperation(chara, ability, SpellLevelPerDayPanel::new));
 		listenerPerDay.setObserved(dclass, ability, dclass.getLevel(), dclass.getSpellBook().get());
 		listenerKnown = new IndirectObservableListener<>(known, 
-				new AppendSpellLevelOperation(ability, SpellLevelPanel::new));
+				new AppendSpellLevelOperation(chara, ability, SpellLevelPanel::new));
 		listenerKnown.setObserved(dclass, ability, dclass.getLevel(), dclass.getSpellBook().get());
 	}
 
@@ -71,14 +71,15 @@ public class SpellPanel extends JPanel {
 	@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 	private static final class AppendSpellLevelOperation implements BiConsumer<JPanel, DDCharacterClass> {
 		@NonFinal int previousHighestSpellLevel = 0;
+		DDCharacter chara;
 		Ability.Scores ability;
-		TriFunction<DDCharacterClass, Integer, Ability.Scores, JPanel> function;
+		QuadFunction<DDCharacter, DDCharacterClass, Integer, Ability.Scores, JPanel> function;
 
 		@Override
 		public void accept(final JPanel root, final DDCharacterClass dclass) {		
 			for (int i = previousHighestSpellLevel; i < dclass.getHighestSpellLevel(); ++i) {
 				if (dclass.getSpellBook().get().numSpellsKnownAtLevel(i) == 0) break;
-				root.add(function.apply(dclass, i, ability));
+				root.add(function.apply(chara, dclass, i, ability));
 			}
 			previousHighestSpellLevel = dclass.getHighestSpellLevel();
 		}

+ 6 - 0
src/main/lombok/org/leumasjaffe/function/QuadFunction.java

@@ -0,0 +1,6 @@
+package org.leumasjaffe.function;
+
+@FunctionalInterface
+public interface QuadFunction<A, B, C, D, R> {
+	R apply(A arg0, B arg1, C arg2, D arg3);
+}