【问题标题】:Can't interract with a custom control onClick无法与自定义控件 onClick 交互
【发布时间】:2014-07-25 18:10:42
【问题描述】:

我无法让我的自定义控件通过交互 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>

这是屏幕控制器:

公共类 ScreenJME 扩展 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!");
}

}

【问题讨论】:

    标签: java xml jmonkeyengine nifty-gui


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-08-20
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      相关资源
      最近更新 更多