Nifty chat box

any1 got some example code for the nifty chat control? I have a look at the tutorial on the nifty wiki and it didn’t work (out dated?).



Thanks.

here’s my XML:

http://code.google.com/p/open-game-finder/source/browse/OGF/TRUNK/Client/src/main/resources/configuration/nifty/lobbyScreen.xml

and here’s how you would consume the sendText event:

[java]

/**

  • Send the text to the server.
  • @param text The text to send.

    */

    @NiftyEventSubscriber(id=“chatPanel”)

    public final void onSendText(final String id, final ChatTextSendEvent event) {

    if (!StringUtils.isEmpty(event.getText())) {

    System.out.println(“chat event received: " + event.getText());

    }

    }

    [/java]

    To add players to the room use

    [java]

    final Element chatPanel = nifty.getCurrentScreen().findElementByName(“chat”);

    final Chat chat = chatPanel.findNiftyControl(“chatPanel”, Chat.class);

    chat.addPlayer(playerName, avatarImage);

    [/java]

    Here, avatarImage is a NiftyImage.

    removing a player from the room is

    [java]

    final Element chatPanel = nifty.getCurrentScreen().findElementByName(“chat”);

    final Chat chatController = chatPanel.findNiftyControl(“chatPanel”, Chat.class);

    chatController.removePlayer(playerName);

    [/java]

    and sending a message to the room is

    [java]

    final Element chatPanel = nifty.getCurrentScreen().findElementByName(“chat”);

    final Chat chatController = chatPanel.findNiftyControl(“chatPanel”, Chat.class);

    chatController.receivedChatLine(playerName +”>" + chatLine, avatarImage);

    [/java]

    Here, once again, avatarImage is a NiftyImage.

    With this you should be able to figure it out. If you still have questions, let me know and I’ll see what I can do about answering them.

Thanks :slight_smile:

Sry, but where do I find this file :



configuration/nifty/ractoc-custom-controls.xml ?

Oh, you don’t need that one. That one only contains my custom message box. I use that one for displaying errors and other messages. It’s not needed to get the lobby screen xml to work though. So you can just go ahead and remove that line.

ok, thx :smiley:

Hi,



sry but I’m still having problems getting this to work. It now says:



WARNING: controlDefinition [nifty-chat] missing.

java.util.NoSuchElementException

hhmmzz… let me check that. I could be that there’s still a reference to the messagebox somewhere in the xml. This used to be necesary in order to be able to create the popup. Recently, I’ve atered the popup so this is no longer needed, but I could have forgotten to remove it here.



Hhmzz not that I can see. Are you sure you are using the latest nifty, and that the nifty-default-control library you are using contains the new chat-control?

I’m using what ever comes with JMonkey,beyound that I have no idea what’s the latest version. I have done a update for JMonkey.

what directory should the xml file be in? At the mo I have it in assets.

hhmmzz… could be it’s not IN the nifty default controls as supplied with JME3.

ok, thx. I’ll look at another way of doing chat for now.