|
From: <jde...@us...> - 2006-11-19 06:54:56
|
Revision: 1676
http://svn.sourceforge.net/pcgen/?rev=1676&view=rev
Author: jdempsey
Date: 2006-11-18 22:54:54 -0800 (Sat, 18 Nov 2006)
Log Message:
-----------
Fix bug #1530489 - Multiple spell books only show once on spell books tab
Modified Paths:
--------------
Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java
Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java
Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoGear.java
Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java
Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-11-19 00:12:10 UTC (rev 1675)
+++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2006-11-19 06:54:54 UTC (rev 1676)
@@ -3760,6 +3760,11 @@
setDirty(true);
}
+ /**
+ * Add an item of equipment to the character.
+ *
+ * @param eq The equipment to be added.
+ */
public void addEquipment(final Equipment eq)
{
equipmentList.add(eq);
@@ -3771,13 +3776,66 @@
if (eq.isType(Constants.s_TYPE_SPELLBOOK))
{
- SpellBook book = new SpellBook(eq.getName(), SpellBook.TYPE_SPELL_BOOK);
- book.setEquip(eq);
- addSpellBook(book);
+ String baseBookname = eq.getName();
+ String bookName = eq.getName();
+ int qty = (int)eq.qty();
+ for (int i=0;i < qty;i++)
+ {
+ if (i > 0)
+ {
+ bookName = baseBookname + " #" + (i+1);
+ }
+ SpellBook book = new SpellBook(bookName, SpellBook.TYPE_SPELL_BOOK);
+ book.setEquip(eq);
+ addSpellBook(book);
+ }
}
setDirty(true);
}
+ /**
+ * Update the number of a particular equipment item the character possesses.
+ * Mostly concerned with ensuring that the spellbook objects remain in sync
+ * with the number of equipment spellbooks.
+ *
+ * @param eq The Equipment being updated.
+ * @param oldQty The original number of items.
+ * @param newQty The new number of items.
+ */
+ public void updateEquipmentQty(final Equipment eq, double oldQty, double newQty)
+ {
+ if (eq.isType(Constants.s_TYPE_SPELLBOOK))
+ {
+ String baseBookname = eq.getName();
+ String bookName = eq.getName();
+ int old = (int)oldQty;
+ int newQ = (int)newQty;
+
+ // Add any new items
+ for (int i=old;i < newQ;i++)
+ {
+ if (i > 0)
+ {
+ bookName = baseBookname + " #" + (i+1);
+ }
+ SpellBook book = new SpellBook(bookName, SpellBook.TYPE_SPELL_BOOK);
+ book.setEquip(eq);
+ addSpellBook(book);
+ }
+
+ // Remove any old items
+ for (int i=old;i > newQ;i--)
+ {
+ if (i > 0)
+ {
+ bookName = baseBookname + " #" + i;
+ }
+ delSpellBook(bookName);
+ }
+ }
+ setDirty(true);
+ }
+
public void addFollower(final Follower aFollower)
{
followerList.add(aFollower);
Modified: Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java 2006-11-19 00:12:10 UTC (rev 1675)
+++ Trunk/pcgen/code/src/java/pcgen/core/character/SpellBook.java 2006-11-19 06:54:54 UTC (rev 1676)
@@ -23,7 +23,10 @@
*/
package pcgen.core.character;
+import pcgen.core.Constants;
import pcgen.core.Equipment;
+import pcgen.core.utils.MessageType;
+import pcgen.core.utils.ShowMessageDelegate;
/**
* <code>SpellBook</code> contains details of a prepared spell list or
@@ -37,7 +40,7 @@
* @version $Revision$
*/
-public class SpellBook
+public class SpellBook implements Cloneable
{
/** Spell book type indicating a list of known spells. */
@@ -257,4 +260,26 @@
this.numSpells = numSpells;
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#clone()
+ */
+ public Object clone()
+ {
+ SpellBook aClone = null;
+ try
+ {
+ aClone = (SpellBook) super.clone();
+ if (equip != null)
+ {
+ aClone.equip = (Equipment) equip.clone();
+ }
+ }
+ catch (CloneNotSupportedException e)
+ {
+ ShowMessageDelegate.showMessageDialog(
+ "Clone of SpellBook failed due to " + e.getMessage(),
+ Constants.s_APPNAME, MessageType.ERROR);
+ }
+ return aClone;
+ }
}
\ No newline at end of file
Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoGear.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoGear.java 2006-11-19 00:12:10 UTC (rev 1675)
+++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoGear.java 2006-11-19 06:54:54 UTC (rev 1676)
@@ -831,6 +831,7 @@
ShowMessageDelegate.showMessageDialog("You can not set the total number of '"+updatedItem.getName() + "' to be "+newQty+" as there is an Equipment Set that is using "+numberOfItemInUse + " of them.", "Error", MessageType.ERROR);
return 0.0;
}
+ pc.updateEquipmentQty(updatedItem, prevQty, newQty);
Float qty = new Float(newQty);
updatedItem.setQty(qty);
updatedItem.setNumberCarried(qty);
Modified: Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java
===================================================================
--- Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java 2006-11-19 00:12:10 UTC (rev 1675)
+++ Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java 2006-11-19 06:54:54 UTC (rev 1676)
@@ -4133,7 +4133,9 @@
if (TAG_QUANTITY.equals(tag))
{
+ float oldQty = aEquip.getQty();
aEquip.setQty(element.getText());
+ thePC.updateEquipmentQty(aEquip, oldQty, aEquip.getQty());
}
else if (TAG_OUTPUTORDER.equals(tag))
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|