Ejemplo n.º 1
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));
        }
      }
    }
  }
Ejemplo n.º 2
0
 public void removeQuestItemFromInventory(String questID) {
   Array<Cell> sourceCells = _inventorySlotTable.getCells();
   for (int index = 0; index < sourceCells.size; index++) {
     InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor());
     if (inventorySlot == null) continue;
     InventoryItem item = inventorySlot.getTopInventoryItem();
     if (item == null) continue;
     String inventoryItemName = item.getName();
     if (inventoryItemName != null && inventoryItemName.equals(questID)) {
       inventorySlot.clearAllInventoryItems(false);
     }
   }
 }