I’m trying to create a dialogue box for non-player characters. Whenever this dialogue box appears, I want its contents to differ depending on which non player character node was clicked. I have an AppState dedicated to this, called NonPlayerCharacterInteractionControl
.
In this class, I have an action handler for incoming inputs registered to the primary appstate:
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals(INPUT_MOUSE_SELECT) && isPressed) {
Geometry clickedGeometry = getGeometryFromMouseCursor();
String tag = (String) getUserDataFromParents((Spatial) clickedGeometry, "tag");
if (tag != null) {
if (tag.equals("NonPlayerCharacter")) {
if (doubleClickDelta > 0.0f) {
Integer id = (Integer) getUserDataFromParents((Spatial) clickedGeometry, "id");
nifty.gotoScreen("dialogue");
}
doubleClickDelta = DOUBLE_CLICK_SPEED;
}
}
}
}
The nifty instance referenced is running off of the following XML file:
<nifty>
<screen id="blank" childLayout="horizontal"></screen>
<screen id="dialogue" childLayout="vertical">
<layer id="background" childLayout="horizontal">
<panel id="text_box" childLayout="vertical" height="40%" width="50%" align="center" margin="5%">
<panel id="dialogue_head" childLayout="horizontal" align="left" height="15%" width="45%" backgroundColor="#010101">
<text text="John Smith" font="Interface/Fonts/Arial.fnt" width="100%" height="100%" />
</panel>
<panel id="dialogue_body" childLayout="horizontal" height="85%" width="100%" backgroundColor="#0f0f0f0f">
<text text="${CALL.getDialogue()}" align="left" font="Interface/Fonts/Arial.fnt" width="100%" height="100%" />
</panel>
</panel>
</layer>
</screen>
</nifty>
Here you’ll notice I have the text for the body of the box set to ${CALL.getDialogue}
, which exists in the NonPlayerCharacterInteractionControl
and looks like this:
public String getDialogue() {
return "Hey! Listen!";
}
But when I run the game, it doesn’t show the new text, only the name of the method I’m calling. What should I do to ensure that it calls the function every time I double-click the NPC?