Game Development Reference
In-Depth Information
6. We should begin this by setting the name of the character; again, we will use
screen.findNiftyControl
to do this:
screen.findNiftyControl("characterName",
Label.class).setText(dialogNode.getCharacterName());
Likewise, the dialog text is set in the same manner.
7. To set the image, we need to create
NiftyImage
and pass it on to
ImageRen-
derer
of an element using the following code:
screen.findElementByName("characterImage").getRenderer(ImageRenderer.class).setImage(nifty.createImage(dialogNode.getCharacterImage(),
true));
8. Next, we clear
dialogOptions
and use
dialogOptions.addItem
to ap-
ply the values available in
DialogNode
.
9. Finally, we call
dialogOptions.refresh()
and
screen.layoutLayers()
and set the
dialogPanel
element to be visible.
10. To find out which item is pressed in
dialogOptions
, we add a listener method
to the class:
public void onDialogOptionSelected(final String id,
final ListBoxSelectionChangedEvent event)
11. Then, we add an annotation to let it know which element to listen to:
@NiftyEventSubscriber(id="dialogOptions")
12. Using
event.getSelectionIndices()
, we can find out which item the
player has pressed.