Some questions on nifty styling, effects and events

So after managing to get Nifty set up properly I’ve started exploring it and it has some excellent features so thanks go out to all the contributors. (And to all other JME contributors too because I don’t think I’ve said that before. :smiley: )

Of course, something would be wrong with the fabric of the universe if I didn’t run into issues. I’m trying to make my own console slash chat box for my game. The inbuilt controls for this are nice but I want to roll my own, partly to learn about nifty, partly to ensure it’s doing exactly what I want.

So here’s my questions:

  1. I wanted to simply add a border to a panel. I figured out how to add a custom style after exploring nifty’s code a little and have that set up nicely but the only way I can see to use a border at all in an onHover Effect. I just want a border there the whole time, is this not possible with the default set up? I managed to achieve the look I wanted using an image so it’s not a big deal but an odd inconsistency and I’d like to know if I’ve missed something.

  2. Handling certain events seems a little tricky. I need know when a user who is typing in a textfield has pressed enter or escape so I can handle my input/console code correctly. There’s some stuff about EventBus scattered around the wiki but I can’t seem to locate anything definitive. Any pages I’ve missed?

  3. I’ve placed textfield into a window and it seems to work just dandy until I drag the window at which point the textfield becomes focused and defocuses when the window is released. Not major but unexpected. Anyway to combat this?

  4. Somewhat related to 1. I notice that on the nifty wiki there is a list of parameters you can add to the effects. At least, I think that’s what it is. Anyway, I can’t find a similar list of effects themselves. I.E onHover, onStartScreen. Is there such a list?

    Thank you~
  1. Images with imageMode set (use the funky stretch version with loads of parameters) are how to do borders in Nifty.

  2. Event Bus is explained in brief in the nifty bible (link to the right of this page) it’s actually pretty simple to use once you start fiddling with it.

  3. Not something I’ve tried myself. You can manually modify focus behaviour using setFocus/isFocussed though iirc.

  4. There is a list on the nifty wiki:

    Not all are fully described there, sometimes I’ve needed to dig into the source to find out how to use things.

Thanks Zarch. You the man.

I never knew about the nifty bible. Guess I need to install a pdf reader now. :3

I’ll see if that answers any of my other queries.

So the bible has 99% of the information there. As it says, you can subscribe to the textfield’s TextFieldChangedEvent in your ScreenController class.

public void onTextFieldChanged(String id, TextFieldChangedEvent event){
System.out.print("Textfield changed: " + event.getText());

Doesn't really help me in this scenario but I'm sure I can find another way to do it.

Thanks again.

Yes, to know immediately as they press the button you will need to add an input handler - I think you can do it in the screen controller, if not you can certainly do it by creating your own version of the text field control.