Nifty Event Problems

Hi everyone. I’m trying to learn how to use Nifty (noob+Nifty!=good lol) and I seem to be having some problems with events. I can get a couple of the events to work (onStartScreen, onEndScreen, onActive) but I can’t seem to get any of the mouse-related events (onHover, onClick). Also, when I click on the panel it bleeds through to the canvas (when I click and drag on the panel it clicks and drags on the canvas). Is there a way to disable that? Here’s the code:



TestNiftyGui.java:

[java]package test;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.system.AppSettings;

import com.jme3.system.JmeCanvasContext;



import de.lessvoid.nifty.Nifty;

import de.lessvoid.nifty.elements.Element;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;



import java.awt.Canvas;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.net.URL;



import javax.swing.JFrame;



public class TestNiftyGui extends SimpleApplication implements ScreenController {



private Nifty nifty;



public static void main(String[] args){





JFrame frame = new JFrame(“Test”);

frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);



frame.setUndecorated(true);



frame.pack();

frame.setLocationRelativeTo(null);

frame.setVisible(true);

frame.setExtendedState(frame.MAXIMIZED_BOTH);





AppSettings settings = new AppSettings(true);

settings.setWidth(frame.getWidth());

settings.setHeight(frame.getHeight());



final TestNiftyGui app = new TestNiftyGui();

app.setPauseOnLostFocus(false);

app.setSettings(settings);

app.createCanvas();

app.startCanvas(true);



JmeCanvasContext context = (JmeCanvasContext) app.getContext();

Canvas canvas = context.getCanvas();

canvas.setSize(settings.getWidth(), settings.getHeight());



frame.addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

app.stop();

}

});



frame.getContentPane().add(canvas);

}



public void simpleInitApp() {

Box b = new Box(Vector3f.ZERO, 1, 1, 1);

Geometry geom = new Geometry(“Box”, b);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat.setTexture(“ColorMap”, assetManager.loadTexture(“Interface/Logo/Monkey.jpg”));

geom.setMaterial(mat);

rootNode.attachChild(geom);



NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,inputManager,audioRenderer,guiViewPort);

nifty = niftyDisplay.getNifty();





this.setPauseOnLostFocus(true);

nifty.fromXml(“test/xml/helloworld.xml”, “start”, this);



// attach the nifty display to the gui view port as a processor

guiViewPort.addProcessor(niftyDisplay);



// disable the fly cam

// flyCam.setEnabled(false);

flyCam.setDragToRotate(true);

}



public void bind(Nifty nifty, Screen screen) {

System.out.println(“bind( " + screen.getScreenId() + “)”);

}



public void onStartScreen() {

System.out.println(“onStartScreen”);

}



public void onEndScreen() {

System.out.println(“onEndScreen”);

}



public void quit(){

System.out.println(“MOOOO”);

}

public void die(){



}

private Element getElement(final String id) {

return nifty.getCurrentScreen().findElementByName(id);

}



}

[/java]



helloworld.xml:

[xml]<?xml version=“1.0” encoding=“UTF-8”?>

<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 http://nifty-gui.sourceforge.net/nifty-1.3.xsd”>

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

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

<screen id=“start” controller=“de.lessvoid.nifty.examples.helloworld.HelloWorldStartScreen”>

<layer id=“layer” backgroundColor=”#23ffff00" childLayout=“center” width=“80%” height=“90%” >

<panel id=“panel” backgroundColor="#103f" childLayout=“vertical” padding=“15px,2px,22px,3px” width=“25%” height=“100%” align=“right”>

<text font=“verdana-small-regular.fnt” text=“MOOO” align=“center” valign=“top” />



<panel id=“panel2” backgroundColor="#212f" childLayout=“center” align=“right” valign=“top” width=“20%” height=“30%” visibletomouse=“true”>

<effect>

<onClick name=“colorPulsate” startColor="#212f" endColor="#011f" period=“1000”/>

</effect>



</panel>

<panel id=“panel3” backgroundColor="#112f" childLayout=“center” align=“left” valign=“top” padding=“20px,20px,20px,20px” width=“30%” height=“30%” visibletomouse=“true”>



</panel>

</panel>





</layer>

</screen>

</nifty>[/xml]







Any ideas? Thanks.







-NomNom

For started, this is wrong.



[xml]

<screen id="start" controller="de.lessvoid.nifty.examples.helloworld.HelloWorldStartScreen">

[/xml]



should be something like (make sure the path is right and points to the REAL screen controller):



[xml]

<screen id="start" controller="test.TestNiftyGui">

[/xml]

Woops… Well, I guess that’s what happens when you just base a program off of another one… Thanks for fixing that :slight_smile: Now the events work with buttons and stuff (just tested it out… I was wondering why my methods weren’t getting called :wink: ). Unfortunately, it still doesn’t fix the non-control events… Darn :confused:

nomnom said:
Unfortunately, it still doesn't fix the non-control events.... Darn :/

What exactly isn't working? Details please (code too if necessary).

Ummmm, code is above (most of the time it is necessary :slight_smile: ).



I’ll try to explain this a bit better: I have a panel that I want to colorPulsate onHover (or click). It works when I do onActive, but not onClick or onHover.



What I want:

[xml]<panel id=“panel2” backgroundColor="#212f" childLayout=“center” align=“right” valign=“top” width=“20%” height=“30%” visibletomouse=“true”>

<effect>

<onHover name=“colorPulsate” startColor="#212f" endColor="#011f" period=“1000”/>

</effect>



</panel>[/xml]



However, that doesn’t work.



What does work:

[xml]<panel id=“panel2” backgroundColor="#212f" childLayout=“center” align=“right” valign=“top” width=“20%” height=“30%” visibletomouse=“true”>

<effect>

<onActive name=“colorPulsate” startColor="#212f" endColor="#011f" period=“1000”/>

</effect>



</panel>[/xml]





Does that make a bit more sense? Sorry for the confusion. Thanks!





-NomNom

Some effects in nifty are kinda broken or not entirely working depending on many factors. Just out of curiosity, could you please test the above with onStartHover?

Nop, didn’t work… It also said that I didn’t have it (I’m running Eclipse with the nightly from 2 days ago). Right now I’m downloading tonight’s nightly and then I’ll try it again. Thanks.



-NomNom

Alright, done some test and I can confirm that this is effing weird.



Seems to me the effect will only activate on an elemnet that is “full screen” or something like that… If I attach your effect to the main layer of the screen, it works fine, if I attach it to one of the children element I’m getting nothing.



@void256 ?

Yay! It wasn’t a completely noobish mistake! Thanks… Hopefully void can figure it out…



-NomNom

nomnom said:
Yay! It wasn't a completely noobish mistake! Thanks... Hopefully void can figure it out...

-NomNom

Not that one, yeah. But I wouldn't brag about noobish mistake after the ScreenController above. ;) lol j/k

Hehehe, yeah… But at least some one corrected me :wink: lol



-NomNom

Erm, maybe it’s simply that you need to write that one attribute correct:



[java]visibleToMouse[/java]



instead of



[java]visibletomouse[/java]



You know, XML is case sensitive? :slight_smile:



Besides that issue this works quite well here. Actually it would make sense because Nifty won’t care about the “visibletomouse” property and therefore the mouse does not “see” the panel at all. That’s why it works with onActive because there is no mouse involved with that kind of effect ^^

Aw, crap… In the end it was a stupid mistake… Thanks void!



-NomNom