Hi guys, I’ve run into another gui problem 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
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…
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 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.
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.
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?
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.
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
Anyways I’ll start working on the key mapping and I’ll see if I run into any more problems.