Dynamic Style/NiftyInputEvent Problem

Hi guys, I’ve run into another gui problem :frowning: I am making a part of my gui that allows the user to choose their keys for controlling a camera. I am not sure how the user can bind something like the up key by just pressing it because that does not change a textfield’s text so there is no way I could determine it was that key that was pressed with the TextFieldChangedEvent event. Because of this my plan was to have the user enter something like the word “up” to let my program know that they want the up key. Now because you might type a wrong word on accident I wanted to add a feature to have my textfield have a certain style if there is invalid input in it and a different style for valid input. However, whenever I do my textfield.setStyle(“style”) the textfield doesn’t change. Nothing is wrong with my style because I have put the style attribute in my xml file on this textfield to test it and the style has worked fine. I’ve done some digging on the web and found that this problem was mentioned on github way back in 2014 so I would assume it is patched?
Here is the url to that: setStyle method on a control doesn't do anything. · Issue #287 · nifty-gui/nifty-gui · GitHub
According to that the problem was styles not automatically reloading. I tried to look for a method to do something like redraw a control or element but I did not find one.
I also tried to dynamically update styles on regular elements like text, this worked just fine for me.

Anyways I am out of ideas for what I am doing wrong this time :confused:

Here is the part of my controller where I try to change the style, on the control and with the getElement() method just to see if I actually had to do it on the element…

TextField movement = screen.findNiftyControl("movementSpeedTextfield", TextField.class);
movement.setText(FileReader.readPreference("CAMERA_MOVEMENT"));
movement.getElement().setStyle("badInput");
movement.setStyle("badInput");
System.err.println();
System.err.println(movement.getStyle());
System.err.println();

(movement.getStyle() ends up printing out “badInput”, and trust me I checked to make sure I didn’t misspell the style name :slight_smile:)

Thank you guys for the help in advance.

2 Likes

http://javadoc.jmonkeyengine.org/com/jme3/input/InputManager.html#addRawInputListener-com.jme3.input.RawInputListener-

To capture raw input events.

1 Like

I think your right pspeed with raw input listeners being the right way to go. Originally after I saw this post I was going to create an appstate just for getting the key code and then converting that to some string in the textfield that has the forcus. For example if I got the up arrow keycode I could display the text ARROW_UP or something. However, I was looking some more into nifty’s screen methods and I found one called addKeyboardInputHandler, now it seems to have the same concept of mapping inputs and then having something else handle them just like the action/analog listeners in jme3, however I’ve run into a problem with the NiftyInputEvent interface. To make this work you must have a key and create a NiftyInputEvent you want it to handle and then compare NiftyInputEvents later on and handle events that way. However, (This might be where some of my java inexpereience comes in) I do not know how I can implement this class because it does not contain anything in the first place… I suppose I could always handle keyboard input directly in my NiftyInputMapping class and return null for the NiftyInputEvent but I fear this would cause some unwanted problems :slight_smile: Has anyone worked with this before that could point me in the right direction? I have read up about this on the manual but it seems like there are only set NiftyInputEvents and you cannot make your own? Anyways thanks for any help on this problem and I am still looking to find out how to dynamically change those styles in case of future use/ just for the sake of knowing. Thanks for the help thusfar.

1 Like

I generally handle keyboard input in JME by creating object to map from key codes (as in com.jme3.input.KeyInput) to action names (as in com.jme3.input.controls.ActionListener). Customizing a camera-control hotkey is then just a matter of modifying the object and re-applying it to the InputManager. In fact, I’ve developed a library (jme3-utilities-ui) to support this paradigm and a reusable NiftyGUI screen (BindScreen) for runtime customization of maps.

I posted a YouTube demo of BindScreen back in March: BindScreen demo - Mar. 2, 2017 - YouTube

The source-code of my demo application is in jme3-utilities/tests/src/main/java/jme3utilities/nifty/test at master · stephengold/jme3-utilities · GitHub

1 Like

It sounds like your key mapping may reimplement Lemur’s InputMapper.

It’s very flexible, is remappable at runtime, supports key combinations, and can treat keys like joystick axes and joystick axes like keys, etc…

2 Likes

It sounds like we arrived independently at similar solutions.

1 Like

Yeah, for reference… to anyone who cares…

The javadoc for InputMapper:
http://jmonkeyengine-contributions.github.io/Lemur/javadoc/Lemur/com/simsilica/lemur/input/InputMapper.html

Lemur project wiki:

Some usage threads:

Some of the links are broken but are easily found on github. I can fix them if there is a strong desire.

One thing I don’t have yet is a Lemur-based input binding UI… but it’s been on my to-do list for a long time.

2 Likes

Thanks for the help so far with the input mapping guys. I know that void256 was active in creating nifty gui, does anyone know if he is still active on the forums and if he would know how to fix that style problem?

1 Like

I can’t be sure… but I sort of remember that he doesn’t even work on nifty anymore… handed it off to someone else.

2 Likes

Tagging him might help: @void256
If that fails, I think the best way for you to pursue this would be to open an issue on GitHub:
Issues · nifty-gui/nifty-gui · GitHub

1 Like

I generally handle textfield validation in NiftyGUI by polling the textfield’s content using getRealText(). If the content is invalid, I disable the [OK] button (or whatever control would commit the input) and display a short explanation to the user using a label.

1 Like

Ok, I made an issue on GitHub saying that you can’t update a controls style. Hopefully someone will see it and fix it

When I was thinking about making my gui I decided I would disable my save button and I wanted to make sure they could know what they messed up right away by changing the style of the textfield. Honestly I also wanted just to get used to the nifty system and to make the gui snazzy :slight_smile:

Anyways I’ll start working on the key mapping and I’ll see if I run into any more problems.

2 Likes