Nifty 1.3 controlDefinition causes issues finding screens

Hi, It’s me again :slight_smile:



Still messing around with nifty 1.3 looking at the chat area example, modifying pieces of code that was deprecated. But now I’m stuck.



It seems that the minute I add the controlDefinition tag, jme can’t find any screens via the screen id, giving me a warning, “INFO: Missing ScreenController for screen [null] using DefaultScreenController() instead but this might not be what you want.”.



These are my files.

default_interfaces.xml

[xml]



<nifty xmlns=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd

xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance

xsi:schemaLocation=“http://nifty-gui.sourceforge.net/nifty-1.3.xsd”>



<useStyles filename=“nifty-default-styles.xml” />

<useControls filename=“nifty-default-controls.xml” />

<!-- <useControls filename=“Interface/controls/loadControls.xml” /> -->

<controlDefinition name=“chatArea” controller=“mmo.ui.interfaces.chat.ChatAreaController”>

<panel childLayout=“center” width="$width" heigh="$height">

<control name=“scrollPanel” id=“scroll_panel” width=“100%” height=“100%” horizontal="$horizontal" vertical="$vertical" autoScroll="$autoScroll">

<label text="$text" id=“text_area” width=“100%” height=“100%”

wrap=“true” textHAlign=“left” textVAlign=“top” align=“left” />

</control>

</panel>

</controlDefinition>







<screen id=“chat_area” controller=“mmo.ui.interfaces.chat.ChatController”>

<layer id=“layer” childLayout=“center”>

<panel id=“dialog” style=“nifty-panel” childLayout=“center”

width=“70%” height=“90%” align=“center” valign=“center”

visibleToMouse=“true”>

<panel childLayout=“vertical” align=“center” valign=“center”>

<!-- Chat area = label surrounded by scroll panel -->

<control name=“chatArea” id=“chat_area” width=“90%” height=“30%” horizontal=“false” autoScroll=“bottom” text=“test” />

<panel height=“30px” />

<!-- Text input -->

<panel childLayout=“horizontal”>

<control name=“textfield” id=“text_input” width=“70%” />

<control name=“button” label=“Send”>

<interact onClick=“sendMessage()” />

</control>

</panel>

</panel>

</panel>

</layer>

</screen>

</nifty>

[/xml]



ChatController.java

[java]

package mmo.ui.interfaces.chat;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.controls.textfield.TextFieldControl;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.input.NiftyInputEvent;

import de.lessvoid.nifty.screen.KeyInputHandler;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;



public class ChatController implements ScreenController {

private Element textInput;

private ChatAreaController chatArea;



@Override

public void bind(Nifty nifty, Screen screen) {

textInput = screen.findElementByName(“text_input”);

chatArea = screen.findControl(“chat_area”, ChatAreaController.class);

}



@Override

public void onStartScreen() {

textInput.addInputHandler(new KeyInputHandler() {

@Override

public boolean keyEvent(NiftyInputEvent inputEvent) {

if(inputEvent == null) return false;

switch(inputEvent) {

case SubmitText:

sendMessage();

return true;

}

return false;

}

});

textInput.setFocus();

}



@Override

public void onEndScreen() {

// TODO Auto-generated method stub



}



/**

  • Sends a message to the chat area

    */

