瀏覽代碼

Adding Character Class information to SpellPanels, this allows us to show the class associated with the spell, as well as other things.

Sam Jaffe 8 年之前
父節點
當前提交
a3ae161a38

+ 9 - 0
resources/spells/default.json

@@ -1,6 +1,11 @@
 {
   "Create Water":{
     "name":"Create Water",
+    "classToLevel":{
+      "Cleric":1,
+      "Druid":1,
+      "Paladin":1
+    },
     "school":"Conjuration",
     "subSchool":"Creation",
     "keywords":["Water"],
@@ -15,6 +20,10 @@
   },
   "Know Direction":{
     "name":"Know Direction",
+    "classToLevel":{
+      "Bard":0,
+      "Druid":0
+    },
     "school":"Divination",
     "keywords":[],
     "components":["V","S"],

+ 2 - 1
src/org/leumasjaffe/charsheet/view/magic/SpellInfoPanel.java

@@ -8,6 +8,7 @@ import java.util.Set;
 
 import javax.swing.JTextArea;
 
+import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpell.Component;
 
@@ -30,7 +31,7 @@ public class SpellInfoPanel extends JPanel {
 	private JTextField action;
 	private JTextField range;
 
-	public SpellInfoPanel(final DDSpell spell) {
+	public SpellInfoPanel(DDCharacterClass dclass, final DDSpell spell) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0, 0};

+ 3 - 2
src/org/leumasjaffe/charsheet/view/magic/SpellLevelPanel.java

@@ -9,6 +9,7 @@ import java.awt.Insets;
 import java.util.Collection;
 
 import org.jdesktop.swingx.VerticalLayout;
+import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 
 public class SpellLevelPanel extends JPanel {
@@ -17,7 +18,7 @@ public class SpellLevelPanel extends JPanel {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	public SpellLevelPanel(JPanel header, Collection<DDSpell> spells) {
+	public SpellLevelPanel(JPanel header, DDCharacterClass dclass, Collection<DDSpell> spells) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
@@ -40,7 +41,7 @@ public class SpellLevelPanel extends JPanel {
 		gbc_panel.gridx = 1;
 		gbc_panel.gridy = 1;
 		add(panel, gbc_panel);
-		spells.forEach(spell -> panel.add(new SpellLine(spell)));
+		spells.forEach(spell -> panel.add(new SpellLine(dclass, spell)));
 		
 		Component horizontalStrut = Box.createHorizontalStrut(20);
 		GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();

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

@@ -3,6 +3,7 @@ package org.leumasjaffe.charsheet.view.magic;
 import javax.swing.JPanel;
 
 import org.leumasjaffe.charsheet.controller.inventory.PopClickListener;
+import org.leumasjaffe.charsheet.model.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 
 import java.awt.GridBagLayout;
@@ -19,7 +20,7 @@ public class SpellLine extends JPanel {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	public SpellLine(final DDSpell spell) {
+	public SpellLine(final DDCharacterClass dclass, final DDSpell spell) {
 		GridBagLayout gridBagLayout = new GridBagLayout();
 		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 		gridBagLayout.rowHeights = new int[]{0, 0};
@@ -100,7 +101,7 @@ public class SpellLine extends JPanel {
 		gbc_lblAction_1.gridy = 0;
 		add(lblRange, gbc_lblAction_1);
 		
-		addMouseListener(new PopClickListener(new SpellMenu(spell)));
+		addMouseListener(new PopClickListener(new SpellMenu(dclass, spell)));
 	}
 
 }

+ 4 - 3
src/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.DDCharacterClass;
 import org.leumasjaffe.charsheet.model.magic.DDSpell;
 
 import javax.swing.JFrame;
@@ -14,12 +15,12 @@ class SpellMenu extends JPopupMenu {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	public SpellMenu(DDSpell spell) {
+	public SpellMenu(final DDCharacterClass dclass, final DDSpell spell) {
 		
 		JMenuItem mntmInfo = new JMenuItem("Info");
 		mntmInfo.addActionListener( e -> {
-			JFrame frame = new JFrame(spell.getName());
-			frame.add(new SpellInfoPanel(spell));
+			JFrame frame = new JFrame(spell.getName() +  " (" + dclass.getName() + " " + spell.getClassLevel(dclass.getName()) + ")");
+			frame.add(new SpellInfoPanel(dclass, spell));
 			frame.pack();
 			frame.setVisible(true);
 		});

+ 8 - 2
src/org/leumasjaffe/charsheet/view/magic/SpellPanel.java

@@ -17,16 +17,22 @@ import org.leumasjaffe.charsheet.model.magic.DDSpell;
 import org.leumasjaffe.charsheet.model.magic.DDSpellList;
 import org.leumasjaffe.charsheet.model.magic.DDSpellbook;
 
+import lombok.AccessLevel;
+import lombok.experimental.FieldDefaults;
+
 import java.awt.GridBagConstraints;
 
+@FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
 public class SpellPanel extends JPanel {
 	/**
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
-	private final int highestSpellLevel;
+	DDCharacterClass dclass;
+	int highestSpellLevel;
 
 	public SpellPanel(final DDCharacterClass cclass) {
+		dclass = cclass;
 		highestSpellLevel = calcHighestSpellLevel(cclass);
 		final DDSpellbook model = cclass.getSpellBook().get();
 		
@@ -78,7 +84,7 @@ public class SpellPanel extends JPanel {
 		
 		for (int i = 0; i < highestSpellLevel; ++i) {
 			Collection<DDSpell> spells = getSpells.apply(i);
-			root.add(new SpellLevelPanel(getPanel.apply(i), spells));
+			root.add(new SpellLevelPanel(getPanel.apply(i), dclass, spells));
 		}
 		
 		preparedPane.setViewportView(root);