Game Development Reference
In-Depth Information
<panel id="hands" backgroundColor="#000f"
childLayout="horizontal" width="25%" align="center"
valign="bottom">
<control name="itemSlot" id="HandLeft" align="left"
/>
<panel width="*" height="1px"/>
<control name="itemSlot" id="HandRight"
align="right" />
</panel>
9. Finally, we have one itemSlot for the legs/feet:
<panel id="legs" backgroundColor="#000f"
childLayout="horizontal" align="center"
valign="bottom">
<control name="itemSlot" id="Foot"/>
</panel>
With the XML elements done, we can turn to the Java code. The following nine steps are
necessary:
1. We create a class called InventoryItem . This has an enum (enumeration) for
different body parts: head, hand, foot, and a name.
2. Next, we'll create the Controller class, InventoryScreenController ,
and have it extend NiftyController ; also, implement Drop-
pableDropFilter .
3. We need to add a map to contain our InventoryItems , with the name as the
key. It can be called itemMap .
4. The bind method should be overridden, and in here, we should find different
DropControls in the InventoryScreen and add this class as a filter using
the following code:
screen.findNiftyControl("HandLeft",
Droppable.class).addFilter(this);
Now, we can generate the item slots in the inventory in a 5 x 5 grid.
5. We define two builders: ControlBuilder for the itemSlot controls and
PanelBuilder to make columns that will contain five itemSlots each.
Search WWH ::




Custom Search