|
From: <jde...@us...> - 2011-01-30 11:34:32
|
Revision: 14480
http://pcgen.svn.sourceforge.net/pcgen/?rev=14480&view=rev
Author: jdempsey
Date: 2011-01-30 11:34:26 +0000 (Sun, 30 Jan 2011)
Log Message:
-----------
Implement EquipmentListFacade handling in EquipmentSetFacade
Issue#: CODE-499
Modified Paths:
--------------
sandbox/cdomui/code/src/java/pcgen/core/facade/EquipmentSetFacade.java
sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java
sandbox/cdomui/code/src/java/pcgen/gui2/util/JTreeTable.java
Modified: sandbox/cdomui/code/src/java/pcgen/core/facade/EquipmentSetFacade.java
===================================================================
--- sandbox/cdomui/code/src/java/pcgen/core/facade/EquipmentSetFacade.java 2011-01-30 07:05:35 UTC (rev 14479)
+++ sandbox/cdomui/code/src/java/pcgen/core/facade/EquipmentSetFacade.java 2011-01-30 11:34:26 UTC (rev 14480)
@@ -28,14 +28,34 @@
import pcgen.core.facade.util.ListFacade;
/**
+ * <code>EquipmentSetFacade</code>defines the interface layer between the UI
+ * and the pcgen core for managing how equipment is worn or placed (t.e.
+ * equipped). There can be multiple instance of this facade per character,
+ * each representing a configuration of equipped gear (e.g. dungeon, boat,
+ * camp).
*
+ * <br/>
+ * Last Editor: $Author: $
+ * Last Edited: $Date: $
+ *
* @author Connor Petty <cpm...@us...>
+ * @version $Revision: $
*/
public interface EquipmentSetFacade
{
public boolean isContainer(EquipmentFacade equipment);
+ /**
+ * This list contains the equipment currently equipped and how many of them
+ * are equipped. The quantity for each item in the list reflects the number
+ * of such items that are equipped on the character as a whole, meaning that
+ * even if that item is equipped in multiple places on the character the
+ * list should show a value in quantity that is the sum of these locations
+ * and quantities at these locations.
+ *
+ * @return The list of equipped items.
+ */
public EquipmentListFacade getEquippedItems();
void addEquipment(EquipPath path, EquipmentFacade equipment, int quantity);
@@ -60,7 +80,7 @@
* (ie. crossbows only accept bolts)
* @param path the path to the container
* @param equipment the equipment that we want to check
- * @return
+ * @return true if the equipment can be placed in the location.
*/
public boolean canEquip(EquipPath path, EquipmentFacade equipment);
Modified: sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java
===================================================================
--- sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java 2011-01-30 07:05:35 UTC (rev 14479)
+++ sandbox/cdomui/code/src/java/pcgen/gui2/facade/EquipmentSetFacadeImpl.java 2011-01-30 11:34:26 UTC (rev 14480)
@@ -112,7 +112,7 @@
paths = new DefaultListFacade<EquipPath>();
bodyStructMap = new HashMap<String, BodyStructure>();
equipmentList = new EquipmentListFacadeImpl();
- //TODO: populate equipmentList
+
for (BodyStructureFacade bodyStruct : dataSet.getEquipmentLocations())
{
bodyStructMap.put(bodyStruct.toString(), (BodyStructure) bodyStruct);
@@ -158,6 +158,7 @@
BodyStructureFacade root = bodyStructMap.get(es.toString());
EquipPathImpl epi = new EquipPathImpl(root, es.getIdPath(), fullPath);
paths.addElement(epi);
+ updateTotalQuantity(es.getItem(), es.getItem().getQty().intValue());
// add to list for recursive calls
children.add(es);
@@ -249,13 +250,15 @@
(Equipment) existing.getPath()[existing.getPath().length - 1];
if (existingItem.equals(item))
{
- existingItem.setQty(existingItem.getQty() + quantity);
+ int totalQuantity = (int) (existingItem.getQty() + quantity);
+ existingItem.setQty(totalQuantity);
EquipSet es =
theCharacter
.getEquipSetByIdPath(((EquipPathImpl) existing)
.getIdPath());
es.setQty(es.getQty() + quantity);
fireQuantityChanged(existing);
+ updateTotalQuantity(existingItem, quantity);
return;
}
}
@@ -279,6 +282,7 @@
fullPath[fullPath.length-1] = equipment;
EquipPathImpl epi = new EquipPathImpl(ep.getRoot(), newSet.getIdPath(), fullPath);
paths.addElement(epi);
+ updateTotalQuantity(item, quantity);
}
/* (non-Javadoc)
@@ -334,8 +338,41 @@
eSet.setQty((float) newQty);
fireQuantityChanged(path);
}
+ updateTotalQuantity(eqI, quantity*-1);
}
+ /**
+ * Update the total quantity held of an item as recorded in the
+ * equipmentList. This will add or remove the item from the list as
+ * required. Items with the same name are aggregated to give a total
+ * amount held.
+ *
+ * @param item The item to be updated
+ * @param amtChanged The amount by which the quantity has changed.
+ */
+ private void updateTotalQuantity(Equipment item, int amtChanged)
+ {
+ for (EquipmentFacade equip : equipmentList)
+ {
+ if (item.equals(equip))
+ {
+ int newQty = equipmentList.getQuantity(equip) + amtChanged;
+ if (newQty > 0)
+ {
+ equipmentList.setQuantity(equip, newQty);
+ }
+ else
+ {
+ equipmentList.removeElement(equip);
+ }
+ return;
+ }
+ }
+
+ // Item is new so add it
+ equipmentList.addElement(item, amtChanged);
+ }
+
/* (non-Javadoc)
* @see pcgen.core.facade.EquipmentSetFacade#getLocation(pcgen.core.facade.EquipmentSetFacade.EquipPath)
*/
Modified: sandbox/cdomui/code/src/java/pcgen/gui2/util/JTreeTable.java
===================================================================
--- sandbox/cdomui/code/src/java/pcgen/gui2/util/JTreeTable.java 2011-01-30 07:05:35 UTC (rev 14479)
+++ sandbox/cdomui/code/src/java/pcgen/gui2/util/JTreeTable.java 2011-01-30 11:34:26 UTC (rev 14480)
@@ -437,12 +437,15 @@
TreePath parentPath = e.getTreePath();
int leadingRow = Integer.MAX_VALUE;
int trailingRow = -1;
- for (Object node : e.getChildren())
+ if (e.getChildren() != null)
{
- TreePath childPath = parentPath.pathByAddingChild(node);
- int row = tree.getRowForPath(childPath);
- leadingRow = Math.min(leadingRow, row);
- trailingRow = Math.max(trailingRow, row);
+ for (Object node : e.getChildren())
+ {
+ TreePath childPath = parentPath.pathByAddingChild(node);
+ int row = tree.getRowForPath(childPath);
+ leadingRow = Math.min(leadingRow, row);
+ trailingRow = Math.max(trailingRow, row);
+ }
}
fireTableRowsUpdated(leadingRow, trailingRow);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|