可以与onClick上的自定义控件进行交互

时间:2014-07-25 18:10:43

标签: java xml jmonkeyengine nifty-gui

我无法通过交互式onClick =“next()”属性获取自定义控件来调用函数。我试图将“next()”函数放在我的screenController和我的buttonController上,但仍然没有结果......我必须在这里找不到简单的东西......

这是我的CustomControl定义:

<nifty-controls xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
      <controlDefinition name="customImage-button" style="nifty-panel-style" controller="com.certification.renderer.jme3.gui.customControls.imagebutton.ImageButtonControl">
        <panel style="#panel" childLayout="overlay" focusable="true" width="$width" heigth="$height">
          <image id="#clicked" name="image-1" style="#select" filename="$img1" visibleToMouse="true" filter="true" > 
            <interact onClickRepeat="pressedButton()" onRelease="releaseButton()" />
          </image>
          <image id="#uncliked" name="image-2" style="#select" filename="$img2" visibleToMouse="true" filter="true">
            <interact onClickRepeat="pressedButton()" onRelease="releaseButton()" />
          </image>
        </panel>
      </controlDefinition>
</nifty-controls>

这是屏幕XML:

<nifty>
    <useStyles filename="nifty-default-styles.xml" />
    <useControls filename="Interface/custom-controls.xml" />


    <screen id="loginScreen" controller="com.certification.renderer.jme3.gui.ScreenJME">
        <layer id="layer3" childLayout="center">

            <control id="numpadnumber-1" style="numpad" name="customImage-button" width="13%" height="11.75%"
                     img1="Interface/images/1_numpad_clicked.png" img2="Interface/images/1_numpad.png" 
                     controller="com.certification.renderer.jme3.gui.customControls.imagebutton.ImageButtonControl" 
                     visibleToMouse="true">
                <effect>
                    <onClick name="fade" start="#f" end="#0" length="15000" />
                </effect>
            </control>
        </layer>
    </screen>
</nifty>

这是屏幕控制器:

public class ScreenJME extends Screen实现了ScreenController {

protected String _path;
private String _key;
protected Nifty _nifty;
protected Application _app;
protected de.lessvoid.nifty.screen.Screen _screen;
private String password = "";

private final float screenHeight = 1050;

ScreenJME()
{
    //EMPTY      
}

ScreenJME(String path, String key, Nifty nifty)
{
    _path = path;
    _key = key;
    _nifty = nifty;
}

@Override
public void bind(Nifty nifty, de.lessvoid.nifty.screen.Screen screen)
{
    this._nifty = nifty;
    this._screen = screen;
    System.out.println("Binding...");
}

@Override
public void onStartScreen()
{
    switch (_key)
    {
        case ("loginScreensss"):
           // populate();
            break;
        default:
            break;
    }
    System.out.println("onStartScreen..");
}

@Override
public void onEndScreen()
{
    System.out.println("..onEndScreen");
}

(...)

public void next()
{
    System.out.println("next() clicked! woohoo!");
}

}

1 个答案:

答案 0 :(得分:2)

控件中的图像将消耗鼠标事件,因为它们位于控制面板的顶部。在这种情况下,添加到面板的任何交互都不会接收鼠标事件。您需要删除图像或使其可见ToMouse =&#34; false&#34;。目前你不能同时拥有这两者。