    public void sendMessage() {

    if(chatArea.getText().isEmpty()) {

    chatArea.append(textInput.getControl(TextFieldControl.class).getText());

    }

    else {

    chatArea.append(“n”+textInput.getControl(TextFieldControl.class).getText());

    }

    textInput.getControl(TextFieldControl.class).setText("");

    textInput.setFocus();

    }

    }

    [/java]



    ChatAreaController.java

    [java]

    package mmo.ui.interfaces.chat;

    import de.lessvoid.xml.xpp3.Attributes;

    import java.util.Properties;



    import de.lessvoid.nifty.Nifty;

    import de.lessvoid.nifty.controls.Controller;

    import de.lessvoid.nifty.controls.ScrollPanel;

    import de.lessvoid.nifty.controls.ScrollPanel.AutoScroll;

    //import de.lessvoid.nifty.elements.ControllerEventListener;

    import de.lessvoid.nifty.elements.Element;

    import de.lessvoid.nifty.elements.render.TextRenderer;

    import de.lessvoid.nifty.input.NiftyInputEvent;

    import de.lessvoid.nifty.screen.Screen;

    //import de.lessvoid.xml.xpp3.Attributes;



    public class ChatAreaController implements Controller {

    private ScrollPanel scrollPanel;

    private Element textArea;

    private Screen screen;





    public void bind(Nifty nifty, Screen screen) {



    }

    public void bind(Nifty nifty, Screen screen, Element element) {

    this.screen = screen;

    scrollPanel = element.findNiftyControl(“scroll_panel”, ScrollPanel.class);

    textArea = element.findElementByName(“text_area”);

    }



    @Override

    public void onStartScreen() {

    }



    @Override

    public void onFocus(boolean getFocus) {

    }



    @Override

    public boolean inputEvent(NiftyInputEvent inputEvent) {

    return false;

    }



    public void setAutoScroll(AutoScroll auto) {

    scrollPanel.setAutoScroll(auto);

    }



    public AutoScroll getAutoScroll() {

    return scrollPanel.getAutoScroll();

    }



    public void append(String text) {

    setText(getText()+text);

    }



    public void setText(String text) {

    textArea.getRenderer(TextRenderer.class).setText(text);

    screen.layoutLayers();

    textArea.setHeight(textArea.getRenderer(TextRenderer.class).getTextHeight());

    }



    public String getText() {

    return textArea.getRenderer(TextRenderer.class).getOriginalText();

    }



    @Override

    public void bind(Nifty nifty, Screen screen, Element elmnt, Properties prprts, Attributes atrbts) {

    throw new UnsupportedOperationException(“Not supported yet.”);

    }



    @Override

    public void init(Properties prprts, Attributes atrbts) {

    throw new UnsupportedOperationException(“Not supported yet.”);

    }

    }

    [/java]



    Running the code as is disables all screens and the game runs like without the use of nifty gui.



    Removing all controlDefinition tags will make my other screens work, just nifty complains that it can’t find the control “chatArea”.



    Think this is a bug internally with nifty or does it look like something is wrong on my end? :S



    Thanks in advance

Hi,



just wanted to state that I experience the same problem. I have my standard UI that works but if I add a control definition like this

[xml]

<controlDefinition name=“button” controller=“openwar.GuiButtonController”>

<panel backgroundColor="#f00f">

<interact onClick=“sayHello()”/>

</panel>

</controlDefinition>

[/xml]

then I get the same error like you. I didn’t do the ChatArea tutorial! Probably a bug somewhere…



Another thing of which I believe could be a bug:



[xml]

<image id=“image_build” …>

<interact onClick=“sayHello()”/>

<effect>

<onHover name=“imageSizePulsate” startSize=“100%” endSize=“105%”/>

</effect>

</image>

[/xml]



It’s just an image, not a control. The onHover effect works but the interact onClick does not. The method “sayHello()” is defined in the controller!

I recently finished my chat area which should make it into nifty default controlls sometime in the near future. It’s a complete chat control which you should be able to just plugin to your GUI. But Void still has to do his thing to make it more in line with the other default controls

The solution to this problem that I came up with is changing

[xml] <label text="$text" id="text_area" width="100%" height="100%"

wrap="true" textHAlign="left" textVAlign="top" align="left" />[/xml]

to

[xml] <text style="nifty-label" text="$text" id="text_area" width="100%" height="100%"

wrap="true" textHAlign="left" textVAlign="top" align="left" /> [/xml]

The label element doesn’t exist anymore. ( Has been removed with Nifty 1.3 )



Now, if you want a label ( with the same functionnalities as the previous element “label” ), you need to use this :

[java]

<control name=“label” … />

[/java]