Game Development Reference
In-Depth Information
6. We can use a for loop to iterate five times over the following block:
panelBuilder = new PanelBuilder("") {{
id("inventoryColumn"+posX);
childLayoutVertical();
}};
panelBuilder.build(nifty, screen,
screen.findElementByName("inventorySlots"));
7. While still inside this for loop, we run another for loop, generating the five
item slots for that column:
slotBuilder = new ControlBuilder("itemSlot") {{
id("itemSlot"+index);
}};
Element e = slotBuilder.build(nifty, screen,
screen.findElementByName("inventoryColumn"+posY));
8. For each of the item slots, we also need to add the following class as a DropFilter:
e.findNiftyControl("itemSlot"+index,
Droppable.class).addFilter(this);
9. The implemented method that is accepted needs some logic. Once an item has
been dropped on an itemSlot , we should check whether it's allowed, and we
can do it with the following lines of code:
InventoryItem item = itemMap.get(drgbl.getId());
if(drpbl1.getId().startsWith(item.getType().name())
|| drpbl1.getId().startsWith("itemSlot")){
return true;
With the item slots done, we can generate some items for testing.
10. First we use a for loop to create 10 InventoryItems with different types
and names.
11. For each of these, we create a Nifty control using ControlBuilder and the
item control we defined earlier, as shown in the following code:
itemBuilder = new ControlBuilder("item") {{
id("item"+index);
visibleToMouse(true);
Search WWH ::




Custom Search