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)); } } } }
public void addEntityToInventory(Entity entity, String itemName) { Array<Cell> sourceCells = _inventorySlotTable.getCells(); int index = 0; for (; index < sourceCells.size; index++) { InventorySlot inventorySlot = ((InventorySlot) sourceCells.get(index).getActor()); if (inventorySlot == null) continue; int numItems = inventorySlot.getNumItems(); if (numItems == 0) { InventoryItem inventoryItem = InventoryItemFactory.getInstance() .getInventoryItem(ItemTypeID.valueOf(entity.getEntityConfig().getItemTypeID())); inventoryItem.setName(itemName); inventorySlot.add(inventoryItem); _dragAndDrop.addSource(new InventorySlotSource(inventorySlot, _dragAndDrop)); break; } } }