示例#1
0
 public static Array<InventoryItemLocation> getInventoryFiltered(
     Table sourceTable, Table targetTable, String filterOutName) {
   Array<InventoryItemLocation> items = getInventoryFiltered(targetTable, filterOutName);
   Array<Cell> sourceCells = sourceTable.getCells();
   int index = 0;
   for (InventoryItemLocation item : items) {
     for (; index < sourceCells.size; index++) {
       InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor());
       if (inventorySlot == null) continue;
       int numItems = inventorySlot.getNumItems();
       if (numItems == 0) {
         item.setLocationIndex(index);
         // System.out.println("[index] " + index + " itemtype: " + item.getItemTypeAtLocation() +
         // " numItems " + numItems);
         index++;
         break;
       }
     }
     if (index == sourceCells.size) {
       // System.out.println("[index] " + index + " itemtype: " + item.getItemTypeAtLocation() + "
       // numItems " + item.getNumberItemsAtLocation());
       item.setLocationIndex(index - 1);
     }
   }
   return items;
 }
示例#2
0
  public static void populateInventory(
      Table targetTable,
      Array<InventoryItemLocation> inventoryItems,
      DragAndDrop draganddrop,
      String defaultName,
      boolean disableNonDefaultItems) {
    clearInventoryItems(targetTable);

    Array<Cell> cells = targetTable.getCells();
    for (int i = 0; i < inventoryItems.size; i++) {
      InventoryItemLocation itemLocation = inventoryItems.get(i);
      ItemTypeID itemTypeID = ItemTypeID.valueOf(itemLocation.getItemTypeAtLocation());
      InventorySlot inventorySlot =
          ((InventorySlot) cells.get(itemLocation.getLocationIndex()).getActor());

      for (int index = 0; index < itemLocation.getNumberItemsAtLocation(); index++) {
        InventoryItem item = InventoryItemFactory.getInstance().getInventoryItem(itemTypeID);
        String itemName = itemLocation.getItemNameProperty();
        if (itemName == null || itemName.isEmpty()) {
          item.setName(defaultName);
        } else {
          item.setName(itemName);
        }

        inventorySlot.add(item);
        if (item.getName().equalsIgnoreCase(defaultName)) {
          draganddrop.addSource(new InventorySlotSource(inventorySlot, draganddrop));
        } else if (disableNonDefaultItems == false) {
          draganddrop.addSource(new InventorySlotSource(inventorySlot, draganddrop));
        }
      }
    }
  }